diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-07-27 01:48:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 01:48:08 +0800 |
commit | bbeecbbb2892b2bc5a7e675b03a5fc5736d34287 (patch) | |
tree | 968b070a4b023af29063e823f1ee9c218c991f49 | |
parent | 5af753a597d565e4654899ea37349ba7e839bb00 (diff) | |
parent | de2cf4e9cd00ec947e265b0bff3f676c02d5a4f7 (diff) | |
download | tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar.gz tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar.bz2 tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar.lz tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar.xz tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.tar.zst tangerine-wallet-browser-bbeecbbb2892b2bc5a7e675b03a5fc5736d34287.zip |
Merge pull request #1828 from MetaMask/betterErrorsOnTx
Nonce Tracker - better error messages, more debug info in tx history data
-rw-r--r-- | app/scripts/controllers/transactions.js | 4 | ||||
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 13 |
2 files changed, 12 insertions, 5 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 5f2d75b47..d6b2b555e 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -200,8 +200,12 @@ module.exports = class TransactionController extends EventEmitter { // get next nonce const txMeta = this.getTx(txId) const fromAddress = txMeta.txParams.from + // wait for a nonce nonceLock = await this.nonceTracker.getNonceLock(fromAddress) + // add nonce to txParams txMeta.txParams.nonce = nonceLock.nextNonce + // add nonce debugging information to txMeta + txMeta.nonceDetails = nonceLock.nonceDetails this.updateTx(txMeta) // sign transaction const rawTx = await this.signTransaction(txId) diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index b76dac4e8..c0746bd87 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -31,14 +31,17 @@ 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, pendingCount } + // return nonce and release cb + return { nextNonce, nonceDetails, releaseLock } } async _getCurrentBlock () { |