diff --git a/lib/modules/transactionTracker/index.js b/lib/modules/transactionTracker/index.js index 6bff5294..2fc3f41a 100644 --- a/lib/modules/transactionTracker/index.js +++ b/lib/modules/transactionTracker/index.js @@ -4,6 +4,7 @@ class TransactionTracker { this.events = embark.events; this.transactions = {}; this.embark = embark; + this.startTimestamp = Date.now() / 1000; embark.events.on("block:pending:transaction", this.onPendingTransaction.bind(this)); embark.events.on("block:header", this.onBlockHeader.bind(this)); @@ -31,6 +32,19 @@ class TransactionTracker { } }); this.events.emit('blockchain:gas:oracle:new'); + this.cullOldTransactions(); + }); + } + + cullOldTransactions() { + const timeLimit = (Date.now() / 1000) - 600; // Transactions old of 10 minutes are not to be counted anymore + if (this.startTimestamp > timeLimit) { + return; + } + Object.keys(this.transactions).forEach(transactionHash => { + if (this.transactions[transactionHash].startTimestamp < timeLimit) { + delete this.transactions[transactionHash]; + } }); }