diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-09-28 04:58:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-28 04:58:54 +0800 |
commit | 4404dfc5d328d57c99190dbcf034102882487177 (patch) | |
tree | 5bae6617ea10d2920983b1bb27eabf01f7da0de4 /app/scripts/lib/pending-tx-tracker.js | |
parent | b41aad6d1ae894ab89380b1c7159da8545ad935b (diff) | |
parent | 5bbea78306f13415f85159f3d23c2b69d8f2a26c (diff) | |
download | tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar.gz tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar.bz2 tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar.lz tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar.xz tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.tar.zst tangerine-wallet-browser-4404dfc5d328d57c99190dbcf034102882487177.zip |
Merge branch 'master' into direct-block-tracker
Diffstat (limited to 'app/scripts/lib/pending-tx-tracker.js')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js index 8da1253a2..b97cec9ce 100644 --- a/app/scripts/lib/pending-tx-tracker.js +++ b/app/scripts/lib/pending-tx-tracker.js @@ -1,7 +1,6 @@ const EventEmitter = require('events') const EthQuery = require('ethjs-query') const sufficientBalance = require('./util').sufficientBalance -const RETRY_LIMIT = 3500 // Retry 3500 blocks, or about 1 day. /* Utility class for tracking the transactions as they @@ -25,11 +24,10 @@ module.exports = class PendingTransactionTracker extends EventEmitter { super() this.query = new EthQuery(config.provider) this.nonceTracker = config.nonceTracker - + this.retryLimit = config.retryLimit || Infinity this.getBalance = config.getBalance this.getPendingTransactions = config.getPendingTransactions this.publishTransaction = config.publishTransaction - this.giveUpOnTransaction = config.giveUpOnTransaction } // checks if a signed tx is in a block and @@ -44,13 +42,13 @@ module.exports = class PendingTransactionTracker extends EventEmitter { if (!txHash) { const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.') noTxHashErr.name = 'NoTxHashError' - this.emit('txFailed', txId, noTxHashErr) + this.emit('tx:failed', txId, noTxHashErr) return } block.transactions.forEach((tx) => { - if (tx.hash === txHash) this.emit('txConfirmed', txId) + if (tx.hash === txHash) this.emit('tx:confirmed', txId) }) }) } @@ -96,7 +94,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter { // ignore resubmit warnings, return early if (isKnownTx) return // encountered real error - transition to error state - this.emit('txFailed', txMeta.id, err) + this.emit('tx:failed', txMeta.id, err) })) } @@ -104,16 +102,16 @@ module.exports = class PendingTransactionTracker extends EventEmitter { const address = txMeta.txParams.from const balance = this.getBalance(address) if (balance === undefined) return - if (!('retryCount' in txMeta)) txMeta.retryCount = 0 - if (txMeta.retryCount > RETRY_LIMIT) { - return this.giveUpOnTransaction(txMeta.id) + if (txMeta.retryCount > this.retryLimit) { + const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`) + return this.emit('tx:failed', txMeta.id, err) } // if the value of the transaction is greater then the balance, fail. if (!sufficientBalance(txMeta.txParams, balance)) { const insufficientFundsError = new Error('Insufficient balance during rebroadcast.') - this.emit('txFailed', txMeta.id, insufficientFundsError) + this.emit('tx:failed', txMeta.id, insufficientFundsError) log.error(insufficientFundsError) return } @@ -125,7 +123,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter { const txHash = await this.publishTransaction(rawTx) // Increment successful tries: - txMeta.retryCount++ + this.emit('tx:retry', txMeta) return txHash } @@ -137,7 +135,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter { if (!txHash) { const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.') noTxHashErr.name = 'NoTxHashError' - this.emit('txFailed', txId, noTxHashErr) + this.emit('tx:failed', txId, noTxHashErr) return } // get latest transaction status @@ -146,14 +144,14 @@ module.exports = class PendingTransactionTracker extends EventEmitter { txParams = await this.query.getTransactionByHash(txHash) if (!txParams) return if (txParams.blockNumber) { - this.emit('txConfirmed', txId) + this.emit('tx:confirmed', txId) } } catch (err) { txMeta.warning = { error: err, message: 'There was a problem loading this transaction.', } - this.emit('txWarning', txMeta) + this.emit('tx:warning', txMeta) throw err } } |