get account sequence in GetTransactionCount (#303)

* get account sequence if querying latest in GetTransactionCount

* use ctx WithHeight in GetTransactionCount; remove nonce query from querier
This commit is contained in:
noot
2020-05-17 11:15:32 -04:00
committed by GitHub
parent 1f63ddfe96
commit 846f48a572
4 changed files with 27 additions and 19 deletions
+9 -4
View File
@@ -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.