{"action":"created","comment":{"url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/comments/119827962","pull_request_review_id":41743271,"id":119827962,"diff_hunk":"@@ -312,6 +323,60 @@ class EthService(\n     }\n   }\n \n+  def getBalance(req: GetBalanceRequest): ServiceResponse[GetBalanceResponse] = {\n+    Future.successful {\n+      withAccount(Address(req.address), req.block) { account =>\n+        GetBalanceResponse(account.balance)\n+      }\n+    }\n+  }\n+\n+  def getStorageAt(req: GetStorageAtRequest): ServiceResponse[GetStorageAtResponse] = {\n+    import io.iohk.ethereum.rlp.UInt256RLPImplicits._\n+\n+    val byteArrayUInt256Serializer = new ByteArrayEncoder[UInt256] {\n+      override def toBytes(input: UInt256): Array[Byte] = input.bytes.toArray[Byte]\n+    }\n+\n+    val rlpUInt256Serializer = new ByteArraySerializable[UInt256] {\n+      override def fromBytes(bytes: Array[Byte]): UInt256 = ByteString(bytes).toUInt256\n+      override def toBytes(input: UInt256): Array[Byte] = input.toBytes\n+    }\n+\n+    Future.successful {\n+      withAccount(Address(req.address), req.block) { account =>\n+        val storageMpt =\n+          MerklePatriciaTrie[UInt256, UInt256](account.storageRoot.toArray[Byte],\n+            blockchainStorages.nodeStorage, crypto.kec256(_: Array[Byte]))(HashByteArraySerializable(byteArrayUInt256Serializer), rlpUInt256Serializer)\n+        GetStorageAtResponse(storageMpt.get(UInt256(req.position)).getOrElse(UInt256(0)).bytes)\n+      }\n+    }\n+  }\n+\n+  def getTransactionCount(req: GetTransactionCountRequest): ServiceResponse[GetTransactionCountResponse] = {\n+    Future.successful {\n+      withAccount(Address(req.address), req.block) { account =>\n+        GetTransactionCountResponse(account.nonce)\n+      }\n+    }\n+  }\n+\n+  private def withAccount[T](address: Address, blockParam: BlockParam)(f: Account => T): Either[JsonRpcError, T] = {\n+    withStateMpt(blockParam) { stateMpt =>\n+      val account = stateMpt.get(kec256(address.toArray)).getOrElse(Account.Empty)\n+      f(account)\n+    }\n+  }\n+\n+  private def withStateMpt[T](blockParam: BlockParam)(f: MerklePatriciaTrie[Array[Byte], Account] => T): Either[JsonRpcError, T] = {\n+    import MerklePatriciaTrie.defaultByteArraySerializable\n+    resolveBlock(blockParam).map { block =>\n+      val stateMpt = MerklePatriciaTrie[Array[Byte], Account](block.header.stateRoot.toArray[Byte],\n+        blockchainStorages.nodeStorage, (input: Array[Byte]) => crypto.kec256(input))","path":"src/main/scala/io/iohk/ethereum/jsonrpc/EthService.scala","position":99,"original_position":99,"commit_id":"b88e641bf0ed194b57f69034f19ce17719f5f77f","original_commit_id":"b88e641bf0ed194b57f69034f19ce17719f5f77f","user":{"login":"rtkaczyk","id":2451341,"avatar_url":"https://avatars1.githubusercontent.com/u/2451341?v=3","gravatar_id":"","url":"https://api.github.com/users/rtkaczyk","html_url":"https://github.com/rtkaczyk","followers_url":"https://api.github.com/users/rtkaczyk/followers","following_url":"https://api.github.com/users/rtkaczyk/following{/other_user}","gists_url":"https://api.github.com/users/rtkaczyk/gists{/gist_id}","starred_url":"https://api.github.com/users/rtkaczyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtkaczyk/subscriptions","organizations_url":"https://api.github.com/users/rtkaczyk/orgs","repos_url":"https://api.github.com/users/rtkaczyk/repos","events_url":"https://api.github.com/users/rtkaczyk/events{/privacy}","received_events_url":"https://api.github.com/users/rtkaczyk/received_events","type":"User","site_admin":false},"body":"That would be OK. We'd also need `MerklePatriciaTrie.accountStorageMpt(...)`.\r\n\r\nBut what do you think about `blockchain.getAccount(address, stateRootHash)` and `blockain.getAccountStorage(address, stateRootHash)`?  I think that's somewhat nicer to look at, I'm just not sure if `Blockchain` was meant to be used that way.\r\n\r\nAlso having those in `Blockchain` separates MPT implementation from its application.","created_at":"2017-06-02T10:36:59Z","updated_at":"2017-06-02T10:36:59Z","html_url":"https://github.com/input-output-hk/etc-client/pull/200#discussion_r119827962","pull_request_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200","_links":{"self":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/comments/119827962"},"html":{"href":"https://github.com/input-output-hk/etc-client/pull/200#discussion_r119827962"},"pull_request":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200"}}},"pull_request":{"url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200","id":123465059,"html_url":"https://github.com/input-output-hk/etc-client/pull/200","diff_url":"https://github.com/input-output-hk/etc-client/pull/200.diff","patch_url":"https://github.com/input-output-hk/etc-client/pull/200.patch","issue_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/200","number":200,"state":"open","locked":false,"title":"Add eth_balance, getStorageAt and getTransactionCount rpc methods","user":{"login":"LukasGasior1","id":5664242,"avatar_url":"https://avatars2.githubusercontent.com/u/5664242?v=3","gravatar_id":"","url":"https://api.github.com/users/LukasGasior1","html_url":"https://github.com/LukasGasior1","followers_url":"https://api.github.com/users/LukasGasior1/followers","following_url":"https://api.github.com/users/LukasGasior1/following{/other_user}","gists_url":"https://api.github.com/users/LukasGasior1/gists{/gist_id}","starred_url":"https://api.github.com/users/LukasGasior1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukasGasior1/subscriptions","organizations_url":"https://api.github.com/users/LukasGasior1/orgs","repos_url":"https://api.github.com/users/LukasGasior1/repos","events_url":"https://api.github.com/users/LukasGasior1/events{/privacy}","received_events_url":"https://api.github.com/users/LukasGasior1/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-06-01T10:19:16Z","updated_at":"2017-06-02T10:36:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee2e0451f8ccf088939102ae3f63933fa9b9fe6c","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200/commits","review_comments_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200/comments","review_comment_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/200/comments","statuses_url":"https://api.github.com/repos/input-output-hk/etc-client/statuses/b88e641bf0ed194b57f69034f19ce17719f5f77f","head":{"label":"input-output-hk:feature/blockRelatedEthMethods","ref":"feature/blockRelatedEthMethods","sha":"b88e641bf0ed194b57f69034f19ce17719f5f77f","user":{"login":"input-output-hk","id":12909177,"avatar_url":"https://avatars0.githubusercontent.com/u/12909177?v=3","gravatar_id":"","url":"https://api.github.com/users/input-output-hk","html_url":"https://github.com/input-output-hk","followers_url":"https://api.github.com/users/input-output-hk/followers","following_url":"https://api.github.com/users/input-output-hk/following{/other_user}","gists_url":"https://api.github.com/users/input-output-hk/gists{/gist_id}","starred_url":"https://api.github.com/users/input-output-hk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/input-output-hk/subscriptions","organizations_url":"https://api.github.com/users/input-output-hk/orgs","repos_url":"https://api.github.com/users/input-output-hk/repos","events_url":"https://api.github.com/users/input-output-hk/events{/privacy}","received_events_url":"https://api.github.com/users/input-output-hk/received_events","type":"Organization","site_admin":false},"repo":{"id":76256113,"name":"etc-client","full_name":"input-output-hk/etc-client","owner":{"login":"input-output-hk","id":12909177,"avatar_url":"https://avatars0.githubusercontent.com/u/12909177?v=3","gravatar_id":"","url":"https://api.github.com/users/input-output-hk","html_url":"https://github.com/input-output-hk","followers_url":"https://api.github.com/users/input-output-hk/followers","following_url":"https://api.github.com/users/input-output-hk/following{/other_user}","gists_url":"https://api.github.com/users/input-output-hk/gists{/gist_id}","starred_url":"https://api.github.com/users/input-output-hk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/input-output-hk/subscriptions","organizations_url":"https://api.github.com/users/input-output-hk/orgs","repos_url":"https://api.github.com/users/input-output-hk/repos","events_url":"https://api.github.com/users/input-output-hk/events{/privacy}","received_events_url":"https://api.github.com/users/input-output-hk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/input-output-hk/etc-client","description":"A Scala based client for Ethereum Classic. ","fork":false,"url":"https://api.github.com/repos/input-output-hk/etc-client","forks_url":"https://api.github.com/repos/input-output-hk/etc-client/forks","keys_url":"https://api.github.com/repos/input-output-hk/etc-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/input-output-hk/etc-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/input-output-hk/etc-client/teams","hooks_url":"https://api.github.com/repos/input-output-hk/etc-client/hooks","issue_events_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/events{/number}","events_url":"https://api.github.com/repos/input-output-hk/etc-client/events","assignees_url":"https://api.github.com/repos/input-output-hk/etc-client/assignees{/user}","branches_url":"https://api.github.com/repos/input-output-hk/etc-client/branches{/branch}","tags_url":"https://api.github.com/repos/input-output-hk/etc-client/tags","blobs_url":"https://api.github.com/repos/input-output-hk/etc-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/input-output-hk/etc-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/input-output-hk/etc-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/input-output-hk/etc-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/input-output-hk/etc-client/statuses/{sha}","languages_url":"https://api.github.com/repos/input-output-hk/etc-client/languages","stargazers_url":"https://api.github.com/repos/input-output-hk/etc-client/stargazers","contributors_url":"https://api.github.com/repos/input-output-hk/etc-client/contributors","subscribers_url":"https://api.github.com/repos/input-output-hk/etc-client/subscribers","subscription_url":"https://api.github.com/repos/input-output-hk/etc-client/subscription","commits_url":"https://api.github.com/repos/input-output-hk/etc-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/input-output-hk/etc-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/input-output-hk/etc-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/input-output-hk/etc-client/contents/{+path}","compare_url":"https://api.github.com/repos/input-output-hk/etc-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/input-output-hk/etc-client/merges","archive_url":"https://api.github.com/repos/input-output-hk/etc-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/input-output-hk/etc-client/downloads","issues_url":"https://api.github.com/repos/input-output-hk/etc-client/issues{/number}","pulls_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls{/number}","milestones_url":"https://api.github.com/repos/input-output-hk/etc-client/milestones{/number}","notifications_url":"https://api.github.com/repos/input-output-hk/etc-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/input-output-hk/etc-client/labels{/name}","releases_url":"https://api.github.com/repos/input-output-hk/etc-client/releases{/id}","deployments_url":"https://api.github.com/repos/input-output-hk/etc-client/deployments","created_at":"2016-12-12T12:51:31Z","updated_at":"2017-05-18T14:24:28Z","pushed_at":"2017-06-02T09:55:36Z","git_url":"git://github.com/input-output-hk/etc-client.git","ssh_url":"git@github.com:input-output-hk/etc-client.git","clone_url":"https://github.com/input-output-hk/etc-client.git","svn_url":"https://github.com/input-output-hk/etc-client","homepage":null,"size":4524,"stargazers_count":7,"watchers_count":7,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":7,"default_branch":"master"}},"base":{"label":"input-output-hk:phase/4/jsonrpc","ref":"phase/4/jsonrpc","sha":"1ff5a74832942ec41a26b3591f9dd8b99b0246db","user":{"login":"input-output-hk","id":12909177,"avatar_url":"https://avatars0.githubusercontent.com/u/12909177?v=3","gravatar_id":"","url":"https://api.github.com/users/input-output-hk","html_url":"https://github.com/input-output-hk","followers_url":"https://api.github.com/users/input-output-hk/followers","following_url":"https://api.github.com/users/input-output-hk/following{/other_user}","gists_url":"https://api.github.com/users/input-output-hk/gists{/gist_id}","starred_url":"https://api.github.com/users/input-output-hk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/input-output-hk/subscriptions","organizations_url":"https://api.github.com/users/input-output-hk/orgs","repos_url":"https://api.github.com/users/input-output-hk/repos","events_url":"https://api.github.com/users/input-output-hk/events{/privacy}","received_events_url":"https://api.github.com/users/input-output-hk/received_events","type":"Organization","site_admin":false},"repo":{"id":76256113,"name":"etc-client","full_name":"input-output-hk/etc-client","owner":{"login":"input-output-hk","id":12909177,"avatar_url":"https://avatars0.githubusercontent.com/u/12909177?v=3","gravatar_id":"","url":"https://api.github.com/users/input-output-hk","html_url":"https://github.com/input-output-hk","followers_url":"https://api.github.com/users/input-output-hk/followers","following_url":"https://api.github.com/users/input-output-hk/following{/other_user}","gists_url":"https://api.github.com/users/input-output-hk/gists{/gist_id}","starred_url":"https://api.github.com/users/input-output-hk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/input-output-hk/subscriptions","organizations_url":"https://api.github.com/users/input-output-hk/orgs","repos_url":"https://api.github.com/users/input-output-hk/repos","events_url":"https://api.github.com/users/input-output-hk/events{/privacy}","received_events_url":"https://api.github.com/users/input-output-hk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/input-output-hk/etc-client","description":"A Scala based client for Ethereum Classic. ","fork":false,"url":"https://api.github.com/repos/input-output-hk/etc-client","forks_url":"https://api.github.com/repos/input-output-hk/etc-client/forks","keys_url":"https://api.github.com/repos/input-output-hk/etc-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/input-output-hk/etc-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/input-output-hk/etc-client/teams","hooks_url":"https://api.github.com/repos/input-output-hk/etc-client/hooks","issue_events_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/events{/number}","events_url":"https://api.github.com/repos/input-output-hk/etc-client/events","assignees_url":"https://api.github.com/repos/input-output-hk/etc-client/assignees{/user}","branches_url":"https://api.github.com/repos/input-output-hk/etc-client/branches{/branch}","tags_url":"https://api.github.com/repos/input-output-hk/etc-client/tags","blobs_url":"https://api.github.com/repos/input-output-hk/etc-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/input-output-hk/etc-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/input-output-hk/etc-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/input-output-hk/etc-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/input-output-hk/etc-client/statuses/{sha}","languages_url":"https://api.github.com/repos/input-output-hk/etc-client/languages","stargazers_url":"https://api.github.com/repos/input-output-hk/etc-client/stargazers","contributors_url":"https://api.github.com/repos/input-output-hk/etc-client/contributors","subscribers_url":"https://api.github.com/repos/input-output-hk/etc-client/subscribers","subscription_url":"https://api.github.com/repos/input-output-hk/etc-client/subscription","commits_url":"https://api.github.com/repos/input-output-hk/etc-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/input-output-hk/etc-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/input-output-hk/etc-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/input-output-hk/etc-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/input-output-hk/etc-client/contents/{+path}","compare_url":"https://api.github.com/repos/input-output-hk/etc-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/input-output-hk/etc-client/merges","archive_url":"https://api.github.com/repos/input-output-hk/etc-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/input-output-hk/etc-client/downloads","issues_url":"https://api.github.com/repos/input-output-hk/etc-client/issues{/number}","pulls_url":"https://api.github.com/repos/input-output-hk/etc-client/pulls{/number}","milestones_url":"https://api.github.com/repos/input-output-hk/etc-client/milestones{/number}","notifications_url":"https://api.github.com/repos/input-output-hk/etc-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/input-output-hk/etc-client/labels{/name}","releases_url":"https://api.github.com/repos/input-output-hk/etc-client/releases{/id}","deployments_url":"https://api.github.com/repos/input-output-hk/etc-client/deployments","created_at":"2016-12-12T12:51:31Z","updated_at":"2017-05-18T14:24:28Z","pushed_at":"2017-06-02T09:55:36Z","git_url":"git://github.com/input-output-hk/etc-client.git","ssh_url":"git@github.com:input-output-hk/etc-client.git","clone_url":"https://github.com/input-output-hk/etc-client.git","svn_url":"https://github.com/input-output-hk/etc-client","homepage":null,"size":4524,"stargazers_count":7,"watchers_count":7,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200"},"html":{"href":"https://github.com/input-output-hk/etc-client/pull/200"},"issue":{"href":"https://api.github.com/repos/input-output-hk/etc-client/issues/200"},"comments":{"href":"https://api.github.com/repos/input-output-hk/etc-client/issues/200/comments"},"review_comments":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200/comments"},"review_comment":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/input-output-hk/etc-client/pulls/200/commits"},"statuses":{"href":"https://api.github.com/repos/input-output-hk/etc-client/statuses/b88e641bf0ed194b57f69034f19ce17719f5f77f"}}}}
{"actor":{"display_login":"rtkaczyk"}}