diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-08-19 06:44:32 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-08-19 06:44:32 +0800 |
commit | 37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2 (patch) | |
tree | 3a255fe683da290c2cd6571114e191f7211a3783 /app | |
parent | f8eca95ca513c6d8af8e599ce143ae0e78b77e26 (diff) | |
download | tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar.gz tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar.bz2 tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar.lz tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar.xz tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.tar.zst tangerine-wallet-browser-37f86e874f8c3c3d5f6d78cd8abeb0c835f20ae2.zip |
fix 0x0 nonce calc.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index a4ee5c38f..3063209ee 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -29,10 +29,8 @@ class NonceTracker { // calculate next nonce // we need to make sure our base count // and pending count are from the same block - const localNonceHex = this._getHighestLocalNonce(address) - let localNonce = parseInt(localNonceHex, 16) + const localNextNonce = this._getLocalNextNonce(address) // throw out localNonce if not a number - if (!Number.isInteger(localNonce)) localNonce = 0 const currentBlock = await this._getCurrentBlock() const pendingTransactions = this.getPendingTransactions(address) const pendingCount = pendingTransactions.length @@ -40,12 +38,11 @@ class NonceTracker { const baseCountHex = await this._getTxCount(address, currentBlock) const baseCount = parseInt(baseCountHex, 16) assert(Number.isInteger(baseCount), `nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`) - if (localNonce) ++localNonce - const nextNonce = Math.max(baseCount + pendingCount, localNonce) + const nextNonce = Math.max(baseCount + pendingCount, localNextNonce) assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`) // collect the numbers used to calculate the nonce for debugging const blockNumber = currentBlock.number - const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount, localNonceHex, localNonce } + const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount, localNextNonce } // return nonce and release cb return { nextNonce, nonceDetails, releaseLock } } @@ -89,14 +86,27 @@ class NonceTracker { return mutex } - _getHighestLocalNonce (address) { + // _getNetworkNonce (address) { + + // } + + _getLocalNextNonce (address) { const confirmedTransactions = this.getConfirmedTransactions(address) const pendingTransactions = this.getPendingTransactions(address) const transactions = confirmedTransactions.concat(pendingTransactions) const localNonces = transactions.map((txMeta) => txMeta.txParams.nonce) - return localNonces.reduce((nonce, highestNonce) => { + const localNonceHex = localNonces.reduce((nonce, highestNonce) => { return parseInt(nonce, 16) > parseInt(highestNonce, 16) ? nonce : highestNonce }, '0x0') + let localNonce = parseInt(localNonceHex, 16) + if ( + // the local nonce is not 0 + localNonce || + // or their are pending or confirmed transactions + pendingTransactions.length || + confirmedTransactions.length + ) ++localNonce + return localNonce } // this is a hotfix for the fact that the blockTracker will |