Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: eth_get_balance rpc endpoint #2100

Merged
merged 1 commit into from
Jun 10, 2019
Merged

feat: eth_get_balance rpc endpoint #2100

merged 1 commit into from
Jun 10, 2019

Conversation

zachdaniel
Copy link
Contributor

@zachdaniel zachdaniel commented Jun 4, 2019

Resolves #2015

Example:

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' <explorer>/api/eth_rpc

Changelog

Enhancements

This mimics the ethGetBalance json rpc. The only issue is that we don't currently create balances for accounts that have a balance at the genesis block. A ticket for doing that is here: #2080

  • I added an entry to CHANGELOG.md with this PR
  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • I checked whether I should update the docs and did so if necessary

@zachdaniel zachdaniel force-pushed the add_eth_getBalance branch from 87c42d6 to 3054dcc Compare June 4, 2019 18:47
@coveralls
Copy link

coveralls commented Jun 4, 2019

Pull Request Test Coverage Report for Build ee4ba479-d2ac-4a3c-95e5-1e27f866e37d

  • 31 of 60 (51.67%) changed or added relevant lines in 8 files are covered.
  • 57 unchanged lines in 13 files lost coverage.
  • Overall coverage decreased (-1.2%) to 79.805%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex 0 1 0.0%
apps/block_scout_web/lib/block_scout_web/views/api/rpc/eth_rpc_view.ex 7 8 87.5%
apps/explorer/lib/explorer/chain/wei.ex 0 2 0.0%
apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/eth_controller.ex 21 26 80.77%
apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex 0 10 0.0%
apps/explorer/lib/explorer/chain.ex 0 10 0.0%
Files with Coverage Reduction New Missed Lines %
apps/indexer/lib/indexer/transform/addresses.ex 1 79.17%
apps/block_scout_web/lib/block_scout_web/channels/exchange_rate_channel.ex 1 50.0%
apps/ethereum_jsonrpc/test/support/ethereum_jsonrpc/case/parity/http_websocket.ex 1 0.0%
apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex 2 76.47%
apps/block_scout_web/lib/block_scout_web/views/address_transaction_view.ex 2 50.0%
apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex 2 90.48%
apps/indexer/lib/indexer/block/fetcher.ex 3 84.0%
apps/ethereum_jsonrpc/test/support/ethereum_jsonrpc/web_socket/case/parity.ex 4 0.0%
apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex 5 35.29%
apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex 6 76.25%
Totals Coverage Status
Change from base Build 7c94713a-f520-4933-913d-641991a525ac: -1.2%
Covered Lines: 4837
Relevant Lines: 6061

💛 - Coveralls

@zachdaniel zachdaniel force-pushed the add_eth_getBalance branch 4 times, most recently from 77fbde7 to b5ff05d Compare June 4, 2019 19:38
vbaranov added a commit that referenced this pull request Jun 4, 2019
Copy link
Contributor

@pasqu4le pasqu4le left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the query that get_balance_as_of_block(address, :earliest) executes.

from(coin_balance in CoinBalance,
where: coin_balance.address_hash == ^address,
where: not is_nil(coin_balance.value),
where: coin_balance.block_number == 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this get the first known coin_balance for the address instead of the one at block 0?

This would fail for addresses whose first coin_balance is not at block 0, is this the intended behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, the "earliest" block does actually mean the genesis block. When I tried this endpoint out I couldn't get any address to respond w/ a non-zero balance on POA with the exception of the master of ceremony, implying that it is just talking about the first block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok if that's the case then there are no problems

Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachdaniel could you please drop a line in the PR description how to call this API endpoint?

@zachdaniel zachdaniel force-pushed the add_eth_getBalance branch 3 times, most recently from e2958bd to 3023081 Compare June 6, 2019 19:30
@zachdaniel zachdaniel force-pushed the add_eth_getBalance branch 2 times, most recently from 6145ff7 to f998c13 Compare June 7, 2019 14:24
@zachdaniel zachdaniel force-pushed the add_eth_getBalance branch from f998c13 to e40027e Compare June 7, 2019 16:43
vbaranov added a commit that referenced this pull request Jun 10, 2019
@vbaranov vbaranov self-requested a review June 10, 2019 12:41
@vbaranov vbaranov merged commit 48bb730 into master Jun 10, 2019
@vbaranov vbaranov deleted the add_eth_getBalance branch June 10, 2019 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add eth_getBalance JSON RPC API method
5 participants