mirror of https://github.com/embarklabs/embark.git
move subscriptions listener to blockchain connector module
This commit is contained in:
parent
eeb8fa752d
commit
53cd27b87d
|
@ -37,6 +37,7 @@ class BlockchainConnector {
|
||||||
this.registerRequests();
|
this.registerRequests();
|
||||||
this.registerWeb3Object();
|
this.registerWeb3Object();
|
||||||
this.registerEvents();
|
this.registerEvents();
|
||||||
|
this.subscribeToPendingTransactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
//initWeb3() {
|
//initWeb3() {
|
||||||
|
@ -300,6 +301,20 @@ class BlockchainConnector {
|
||||||
// can just be a command without a callback
|
// can just be a command without a callback
|
||||||
this.events.emit("runcode:register", "web3", this.web3);
|
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;
|
module.exports = BlockchainConnector;
|
||||||
|
|
|
@ -95,22 +95,9 @@ class Test {
|
||||||
this.sim = getSimulator();
|
this.sim = getSimulator();
|
||||||
}
|
}
|
||||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||||
this.subscribeToPendingTransactions();
|
|
||||||
callback();
|
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() {
|
initDeployServices() {
|
||||||
this.engine.startService("web3", {
|
this.engine.startService("web3", {
|
||||||
web3: this.web3
|
web3: this.web3
|
||||||
|
|
Loading…
Reference in New Issue