mirror of https://github.com/embarklabs/embark.git
Listen to contract events
This commit is contained in:
parent
5fa118ae2e
commit
4c27d34e0c
|
@ -20,6 +20,7 @@ class BlockchainConnector {
|
|||
this.web3Endpoint = '';
|
||||
this.isWeb3Ready = false;
|
||||
this.wait = options.wait;
|
||||
this.contractsSubscriptions = [];
|
||||
|
||||
self.events.setCommandHandler("blockchain:web3:isReady", (cb) => {
|
||||
cb(self.isWeb3Ready);
|
||||
|
@ -29,6 +30,8 @@ class BlockchainConnector {
|
|||
cb(self);
|
||||
});
|
||||
|
||||
embark.registerActionForEvent("contracts:deploy:afterAll", this.subscribeToContractEvents.bind(this));
|
||||
|
||||
if (!this.web3) {
|
||||
this.initWeb3();
|
||||
} else {
|
||||
|
@ -601,6 +604,28 @@ class BlockchainConnector {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
subscribeToContractEvents(callback) {
|
||||
this.contractsSubscriptions.forEach((eventEmitter) => {
|
||||
eventEmitter.unsubscribe();
|
||||
});
|
||||
this.contractsSubscriptions = [];
|
||||
this.events.request("contracts:list", (_err, contractsList) => {
|
||||
contractsList.forEach(contractObject => {
|
||||
if (!contractObject.address){
|
||||
return;
|
||||
}
|
||||
|
||||
const contract = this.ContractObject({abi: contractObject.abiDefinition, address: contractObject.address});
|
||||
const eventEmitter = contract.events.allEvents();
|
||||
this.contractsSubscriptions.push(eventEmitter);
|
||||
eventEmitter.on('data', (data) => {
|
||||
|
||||
});
|
||||
});
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
BlockchainConnector.ACCEPTED_TYPES = ['rpc', 'ws', 'vm'];
|
||||
|
|
|
@ -16,7 +16,6 @@ const parseRequest = function (reqBody) {
|
|||
} catch (e) {
|
||||
return; // Request is not a json. Do nothing
|
||||
}
|
||||
console.error("Request ", jsonO)
|
||||
if (jsonO.method === "eth_sendTransaction") {
|
||||
commList[jsonO.id] = {
|
||||
type: 'contract-log',
|
||||
|
@ -38,7 +37,6 @@ const parseResponse = function (ipc, resBody) {
|
|||
} catch (e) {
|
||||
return; // Response is not a json. Do nothing
|
||||
}
|
||||
console.error("Response", jsonO)
|
||||
if (commList[jsonO.id]) {
|
||||
commList[jsonO.id].transactionHash = jsonO.result;
|
||||
transactions[jsonO.result] = {commListId: jsonO.id};
|
||||
|
|
Loading…
Reference in New Issue