From 378ce554e555d679daa22a5b9ccbf600d21b2fb1 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Wed, 30 Jun 2021 11:02:37 +0900 Subject: [PATCH] cleanup --- ethereum/rpc/namespaces/eth/api.go | 42 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/ethereum/rpc/namespaces/eth/api.go b/ethereum/rpc/namespaces/eth/api.go index 2c95cfa83b..7fe3cbd726 100644 --- a/ethereum/rpc/namespaces/eth/api.go +++ b/ethereum/rpc/namespaces/eth/api.go @@ -257,9 +257,9 @@ func (e *PublicAPI) GetTransactionCount(address common.Address, blockNum rpctype } includePending := blockNum == rpctypes.EthPendingBlockNumber - nonce, error := getAccountNonce(e.clientCtx, e.backend, address, includePending, e.logger) - if error != nil { - return nil, error + nonce, err := getAccountNonce(e.clientCtx, e.backend, address, includePending, e.logger) + if err != nil { + return nil, err } n := hexutil.Uint64(nonce) @@ -1089,24 +1089,26 @@ func getAccountNonce(ctx client.Context, backend backend.Backend, accAddr common return 0, err } - if pending { - // the account retriever doesn't include the uncommitted transactions on the nonce so we need to - // to manually add them. - pendingTxs, err := backend.PendingTransactions() - if err != nil { - logger.Errorln("fails to fetch pending transactions") - return nonce, nil - } + if !pending { + return nonce, nil + } - // add the uncommitted txs to the nonce counter - if len(pendingTxs) != 0 { - for i := range pendingTxs { - if pendingTxs[i] == nil { - continue - } - if pendingTxs[i].From == accAddr { - nonce++ - } + // the account retriever doesn't include the uncommitted transactions on the nonce so we need to + // to manually add them. + pendingTxs, err := backend.PendingTransactions() + if err != nil { + logger.Errorln("fails to fetch pending transactions") + return nonce, nil + } + + // add the uncommitted txs to the nonce counter + if len(pendingTxs) != 0 { + for i := range pendingTxs { + if pendingTxs[i] == nil { + continue + } + if pendingTxs[i].From == accAddr { + nonce++ } } }