1
0
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:
kumavis 2017-08-22 14:15:56 -07:00
parent e43da3e4aa
commit a7e3dc8327

View File

@ -94,30 +94,39 @@ class NonceTracker {
} }
async _getlocalNextNonce (address) { async _getlocalNextNonce (address) {
const confirmedTransactions = this.getConfirmedTransactions(address) let nextNonce
const pendingTransactions = this.getPendingTransactions(address) // check our local tx history for the highest nonce (if any)
const transactions = confirmedTransactions.concat(pendingTransactions) const highestNonce = this._getLocalHighestNonce(address)
const highestNonce = this._getHighestNonce(transactions) const haveHighestNonce = Number.isInteger(highestNonce)
let localNonce = highestNonce if (haveHighestNonce) {
// throw out localNonce if not a number // next nonce is the nonce after our last
if (!Number.isInteger(highestNonce)) localNonce = 0 nextNonce = highestNonce + 1
const pendingCount = this._getPendingTransactionCount(address) } else {
const confirmedCount = confirmedTransactions.length // no local tx history so next must be first (zero)
if ( nextNonce = 0
// the local nonce is not 0 }
localNonce || const nonceDetails = { highestNonce }
// or their are pending or confirmed transactions return { name: 'local', nonce: nextNonce, details: nonceDetails }
pendingCount ||
confirmedCount
) ++localNonce
const nonceDetails = { highestNonce, localNonce, pendingCount, confirmedCount }
return { name: 'local', nonce: localNonce, details: nonceDetails }
} }
_getLocalPendingNonce (address) { _getLocalPendingNonce (address) {
const pendingTransactions = this.getPendingTransactions(address) const pendingTransactions = this.getPendingTransactions(address)
const localNonce = this._getHighestNonce(pendingTransactions) const highestNonce = this._getHighestNonce(pendingTransactions)
return localNonce 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) { _getPendingTransactionCount (address) {