mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
nonce-tracker - simplify _getlocalNextNonce
This commit is contained in:
parent
e43da3e4aa
commit
a7e3dc8327
@ -94,30 +94,39 @@ class NonceTracker {
|
||||
}
|
||||
|
||||
async _getlocalNextNonce (address) {
|
||||
const confirmedTransactions = this.getConfirmedTransactions(address)
|
||||
const pendingTransactions = this.getPendingTransactions(address)
|
||||
const transactions = confirmedTransactions.concat(pendingTransactions)
|
||||
const highestNonce = this._getHighestNonce(transactions)
|
||||
let localNonce = highestNonce
|
||||
// throw out localNonce if not a number
|
||||
if (!Number.isInteger(highestNonce)) localNonce = 0
|
||||
const pendingCount = this._getPendingTransactionCount(address)
|
||||
const confirmedCount = confirmedTransactions.length
|
||||
if (
|
||||
// the local nonce is not 0
|
||||
localNonce ||
|
||||
// or their are pending or confirmed transactions
|
||||
pendingCount ||
|
||||
confirmedCount
|
||||
) ++localNonce
|
||||
const nonceDetails = { highestNonce, localNonce, pendingCount, confirmedCount }
|
||||
return { name: 'local', nonce: localNonce, details: nonceDetails }
|
||||
let nextNonce
|
||||
// check our local tx history for the highest nonce (if any)
|
||||
const highestNonce = this._getLocalHighestNonce(address)
|
||||
const haveHighestNonce = Number.isInteger(highestNonce)
|
||||
if (haveHighestNonce) {
|
||||
// next nonce is the nonce after our last
|
||||
nextNonce = highestNonce + 1
|
||||
} else {
|
||||
// no local tx history so next must be first (zero)
|
||||
nextNonce = 0
|
||||
}
|
||||
const nonceDetails = { highestNonce }
|
||||
return { name: 'local', nonce: nextNonce, details: nonceDetails }
|
||||
}
|
||||
|
||||
_getLocalPendingNonce (address) {
|
||||
const pendingTransactions = this.getPendingTransactions(address)
|
||||
const localNonce = this._getHighestNonce(pendingTransactions)
|
||||
return localNonce
|
||||
const highestNonce = this._getHighestNonce(pendingTransactions)
|
||||
return highestNonce
|
||||
}
|
||||
|
||||
_getLocalConfirmedNonce (address) {
|
||||
const pendingTransactions = this.getConfirmedTransactions(address)
|
||||
const highestNonce = this._getHighestNonce(pendingTransactions)
|
||||
return highestNonce
|
||||
}
|
||||
|
||||
_getLocalHighestNonce (address) {
|
||||
const confirmedTransactions = this.getConfirmedTransactions(address)
|
||||
const pendingTransactions = this.getPendingTransactions(address)
|
||||
const transactions = confirmedTransactions.concat(pendingTransactions)
|
||||
const highestNonce = this._getHighestNonce(transactions)
|
||||
return highestNonce
|
||||
}
|
||||
|
||||
_getPendingTransactionCount (address) {
|
||||
|
Loading…
Reference in New Issue
Block a user