Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

eth_getBlockByNumber impl #87

Merged
merged 12 commits into from
Sep 24, 2019
Merged

Conversation

austinabell
Copy link

@austinabell austinabell commented Aug 30, 2019

Notes:

  • Tx hashes are hashes of the amino encoded tx (since that is how they are referenced by getting transaction by hash through tendermint)
  • Will wait to include logs bloom filter once similar logic is completed with Implement eth_getLogs #55
  • Gas usage for block cannot be calculated when txs are not populated, will look into saving gasUsed by block later if necessary

To test:

  1. Run the Ethermint node:
make install 
rm -rf ~/.emint*
emintd init moniker --chain-id 3
emintcli config chain-id 3
emintcli config output json
emintcli config indent true
emintcli config trust-node true
emintcli keys add austin
testpass
testpass
emintcli emintkeys add austineth
testpass
testpass
emintd add-genesis-account $(emintcli keys show austin -a) 1000photon,100000000stake
emintd add-genesis-account $(emintcli emintkeys show austineth -a) 100000000photon,100000000stake
emintd gentx --name austin
testpass
emintd collect-gentxs
emintd validate-genesis
emintd start --pruning=nothing --rpc.unsafe --log_level "main:info,state:info,mempool:info,*:error"

  1. Start rest server with unlocked key to send tx to test functionality
emintcli rest-server --laddr "tcp://localhost:8545" --unlock-key austineth
  1. Send a transaction to test all values in a block:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0x'$(echo -n $(emintcli emintkeys show austineth -w))'","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x12","value":"0x20","data":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}],"id":1}' -H "Content-Type: application/json" http://localhost:8545/rpc

Retrieve block based on block transaction(s) processed (replace 0x2 with block number):

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x2", false],"id":1}' -H "Content-Type: application/json" http://localhost:8545/rpc
## Response: {"jsonrpc":"2.0","id":1,"result":{"difficulty":null,"extraData":null,"gasLimit":"0xffffffffffffffff","gasUsed":null,"hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","logsBloom":"","miner":"13C1A823D673ACAE1F5B03266B06E210E73DC650840F383DD72AB1152BF78AD3","nonce":null,"number":2,"parentHash":"97CB044D3F23C4F2546C40C479D91B62CBAA8FC0A0245522134A9F0B350DBE5B","sha3Uncles":null,"size":"0x34f","stateRoot":"0CC2CBC2FB4F0F610C81BD4FC6970B6AF691795A9460A6B2CC0D1B63BBB101DD","timestamp":"0x5d892e6d","totalDifficulty":null,"transactions":["0x51271e6720e1e87c8fbbe0ed83f979798549f56d29dabde6382fdab1111294de"],"transactionsRoot":"3A7890603A4AD8DB38E5F4E6F2F35069A688FFE1FA0F5AFB74150A79C84A0FF8","uncles":null}}

and set the full tx flag to test that functionality:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x2", true],"id":1}' -H "Content-Type: application/json" http://localhost:8545/rpc
## Response: {"jsonrpc":"2.0","id":1,"result":{"difficulty":null,"extraData":null,"gasLimit":"0xffffffffffffffff","gasUsed":547200,"hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","logsBloom":"","miner":"13C1A823D673ACAE1F5B03266B06E210E73DC650840F383DD72AB1152BF78AD3","nonce":null,"number":2,"parentHash":"97CB044D3F23C4F2546C40C479D91B62CBAA8FC0A0245522134A9F0B350DBE5B","sha3Uncles":null,"size":"0x34f","stateRoot":"0CC2CBC2FB4F0F610C81BD4FC6970B6AF691795A9460A6B2CC0D1B63BBB101DD","timestamp":"0x5d892e6d","totalDifficulty":null,"transactions":[{"blockHash":"0x048091bc7ddc283f77bfbf91d73c44da58c3df8a9cbc867405d8b7f3daada22f","blockNumber":"0x2","from":"0x4c98655e693f7d1ba2c43f38720c99201a1c7498","gas":"0x76c0","gasPrice":"0x12","hash":"0x4db86f1646925f36f06257e1f57c43cd6947f283e93e18d00441178f7ce2d4eb","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675","nonce":"0x0","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":"0x0","value":"0x20","v":"0x2a","r":"0xb683b308cc7f8d91b91f7f73dcc87e3f2fde625727b06b523eed3164c705e0ef","s":"0x566c420cdd54accb2447e8dbd1836c91f3018dc96fffd887d3f4041b8f3c44ee"}],"transactionsRoot":"3A7890603A4AD8DB38E5F4E6F2F35069A688FFE1FA0F5AFB74150A79C84A0FF8","uncles":null}}

@austinabell austinabell marked this pull request as ready for review September 23, 2019 20:52
@austinabell austinabell changed the title WIP eth_getBlockByNumber impl eth_getBlockByNumber impl Sep 23, 2019
x/evm/types/msg.go Show resolved Hide resolved
rpc/eth_api.go Outdated Show resolved Hide resolved
rpc/eth_api.go Show resolved Hide resolved
rpc/eth_api.go Show resolved Hide resolved
@austinabell austinabell merged commit 4a03033 into development Sep 24, 2019
@austinabell austinabell deleted the austin/eth_getBlockByNumber branch September 24, 2019 19:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants