diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-06-22 10:51:00 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-06-22 10:51:00 +0800 |
commit | 92df9965ebd4a833817c32fd32f7e4533ec7fe19 (patch) | |
tree | e7fdeb325f6bdd9ad57941d3c8d95e7a341afdb5 /app/scripts/lib/nonce-tracker.js | |
parent | fa8c74fe9b19229580224815cc131611ee29027c (diff) | |
download | tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar.gz tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar.bz2 tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar.lz tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar.xz tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.tar.zst tangerine-wallet-browser-92df9965ebd4a833817c32fd32f7e4533ec7fe19.zip |
fix nonceTracker
Diffstat (limited to 'app/scripts/lib/nonce-tracker.js')
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index ff2317a91..4ea511dec 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -2,7 +2,7 @@ const EthQuery = require('eth-query') class NonceTracker { - constructor({ blockTracker, provider, getPendingTransactions }) { + constructor ({ blockTracker, provider, getPendingTransactions }) { this.blockTracker = blockTracker this.ethQuery = new EthQuery(provider) this.getPendingTransactions = getPendingTransactions @@ -11,7 +11,7 @@ class NonceTracker { // releaseLock must be called // releaseLock must be called after adding signed tx to pending transactions (or discarding) - async getNonceLock(address) { + async getNonceLock (address) { // await lock free await this.lockMap[address] // take lock @@ -21,12 +21,12 @@ class NonceTracker { const blockNumber = currentBlock.number const pendingTransactions = this.getPendingTransactions(address) const baseCount = await this._getTxCount(address, blockNumber) - const nextNonce = parseInt(baseCount) + pendingTransactions.length + 1 + const nextNonce = parseInt(baseCount) + pendingTransactions.length // return next nonce and release cb return { nextNonce: nextNonce.toString(16), releaseLock } } - async _getCurrentBlock() { + async _getCurrentBlock () { const currentBlock = this.blockTracker.getCurrentBlock() if (currentBlock) return currentBlock return await Promise((reject, resolve) => { @@ -34,15 +34,13 @@ class NonceTracker { }) } - _takeLock(lockId) { + _takeLock (lockId) { let releaseLock = null // create and store lock const lock = new Promise((resolve, reject) => { releaseLock = resolve }) this.lockMap[lockId] = lock // setup lock teardown - lock.then(() => { - delete this.lockMap[lockId] - }) + lock.then(() => delete this.lockMap[lockId]) return releaseLock } |