mirror of https://github.com/embarklabs/embark.git
add transactionTracker to track transactions and their time
This commit is contained in:
parent
636431d338
commit
3a6ed745f6
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue