diff options
author | Kevin Serrano <kevin.serrano@consensys.net> | 2017-10-10 02:54:16 +0800 |
---|---|---|
committer | Kevin Serrano <kevin.serrano@consensys.net> | 2017-10-10 02:54:16 +0800 |
commit | 5ae5ee9a2080017d56f7096a8fe5bef54368603a (patch) | |
tree | 41059e0891f120754ab08f8629fb3093db4dbe5c /app/scripts/lib/pending-tx-tracker.js | |
parent | e557d7f7563d6e9ac9a9a98f012a324ce3c0881a (diff) | |
parent | 4a4338c1f4669f621fc39d34b06a77f247c7ce65 (diff) | |
download | tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar.gz tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar.bz2 tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar.lz tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar.xz tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.tar.zst tangerine-wallet-browser-5ae5ee9a2080017d56f7096a8fe5bef54368603a.zip |
Merge branch 'master' into precision-fix
Diffstat (limited to 'app/scripts/lib/pending-tx-tracker.js')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 21 |
1 files changed, 21 insertions, 0 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 + } + } |