aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/nonce-tracker.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-08-04 06:05:32 +0800
committerkumavis <aaron@kumavis.me>2017-08-04 06:05:32 +0800
commitda16f396266daa5ab0acc8f0c04d3e25b98c39f0 (patch)
tree44fad3fc645ac8165e4832259d8c6fe43196bccb /app/scripts/lib/nonce-tracker.js
parentda7471e0958d30b4465ef35090dbfa05b85471f0 (diff)
downloadtangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.tar.gz
tangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.tar.zst
tangerine-wallet-browser-da16f396266daa5ab0acc8f0c04d3e25b98c39f0.zip
Merge branch 'master' of github.com:MetaMask/metamask-extension into greenkeeper/initial
Diffstat (limited to 'app/scripts/lib/nonce-tracker.js')
-rw-r--r--app/scripts/lib/nonce-tracker.js28
1 files changed, 19 insertions, 9 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index b76dac4e8..8328e81ec 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -4,8 +4,8 @@ const Mutex = require('await-semaphore').Mutex
class NonceTracker {
- constructor ({ blockTracker, provider, getPendingTransactions }) {
- this.blockTracker = blockTracker
+ constructor ({ provider, getPendingTransactions }) {
+ this.provider = provider
this.ethQuery = new EthQuery(provider)
this.getPendingTransactions = getPendingTransactions
this.lockMap = {}
@@ -31,21 +31,25 @@ class NonceTracker {
const currentBlock = await this._getCurrentBlock()
const pendingTransactions = this.getPendingTransactions(address)
const pendingCount = pendingTransactions.length
- assert(Number.isInteger(pendingCount), 'nonce-tracker - pendingCount is an integer')
+ assert(Number.isInteger(pendingCount), `nonce-tracker - pendingCount is not an integer - got: (${typeof pendingCount}) "${pendingCount}"`)
const baseCountHex = await this._getTxCount(address, currentBlock)
const baseCount = parseInt(baseCountHex, 16)
- assert(Number.isInteger(baseCount), 'nonce-tracker - baseCount is an integer')
+ assert(Number.isInteger(baseCount), `nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`)
const nextNonce = baseCount + pendingCount
- assert(Number.isInteger(nextNonce), 'nonce-tracker - nextNonce is an integer')
- // return next nonce and release cb
- return { nextNonce, releaseLock }
+ 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 }
+ // return nonce and release cb
+ return { nextNonce, nonceDetails, releaseLock }
}
async _getCurrentBlock () {
- const currentBlock = this.blockTracker.getCurrentBlock()
+ const blockTracker = this._getBlockTracker()
+ const currentBlock = blockTracker.getCurrentBlock()
if (currentBlock) return currentBlock
return await Promise((reject, resolve) => {
- this.blockTracker.once('latest', resolve)
+ blockTracker.once('latest', resolve)
})
}
@@ -79,6 +83,12 @@ class NonceTracker {
return mutex
}
+ // this is a hotfix for the fact that the blockTracker will
+ // change when the network changes
+ _getBlockTracker () {
+ return this.provider._blockTracker
+ }
+
}
module.exports = NonceTracker