aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-07-28 06:10:02 +0800
committerDan Finlay <dan@danfinlay.com>2017-07-28 06:10:02 +0800
commitf8cadbcb323f2d41d6a2cad78479917f20b113bd (patch)
tree3f1dc1e4d399b26ef929d4a0d51ded3c11c814fc /app/scripts/lib
parent8ba32d5ea8cbd30b85cade9fccaaa6c0f3f5cd04 (diff)
parente3b5bb2052d59afbf9c2761af883de719261062e (diff)
downloadtangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.gz
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.tar.zst
tangerine-wallet-browser-f8cadbcb323f2d41d6a2cad78479917f20b113bd.zip
Merge branch 'master' into NewUI
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/nonce-tracker.js28
-rw-r--r--app/scripts/lib/util.js8
2 files changed, 27 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
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
new file mode 100644
index 000000000..bddd60ee8
--- /dev/null
+++ b/app/scripts/lib/util.js
@@ -0,0 +1,8 @@
+module.exports = {
+ getStack,
+}
+
+function getStack () {
+ const stack = new Error('Stack trace generator - not an error').stack
+ return stack
+}