diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index e0b31fcf5..79c372d72 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -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']; diff --git a/lib/modules/blockchain_process/proxy.js b/lib/modules/blockchain_process/proxy.js index 33ffbcc66..afdfbc1ec 100644 --- a/lib/modules/blockchain_process/proxy.js +++ b/lib/modules/blockchain_process/proxy.js @@ -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};