mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1828 from MetaMask/betterErrorsOnTx
Nonce Tracker - better error messages, more debug info in tx history data
This commit is contained in:
commit
bbeecbbb28
@ -200,8 +200,12 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
// get next nonce
|
// get next nonce
|
||||||
const txMeta = this.getTx(txId)
|
const txMeta = this.getTx(txId)
|
||||||
const fromAddress = txMeta.txParams.from
|
const fromAddress = txMeta.txParams.from
|
||||||
|
// wait for a nonce
|
||||||
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
|
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
|
||||||
|
// add nonce to txParams
|
||||||
txMeta.txParams.nonce = nonceLock.nextNonce
|
txMeta.txParams.nonce = nonceLock.nextNonce
|
||||||
|
// add nonce debugging information to txMeta
|
||||||
|
txMeta.nonceDetails = nonceLock.nonceDetails
|
||||||
this.updateTx(txMeta)
|
this.updateTx(txMeta)
|
||||||
// sign transaction
|
// sign transaction
|
||||||
const rawTx = await this.signTransaction(txId)
|
const rawTx = await this.signTransaction(txId)
|
||||||
|
@ -31,14 +31,17 @@ class NonceTracker {
|
|||||||
const currentBlock = await this._getCurrentBlock()
|
const currentBlock = await this._getCurrentBlock()
|
||||||
const pendingTransactions = this.getPendingTransactions(address)
|
const pendingTransactions = this.getPendingTransactions(address)
|
||||||
const pendingCount = pendingTransactions.length
|
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 baseCountHex = await this._getTxCount(address, currentBlock)
|
||||||
const baseCount = parseInt(baseCountHex, 16)
|
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
|
const nextNonce = baseCount + pendingCount
|
||||||
assert(Number.isInteger(nextNonce), 'nonce-tracker - nextNonce is an integer')
|
assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
|
||||||
// return next nonce and release cb
|
// collect the numbers used to calculate the nonce for debugging
|
||||||
return { nextNonce, releaseLock }
|
const blockNumber = currentBlock.number
|
||||||
|
const nonceDetails = { blockNumber, baseCount, pendingCount }
|
||||||
|
// return nonce and release cb
|
||||||
|
return { nextNonce, nonceDetails, releaseLock }
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getCurrentBlock () {
|
async _getCurrentBlock () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user