mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
transactions - update pending-tx-tracker to use the new block tracker
This commit is contained in:
parent
10aecf4922
commit
c4b09da34e
@ -27,6 +27,7 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
this.getPendingTransactions = config.getPendingTransactions
|
this.getPendingTransactions = config.getPendingTransactions
|
||||||
this.getCompletedTransactions = config.getCompletedTransactions
|
this.getCompletedTransactions = config.getCompletedTransactions
|
||||||
this.publishTransaction = config.publishTransaction
|
this.publishTransaction = config.publishTransaction
|
||||||
|
this.confirmTransaction = config.confirmTransaction
|
||||||
this._checkPendingTxs()
|
this._checkPendingTxs()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +38,8 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
@emits tx:confirmed
|
@emits tx:confirmed
|
||||||
@emits tx:failed
|
@emits tx:failed
|
||||||
*/
|
*/
|
||||||
checkForTxInBlock (block) {
|
async checkForTxInBlock (blockNumber) {
|
||||||
|
const block = await this._getBlock(blockNumber)
|
||||||
const signedTxList = this.getPendingTransactions()
|
const signedTxList = this.getPendingTransactions()
|
||||||
if (!signedTxList.length) return
|
if (!signedTxList.length) return
|
||||||
signedTxList.forEach((txMeta) => {
|
signedTxList.forEach((txMeta) => {
|
||||||
@ -51,9 +53,12 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!block.transactions.length) return
|
||||||
|
|
||||||
block.transactions.forEach((tx) => {
|
block.transactions.forEach((hash) => {
|
||||||
if (tx.hash === txHash) this.emit('tx:confirmed', txId)
|
if (hash === txHash) {
|
||||||
|
this.confirmTransaction(txId)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -70,7 +75,7 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if we synced by more than one block, check for missed pending transactions
|
// if we synced by more than one block, check for missed pending transactions
|
||||||
const diff = Number.parseInt(newBlock.number, 16) - Number.parseInt(oldBlock.number, 16)
|
const diff = Number.parseInt(newBlock, 16) - Number.parseInt(oldBlock, 16)
|
||||||
if (diff > 1) this._checkPendingTxs()
|
if (diff > 1) this._checkPendingTxs()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +84,11 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
@param block {object} - a block object
|
@param block {object} - a block object
|
||||||
@emits tx:warning
|
@emits tx:warning
|
||||||
*/
|
*/
|
||||||
resubmitPendingTxs (block) {
|
resubmitPendingTxs (blockNumber) {
|
||||||
const pending = this.getPendingTransactions()
|
const pending = this.getPendingTransactions()
|
||||||
// only try resubmitting if their are transactions to resubmit
|
// only try resubmitting if their are transactions to resubmit
|
||||||
if (!pending.length) return
|
if (!pending.length) return
|
||||||
pending.forEach((txMeta) => this._resubmitTx(txMeta, block.number).catch((err) => {
|
pending.forEach((txMeta) => this._resubmitTx(txMeta, blockNumber).catch((err) => {
|
||||||
/*
|
/*
|
||||||
Dont marked as failed if the error is a "known" transaction warning
|
Dont marked as failed if the error is a "known" transaction warning
|
||||||
"there is already a transaction with the same sender-nonce
|
"there is already a transaction with the same sender-nonce
|
||||||
@ -179,7 +184,7 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
txParams = await this.query.getTransactionByHash(txHash)
|
txParams = await this.query.getTransactionByHash(txHash)
|
||||||
if (!txParams) return
|
if (!txParams) return
|
||||||
if (txParams.blockNumber) {
|
if (txParams.blockNumber) {
|
||||||
this.emit('tx:confirmed', txId)
|
this.confirmTransaction(txId)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
txMeta.warning = {
|
txMeta.warning = {
|
||||||
@ -206,11 +211,17 @@ class PendingTransactionTracker extends EventEmitter {
|
|||||||
nonceGlobalLock.releaseLock()
|
nonceGlobalLock.releaseLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _getBlock (blockNumber) {
|
||||||
|
return await this.query.getBlockByNumber(blockNumber, false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
checks to see if a confirmed txMeta has the same nonce
|
checks to see if a confirmed txMeta has the same nonce
|
||||||
@param txMeta {Object} - txMeta object
|
@param txMeta {Object} - txMeta object
|
||||||
@returns {boolean}
|
@returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
async _checkIfNonceIsTaken (txMeta) {
|
async _checkIfNonceIsTaken (txMeta) {
|
||||||
const address = txMeta.txParams.from
|
const address = txMeta.txParams.from
|
||||||
const completed = this.getCompletedTransactions(address)
|
const completed = this.getCompletedTransactions(address)
|
||||||
|
@ -13,7 +13,7 @@ const otherNetworkId = 36
|
|||||||
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
||||||
|
|
||||||
|
|
||||||
describe.only('PendingTransactionTracker', function () {
|
describe('PendingTransactionTracker', function () {
|
||||||
let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub,
|
let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub,
|
||||||
provider, txMeta3, txList, knownErrors
|
provider, txMeta3, txList, knownErrors
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
Loading…
Reference in New Issue
Block a user