mirror of https://github.com/embarklabs/embark.git
Add endpoint
This commit is contained in:
parent
4c27d34e0c
commit
6ce78dfce3
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue