mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-08 13:25:17 +00:00
remove old transactions to lighten the memory
This commit is contained in:
parent
bad6eb3e04
commit
b6746f043a
@ -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];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user