add transactionTracker to track transactions and their time

This commit is contained in:
Jonathan Rainville 2018-08-29 15:46:17 -04:00 committed by Pascal Precht
parent 636431d338
commit 3a6ed745f6
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 39 additions and 4 deletions

View File

@ -201,6 +201,7 @@ class Engine {
this.registerModule('ens');
this.registerModule('console_listener', {ipc: self.ipc});
this.registerModule('deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile});
this.registerModule('transactionTracker');
this.events.on('file-event', function ({fileType, path}) {
clearTimeout(self.fileTimeout);

View File

@ -594,6 +594,16 @@ class BlockchainConnector {
.on("data", function (blockHeader) {
self.events.emit('block:header', blockHeader);
});
if (self.pendingSubscription) {
self.pendingSubscription.unsubscribe();
}
self.pendingSubscription = self.web3.eth
.subscribe('pendingTransactions', function(error, transaction){
if (!error) {
self.events.emit('block:pending:transaction', transaction);
}
});
});
}
}

View File

@ -26,10 +26,6 @@ class EmbarkSpec extends Base {
console.log(fmt, receipt.className, receipt.gasUsed);
}
function onBlockHeader(blockHeader) {
self.stats.totalGasCost += blockHeader.gasUsed;
self.stats.test.gasUsed += blockHeader.gasUsed;
}
function onBlockHeader(blockHeader) {
if(!self.listenForGas) {

View File

@ -0,0 +1,28 @@
class TransactionTracker {
constructor(embark, _options) {
this.logger = embark.logger;
this.events = embark.events;
this.transactions = {};
embark.events.on("block:pending:transaction", this.onPendingTransaction.bind(this));
embark.events.on("block:header", this.onBlockHeader.bind(this));
}
onPendingTransaction(pendingTransaction) {
this.transactions[pendingTransaction] = {
startTimestamp: Date.now() / 1000
};
}
onBlockHeader(blockHeader) {
this.events.request("blockchain:block:byNumber", blockHeader.hash, (err, block) => {
block.transactions.forEach(transaction => {
if (this.transactions[transaction.hash]) {
Object.assign(this.transactions[transaction.hash], transaction, {endTimestamp: block.timestamp, wait: block.timestamp - this.transactions[transaction.hash].startTimestamp});
}
});
});
}
}
module.exports = TransactionTracker;