move subscriptions listener to blockchain connector module

This commit is contained in:
Iuri Matias 2018-08-10 16:26:05 -04:00
parent eeb8fa752d
commit 53cd27b87d
2 changed files with 15 additions and 13 deletions

View File

@ -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;

View File

@ -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