diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2017-10-07 05:03:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-07 05:03:04 +0800 |
commit | 0c61695656054d5da43a8bfb10d7a15cb2958d81 (patch) | |
tree | fa5b4d2789235ea23275e6e5bab08eb434e52eb8 /app/scripts/lib | |
parent | 52bfed5d13846326fbd8940dbb7c91a4f399b190 (diff) | |
parent | fa11bbf99673bb6b2dd4ad5f291d63ff1358fda6 (diff) | |
download | tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar.gz tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar.bz2 tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar.lz tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar.xz tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.tar.zst tangerine-wallet-browser-0c61695656054d5da43a8bfb10d7a15cb2958d81.zip |
Merge branch 'master' into SignTypedData
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 21 | ||||
-rw-r--r-- | app/scripts/lib/tx-state-manager.js | 8 |
2 files changed, 28 insertions, 1 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js index 8a626e222..df504c126 100644 --- a/app/scripts/lib/pending-tx-tracker.js +++ b/app/scripts/lib/pending-tx-tracker.js @@ -25,7 +25,9 @@ module.exports = class PendingTransactionTracker extends EventEmitter { // default is one day this.retryTimePeriod = config.retryTimePeriod || 86400000 this.getPendingTransactions = config.getPendingTransactions + this.getCompletedTransactions = config.getCompletedTransactions this.publishTransaction = config.publishTransaction + this._checkPendingTxs() } // checks if a signed tx is in a block and @@ -120,6 +122,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter { async _checkPendingTx (txMeta) { const txHash = txMeta.hash const txId = txMeta.id + // extra check in case there was an uncaught error during the // signature and submission process if (!txHash) { @@ -128,6 +131,15 @@ module.exports = class PendingTransactionTracker extends EventEmitter { this.emit('tx:failed', txId, noTxHashErr) return } + + // If another tx with the same nonce is mined, set as failed. + const taken = await this._checkIfNonceIsTaken(txMeta) + if (taken) { + const nonceTakenErr = new Error('Another transaction with this nonce has been mined.') + nonceTakenErr.name = 'NonceTakenErr' + return this.emit('tx:failed', txId, nonceTakenErr) + } + // get latest transaction status let txParams try { @@ -159,4 +171,13 @@ module.exports = class PendingTransactionTracker extends EventEmitter { } nonceGlobalLock.releaseLock() } + + async _checkIfNonceIsTaken (txMeta) { + const completed = this.getCompletedTransactions() + const sameNonce = completed.filter((otherMeta) => { + return otherMeta.txParams.nonce === txMeta.txParams.nonce + }) + return sameNonce.length > 0 + } + } diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index cf8117864..2250403f6 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -46,6 +46,12 @@ module.exports = class TransactionStateManger extends EventEmitter { return this.getFilteredTxList(opts) } + getConfirmedTransactions (address) { + const opts = { status: 'confirmed' } + if (address) opts.from = address + return this.getFilteredTxList(opts) + } + addTx (txMeta) { this.once(`${txMeta.id}:signed`, function (txId) { this.removeAllListeners(`${txMeta.id}:rejected`) @@ -242,4 +248,4 @@ module.exports = class TransactionStateManger extends EventEmitter { _saveTxList (transactions) { this.store.updateState({ transactions }) } -}
\ No newline at end of file +} |