diff --git a/rpc/eth_api.go b/rpc/eth_api.go index ebb66761..71c72bb6 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -181,14 +181,19 @@ func (e *PublicEthAPI) GetStorageAt(address common.Address, key string, blockNum // GetTransactionCount returns the number of transactions at the given address up to the given block number. func (e *PublicEthAPI) GetTransactionCount(address common.Address, blockNum BlockNumber) (*hexutil.Uint64, error) { ctx := e.cliCtx.WithHeight(blockNum.Int64()) - res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/nonce/%s", types.ModuleName, address.Hex()), nil) + + // Get nonce (sequence) from account + from := sdk.AccAddress(address.Bytes()) + authclient.Codec = codec.NewAppCodec(ctx.Codec) + accRet := authtypes.NewAccountRetriever(authclient.Codec, ctx) + + _, nonce, err := accRet.GetAccountNumberSequence(from) if err != nil { return nil, err } - var out types.QueryResNonce - e.cliCtx.Codec.MustUnmarshalJSON(res, &out) - return (*hexutil.Uint64)(&out.Nonce), nil + n := hexutil.Uint64(nonce) + return &n, nil } // GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash. diff --git a/tests/rpc_test.go b/tests/rpc_test.go index 5eccd7f4..52e65bac 100644 --- a/tests/rpc_test.go +++ b/tests/rpc_test.go @@ -637,3 +637,21 @@ func TestBlockBloom_Hash(t *testing.T) { lb := hexToBigInt(t, block["logsBloom"].(string)) require.NotEqual(t, big.NewInt(0), lb) } + +func getNonce(t *testing.T) hexutil.Uint64 { + from := getAddress(t) + param := []interface{}{hexutil.Bytes(from), "latest"} + rpcRes := call(t, "eth_getTransactionCount", param) + + var nonce hexutil.Uint64 + err := json.Unmarshal(rpcRes.Result, &nonce) + require.NoError(t, err) + return nonce +} + +func TestEth_GetTransactionCount(t *testing.T) { + prev := getNonce(t) + sendTestTransaction(t) + post := getNonce(t) + require.Equal(t, prev, post-1) +} diff --git a/x/evm/keeper/querier.go b/x/evm/keeper/querier.go index 5d85d9fd..2fed9c26 100644 --- a/x/evm/keeper/querier.go +++ b/x/evm/keeper/querier.go @@ -32,8 +32,6 @@ func NewQuerier(keeper Keeper) sdk.Querier { return queryStorage(ctx, path, keeper) case types.QueryCode: return queryCode(ctx, path, keeper) - case types.QueryNonce: - return queryNonce(ctx, path, keeper) case types.QueryHashToHeight: return queryHashToHeight(ctx, path, keeper) case types.QueryTransactionLogs: @@ -113,18 +111,6 @@ func queryCode(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) { return bz, nil } -func queryNonce(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) { - addr := ethcmn.HexToAddress(path[1]) - nonce := keeper.GetNonce(ctx, addr) - nRes := types.QueryResNonce{Nonce: nonce} - bz, err := codec.MarshalJSONIndent(keeper.cdc, nRes) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return bz, nil -} - func queryHashToHeight(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) { blockHash := ethcmn.FromHex(path[1]) blockNumber, err := keeper.GetBlockHashMapping(ctx, blockHash) diff --git a/x/evm/keeper/querier_test.go b/x/evm/keeper/querier_test.go index d6d7d688..d4d115f0 100644 --- a/x/evm/keeper/querier_test.go +++ b/x/evm/keeper/querier_test.go @@ -24,7 +24,6 @@ func (suite *KeeperTestSuite) TestQuerier() { {"block number", []string{types.QueryBlockNumber, "0x0"}, func() {}, true}, {"storage", []string{types.QueryStorage, "0x0", "0x0"}, func() {}, true}, {"code", []string{types.QueryCode, "0x0"}, func() {}, true}, - {"nonce", []string{types.QueryNonce, "0x0"}, func() {}, true}, // {"hash to height", []string{types.QueryHashToHeight, "0x0"}, func() {}, true}, {"tx logs", []string{types.QueryTransactionLogs, "0x0"}, func() {}, true}, // {"logs bloom", []string{types.QueryLogsBloom, "0x0"}, func() {}, true},