mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
nonce-tracker - pass tests
This commit is contained in:
parent
38ba31bbe0
commit
604c91f7b2
@ -30,9 +30,11 @@ class NonceTracker {
|
|||||||
const nonceDetails = await this._getNetworkNonceAndDetails(address)
|
const nonceDetails = await this._getNetworkNonceAndDetails(address)
|
||||||
const networkNonce = nonceDetails.networkNonce
|
const networkNonce = nonceDetails.networkNonce
|
||||||
const nextNonce = Math.max(networkNonce, localNextNonce)
|
const nextNonce = Math.max(networkNonce, localNextNonce)
|
||||||
|
const currentPendingNonce = this._getLocalPendingNonce(address)
|
||||||
assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
|
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
|
// collect the numbers used to calculate the nonce for debugging
|
||||||
nonceDetails.localNextNonce = localNextNonce
|
nonceDetails.localNextNonce = localNextNonce
|
||||||
|
nonceDetails.currentPendingNonce = currentPendingNonce
|
||||||
// return nonce and release cb
|
// return nonce and release cb
|
||||||
return { nextNonce, nonceDetails, releaseLock }
|
return { nextNonce, nonceDetails, releaseLock }
|
||||||
}
|
}
|
||||||
@ -82,17 +84,14 @@ class NonceTracker {
|
|||||||
// and pending count are from the same block
|
// and pending count are from the same block
|
||||||
const currentBlock = await this._getCurrentBlock()
|
const currentBlock = await this._getCurrentBlock()
|
||||||
const blockNumber = currentBlock.blockNumber
|
const blockNumber = currentBlock.blockNumber
|
||||||
const pendingNonce = this._getLocalPendingNonce(address)
|
|
||||||
const pendingCount = this._getPendingTransactionCount(address)
|
|
||||||
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 not an integer - got: (${typeof baseCount}) "${baseCount}"`)
|
assert(Number.isInteger(baseCount), `nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`)
|
||||||
// if the nonce provided by the network is higher then a pending tx
|
// if the nonce provided by the network is higher then a pending tx
|
||||||
// toss out the pending txCount
|
// toss out the pending txCount
|
||||||
const networkNonce = pendingNonce > baseCount ? baseCount + pendingCount : baseCount
|
const networkNonce = baseCount
|
||||||
|
|
||||||
return {networkNonce, blockNumber, baseCountHex, baseCount, pendingCount, pendingNonce}
|
return {networkNonce, blockNumber, baseCountHex, baseCount}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getLocalNextNonce (address) {
|
_getLocalNextNonce (address) {
|
||||||
|
Loading…
Reference in New Issue
Block a user