Add endpoint

This commit is contained in:
Anthony Laibe 2018-10-09 14:38:51 +01:00 committed by Pascal Precht
parent 4c27d34e0c
commit 6ce78dfce3
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 22 additions and 1 deletions

View File

@ -21,6 +21,7 @@ class BlockchainConnector {
this.isWeb3Ready = false;
this.wait = options.wait;
this.contractsSubscriptions = [];
this.contractsEvents = [];
self.events.setCommandHandler("blockchain:web3:isReady", (cb) => {
cb(self.isWeb3Ready);
@ -369,6 +370,24 @@ class BlockchainConnector {
});
}
);
plugin.registerAPICall(
'ws',
'/embark-api/blockchain/contracts/event',
(ws, _req) => {
this.events.on('blockchain:contracts:event', function(data) {
ws.send(JSON.stringify(data), () => {});
});
}
);
plugin.registerAPICall(
'get',
'/embark-api/blockchain/contracts/events',
(_req, res) => {
res.send(JSON.stringify(this.contractsEvents));
}
);
}
getAccountsWithTransactionCount(callback) {
@ -620,7 +639,9 @@ class BlockchainConnector {
const eventEmitter = contract.events.allEvents();
this.contractsSubscriptions.push(eventEmitter);
eventEmitter.on('data', (data) => {
const dataWithName = Object.assign(data, {name: contractObject.className});
this.contractsEvents.push(dataWithName)
this.events.emit('blockchain:contract:event', dataWithName);
});
});
callback();