mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
add a check for weather a tx is included in a block when jumping blocks
This commit is contained in:
parent
1a4f982739
commit
a10740af7e
@ -26,6 +26,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.txProviderUtils = new TxProviderUtil(this.query)
|
this.txProviderUtils = new TxProviderUtil(this.query)
|
||||||
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
|
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
|
||||||
this.blockTracker.on('block', this.resubmitPendingTxs.bind(this))
|
this.blockTracker.on('block', this.resubmitPendingTxs.bind(this))
|
||||||
|
this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this))
|
||||||
this.signEthTx = opts.signTransaction
|
this.signEthTx = opts.signTransaction
|
||||||
this.nonceLock = Semaphore(1)
|
this.nonceLock = Semaphore(1)
|
||||||
|
|
||||||
@ -369,6 +370,15 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryPendingTxs ({oldBlock, newBlock}) {
|
||||||
|
if (!oldBlock) {
|
||||||
|
this._checkPendingTxs()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const diff = Number.parseInt(newBlock.number) - Number.parseInt(oldBlock.number)
|
||||||
|
if (diff > 1) this._checkPendingTxs()
|
||||||
|
}
|
||||||
|
|
||||||
// PRIVATE METHODS
|
// PRIVATE METHODS
|
||||||
|
|
||||||
// Should find the tx in the tx list and
|
// Should find the tx in the tx list and
|
||||||
@ -443,6 +453,37 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
this.txProviderUtils.publishTransaction(rawTx, cb)
|
this.txProviderUtils.publishTransaction(rawTx, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_checkPendingTxs () {
|
||||||
|
var signedTxList = this.getFilteredTxList({status: 'submitted'})
|
||||||
|
if (!signedTxList.length) return
|
||||||
|
signedTxList.forEach((txMeta) => {
|
||||||
|
var txHash = txMeta.hash
|
||||||
|
var txId = txMeta.id
|
||||||
|
if (!txHash) {
|
||||||
|
const errReason = {
|
||||||
|
errCode: 'No hash was provided',
|
||||||
|
message: 'We had an error while submitting this transaction, please try again.',
|
||||||
|
}
|
||||||
|
return this.setTxStatusFailed(txId, errReason)
|
||||||
|
}
|
||||||
|
this.query.getTransactionByHash(txHash, (err, txParams) => {
|
||||||
|
if (err || !txParams) {
|
||||||
|
if (!txParams) return
|
||||||
|
txMeta.err = {
|
||||||
|
isWarning: true,
|
||||||
|
errorCode: err,
|
||||||
|
message: 'There was a problem loading this transaction.',
|
||||||
|
}
|
||||||
|
this.updateTx(txMeta)
|
||||||
|
return log.error(err)
|
||||||
|
}
|
||||||
|
if (txParams.blockNumber) {
|
||||||
|
this.setTxStatusConfirmed(txId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ describe('Transaction Controller', function () {
|
|||||||
txController = new TransactionController({
|
txController = new TransactionController({
|
||||||
networkStore: new ObservableStore(currentNetworkId),
|
networkStore: new ObservableStore(currentNetworkId),
|
||||||
txHistoryLimit: 10,
|
txHistoryLimit: 10,
|
||||||
|
provider: { _blockTracker: new EventEmitter()},
|
||||||
blockTracker: new EventEmitter(),
|
blockTracker: new EventEmitter(),
|
||||||
ethQuery: new EthQuery(new EventEmitter()),
|
ethQuery: new EthQuery(new EventEmitter()),
|
||||||
signTransaction: (ethTx) => new Promise((resolve) => {
|
signTransaction: (ethTx) => new Promise((resolve) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user