aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2018-03-08 14:01:14 +0800
committerfrankiebee <frankie.diamond@gmail.com>2018-03-08 14:01:14 +0800
commit4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c (patch)
tree3054c83ff74d8fe70a8095c027ddb674dd209822 /app
parent8adb03074c6315b4bdcffdd22abca2c84c7a6985 (diff)
downloadtangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar.gz
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar.bz2
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar.lz
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar.xz
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.tar.zst
tangerine-wallet-browser-4a3288fec9ae7bd717b539d9bfcb8d5ba5b1ef8c.zip
transactions - make _markNonceDuplicatesDropped
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/transactions.js41
1 files changed, 20 insertions, 21 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index aad3f9952..e903c73e8 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -91,21 +91,7 @@ module.exports = class TransactionController extends EventEmitter {
this.pendingTxTracker.on('tx:warning', (txMeta) => {
this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:warning')
})
- this.pendingTxTracker.on('tx:confirmed', (txId) => {
- this.txStateManager.setTxStatusConfirmed(txId)
- // get the confirmed transactions nonce and from address
- const txMeta = this.txStateManager.getTx(txId)
- const { nonce, from } = txMeta.txParams
- const sameNonceTxs = this.txStateManager.getFilteredTxList({nonce, from})
- if (!sameNonceTxs.length) return
- // mark all same nonce transactions as dropped and give i a replacedBy hash
- sameNonceTxs.forEach((otherTxMeta) => {
- if (otherTxMeta === txId) return
- otherTxMeta.replacedBy = txMeta.hash
- this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:confirmed reference to confirmed txHash with same nonce')
- this.txStateManager.setTxStatusDropped(otherTxMeta.id)
- })
- })
+ this.pendingTxTracker.on('tx:confirmed', (txId) => this._markNonceDuplicatesDropped(txId))
this.pendingTxTracker.on('tx:failed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))
this.pendingTxTracker.on('tx:block-update', (txMeta, latestBlockNumber) => {
if (!txMeta.firstRetryBlockNumber) {
@@ -238,7 +224,6 @@ module.exports = class TransactionController extends EventEmitter {
txParams: originalTxMeta.txParams,
lastGasPrice,
loadingDefaults: false,
- nonceSpecified: true,
})
this.addTx(txMeta)
this.emit('newUnapprovedTx', txMeta)
@@ -264,11 +249,9 @@ module.exports = class TransactionController extends EventEmitter {
// wait for a nonce
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
// add nonce to txParams
- const nonce = txMeta.nonceSpecified ? txMeta.txParams.nonce : nonceLock.nextNonce
- if (nonce > nonceLock.nextNonce) {
- const message = `Specified nonce may not be larger than account's next valid nonce.`
- throw new Error(message)
- }
+ // if txMeta has lastGasPrice then it is a retry at same nonce with higher
+ // gas price transaction and their for the nonce should not be calculated
+ const nonce = txMeta.lastGasPrice ? txMeta.txParams.nonce : nonceLock.nextNonce
txMeta.txParams.nonce = ethUtil.addHexPrefix(nonce.toString(16))
// add nonce debugging information to txMeta
txMeta.nonceDetails = nonceLock.nonceDetails
@@ -325,6 +308,22 @@ module.exports = class TransactionController extends EventEmitter {
// PRIVATE METHODS
//
+ _markNonceDuplicatesDropped (txId) {
+ this.txStateManager.setTxStatusConfirmed(txId)
+ // get the confirmed transactions nonce and from address
+ const txMeta = this.txStateManager.getTx(txId)
+ const { nonce, from } = txMeta.txParams
+ const sameNonceTxs = this.txStateManager.getFilteredTxList({nonce, from})
+ if (!sameNonceTxs.length) return
+ // mark all same nonce transactions as dropped and give i a replacedBy hash
+ sameNonceTxs.forEach((otherTxMeta) => {
+ if (otherTxMeta === txId) return
+ otherTxMeta.replacedBy = txMeta.hash
+ this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:confirmed reference to confirmed txHash with same nonce')
+ this.txStateManager.setTxStatusDropped(otherTxMeta.id)
+ })
+ }
+
_updateMemstore () {
const unapprovedTxs = this.txStateManager.getUnapprovedTxList()
const selectedAddressTxList = this.txStateManager.getFilteredTxList({