mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2233 from MetaMask/remove-accountTracker-from-transactions
pending-tx - dont check the balance to rebrodcast
This commit is contained in:
commit
7bdf73b1dd
@ -32,7 +32,6 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
this.provider = opts.provider
|
||||
this.blockTracker = opts.blockTracker
|
||||
this.signEthTx = opts.signTransaction
|
||||
this.accountTracker = opts.accountTracker
|
||||
|
||||
this.memStore = new ObservableStore({})
|
||||
this.query = new EthQuery(this.provider)
|
||||
@ -61,11 +60,6 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
provider: this.provider,
|
||||
nonceTracker: this.nonceTracker,
|
||||
retryLimit: 3500, // Retry 3500 blocks, or about 1 day.
|
||||
getBalance: (address) => {
|
||||
const account = this.accountTracker.store.getState().accounts[address]
|
||||
if (!account) return
|
||||
return account.balance
|
||||
},
|
||||
publishTransaction: (rawTx) => this.query.sendRawTransaction(rawTx),
|
||||
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
|
||||
})
|
||||
@ -84,10 +78,7 @@ module.exports = class TransactionController extends EventEmitter {
|
||||
this.blockTracker.on('block', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker))
|
||||
// this is a little messy but until ethstore has been either
|
||||
// removed or redone this is to guard against the race condition
|
||||
// where accountTracker hasent been populated by the results yet
|
||||
this.blockTracker.once('latest', () => {
|
||||
this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker))
|
||||
})
|
||||
this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker))
|
||||
this.blockTracker.on('sync', this.pendingTxTracker.queryPendingTxs.bind(this.pendingTxTracker))
|
||||
// memstore is computed from a few different stores
|
||||
this._updateMemstore()
|
||||
|
@ -1,6 +1,5 @@
|
||||
const EventEmitter = require('events')
|
||||
const EthQuery = require('ethjs-query')
|
||||
const sufficientBalance = require('./util').sufficientBalance
|
||||
/*
|
||||
|
||||
Utility class for tracking the transactions as they
|
||||
@ -12,7 +11,6 @@ const sufficientBalance = require('./util').sufficientBalance
|
||||
requires a: {
|
||||
provider: //,
|
||||
nonceTracker: //see nonce tracker,
|
||||
getBalnce: //(address) a function for getting balances,
|
||||
getPendingTransactions: //() a function for getting an array of transactions,
|
||||
publishTransaction: //(rawTx) a async function for publishing raw transactions,
|
||||
}
|
||||
@ -25,7 +23,6 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
|
||||
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
|
||||
}
|
||||
@ -99,23 +96,11 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
|
||||
}
|
||||
|
||||
async _resubmitTx (txMeta) {
|
||||
const address = txMeta.txParams.from
|
||||
const balance = this.getBalance(address)
|
||||
if (balance === undefined) return
|
||||
|
||||
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('tx:failed', txMeta.id, insufficientFundsError)
|
||||
log.error(insufficientFundsError)
|
||||
return
|
||||
}
|
||||
|
||||
// Only auto-submit already-signed txs:
|
||||
if (!('rawTx' in txMeta)) return
|
||||
|
||||
|
@ -132,7 +132,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
provider: this.provider,
|
||||
blockTracker: this.blockTracker,
|
||||
ethQuery: this.ethQuery,
|
||||
accountTracker: this.accountTracker,
|
||||
})
|
||||
this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts))
|
||||
|
||||
|
@ -40,14 +40,12 @@ describe('PendingTransactionTracker', function () {
|
||||
|
||||
pendingTxTracker = new PendingTransactionTracker({
|
||||
provider,
|
||||
getBalance: () => {},
|
||||
nonceTracker: {
|
||||
getGlobalLock: async () => {
|
||||
return { releaseLock: () => {} }
|
||||
}
|
||||
},
|
||||
getPendingTransactions: () => {return []},
|
||||
sufficientBalance: () => {},
|
||||
publishTransaction: () => {},
|
||||
})
|
||||
})
|
||||
@ -213,30 +211,7 @@ describe('PendingTransactionTracker', function () {
|
||||
pendingTxTracker.resubmitPendingTxs()
|
||||
})
|
||||
})
|
||||
describe('#_resubmitTx with a too-low balance', function () {
|
||||
it('should return before publishing the transaction because to low of balance', function (done) {
|
||||
const lowBalance = '0x0'
|
||||
pendingTxTracker.getBalance = (address) => {
|
||||
assert.equal(address, txMeta.txParams.from, 'Should pass the address')
|
||||
return lowBalance
|
||||
}
|
||||
pendingTxTracker.publishTransaction = async (rawTx) => {
|
||||
done(new Error('tried to publish transaction'))
|
||||
}
|
||||
|
||||
// Stubbing out current account state:
|
||||
// Adding the fake tx:
|
||||
pendingTxTracker.once('tx:failed', (txId, err) => {
|
||||
assert(err, 'Should have a error')
|
||||
done()
|
||||
})
|
||||
pendingTxTracker._resubmitTx(txMeta)
|
||||
.catch((err) => {
|
||||
assert.ifError(err, 'should not throw an error')
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#_resubmitTx', function () {
|
||||
it('should publishing the transaction', function (done) {
|
||||
const enoughBalance = '0x100000'
|
||||
pendingTxTracker.getBalance = (address) => {
|
||||
|
@ -25,7 +25,6 @@ describe('Transaction Controller', function () {
|
||||
networkStore: new ObservableStore(currentNetworkId),
|
||||
txHistoryLimit: 10,
|
||||
blockTracker: { getCurrentBlock: noop, on: noop, once: noop },
|
||||
accountTracker: { store: { getState: noop } },
|
||||
signTransaction: (ethTx) => new Promise((resolve) => {
|
||||
ethTx.sign(privKey)
|
||||
resolve()
|
||||
@ -383,30 +382,6 @@ describe('Transaction Controller', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getBalance', function () {
|
||||
it('gets balance', function () {
|
||||
sinon.stub(txController.accountTracker.store, 'getState').callsFake(() => {
|
||||
return {
|
||||
accounts: {
|
||||
'0x1678a085c290ebd122dc42cba69373b5953b831d': {
|
||||
address: '0x1678a085c290ebd122dc42cba69373b5953b831d',
|
||||
balance: '0x00000000000000056bc75e2d63100000',
|
||||
code: '0x',
|
||||
nonce: '0x0',
|
||||
},
|
||||
'0xc684832530fcbddae4b4230a47e991ddcec2831d': {
|
||||
address: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
|
||||
balance: '0x0',
|
||||
code: '0x',
|
||||
nonce: '0x0',
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
assert.equal(txController.pendingTxTracker.getBalance('0x1678a085c290ebd122dc42cba69373b5953b831d'), '0x00000000000000056bc75e2d63100000')
|
||||
assert.equal(txController.pendingTxTracker.getBalance('0xc684832530fcbddae4b4230a47e991ddcec2831d'), '0x0')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getPendingTransactions', function () {
|
||||
beforeEach(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user