{"action":"created","comment":{"url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/comments/235977590","pull_request_review_id":177972907,"id":235977590,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNTk3NzU5MA==","diff_hunk":"@@ -141,3 +141,78 @@ export async function getToken(\n     throw err;\r\n   }\r\n }\r\n+\r\n+/**\r\n+ * Retrieves the complete information about all (or a list of) tokens.\r\n+ * @param url RPC Node url to query.\r\n+ * @param scriptHashArray Array of NEP5 contract scriptHashes.\r\n+ * @param address Optional address to query the balance for. If provided, the returned object will include the balance property.\r\n+ */\r\n+export async function getTokens(\r\n+  url: string,\r\n+  scriptHashArray: string[],\r\n+  address?: string\r\n+): Promise<TokenInfo[]> {\r\n+  const sb = new sc.ScriptBuilder();\r\n+  scriptHashArray.forEach(scriptHash => {\r\n+    if (address) {\r\n+      const addrScriptHash = u.reverseHex(\r\n+        wallet.getScriptHashFromAddress(address)\r\n+      );\r\n+      sb.emitAppCall(scriptHash, \"name\")\r\n+        .emitAppCall(scriptHash, \"symbol\")\r\n+        .emitAppCall(scriptHash, \"decimals\")\r\n+        .emitAppCall(scriptHash, \"totalSupply\")\r\n+        .emitAppCall(scriptHash, \"balanceOf\", [addrScriptHash]);\r\n+    } else {\r\n+      sb.emitAppCall(scriptHash, \"name\")\r\n+        .emitAppCall(scriptHash, \"symbol\")\r\n+        .emitAppCall(scriptHash, \"decimals\")\r\n+        .emitAppCall(scriptHash, \"totalSupply\");\r\n+    }\r\n+  });\r\n+\r\n+  try {\r\n+    const res = await rpc.Query.invokeScript(sb.str).execute(url);\r\n+\r\n+    const result: TokenInfo[] = [];\r\n+    const step = address ? 5 : 4;\r\n+    for (let i = 0; i < res.result.stack.length; i += step) {\r\n+      const name = rpc.StringParser(res.result.stack[i]);\r\n+      const symbol = rpc.StringParser(res.result.stack[i + 1]);\r\n+      const decimals = rpc.IntegerParser(res.result.stack[i + 2]);\r\n+      const totalSupply = rpc\r\n+        .Fixed8Parser(res.result.stack[i + 3])\r\n+        .dividedBy(\r\n+          Math.pow(10, decimals - rpc.IntegerParser(res.result.stack[i + 2]))\r\n+        )\r\n+        .toNumber();\r\n+      const balance = address\r\n+        ? rpc\r\n+            .Fixed8Parser(res.result.stack[i + 4])\r\n+            .dividedBy(\r\n+              Math.pow(\r\n+                10,\r\n+                decimals - rpc.IntegerParser(res.result.stack[i + 2])\r\n+              )\r\n+            )\r\n+        : undefined;\r\n+\r\n+      const obj = {\r\n+        name,\r\n+        symbol,\r\n+        decimals,\r\n+        totalSupply,\r\n+        balance\r\n+      };\r\n+      \r\n+      if(!obj.balance) delete obj.balance;\r\n+\r\n+      result.push(obj);\r\n+    }\r\n+    return result;\r\n+  } catch (err) {\r\n+    log.error(`getToken failed with : ${err.message}`);\r\n+    throw err;\r","path":"packages/neon-nep5/src/main.ts","position":78,"original_position":76,"commit_id":"cb20f02a61bbacb814e64397517f5a9c0fdb57ea","original_commit_id":"414dff21c4e20a2a91db144db474157b67af34dc","user":{"login":"DalderupMaurice","id":10922045,"node_id":"MDQ6VXNlcjEwOTIyMDQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10922045?v=4","gravatar_id":"","url":"https://api.github.com/users/DalderupMaurice","html_url":"https://github.com/DalderupMaurice","followers_url":"https://api.github.com/users/DalderupMaurice/followers","following_url":"https://api.github.com/users/DalderupMaurice/following{/other_user}","gists_url":"https://api.github.com/users/DalderupMaurice/gists{/gist_id}","starred_url":"https://api.github.com/users/DalderupMaurice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DalderupMaurice/subscriptions","organizations_url":"https://api.github.com/users/DalderupMaurice/orgs","repos_url":"https://api.github.com/users/DalderupMaurice/repos","events_url":"https://api.github.com/users/DalderupMaurice/events{/privacy}","received_events_url":"https://api.github.com/users/DalderupMaurice/received_events","type":"User","site_admin":false},"body":"In my opinion, this is not the place where the \"truly useful\" are created.\r\nIf anything goes wrong on a deeper level (at the creation of the build script or something), this is the place where it should provide the necessary useful message(s) for the user to understand what went wrong. \r\n\r\nI think it's sufficient to have the underlying error (if the message is clear enough and if it's useful for the user) with the called function name contained in the error as done right here --> `log.error(\"getToken failed with : ${err.message}\");`\r\n\r\nAlthough this is just my sole opinion and better ways are 100% certainly possible. Maybe this is something to discuss on Slack/Discord instead.\r\n\r\nAs a last note, I've now move the try/catch up. If you'd like it to be reverted right now or applied to the other functions, I'm willing to do so!","created_at":"2018-11-23T15:48:42Z","updated_at":"2018-11-23T15:48:42Z","html_url":"https://github.com/CityOfZion/neon-js/pull/343#discussion_r235977590","pull_request_url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/comments/235977590"},"html":{"href":"https://github.com/CityOfZion/neon-js/pull/343#discussion_r235977590"},"pull_request":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343"}},"in_reply_to_id":232517401},"pull_request":{"url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343","id":229953600,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5OTUzNjAw","html_url":"https://github.com/CityOfZion/neon-js/pull/343","diff_url":"https://github.com/CityOfZion/neon-js/pull/343.diff","patch_url":"https://github.com/CityOfZion/neon-js/pull/343.patch","issue_url":"https://api.github.com/repos/CityOfZion/neon-js/issues/343","number":343,"state":"open","locked":false,"title":"feat(nep-5): added getTokens functionality","user":{"login":"DalderupMaurice","id":10922045,"node_id":"MDQ6VXNlcjEwOTIyMDQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10922045?v=4","gravatar_id":"","url":"https://api.github.com/users/DalderupMaurice","html_url":"https://github.com/DalderupMaurice","followers_url":"https://api.github.com/users/DalderupMaurice/followers","following_url":"https://api.github.com/users/DalderupMaurice/following{/other_user}","gists_url":"https://api.github.com/users/DalderupMaurice/gists{/gist_id}","starred_url":"https://api.github.com/users/DalderupMaurice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DalderupMaurice/subscriptions","organizations_url":"https://api.github.com/users/DalderupMaurice/orgs","repos_url":"https://api.github.com/users/DalderupMaurice/repos","events_url":"https://api.github.com/users/DalderupMaurice/events{/privacy}","received_events_url":"https://api.github.com/users/DalderupMaurice/received_events","type":"User","site_admin":false},"body":"You're able to get multiple token balances in 1 call, but not the ability to get multiple tokens (with more detailed info) in 1 call.\r\nThis PR resolves this issue, with the addition of `getTokens`","created_at":"2018-11-11T13:59:12Z","updated_at":"2018-11-23T15:48:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19763eae7264bed3046d98e1b3bdf4e2152e0071","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343/commits","review_comments_url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343/comments","review_comment_url":"https://api.github.com/repos/CityOfZion/neon-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CityOfZion/neon-js/issues/343/comments","statuses_url":"https://api.github.com/repos/CityOfZion/neon-js/statuses/cb20f02a61bbacb814e64397517f5a9c0fdb57ea","head":{"label":"DalderupMaurice:feat/getTokens","ref":"feat/getTokens","sha":"cb20f02a61bbacb814e64397517f5a9c0fdb57ea","user":{"login":"DalderupMaurice","id":10922045,"node_id":"MDQ6VXNlcjEwOTIyMDQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10922045?v=4","gravatar_id":"","url":"https://api.github.com/users/DalderupMaurice","html_url":"https://github.com/DalderupMaurice","followers_url":"https://api.github.com/users/DalderupMaurice/followers","following_url":"https://api.github.com/users/DalderupMaurice/following{/other_user}","gists_url":"https://api.github.com/users/DalderupMaurice/gists{/gist_id}","starred_url":"https://api.github.com/users/DalderupMaurice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DalderupMaurice/subscriptions","organizations_url":"https://api.github.com/users/DalderupMaurice/orgs","repos_url":"https://api.github.com/users/DalderupMaurice/repos","events_url":"https://api.github.com/users/DalderupMaurice/events{/privacy}","received_events_url":"https://api.github.com/users/DalderupMaurice/received_events","type":"User","site_admin":false},"repo":{"id":129950871,"node_id":"MDEwOlJlcG9zaXRvcnkxMjk5NTA4NzE=","name":"neon-js","full_name":"DalderupMaurice/neon-js","private":false,"owner":{"login":"DalderupMaurice","id":10922045,"node_id":"MDQ6VXNlcjEwOTIyMDQ1","avatar_url":"https://avatars0.githubusercontent.com/u/10922045?v=4","gravatar_id":"","url":"https://api.github.com/users/DalderupMaurice","html_url":"https://github.com/DalderupMaurice","followers_url":"https://api.github.com/users/DalderupMaurice/followers","following_url":"https://api.github.com/users/DalderupMaurice/following{/other_user}","gists_url":"https://api.github.com/users/DalderupMaurice/gists{/gist_id}","starred_url":"https://api.github.com/users/DalderupMaurice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DalderupMaurice/subscriptions","organizations_url":"https://api.github.com/users/DalderupMaurice/orgs","repos_url":"https://api.github.com/users/DalderupMaurice/repos","events_url":"https://api.github.com/users/DalderupMaurice/events{/privacy}","received_events_url":"https://api.github.com/users/DalderupMaurice/received_events","type":"User","site_admin":false},"html_url":"https://github.com/DalderupMaurice/neon-js","description":"Javascript libraries that allow the applications to interact with NEO blockchain","fork":true,"url":"https://api.github.com/repos/DalderupMaurice/neon-js","forks_url":"https://api.github.com/repos/DalderupMaurice/neon-js/forks","keys_url":"https://api.github.com/repos/DalderupMaurice/neon-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DalderupMaurice/neon-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DalderupMaurice/neon-js/teams","hooks_url":"https://api.github.com/repos/DalderupMaurice/neon-js/hooks","issue_events_url":"https://api.github.com/repos/DalderupMaurice/neon-js/issues/events{/number}","events_url":"https://api.github.com/repos/DalderupMaurice/neon-js/events","assignees_url":"https://api.github.com/repos/DalderupMaurice/neon-js/assignees{/user}","branches_url":"https://api.github.com/repos/DalderupMaurice/neon-js/branches{/branch}","tags_url":"https://api.github.com/repos/DalderupMaurice/neon-js/tags","blobs_url":"https://api.github.com/repos/DalderupMaurice/neon-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DalderupMaurice/neon-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DalderupMaurice/neon-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/DalderupMaurice/neon-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DalderupMaurice/neon-js/statuses/{sha}","languages_url":"https://api.github.com/repos/DalderupMaurice/neon-js/languages","stargazers_url":"https://api.github.com/repos/DalderupMaurice/neon-js/stargazers","contributors_url":"https://api.github.com/repos/DalderupMaurice/neon-js/contributors","subscribers_url":"https://api.github.com/repos/DalderupMaurice/neon-js/subscribers","subscription_url":"https://api.github.com/repos/DalderupMaurice/neon-js/subscription","commits_url":"https://api.github.com/repos/DalderupMaurice/neon-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/DalderupMaurice/neon-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/DalderupMaurice/neon-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/DalderupMaurice/neon-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/DalderupMaurice/neon-js/contents/{+path}","compare_url":"https://api.github.com/repos/DalderupMaurice/neon-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DalderupMaurice/neon-js/merges","archive_url":"https://api.github.com/repos/DalderupMaurice/neon-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DalderupMaurice/neon-js/downloads","issues_url":"https://api.github.com/repos/DalderupMaurice/neon-js/issues{/number}","pulls_url":"https://api.github.com/repos/DalderupMaurice/neon-js/pulls{/number}","milestones_url":"https://api.github.com/repos/DalderupMaurice/neon-js/milestones{/number}","notifications_url":"https://api.github.com/repos/DalderupMaurice/neon-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DalderupMaurice/neon-js/labels{/name}","releases_url":"https://api.github.com/repos/DalderupMaurice/neon-js/releases{/id}","deployments_url":"https://api.github.com/repos/DalderupMaurice/neon-js/deployments","created_at":"2018-04-17T18:50:46Z","updated_at":"2018-04-18T06:40:05Z","pushed_at":"2018-11-23T15:41:16Z","git_url":"git://github.com/DalderupMaurice/neon-js.git","ssh_url":"git@github.com:DalderupMaurice/neon-js.git","clone_url":"https://github.com/DalderupMaurice/neon-js.git","svn_url":"https://github.com/DalderupMaurice/neon-js","homepage":"https://cityofzion.io/neon-js","size":38481,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"CityOfZion:dev","ref":"dev","sha":"df13cac09df92172b8a3fbe9e585d0a3112c9019","user":{"login":"CityOfZion","id":29782569,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI5NzgyNTY5","avatar_url":"https://avatars1.githubusercontent.com/u/29782569?v=4","gravatar_id":"","url":"https://api.github.com/users/CityOfZion","html_url":"https://github.com/CityOfZion","followers_url":"https://api.github.com/users/CityOfZion/followers","following_url":"https://api.github.com/users/CityOfZion/following{/other_user}","gists_url":"https://api.github.com/users/CityOfZion/gists{/gist_id}","starred_url":"https://api.github.com/users/CityOfZion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CityOfZion/subscriptions","organizations_url":"https://api.github.com/users/CityOfZion/orgs","repos_url":"https://api.github.com/users/CityOfZion/repos","events_url":"https://api.github.com/users/CityOfZion/events{/privacy}","received_events_url":"https://api.github.com/users/CityOfZion/received_events","type":"Organization","site_admin":false},"repo":{"id":96053720,"node_id":"MDEwOlJlcG9zaXRvcnk5NjA1MzcyMA==","name":"neon-js","full_name":"CityOfZion/neon-js","private":false,"owner":{"login":"CityOfZion","id":29782569,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI5NzgyNTY5","avatar_url":"https://avatars1.githubusercontent.com/u/29782569?v=4","gravatar_id":"","url":"https://api.github.com/users/CityOfZion","html_url":"https://github.com/CityOfZion","followers_url":"https://api.github.com/users/CityOfZion/followers","following_url":"https://api.github.com/users/CityOfZion/following{/other_user}","gists_url":"https://api.github.com/users/CityOfZion/gists{/gist_id}","starred_url":"https://api.github.com/users/CityOfZion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CityOfZion/subscriptions","organizations_url":"https://api.github.com/users/CityOfZion/orgs","repos_url":"https://api.github.com/users/CityOfZion/repos","events_url":"https://api.github.com/users/CityOfZion/events{/privacy}","received_events_url":"https://api.github.com/users/CityOfZion/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/CityOfZion/neon-js","description":"Javascript libraries that allow the applications to interact with NEO blockchain","fork":false,"url":"https://api.github.com/repos/CityOfZion/neon-js","forks_url":"https://api.github.com/repos/CityOfZion/neon-js/forks","keys_url":"https://api.github.com/repos/CityOfZion/neon-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CityOfZion/neon-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CityOfZion/neon-js/teams","hooks_url":"https://api.github.com/repos/CityOfZion/neon-js/hooks","issue_events_url":"https://api.github.com/repos/CityOfZion/neon-js/issues/events{/number}","events_url":"https://api.github.com/repos/CityOfZion/neon-js/events","assignees_url":"https://api.github.com/repos/CityOfZion/neon-js/assignees{/user}","branches_url":"https://api.github.com/repos/CityOfZion/neon-js/branches{/branch}","tags_url":"https://api.github.com/repos/CityOfZion/neon-js/tags","blobs_url":"https://api.github.com/repos/CityOfZion/neon-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CityOfZion/neon-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CityOfZion/neon-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/CityOfZion/neon-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CityOfZion/neon-js/statuses/{sha}","languages_url":"https://api.github.com/repos/CityOfZion/neon-js/languages","stargazers_url":"https://api.github.com/repos/CityOfZion/neon-js/stargazers","contributors_url":"https://api.github.com/repos/CityOfZion/neon-js/contributors","subscribers_url":"https://api.github.com/repos/CityOfZion/neon-js/subscribers","subscription_url":"https://api.github.com/repos/CityOfZion/neon-js/subscription","commits_url":"https://api.github.com/repos/CityOfZion/neon-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/CityOfZion/neon-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/CityOfZion/neon-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/CityOfZion/neon-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/CityOfZion/neon-js/contents/{+path}","compare_url":"https://api.github.com/repos/CityOfZion/neon-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CityOfZion/neon-js/merges","archive_url":"https://api.github.com/repos/CityOfZion/neon-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CityOfZion/neon-js/downloads","issues_url":"https://api.github.com/repos/CityOfZion/neon-js/issues{/number}","pulls_url":"https://api.github.com/repos/CityOfZion/neon-js/pulls{/number}","milestones_url":"https://api.github.com/repos/CityOfZion/neon-js/milestones{/number}","notifications_url":"https://api.github.com/repos/CityOfZion/neon-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CityOfZion/neon-js/labels{/name}","releases_url":"https://api.github.com/repos/CityOfZion/neon-js/releases{/id}","deployments_url":"https://api.github.com/repos/CityOfZion/neon-js/deployments","created_at":"2017-07-02T23:10:03Z","updated_at":"2018-11-20T09:09:58Z","pushed_at":"2018-11-23T15:41:17Z","git_url":"git://github.com/CityOfZion/neon-js.git","ssh_url":"git@github.com:CityOfZion/neon-js.git","clone_url":"https://github.com/CityOfZion/neon-js.git","svn_url":"https://github.com/CityOfZion/neon-js","homepage":"https://cityofzion.io/neon-js","size":38880,"stargazers_count":129,"watchers_count":129,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":131,"mirror_url":null,"archived":false,"open_issues_count":16,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":131,"open_issues":16,"watchers":129,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343"},"html":{"href":"https://github.com/CityOfZion/neon-js/pull/343"},"issue":{"href":"https://api.github.com/repos/CityOfZion/neon-js/issues/343"},"comments":{"href":"https://api.github.com/repos/CityOfZion/neon-js/issues/343/comments"},"review_comments":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343/comments"},"review_comment":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CityOfZion/neon-js/pulls/343/commits"},"statuses":{"href":"https://api.github.com/repos/CityOfZion/neon-js/statuses/cb20f02a61bbacb814e64397517f5a9c0fdb57ea"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"DalderupMaurice"}}