diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 686203d4c..378a8574c 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -37,6 +37,7 @@ class BlockchainConnector { this.registerRequests(); this.registerWeb3Object(); this.registerEvents(); + this.subscribeToPendingTransactions(); } //initWeb3() { @@ -300,6 +301,20 @@ class BlockchainConnector { // can just be a command without a callback this.events.emit("runcode:register", "web3", this.web3); } + + subscribeToPendingTransactions() { + const self = this; + this.onReady(() => { + if (self.logsSubscription) { + self.logsSubscription.unsubscribe(); + } + self.logsSubscription = self.web3.eth + .subscribe('newBlockHeaders', () => {}) + .on("data", function (blockHeader) { + self.events.emit('block:header', blockHeader); + }); + }); + } } module.exports = BlockchainConnector; diff --git a/lib/tests/test.js b/lib/tests/test.js index 9753f1437..64cd218d9 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -95,22 +95,9 @@ class Test { this.sim = getSimulator(); } this.web3.setProvider(this.sim.provider(this.simOptions)); - this.subscribeToPendingTransactions(); callback(); } - subscribeToPendingTransactions() { - const self = this; - if (self.logsSubscription) { - self.logsSubscription.unsubscribe(); - } - self.logsSubscription = self.web3.eth - .subscribe('newBlockHeaders') - .on("data", function (blockHeader) { - self.engine.events.emit('block:header', blockHeader); - }); - } - initDeployServices() { this.engine.startService("web3", { web3: this.web3