diff --git a/api/api.go b/api/api.go index 77b701ee..8cf478eb 100644 --- a/api/api.go +++ b/api/api.go @@ -200,7 +200,7 @@ func (s *BlockChainAPI) GetTransactionCount( address common.Address, blockNumberOrHash *rpc.BlockNumberOrHash, ) (*hexutil.Uint64, error) { - nonce := uint64(1050510) + nonce := s.Store.GetAccountNonce(context.Background(), address) return (*hexutil.Uint64)(&nonce), nil } diff --git a/api/api_test.go b/api/api_test.go index aef1397c..fd1792cf 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -14,6 +14,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/rpc" + "github.com/onflow/cadence" + "github.com/onflow/cadence/runtime/stdlib" "github.com/onflow/flow-evm-gateway/api" "github.com/onflow/flow-evm-gateway/storage" "github.com/stretchr/testify/assert" @@ -165,6 +167,7 @@ func TestBlockChainAPI(t *testing.T) { key, _ := crypto.GenerateKey() addr := crypto.PubkeyToAddress(key.PublicKey) blockNumberOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) + txCount, err := blockchainAPI.GetTransactionCount( context.Background(), addr, @@ -172,7 +175,50 @@ func TestBlockChainAPI(t *testing.T) { ) require.NoError(t, err) - nonce := uint64(1050510) + nonce := uint64(0) + assert.Equal(t, txCount, (*hexutil.Uint64)(&nonce)) + + evt := cadence.Event{ + EventType: cadence.NewEventType( + stdlib.FlowLocation{}, + "evm.TransactionExecuted", + []cadence.Field{ + cadence.NewField("blockHeight", cadence.UInt64Type{}), + cadence.NewField("transactionHash", cadence.StringType{}), + cadence.NewField("transaction", cadence.StringType{}), + cadence.NewField("failed", cadence.BoolType{}), + cadence.NewField("transactionType", cadence.UInt8Type{}), + cadence.NewField("gasConsumed", cadence.UInt64Type{}), + cadence.NewField("deployedContractAddress", cadence.StringType{}), + cadence.NewField("returnedValue", cadence.StringType{}), + cadence.NewField("logs", cadence.StringType{}), + }, + nil, + ), + Fields: []cadence.Value{ + cadence.NewUInt64(3), + cadence.String("0xb47d74ea64221eb941490bdc0c9a404dacd0a8573379a45c992ac60ee3e83c3c"), + cadence.String("b88c02f88982029a01808083124f809499466ed2e37b892a2ee3e9cd55a98b68f5735db280a4c6888fa10000000000000000000000000000000000000000000000000000000000000006c001a0f84168f821b427dc158c4d8083bdc4b43e178cf0977a2c5eefbcbedcc4e351b0a066a747a38c6c266b9dc2136523cef04395918de37773db63d574aabde59c12eb"), + cadence.NewBool(false), + cadence.NewUInt8(2), + cadence.NewUInt64(22514), + cadence.String("0000000000000000000000000000000000000000"), + cadence.String("000000000000000000000000000000000000000000000000000000000000002a"), + cadence.String("f85af8589499466ed2e37b892a2ee3e9cd55a98b68f5735db2e1a024abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503daa0000000000000000000000000000000000000000000000000000000000000002a"), + }, + } + + store := blockchainAPI.Store + store.UpdateAccountNonce(context.Background(), evt) + + txCount, err = blockchainAPI.GetTransactionCount( + context.Background(), + common.HexToAddress("0x658Bdf435d810C91414eC09147DAA6DB62406379"), + &blockNumberOrHash, + ) + require.NoError(t, err) + + nonce = uint64(1) assert.Equal(t, txCount, (*hexutil.Uint64)(&nonce)) }) diff --git a/api/fixtures/eth_json_rpc_requests.json b/api/fixtures/eth_json_rpc_requests.json index ee2e6b89..7d368fa8 100644 --- a/api/fixtures/eth_json_rpc_requests.json +++ b/api/fixtures/eth_json_rpc_requests.json @@ -1,35 +1,35 @@ {"jsonrpc":"2.0","id":1,"method":"eth_chainId","params": []} -{"jsonrpc":"2.0","id":2,"method":"eth_blockNumber","params": []} -{"jsonrpc":"2.0","id":3,"method":"eth_syncing","params": []} -{"jsonrpc":"2.0","id":4,"method":"eth_sendRawTransaction","params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"]} -{"jsonrpc":"2.0","id":5,"method":"eth_gasPrice","params":[]} -{"jsonrpc":"2.0","id":6,"method":"eth_getBalance","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1","latest"]} -{"jsonrpc":"2.0","id":7,"method":"eth_getCode","params":["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b","0x2"]} -{"jsonrpc":"2.0","id":8,"method":"eth_getStorageAt","params":["0x295a70b2de5e3953354a6a8344e616ed314d7251","0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9","latest"]} -{"jsonrpc":"2.0","id":9,"method":"eth_getTransactionCount","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1","latest"]} -{"jsonrpc":"2.0","id":10,"method":"eth_getTransactionByHash","params":["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"]} -{"jsonrpc":"2.0","id":11,"method":"eth_getTransactionByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"]} -{"jsonrpc":"2.0","id":12,"method":"eth_getTransactionByBlockNumberAndIndex","params":["0x29c", "0x0"]} -{"jsonrpc":"2.0","id":13,"method":"eth_getTransactionReceipt","params":["0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"]} -{"jsonrpc":"2.0","id":14,"method":"eth_coinbase"} -{"jsonrpc":"2.0","id":15,"method":"eth_getBlockByHash","params":["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",false]} -{"jsonrpc":"2.0","id":16,"method":"eth_getBlockByNumber","params":["0x1b4",true]} -{"jsonrpc":"2.0","id":17,"method":"eth_getBlockTransactionCountByHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"]} -{"jsonrpc":"2.0","id":18,"method":"eth_getBlockTransactionCountByNumber","params":["0xe8"]} -{"jsonrpc":"2.0","id":19,"method":"eth_getUncleCountByBlockHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"]} -{"jsonrpc":"2.0","id":20,"method":"eth_getUncleCountByBlockNumber","params":["0xe8"]} -{"jsonrpc":"2.0","id":21,"method":"eth_getLogs","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}]} -{"jsonrpc":"2.0","id":22,"method":"eth_newFilter","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}]} -{"jsonrpc":"2.0","id":23,"method":"eth_uninstallFilter","params":["0xb"]} -{"jsonrpc":"2.0","id":24,"method":"eth_getFilterLogs","params":["0x16"]} -{"jsonrpc":"2.0","id":25,"method":"eth_getFilterChanges","params":["0x16"]} -{"jsonrpc":"2.0","id":26,"method":"eth_newBlockFilter","params":[]} -{"jsonrpc":"2.0","id":27,"method":"eth_newPendingTransactionFilter","params":[]} -{"jsonrpc":"2.0","id":28,"method":"eth_accounts","params":[]} -{"jsonrpc":"2.0","id":29,"method":"eth_call","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]} -{"jsonrpc":"2.0","id":30,"method":"eth_estimateGas","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]} -{"jsonrpc":"2.0","id":31,"method":"eth_getUncleByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x45"]} -{"jsonrpc":"2.0","id":32,"method":"eth_getUncleByBlockNumberAndIndex","params":["0xe8", "0x45"]} -{"jsonrpc":"2.0","id":33,"method":"eth_sign","params":["0x9b2055d370f73ec7d8a03e965129118dc8f5bf83","0xdeadbeaf"]} -{"jsonrpc":"2.0","id":34,"method":"eth_signTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]} -{"jsonrpc":"2.0","id":35,"method":"eth_sendTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]} \ No newline at end of file +{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params": []} +{"jsonrpc":"2.0","id":1,"method":"eth_syncing","params": []} +{"jsonrpc":"2.0","id":1,"method":"eth_sendRawTransaction","params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"]} +{"jsonrpc":"2.0","id":1,"method":"eth_gasPrice","params":[]} +{"jsonrpc":"2.0","id":1,"method":"eth_getBalance","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1","latest"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getCode","params":["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b","0x2"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getStorageAt","params":["0x295a70b2de5e3953354a6a8344e616ed314d7251","0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9","latest"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getTransactionCount","params":["0x407d73d8a49eeb85d32cf465507dd71d507100c1","latest"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getTransactionByHash","params":["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getTransactionByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x0"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getTransactionByBlockNumberAndIndex","params":["0x29c", "0x0"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getTransactionReceipt","params":["0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"]} +{"jsonrpc":"2.0","id":1,"method":"eth_coinbase"} +{"jsonrpc":"2.0","id":1,"method":"eth_getBlockByHash","params":["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",false]} +{"jsonrpc":"2.0","id":1,"method":"eth_getBlockByNumber","params":["0x1b4",true]} +{"jsonrpc":"2.0","id":1,"method":"eth_getBlockTransactionCountByHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getBlockTransactionCountByNumber","params":["0xe8"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getUncleCountByBlockHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getUncleCountByBlockNumber","params":["0xe8"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}]} +{"jsonrpc":"2.0","id":1,"method":"eth_newFilter","params":[{"topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]}]} +{"jsonrpc":"2.0","id":1,"method":"eth_uninstallFilter","params":["0xb"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getFilterLogs","params":["0x16"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getFilterChanges","params":["0x16"]} +{"jsonrpc":"2.0","id":1,"method":"eth_newBlockFilter","params":[]} +{"jsonrpc":"2.0","id":1,"method":"eth_newPendingTransactionFilter","params":[]} +{"jsonrpc":"2.0","id":1,"method":"eth_accounts","params":[]} +{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]} +{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]} +{"jsonrpc":"2.0","id":1,"method":"eth_getUncleByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x45"]} +{"jsonrpc":"2.0","id":1,"method":"eth_getUncleByBlockNumberAndIndex","params":["0xe8", "0x45"]} +{"jsonrpc":"2.0","id":1,"method":"eth_sign","params":["0x9b2055d370f73ec7d8a03e965129118dc8f5bf83","0xdeadbeaf"]} +{"jsonrpc":"2.0","id":1,"method":"eth_signTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]} +{"jsonrpc":"2.0","id":1,"method":"eth_sendTransaction","params":[{"from":"0x3b7252d007059ffc82d16d022da3cbf9992d2f70", "to":"0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0", "value":"0x16345785d8a0000", "gasLimit":"0x5208", "gasPrice":"0x55ae82600"}]} \ No newline at end of file diff --git a/api/fixtures/eth_json_rpc_responses.json b/api/fixtures/eth_json_rpc_responses.json index 6fe8b677..0cf95f43 100644 --- a/api/fixtures/eth_json_rpc_responses.json +++ b/api/fixtures/eth_json_rpc_responses.json @@ -1,35 +1,35 @@ {"jsonrpc":"2.0","id":1,"result":"0x29a"} -{"jsonrpc":"2.0","id":2,"result":"0x0"} -{"jsonrpc":"2.0","id":3,"result":false} -{"jsonrpc":"2.0","id":4,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"} -{"jsonrpc":"2.0","id":5,"result":"0x1dfd14000"} -{"jsonrpc":"2.0","id":6,"result":"0x65"} -{"jsonrpc":"2.0","id":7,"result":"0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"} -{"jsonrpc":"2.0","id":8,"result":"0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"} -{"jsonrpc":"2.0","id":9,"result":"0x10078e"} -{"jsonrpc":"2.0","id":10,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} -{"jsonrpc":"2.0","id":11,"result":{"blockHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} -{"jsonrpc":"2.0","id":12,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} -{"jsonrpc":"2.0","id":13,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","contractAddress":null,"cumulativeGasUsed":"0xc350","effectiveGasPrice":"0x4a817c800","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gasUsed":"0x9c40","logs":[],"logsBloom":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","status":"0x1","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionHash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","transactionIndex":"0x40","type":"0x2"}} -{"jsonrpc":"2.0","id":14,"result":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"} -{"jsonrpc":"2.0","id":15,"result":{"difficulty":"0x4ea3f27bc","extraData":"0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32","gasLimit":"0x1388","gasUsed":"0x0","hash":"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0xbb7b8287f3f0a933474a79eae42cbca977791171","mixHash":"0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843","nonce":"0x689056015818adbe","number":"0x1b4","parentHash":"0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x220","stateRoot":"0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d","timestamp":"0x55ba467c","totalDifficulty":"0x78ed983323d","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}} -{"jsonrpc":"2.0","id":16,"result":{"difficulty":"0x4ea3f27bc","extraData":"0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32","gasLimit":"0x1388","gasUsed":"0x0","hash":"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0xbb7b8287f3f0a933474a79eae42cbca977791171","mixHash":"0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843","nonce":"0x689056015818adbe","number":"0x1b4","parentHash":"0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x220","stateRoot":"0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d","timestamp":"0x55ba467c","totalDifficulty":"0x78ed983323d","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}} -{"jsonrpc":"2.0","id":17,"result":"0x188aa"} -{"jsonrpc":"2.0","id":18,"result":"0x20a"} -{"jsonrpc":"2.0","id":19,"result":"0x0"} -{"jsonrpc":"2.0","id":20,"result":"0x0"} -{"jsonrpc":"2.0","id":21,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} -{"jsonrpc":"2.0","id":22,"result":"filter0"} -{"jsonrpc":"2.0","id":23,"result":true} -{"jsonrpc":"2.0","id":24,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} -{"jsonrpc":"2.0","id":25,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} -{"jsonrpc":"2.0","id":26,"result":"block_filter"} -{"jsonrpc":"2.0","id":27,"result":"pending_tx_filter"} -{"jsonrpc":"2.0","id":28,"result":[]} -{"jsonrpc":"2.0","id":29,"result":"0x00010203040506070809"} -{"jsonrpc":"2.0","id":30,"result":"0x69"} -{"jsonrpc":"2.0","id":31,"result":{}} -{"jsonrpc":"2.0","id":32,"result":{}} -{"jsonrpc":"2.0","id":33,"error":{"code":-32000,"message":"method is not implemented"}} -{"jsonrpc":"2.0","id":34,"error":{"code":-32000,"message":"method is not implemented"}} -{"jsonrpc":"2.0","id":35,"error":{"code":-32000,"message":"method is not implemented"}} \ No newline at end of file +{"jsonrpc":"2.0","id":1,"result":"0x0"} +{"jsonrpc":"2.0","id":1,"result":false} +{"jsonrpc":"2.0","id":1,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"} +{"jsonrpc":"2.0","id":1,"result":"0x1dfd14000"} +{"jsonrpc":"2.0","id":1,"result":"0x65"} +{"jsonrpc":"2.0","id":1,"result":"0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"} +{"jsonrpc":"2.0","id":1,"result":"0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"} +{"jsonrpc":"2.0","id":1,"result":"0x0"} +{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} +{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} +{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gas":"0xc350","gasPrice":"0x4a817c800","hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","input":"0x3078363836353663366336663231","nonce":"0x15","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionIndex":"0x40","value":"0xf3dbb76162000","type":"0x0","v":"0x25","r":"0x96","s":"0xfa"}} +{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2","blockNumber":"0x5daf3b","contractAddress":null,"cumulativeGasUsed":"0xc350","effectiveGasPrice":"0x4a817c800","from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d","gasUsed":"0x9c40","logs":[],"logsBloom":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","status":"0x1","to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb","transactionHash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b","transactionIndex":"0x40","type":"0x2"}} +{"jsonrpc":"2.0","id":1,"result":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"} +{"jsonrpc":"2.0","id":1,"result":{"difficulty":"0x4ea3f27bc","extraData":"0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32","gasLimit":"0x1388","gasUsed":"0x0","hash":"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0xbb7b8287f3f0a933474a79eae42cbca977791171","mixHash":"0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843","nonce":"0x689056015818adbe","number":"0x1b4","parentHash":"0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x220","stateRoot":"0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d","timestamp":"0x55ba467c","totalDifficulty":"0x78ed983323d","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}} +{"jsonrpc":"2.0","id":1,"result":{"difficulty":"0x4ea3f27bc","extraData":"0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32","gasLimit":"0x1388","gasUsed":"0x0","hash":"0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0xbb7b8287f3f0a933474a79eae42cbca977791171","mixHash":"0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843","nonce":"0x689056015818adbe","number":"0x1b4","parentHash":"0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x220","stateRoot":"0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d","timestamp":"0x55ba467c","totalDifficulty":"0x78ed983323d","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]}} +{"jsonrpc":"2.0","id":1,"result":"0x188aa"} +{"jsonrpc":"2.0","id":1,"result":"0x20a"} +{"jsonrpc":"2.0","id":1,"result":"0x0"} +{"jsonrpc":"2.0","id":1,"result":"0x0"} +{"jsonrpc":"2.0","id":1,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} +{"jsonrpc":"2.0","id":1,"result":"filter0"} +{"jsonrpc":"2.0","id":1,"result":true} +{"jsonrpc":"2.0","id":1,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} +{"jsonrpc":"2.0","id":1,"result":[{"address":"0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d","topics":["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"],"data":"0x000000","blockNumber":"0x1b4","transactionHash":"0x00df829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf","transactionIndex":"0x0","blockHash":"0x008216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d","logIndex":"0x1","removed":false}]} +{"jsonrpc":"2.0","id":1,"result":"block_filter"} +{"jsonrpc":"2.0","id":1,"result":"pending_tx_filter"} +{"jsonrpc":"2.0","id":1,"result":[]} +{"jsonrpc":"2.0","id":1,"result":"0x00010203040506070809"} +{"jsonrpc":"2.0","id":1,"result":"0x69"} +{"jsonrpc":"2.0","id":1,"result":{}} +{"jsonrpc":"2.0","id":1,"result":{}} +{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"method is not implemented"}} +{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"method is not implemented"}} +{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"method is not implemented"}} \ No newline at end of file diff --git a/cmd/server/main.go b/cmd/server/main.go index e85388c1..cfa8fed8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -138,6 +138,9 @@ func runIndexer(ctx context.Context, store *storage.Store, logger zerolog.Logger } for _, event := range response.Events { logger.Info().Msgf(" %s", event.Value) + if event.Type == "flow.evm.TransactionExecuted" { + store.UpdateAccountNonce(ctx, event.Value) + } } lastHeight = response.Height diff --git a/go.mod b/go.mod index 190a83b3..83f7b3b4 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.20 require ( github.com/ethereum/go-ethereum v1.13.5 github.com/gorilla/websocket v1.5.0 + github.com/onflow/cadence v0.42.6 github.com/onflow/flow-go-sdk v0.44.1-0.20231220221922-58fb441b7228 github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 @@ -63,7 +64,6 @@ require ( github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onflow/atree v0.6.0 // indirect - github.com/onflow/cadence v0.42.6 // indirect github.com/onflow/crypto v0.24.9 // indirect github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231121210617-52ee94b830c2 // indirect github.com/onsi/ginkgo v1.16.5 // indirect diff --git a/storage/store.go b/storage/store.go index db2d8444..2c915b71 100644 --- a/storage/store.go +++ b/storage/store.go @@ -1,13 +1,21 @@ package storage import ( + "bytes" "context" + "encoding/hex" "sync" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/onflow/cadence" ) type Store struct { mu sync.RWMutex latestHeight uint64 + accountNonce map[common.Address]uint64 } // NewStore returns a new in-memory Store implementation. @@ -16,7 +24,9 @@ type Store struct { // this race condition, we should require an initial value for // `latestHeight` in `NewStore`. func NewStore() *Store { - return &Store{} + return &Store{ + accountNonce: make(map[common.Address]uint64), + } } func (s *Store) LatestBlockHeight(ctx context.Context) (uint64, error) { @@ -26,6 +36,60 @@ func (s *Store) LatestBlockHeight(ctx context.Context) (uint64, error) { return s.latestHeight, nil } +func (s *Store) GetAccountNonce(ctx context.Context, address common.Address) uint64 { + s.mu.Lock() + defer s.mu.Unlock() + + return s.accountNonce[address] +} + +func (s *Store) UpdateAccountNonce(ctx context.Context, event cadence.Event) { + s.mu.Lock() + defer s.mu.Unlock() + + txTypeValue := event.GetFieldValues()[4] + txTypeCadence, ok := txTypeValue.(cadence.UInt8) + if !ok { + return + } + + txType := txTypeCadence.ToGoValue().(uint8) + + if txType == 255 { + return + } + + txEncoded := event.GetFieldValues()[2] + txEncodedCadence, ok := txEncoded.(cadence.String) + if !ok { + return + } + + txRlpEncoded := txEncodedCadence.ToGoValue().(string) + + decodedTx, err := hex.DecodeString(txRlpEncoded) + if err != nil { + panic(err) + } + trx := &types.Transaction{} + encodedLen := uint(len(txRlpEncoded)) + err = trx.DecodeRLP( + rlp.NewStream( + bytes.NewReader(decodedTx), + uint64(encodedLen), + ), + ) + if err != nil { + panic(err) + } + from, err := types.Sender(types.LatestSignerForChainID(trx.ChainId()), trx) + if err != nil { + panic(err) + } + + s.accountNonce[from] = s.accountNonce[from] + 1 +} + func (s *Store) StoreBlockHeight(ctx context.Context, blockHeight uint64) error { s.mu.Lock() defer s.mu.Unlock()