{"action":"created","comment":{"url":"https://api.github.com/repos/nimiq/accounts/pulls/comments/239979777","pull_request_review_id":182916012,"id":239979777,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzOTk3OTc3Nw==","diff_hunk":"@@ -0,0 +1,58 @@\n+import { AccountInfo } from '@/lib/AccountInfo';\n+import { NetworkClient } from '@nimiq/network-client';\n+import { WalletStore } from '@/lib/WalletStore';\n+\n+export default class AccountFinder {\n+    public static async findAccounts(\n+        deriveAccounts: (startIndex: number, count: number) => Promise<Array<{ address: string, keyPath: string }>>,\n+        deriveWalletId: (accounts: Array<{ address: string, keyPath: string, balance: number }>) => Promise<string>,\n+        defaultLabel: string = 'Standard Account',\n+        onIntermediateResult?: (accounts: Array<{ address: string, keyPath: string, balance: number }>) => void,\n+    ): Promise<AccountInfo[]> {\n+        await NetworkClient.Instance.init(); // initialize NetworkClient if not initialized yet\n+        const foundAccounts: Array<{ address: string, keyPath: string, balance: number }> = [];\n+        let nextStartIndex = 0;\n+        let derivedAccountsPromise = deriveAccounts(nextStartIndex, AccountFinder.MAX_ALLOWED_GAP);\n+        nextStartIndex += AccountFinder.MAX_ALLOWED_GAP;\n+        while (true) {\n+            const derivedAccounts = await derivedAccountsPromise;\n+            if (derivedAccounts.length !== AccountFinder.MAX_ALLOWED_GAP) {\n+                throw new Error('\\'deriveAccounts\\' returned wrong number of accounts');\n+            }\n+\n+            // already start deriving next accounts\n+            derivedAccountsPromise = deriveAccounts(nextStartIndex, AccountFinder.MAX_ALLOWED_GAP);\n+            nextStartIndex += derivedAccounts.length; // by always advancing in blocks of MAX_ALLOWED_GAP it can happen\n+            // that we include accounts that are more than MAX_ALLOWED_GAP apart (e.g. one towards the beginning of\n+            // the first block, the other one towards the end of the second block). But that's actually not bad.\n+\n+            // find accounts with a balance > 0\n+            // TODO should use transaction receipts combined with balance\n+            let didFindAccounts = false;\n+            const userFriendlyAddresses = derivedAccounts.map(({ address }) => address);\n+            const balances = await NetworkClient.Instance.getBalance(userFriendlyAddresses);\n+            for (const account of derivedAccounts) {\n+                const balance = balances.get(account.address);\n+                if (balance === undefined || balance === 0) continue;\n+                foundAccounts.push(Object.assign({}, account, { balance }));\n+                didFindAccounts = true;","path":"src/lib/AccountFinder.ts","position":38,"original_position":38,"commit_id":"824a1744582ecd5dff04b37419f9a7d385a51fa7","original_commit_id":"824a1744582ecd5dff04b37419f9a7d385a51fa7","user":{"login":"danimoh","id":6204514,"node_id":"MDQ6VXNlcjYyMDQ1MTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6204514?v=4","gravatar_id":"","url":"https://api.github.com/users/danimoh","html_url":"https://github.com/danimoh","followers_url":"https://api.github.com/users/danimoh/followers","following_url":"https://api.github.com/users/danimoh/following{/other_user}","gists_url":"https://api.github.com/users/danimoh/gists{/gist_id}","starred_url":"https://api.github.com/users/danimoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danimoh/subscriptions","organizations_url":"https://api.github.com/users/danimoh/orgs","repos_url":"https://api.github.com/users/danimoh/repos","events_url":"https://api.github.com/users/danimoh/events{/privacy}","received_events_url":"https://api.github.com/users/danimoh/received_events","type":"User","site_admin":false},"body":"Will probably keep this behavior, as discussed.","created_at":"2018-12-08T00:03:56Z","updated_at":"2018-12-08T00:03:56Z","html_url":"https://github.com/nimiq/accounts/pull/91#discussion_r239979777","pull_request_url":"https://api.github.com/repos/nimiq/accounts/pulls/91","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/comments/239979777"},"html":{"href":"https://github.com/nimiq/accounts/pull/91#discussion_r239979777"},"pull_request":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/91"}},"in_reply_to_id":239954233},"pull_request":{"url":"https://api.github.com/repos/nimiq/accounts/pulls/91","id":236753812,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM2NzUzODEy","html_url":"https://github.com/nimiq/accounts/pull/91","diff_url":"https://github.com/nimiq/accounts/pull/91.diff","patch_url":"https://github.com/nimiq/accounts/pull/91.patch","issue_url":"https://api.github.com/repos/nimiq/accounts/issues/91","number":91,"state":"open","locked":false,"title":"move account finding to a library and refactor LoginSuccess","user":{"login":"danimoh","id":6204514,"node_id":"MDQ6VXNlcjYyMDQ1MTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6204514?v=4","gravatar_id":"","url":"https://api.github.com/users/danimoh","html_url":"https://github.com/danimoh","followers_url":"https://api.github.com/users/danimoh/followers","following_url":"https://api.github.com/users/danimoh/following{/other_user}","gists_url":"https://api.github.com/users/danimoh/gists{/gist_id}","starred_url":"https://api.github.com/users/danimoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danimoh/subscriptions","organizations_url":"https://api.github.com/users/danimoh/orgs","repos_url":"https://api.github.com/users/danimoh/repos","events_url":"https://api.github.com/users/danimoh/events{/privacy}","received_events_url":"https://api.github.com/users/danimoh/received_events","type":"User","site_admin":false},"body":"- create a library AccountFinder that orchestrates finding used accounts from derived accounts via the network\r\n- refactor LoginSuccess to use AccountFinder and also clean up and structure the code and fix some smaller issues\r\n- fix indentation in router.ts","created_at":"2018-12-07T04:46:42Z","updated_at":"2018-12-08T00:03:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"236e6c6565fe72eeb9d817c5848562a4e040b62f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/nimiq/accounts/pulls/91/commits","review_comments_url":"https://api.github.com/repos/nimiq/accounts/pulls/91/comments","review_comment_url":"https://api.github.com/repos/nimiq/accounts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nimiq/accounts/issues/91/comments","statuses_url":"https://api.github.com/repos/nimiq/accounts/statuses/824a1744582ecd5dff04b37419f9a7d385a51fa7","head":{"label":"nimiq:daniel/account-finder","ref":"daniel/account-finder","sha":"824a1744582ecd5dff04b37419f9a7d385a51fa7","user":{"login":"nimiq","id":33815469,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzODE1NDY5","avatar_url":"https://avatars1.githubusercontent.com/u/33815469?v=4","gravatar_id":"","url":"https://api.github.com/users/nimiq","html_url":"https://github.com/nimiq","followers_url":"https://api.github.com/users/nimiq/followers","following_url":"https://api.github.com/users/nimiq/following{/other_user}","gists_url":"https://api.github.com/users/nimiq/gists{/gist_id}","starred_url":"https://api.github.com/users/nimiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nimiq/subscriptions","organizations_url":"https://api.github.com/users/nimiq/orgs","repos_url":"https://api.github.com/users/nimiq/repos","events_url":"https://api.github.com/users/nimiq/events{/privacy}","received_events_url":"https://api.github.com/users/nimiq/received_events","type":"Organization","site_admin":false},"repo":{"id":140697254,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA2OTcyNTQ=","name":"accounts","full_name":"nimiq/accounts","private":false,"owner":{"login":"nimiq","id":33815469,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzODE1NDY5","avatar_url":"https://avatars1.githubusercontent.com/u/33815469?v=4","gravatar_id":"","url":"https://api.github.com/users/nimiq","html_url":"https://github.com/nimiq","followers_url":"https://api.github.com/users/nimiq/followers","following_url":"https://api.github.com/users/nimiq/following{/other_user}","gists_url":"https://api.github.com/users/nimiq/gists{/gist_id}","starred_url":"https://api.github.com/users/nimiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nimiq/subscriptions","organizations_url":"https://api.github.com/users/nimiq/orgs","repos_url":"https://api.github.com/users/nimiq/repos","events_url":"https://api.github.com/users/nimiq/events{/privacy}","received_events_url":"https://api.github.com/users/nimiq/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/nimiq/accounts","description":null,"fork":false,"url":"https://api.github.com/repos/nimiq/accounts","forks_url":"https://api.github.com/repos/nimiq/accounts/forks","keys_url":"https://api.github.com/repos/nimiq/accounts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nimiq/accounts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nimiq/accounts/teams","hooks_url":"https://api.github.com/repos/nimiq/accounts/hooks","issue_events_url":"https://api.github.com/repos/nimiq/accounts/issues/events{/number}","events_url":"https://api.github.com/repos/nimiq/accounts/events","assignees_url":"https://api.github.com/repos/nimiq/accounts/assignees{/user}","branches_url":"https://api.github.com/repos/nimiq/accounts/branches{/branch}","tags_url":"https://api.github.com/repos/nimiq/accounts/tags","blobs_url":"https://api.github.com/repos/nimiq/accounts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nimiq/accounts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nimiq/accounts/git/refs{/sha}","trees_url":"https://api.github.com/repos/nimiq/accounts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nimiq/accounts/statuses/{sha}","languages_url":"https://api.github.com/repos/nimiq/accounts/languages","stargazers_url":"https://api.github.com/repos/nimiq/accounts/stargazers","contributors_url":"https://api.github.com/repos/nimiq/accounts/contributors","subscribers_url":"https://api.github.com/repos/nimiq/accounts/subscribers","subscription_url":"https://api.github.com/repos/nimiq/accounts/subscription","commits_url":"https://api.github.com/repos/nimiq/accounts/commits{/sha}","git_commits_url":"https://api.github.com/repos/nimiq/accounts/git/commits{/sha}","comments_url":"https://api.github.com/repos/nimiq/accounts/comments{/number}","issue_comment_url":"https://api.github.com/repos/nimiq/accounts/issues/comments{/number}","contents_url":"https://api.github.com/repos/nimiq/accounts/contents/{+path}","compare_url":"https://api.github.com/repos/nimiq/accounts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nimiq/accounts/merges","archive_url":"https://api.github.com/repos/nimiq/accounts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nimiq/accounts/downloads","issues_url":"https://api.github.com/repos/nimiq/accounts/issues{/number}","pulls_url":"https://api.github.com/repos/nimiq/accounts/pulls{/number}","milestones_url":"https://api.github.com/repos/nimiq/accounts/milestones{/number}","notifications_url":"https://api.github.com/repos/nimiq/accounts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nimiq/accounts/labels{/name}","releases_url":"https://api.github.com/repos/nimiq/accounts/releases{/id}","deployments_url":"https://api.github.com/repos/nimiq/accounts/deployments","created_at":"2018-07-12T10:17:09Z","updated_at":"2018-12-07T23:01:40Z","pushed_at":"2018-12-07T23:01:40Z","git_url":"git://github.com/nimiq/accounts.git","ssh_url":"git@github.com:nimiq/accounts.git","clone_url":"https://github.com/nimiq/accounts.git","svn_url":"https://github.com/nimiq/accounts","homepage":null,"size":1289,"stargazers_count":1,"watchers_count":1,"language":"Vue","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":16,"license":null,"forks":1,"open_issues":16,"watchers":1,"default_branch":"master"}},"base":{"label":"nimiq:master","ref":"master","sha":"29ee2e682479a654bc8dbcb8fc39f04dc0593e2a","user":{"login":"nimiq","id":33815469,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzODE1NDY5","avatar_url":"https://avatars1.githubusercontent.com/u/33815469?v=4","gravatar_id":"","url":"https://api.github.com/users/nimiq","html_url":"https://github.com/nimiq","followers_url":"https://api.github.com/users/nimiq/followers","following_url":"https://api.github.com/users/nimiq/following{/other_user}","gists_url":"https://api.github.com/users/nimiq/gists{/gist_id}","starred_url":"https://api.github.com/users/nimiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nimiq/subscriptions","organizations_url":"https://api.github.com/users/nimiq/orgs","repos_url":"https://api.github.com/users/nimiq/repos","events_url":"https://api.github.com/users/nimiq/events{/privacy}","received_events_url":"https://api.github.com/users/nimiq/received_events","type":"Organization","site_admin":false},"repo":{"id":140697254,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA2OTcyNTQ=","name":"accounts","full_name":"nimiq/accounts","private":false,"owner":{"login":"nimiq","id":33815469,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzODE1NDY5","avatar_url":"https://avatars1.githubusercontent.com/u/33815469?v=4","gravatar_id":"","url":"https://api.github.com/users/nimiq","html_url":"https://github.com/nimiq","followers_url":"https://api.github.com/users/nimiq/followers","following_url":"https://api.github.com/users/nimiq/following{/other_user}","gists_url":"https://api.github.com/users/nimiq/gists{/gist_id}","starred_url":"https://api.github.com/users/nimiq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nimiq/subscriptions","organizations_url":"https://api.github.com/users/nimiq/orgs","repos_url":"https://api.github.com/users/nimiq/repos","events_url":"https://api.github.com/users/nimiq/events{/privacy}","received_events_url":"https://api.github.com/users/nimiq/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/nimiq/accounts","description":null,"fork":false,"url":"https://api.github.com/repos/nimiq/accounts","forks_url":"https://api.github.com/repos/nimiq/accounts/forks","keys_url":"https://api.github.com/repos/nimiq/accounts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nimiq/accounts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nimiq/accounts/teams","hooks_url":"https://api.github.com/repos/nimiq/accounts/hooks","issue_events_url":"https://api.github.com/repos/nimiq/accounts/issues/events{/number}","events_url":"https://api.github.com/repos/nimiq/accounts/events","assignees_url":"https://api.github.com/repos/nimiq/accounts/assignees{/user}","branches_url":"https://api.github.com/repos/nimiq/accounts/branches{/branch}","tags_url":"https://api.github.com/repos/nimiq/accounts/tags","blobs_url":"https://api.github.com/repos/nimiq/accounts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nimiq/accounts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nimiq/accounts/git/refs{/sha}","trees_url":"https://api.github.com/repos/nimiq/accounts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nimiq/accounts/statuses/{sha}","languages_url":"https://api.github.com/repos/nimiq/accounts/languages","stargazers_url":"https://api.github.com/repos/nimiq/accounts/stargazers","contributors_url":"https://api.github.com/repos/nimiq/accounts/contributors","subscribers_url":"https://api.github.com/repos/nimiq/accounts/subscribers","subscription_url":"https://api.github.com/repos/nimiq/accounts/subscription","commits_url":"https://api.github.com/repos/nimiq/accounts/commits{/sha}","git_commits_url":"https://api.github.com/repos/nimiq/accounts/git/commits{/sha}","comments_url":"https://api.github.com/repos/nimiq/accounts/comments{/number}","issue_comment_url":"https://api.github.com/repos/nimiq/accounts/issues/comments{/number}","contents_url":"https://api.github.com/repos/nimiq/accounts/contents/{+path}","compare_url":"https://api.github.com/repos/nimiq/accounts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nimiq/accounts/merges","archive_url":"https://api.github.com/repos/nimiq/accounts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nimiq/accounts/downloads","issues_url":"https://api.github.com/repos/nimiq/accounts/issues{/number}","pulls_url":"https://api.github.com/repos/nimiq/accounts/pulls{/number}","milestones_url":"https://api.github.com/repos/nimiq/accounts/milestones{/number}","notifications_url":"https://api.github.com/repos/nimiq/accounts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nimiq/accounts/labels{/name}","releases_url":"https://api.github.com/repos/nimiq/accounts/releases{/id}","deployments_url":"https://api.github.com/repos/nimiq/accounts/deployments","created_at":"2018-07-12T10:17:09Z","updated_at":"2018-12-07T23:01:40Z","pushed_at":"2018-12-07T23:01:40Z","git_url":"git://github.com/nimiq/accounts.git","ssh_url":"git@github.com:nimiq/accounts.git","clone_url":"https://github.com/nimiq/accounts.git","svn_url":"https://github.com/nimiq/accounts","homepage":null,"size":1289,"stargazers_count":1,"watchers_count":1,"language":"Vue","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":16,"license":null,"forks":1,"open_issues":16,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/91"},"html":{"href":"https://github.com/nimiq/accounts/pull/91"},"issue":{"href":"https://api.github.com/repos/nimiq/accounts/issues/91"},"comments":{"href":"https://api.github.com/repos/nimiq/accounts/issues/91/comments"},"review_comments":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/91/comments"},"review_comment":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nimiq/accounts/pulls/91/commits"},"statuses":{"href":"https://api.github.com/repos/nimiq/accounts/statuses/824a1744582ecd5dff04b37419f9a7d385a51fa7"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"danimoh"}}