aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-07-19 03:48:16 +0800
committerkumavis <aaron@kumavis.me>2017-07-19 03:48:16 +0800
commit4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8 (patch)
treecec3da1182b72b0f6cda2091b9086dac7b0da102 /app
parent1e718505824f5ee566138edb6de1f914397100b6 (diff)
downloadtangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar.gz
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar.bz2
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar.lz
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar.xz
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.tar.zst
tangerine-wallet-browser-4f9fc8014a1830c9ec7bd35b77f5ee4f5a089fb8.zip
nonce-tracker - validate nonce calc components
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/nonce-tracker.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index ab2893b10..cea798915 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -1,4 +1,5 @@
const EthQuery = require('eth-query')
+const assert = require('assert')
class NonceTracker {
@@ -21,10 +22,15 @@ class NonceTracker {
// and pending count are from the same block
const currentBlock = await this._getCurrentBlock()
const pendingTransactions = this.getPendingTransactions(address)
- const baseCount = await this._getTxCount(address, currentBlock)
- const nextNonce = parseInt(baseCount) + pendingTransactions.length
+ const pendingCount = pendingTransactions.length
+ assert(Number.isInteger(pendingCount), 'nonce-tracker - pendingCount is an integer')
+ const baseCountHex = await this._getTxCount(address, currentBlock)
+ const baseCount = parseInt(baseCountHex, 16)
+ assert(Number.isInteger(baseCount), 'nonce-tracker - baseCount is an integer')
+ const nextNonce = baseCount + pendingCount
+ assert(Number.isInteger(nextNonce), 'nonce-tracker - nextNonce is an integer')
// return next nonce and release cb
- return { nextNonce: nextNonce.toString(16), releaseLock }
+ return { nextNonce: '0x' + nextNonce.toString(16), releaseLock }
}
async _getCurrentBlock () {