aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-19 06:01:05 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-19 06:01:05 +0800
commitf8eca95ca513c6d8af8e599ce143ae0e78b77e26 (patch)
tree429e4c88d948cc939e6aaff5bb95fd9586d0f100
parenta5a32f3d5742972586893741847ea4516afa19ac (diff)
downloadtangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar.gz
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar.bz2
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar.lz
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar.xz
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.tar.zst
tangerine-wallet-browser-f8eca95ca513c6d8af8e599ce143ae0e78b77e26.zip
include pendingTxs in localNonce
-rw-r--r--app/scripts/lib/nonce-tracker.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index 3a26c374c..a4ee5c38f 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -29,14 +29,10 @@ class NonceTracker {
// calculate next nonce
// we need to make sure our base count
// and pending count are from the same block
- const localNonceHex = this._getLocalNonce(address)
+ const localNonceHex = this._getHighestLocalNonce(address)
let localNonce = parseInt(localNonceHex, 16)
- try {
- assert(Number.isInteger(localNonce), `nonce-tracker - localNonce is not an integer - got: (${typeof localNonce}) "${localNonce}"`)
- } catch (e) {
- // throw out localNonce if not a number
- localNonce = 0
- }
+ // 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
@@ -44,7 +40,8 @@ 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}"`)
- const nextNonce = Math.max(baseCount, localNonce + 1) + pendingCount
+ if (localNonce) ++localNonce
+ const nextNonce = Math.max(baseCount + pendingCount, localNonce)
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
@@ -92,9 +89,11 @@ class NonceTracker {
return mutex
}
- _getLocalNonce (address) {
+ _getHighestLocalNonce (address) {
const confirmedTransactions = this.getConfirmedTransactions(address)
- const localNonces = confirmedTransactions.map((txMeta) => txMeta.txParams.nonce)
+ const pendingTransactions = this.getPendingTransactions(address)
+ const transactions = confirmedTransactions.concat(pendingTransactions)
+ const localNonces = transactions.map((txMeta) => txMeta.txParams.nonce)
return localNonces.reduce((nonce, highestNonce) => {
return parseInt(nonce, 16) > parseInt(highestNonce, 16) ? nonce : highestNonce
}, '0x0')