diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index dab6ace1f..0fb245f7b 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -94,30 +94,39 @@ class NonceTracker { } async _getlocalNextNonce (address) { - const confirmedTransactions = this.getConfirmedTransactions(address) - const pendingTransactions = this.getPendingTransactions(address) - const transactions = confirmedTransactions.concat(pendingTransactions) - const highestNonce = this._getHighestNonce(transactions) - let localNonce = highestNonce - // throw out localNonce if not a number - if (!Number.isInteger(highestNonce)) localNonce = 0 - const pendingCount = this._getPendingTransactionCount(address) - const confirmedCount = confirmedTransactions.length - if ( - // the local nonce is not 0 - localNonce || - // or their are pending or confirmed transactions - pendingCount || - confirmedCount - ) ++localNonce - const nonceDetails = { highestNonce, localNonce, pendingCount, confirmedCount } - return { name: 'local', nonce: localNonce, details: nonceDetails } + let nextNonce + // check our local tx history for the highest nonce (if any) + const highestNonce = this._getLocalHighestNonce(address) + const haveHighestNonce = Number.isInteger(highestNonce) + if (haveHighestNonce) { + // next nonce is the nonce after our last + nextNonce = highestNonce + 1 + } else { + // no local tx history so next must be first (zero) + nextNonce = 0 + } + const nonceDetails = { highestNonce } + return { name: 'local', nonce: nextNonce, details: nonceDetails } } _getLocalPendingNonce (address) { const pendingTransactions = this.getPendingTransactions(address) - const localNonce = this._getHighestNonce(pendingTransactions) - return localNonce + const highestNonce = this._getHighestNonce(pendingTransactions) + return highestNonce + } + + _getLocalConfirmedNonce (address) { + const pendingTransactions = this.getConfirmedTransactions(address) + const highestNonce = this._getHighestNonce(pendingTransactions) + return highestNonce + } + + _getLocalHighestNonce (address) { + const confirmedTransactions = this.getConfirmedTransactions(address) + const pendingTransactions = this.getPendingTransactions(address) + const transactions = confirmedTransactions.concat(pendingTransactions) + const highestNonce = this._getHighestNonce(transactions) + return highestNonce } _getPendingTransactionCount (address) { |