diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-08-24 10:34:20 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-08-24 10:34:20 +0800 |
commit | 1f0223d0a0b617ffaf1704210b7ed328d12c48d1 (patch) | |
tree | 80d37dceefe46a4ccc1f20f6eb31115de4eb8c0f /app/scripts | |
parent | ebe8ceeba48463b430c32c325230eb641124a3eb (diff) | |
download | tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar.gz tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar.bz2 tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar.lz tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar.xz tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.tar.zst tangerine-wallet-browser-1f0223d0a0b617ffaf1704210b7ed328d12c48d1.zip |
Simplify nonce calculation
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index 30c59fa46..db5a5327f 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -28,9 +28,9 @@ class NonceTracker { const releaseLock = await this._takeMutex(address) // evaluate multiple nextNonce strategies const nonceDetails = {} - const localNonceResult = await this._getlocalNextNonce(address) - nonceDetails.local = localNonceResult.details const networkNonceResult = await this._getNetworkNextNonce(address) + const localNonceResult = await this._getLocalNextNonce(address, networkNonceResult) + nonceDetails.local = localNonceResult.details nonceDetails.network = networkNonceResult.details const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce) assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`) @@ -81,15 +81,16 @@ class NonceTracker { return { name: 'network', nonce: baseCount, details: nonceDetails } } - async _getlocalNextNonce (address) { + async _getLocalNextNonce (address, networkNonce) { let nextNonce // check our local tx history for the highest nonce (if any) const confirmedTransactions = this.getConfirmedTransactions(address) const pendingTransactions = this.getPendingTransactions(address) const transactions = confirmedTransactions.concat(pendingTransactions) + const highestConfirmedNonce = this._getHighestNonce(confirmedTransactions) const highestPendingNonce = this._getHighestNonce(pendingTransactions) - const highestNonce = this._getHighestNonce(transactions) + const highestNonce = Math.max(highestConfirmedNonce, highestPendingNonce) const haveHighestNonce = Number.isInteger(highestNonce) if (haveHighestNonce) { |