{"action":"created","comment":{"url":"https://api.github.com/repos/muun/bitforge/pulls/comments/30359070","id":30359070,"diff_hunk":"@@ -0,0 +1,127 @@\n+from collections import namedtuple\n+from errors import BitforgeError, KeyValueError, StringError\n+\n+\n+# TODO: document these fields\n+# TODO: which should be unique? It should be enforced\n+BaseNetwork = namedtuple('Network', [\n+    # Descriptors\n+    'name',\n+    'aliases',\n+    # Serialization magic numbers\n+    'pubkeyhash',\n+    'wif_prefix',\n+    'scripthash',\n+    'hd_public_key',\n+    'hd_private_key',\n+    'magic',\n+    # Network parameters\n+    'port',\n+    'seeds',\n+])\n+\n+\n+class Network(BaseNetwork):\n+    \"\"\"Parameters of a Bitcoin-compatible network.\"\"\"\n+\n+    class Error(BitforgeError):\n+        pass\n+\n+    class UnknownNetwork(Error, KeyValueError):\n+        \"\"\"No network with '{key}' matching '{value}'\"\"\"\n+\n+    class MultipleNetworks(Error, KeyValueError):\n+        \"\"\"Multiple networks with '{key}' matching '{value}'\"\"\"\n+\n+    class ExistingNetworkName(Error, StringError):\n+        \"\"\"Network name '{string}' already taken\"\"\"\n+\n+    _networks = {}\n+\n+    @classmethod\n+    def get(cls, name, raises=True):\n+        \"\"\"Get a network by name or alias.\"\"\"\n+\n+        network = cls._networks.get(name, None)\n+\n+        if raises and network is None:\n+            raise Network.UnknownNetwork('name', name)\n+\n+        return network\n+\n+    # TODO: discuss if this method should exist at all","path":"bitforge/network.py","position":52,"original_position":52,"commit_id":"0345a500a8a7339e58cf02b5073b1dc5ec9fa6f3","original_commit_id":"0345a500a8a7339e58cf02b5073b1dc5ec9fa6f3","user":{"login":"esneider","id":667132,"avatar_url":"https://avatars.githubusercontent.com/u/667132?v=3","gravatar_id":"","url":"https://api.github.com/users/esneider","html_url":"https://github.com/esneider","followers_url":"https://api.github.com/users/esneider/followers","following_url":"https://api.github.com/users/esneider/following{/other_user}","gists_url":"https://api.github.com/users/esneider/gists{/gist_id}","starred_url":"https://api.github.com/users/esneider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/esneider/subscriptions","organizations_url":"https://api.github.com/users/esneider/orgs","repos_url":"https://api.github.com/users/esneider/repos","events_url":"https://api.github.com/users/esneider/events{/privacy}","received_events_url":"https://api.github.com/users/esneider/received_events","type":"User","site_admin":false},"body":"The issue I see with this method is that a filtering parameter either:\r\n* Is unique by design: in this case the uniqueness should be enforced, as with network names\r\n* May not be unique: in which case using it is probably a mistake","created_at":"2015-05-14T20:27:15Z","updated_at":"2015-05-14T20:27:15Z","html_url":"https://github.com/muun/bitforge/pull/12#discussion_r30359070","pull_request_url":"https://api.github.com/repos/muun/bitforge/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/muun/bitforge/pulls/comments/30359070"},"html":{"href":"https://github.com/muun/bitforge/pull/12#discussion_r30359070"},"pull_request":{"href":"https://api.github.com/repos/muun/bitforge/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/muun/bitforge/pulls/12","id":35394550,"html_url":"https://github.com/muun/bitforge/pull/12","diff_url":"https://github.com/muun/bitforge/pull/12.diff","patch_url":"https://github.com/muun/bitforge/pull/12.patch","issue_url":"https://api.github.com/repos/muun/bitforge/issues/12","number":12,"state":"open","locked":false,"title":"Make Network a proper class","user":{"login":"esneider","id":667132,"avatar_url":"https://avatars.githubusercontent.com/u/667132?v=3","gravatar_id":"","url":"https://api.github.com/users/esneider","html_url":"https://github.com/esneider","followers_url":"https://api.github.com/users/esneider/followers","following_url":"https://api.github.com/users/esneider/following{/other_user}","gists_url":"https://api.github.com/users/esneider/gists{/gist_id}","starred_url":"https://api.github.com/users/esneider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/esneider/subscriptions","organizations_url":"https://api.github.com/users/esneider/orgs","repos_url":"https://api.github.com/users/esneider/repos","events_url":"https://api.github.com/users/esneider/events{/privacy}","received_events_url":"https://api.github.com/users/esneider/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-14T05:13:58Z","updated_at":"2015-05-14T20:27:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43cbc3adb3baf222ed149ca645d15b18415a5e77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/muun/bitforge/pulls/12/commits","review_comments_url":"https://api.github.com/repos/muun/bitforge/pulls/12/comments","review_comment_url":"https://api.github.com/repos/muun/bitforge/pulls/comments{/number}","comments_url":"https://api.github.com/repos/muun/bitforge/issues/12/comments","statuses_url":"https://api.github.com/repos/muun/bitforge/statuses/0345a500a8a7339e58cf02b5073b1dc5ec9fa6f3","head":{"label":"muun:network","ref":"network","sha":"0345a500a8a7339e58cf02b5073b1dc5ec9fa6f3","user":{"login":"muun","id":10998166,"avatar_url":"https://avatars.githubusercontent.com/u/10998166?v=3","gravatar_id":"","url":"https://api.github.com/users/muun","html_url":"https://github.com/muun","followers_url":"https://api.github.com/users/muun/followers","following_url":"https://api.github.com/users/muun/following{/other_user}","gists_url":"https://api.github.com/users/muun/gists{/gist_id}","starred_url":"https://api.github.com/users/muun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muun/subscriptions","organizations_url":"https://api.github.com/users/muun/orgs","repos_url":"https://api.github.com/users/muun/repos","events_url":"https://api.github.com/users/muun/events{/privacy}","received_events_url":"https://api.github.com/users/muun/received_events","type":"Organization","site_admin":false},"repo":{"id":33558179,"name":"bitforge","full_name":"muun/bitforge","owner":{"login":"muun","id":10998166,"avatar_url":"https://avatars.githubusercontent.com/u/10998166?v=3","gravatar_id":"","url":"https://api.github.com/users/muun","html_url":"https://github.com/muun","followers_url":"https://api.github.com/users/muun/followers","following_url":"https://api.github.com/users/muun/following{/other_user}","gists_url":"https://api.github.com/users/muun/gists{/gist_id}","starred_url":"https://api.github.com/users/muun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muun/subscriptions","organizations_url":"https://api.github.com/users/muun/orgs","repos_url":"https://api.github.com/users/muun/repos","events_url":"https://api.github.com/users/muun/events{/privacy}","received_events_url":"https://api.github.com/users/muun/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/muun/bitforge","description":"A python bitcoin library","fork":false,"url":"https://api.github.com/repos/muun/bitforge","forks_url":"https://api.github.com/repos/muun/bitforge/forks","keys_url":"https://api.github.com/repos/muun/bitforge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/muun/bitforge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/muun/bitforge/teams","hooks_url":"https://api.github.com/repos/muun/bitforge/hooks","issue_events_url":"https://api.github.com/repos/muun/bitforge/issues/events{/number}","events_url":"https://api.github.com/repos/muun/bitforge/events","assignees_url":"https://api.github.com/repos/muun/bitforge/assignees{/user}","branches_url":"https://api.github.com/repos/muun/bitforge/branches{/branch}","tags_url":"https://api.github.com/repos/muun/bitforge/tags","blobs_url":"https://api.github.com/repos/muun/bitforge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/muun/bitforge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/muun/bitforge/git/refs{/sha}","trees_url":"https://api.github.com/repos/muun/bitforge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/muun/bitforge/statuses/{sha}","languages_url":"https://api.github.com/repos/muun/bitforge/languages","stargazers_url":"https://api.github.com/repos/muun/bitforge/stargazers","contributors_url":"https://api.github.com/repos/muun/bitforge/contributors","subscribers_url":"https://api.github.com/repos/muun/bitforge/subscribers","subscription_url":"https://api.github.com/repos/muun/bitforge/subscription","commits_url":"https://api.github.com/repos/muun/bitforge/commits{/sha}","git_commits_url":"https://api.github.com/repos/muun/bitforge/git/commits{/sha}","comments_url":"https://api.github.com/repos/muun/bitforge/comments{/number}","issue_comment_url":"https://api.github.com/repos/muun/bitforge/issues/comments{/number}","contents_url":"https://api.github.com/repos/muun/bitforge/contents/{+path}","compare_url":"https://api.github.com/repos/muun/bitforge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/muun/bitforge/merges","archive_url":"https://api.github.com/repos/muun/bitforge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/muun/bitforge/downloads","issues_url":"https://api.github.com/repos/muun/bitforge/issues{/number}","pulls_url":"https://api.github.com/repos/muun/bitforge/pulls{/number}","milestones_url":"https://api.github.com/repos/muun/bitforge/milestones{/number}","notifications_url":"https://api.github.com/repos/muun/bitforge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/muun/bitforge/labels{/name}","releases_url":"https://api.github.com/repos/muun/bitforge/releases{/id}","created_at":"2015-04-07T17:34:39Z","updated_at":"2015-05-12T18:55:14Z","pushed_at":"2015-05-14T05:13:58Z","git_url":"git://github.com/muun/bitforge.git","ssh_url":"git@github.com:muun/bitforge.git","clone_url":"https://github.com/muun/bitforge.git","svn_url":"https://github.com/muun/bitforge","homepage":null,"size":280,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":7,"forks":2,"open_issues":7,"watchers":7,"default_branch":"master"}},"base":{"label":"muun:master","ref":"master","sha":"4eeba54c05bdc3c847e71f036d8a1e73b1ecb40d","user":{"login":"muun","id":10998166,"avatar_url":"https://avatars.githubusercontent.com/u/10998166?v=3","gravatar_id":"","url":"https://api.github.com/users/muun","html_url":"https://github.com/muun","followers_url":"https://api.github.com/users/muun/followers","following_url":"https://api.github.com/users/muun/following{/other_user}","gists_url":"https://api.github.com/users/muun/gists{/gist_id}","starred_url":"https://api.github.com/users/muun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muun/subscriptions","organizations_url":"https://api.github.com/users/muun/orgs","repos_url":"https://api.github.com/users/muun/repos","events_url":"https://api.github.com/users/muun/events{/privacy}","received_events_url":"https://api.github.com/users/muun/received_events","type":"Organization","site_admin":false},"repo":{"id":33558179,"name":"bitforge","full_name":"muun/bitforge","owner":{"login":"muun","id":10998166,"avatar_url":"https://avatars.githubusercontent.com/u/10998166?v=3","gravatar_id":"","url":"https://api.github.com/users/muun","html_url":"https://github.com/muun","followers_url":"https://api.github.com/users/muun/followers","following_url":"https://api.github.com/users/muun/following{/other_user}","gists_url":"https://api.github.com/users/muun/gists{/gist_id}","starred_url":"https://api.github.com/users/muun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muun/subscriptions","organizations_url":"https://api.github.com/users/muun/orgs","repos_url":"https://api.github.com/users/muun/repos","events_url":"https://api.github.com/users/muun/events{/privacy}","received_events_url":"https://api.github.com/users/muun/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/muun/bitforge","description":"A python bitcoin library","fork":false,"url":"https://api.github.com/repos/muun/bitforge","forks_url":"https://api.github.com/repos/muun/bitforge/forks","keys_url":"https://api.github.com/repos/muun/bitforge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/muun/bitforge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/muun/bitforge/teams","hooks_url":"https://api.github.com/repos/muun/bitforge/hooks","issue_events_url":"https://api.github.com/repos/muun/bitforge/issues/events{/number}","events_url":"https://api.github.com/repos/muun/bitforge/events","assignees_url":"https://api.github.com/repos/muun/bitforge/assignees{/user}","branches_url":"https://api.github.com/repos/muun/bitforge/branches{/branch}","tags_url":"https://api.github.com/repos/muun/bitforge/tags","blobs_url":"https://api.github.com/repos/muun/bitforge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/muun/bitforge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/muun/bitforge/git/refs{/sha}","trees_url":"https://api.github.com/repos/muun/bitforge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/muun/bitforge/statuses/{sha}","languages_url":"https://api.github.com/repos/muun/bitforge/languages","stargazers_url":"https://api.github.com/repos/muun/bitforge/stargazers","contributors_url":"https://api.github.com/repos/muun/bitforge/contributors","subscribers_url":"https://api.github.com/repos/muun/bitforge/subscribers","subscription_url":"https://api.github.com/repos/muun/bitforge/subscription","commits_url":"https://api.github.com/repos/muun/bitforge/commits{/sha}","git_commits_url":"https://api.github.com/repos/muun/bitforge/git/commits{/sha}","comments_url":"https://api.github.com/repos/muun/bitforge/comments{/number}","issue_comment_url":"https://api.github.com/repos/muun/bitforge/issues/comments{/number}","contents_url":"https://api.github.com/repos/muun/bitforge/contents/{+path}","compare_url":"https://api.github.com/repos/muun/bitforge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/muun/bitforge/merges","archive_url":"https://api.github.com/repos/muun/bitforge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/muun/bitforge/downloads","issues_url":"https://api.github.com/repos/muun/bitforge/issues{/number}","pulls_url":"https://api.github.com/repos/muun/bitforge/pulls{/number}","milestones_url":"https://api.github.com/repos/muun/bitforge/milestones{/number}","notifications_url":"https://api.github.com/repos/muun/bitforge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/muun/bitforge/labels{/name}","releases_url":"https://api.github.com/repos/muun/bitforge/releases{/id}","created_at":"2015-04-07T17:34:39Z","updated_at":"2015-05-12T18:55:14Z","pushed_at":"2015-05-14T05:13:58Z","git_url":"git://github.com/muun/bitforge.git","ssh_url":"git@github.com:muun/bitforge.git","clone_url":"https://github.com/muun/bitforge.git","svn_url":"https://github.com/muun/bitforge","homepage":null,"size":280,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":7,"forks":2,"open_issues":7,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/muun/bitforge/pulls/12"},"html":{"href":"https://github.com/muun/bitforge/pull/12"},"issue":{"href":"https://api.github.com/repos/muun/bitforge/issues/12"},"comments":{"href":"https://api.github.com/repos/muun/bitforge/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/muun/bitforge/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/muun/bitforge/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/muun/bitforge/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/muun/bitforge/statuses/0345a500a8a7339e58cf02b5073b1dc5ec9fa6f3"}}}}