Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: add eth_nextNonce RPC method #15840

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down