mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
internal/ethapi: add eth_nextNonce RPC method
This commit is contained in:
parent
83d1657444
commit
b7b78c0058
3 changed files with 13 additions and 2 deletions
|
|
@ -104,7 +104,7 @@ func toBlockNumber(num *big.Int) rpc.BlockNumber {
|
|||
// PendingAccountNonce implements bind.ContractTransactor retrieving the current
|
||||
// pending nonce associated with an account.
|
||||
func (b *ContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (nonce uint64, err error) {
|
||||
out, err := b.txapi.GetTransactionCount(ctx, account, rpc.PendingBlockNumber)
|
||||
out, err := b.txapi.NextNonce(ctx, account)
|
||||
if out != nil {
|
||||
nonce = uint64(*out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ func (ec *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]
|
|||
// This is the nonce that should be used for the next transaction.
|
||||
func (ec *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
|
||||
var result hexutil.Uint64
|
||||
err := ec.c.CallContext(ctx, &result, "eth_getTransactionCount", account, "pending")
|
||||
err := ec.c.CallContext(ctx, &result, "eth_nextNonce", account)
|
||||
return uint64(result), err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -971,6 +971,17 @@ func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, addr
|
|||
return (*hexutil.Uint64)(&nonce), state.Error()
|
||||
}
|
||||
|
||||
// NextNonce returns the next nonce for the given address taking into account any pending transactions the address has
|
||||
func (s *PublicTransactionPoolAPI) NextNonce(ctx context.Context, address common.Address) (*hexutil.Uint64, error) {
|
||||
// Ask transaction pool for the nonce which includes pending transactions
|
||||
nonce, err := s.b.GetPoolNonce(ctx, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return (*hexutil.Uint64)(&nonce), nil
|
||||
}
|
||||
|
||||
// GetTransactionByHash returns the transaction for the given hash
|
||||
func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) *RPCTransaction {
|
||||
// Try to return an already finalized transaction
|
||||
|
|
|
|||
Loading…
Reference in a new issue