aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-08-23 05:15:56 +0800
committerkumavis <aaron@kumavis.me>2017-08-23 05:15:56 +0800
commita7e3dc83272d795a48ee7e10c2588a18affbe72e (patch)
tree34f8357c82e3c0ea8addc56a685497187c779dc4 /app
parente43da3e4aa703cf49543df7726b8cbeea987943d (diff)
downloadtangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar.gz
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar.bz2
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar.lz
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar.xz
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.tar.zst
tangerine-wallet-browser-a7e3dc83272d795a48ee7e10c2588a18affbe72e.zip
nonce-tracker - simplify _getlocalNextNonce
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/nonce-tracker.js49
1 files changed, 29 insertions, 20 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index dab6ace1f..0fb245f7b 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -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) {