Commit 61e7d9d1 authored by Juan Nogueira's avatar Juan Nogueira
Browse files

Fabric connector update

parent f34cd24b
......@@ -42,15 +42,28 @@ class FabricConnector {
const contract = network.getContract(config.blockchains.fabric.fabricContract);
const remoteEvent = config.blockchains.fabric.fabricRemoteRequestEvent;
/*
await network.addBlockListener('my-block-listener', (err, block) => {
if (err) {
console.error(err);
return;
}
console.log(`Block: ${JSON.stringify(block)}`);
});
*/
await contract.addContractListener('listener', remoteEvent, this.eventReceivedFromFabric.bind(this));
}
eventReceivedFromFabric(err, event) {
eventReceivedFromFabric(err, event, blockNumber, transactionId, status) {
this.printLine('Event received from fabric blockchain');
//console.log(blockNumber, transactionId, status);
if (err) {
console.error(err);
} else {
} else if (status == 'VALID') {
//console.log(event);
const eventData = this.getDataFromFabricEvent(event);
console.log(eventData);
......@@ -76,16 +89,7 @@ class FabricConnector {
}
getDataFromFabricEvent(event) {
const evt = JSON.parse(event.payload.toString());
return {
...evt,
event: {
...evt.event,
sourceBlockchain: 'fabric',
sourceContract: config.blockchains.fabric.fabricContract
}
}
return JSON.parse(event.payload.toString());
}
async loadFabricGateway() {
......@@ -117,13 +121,13 @@ class FabricConnector {
const contract = network.getContract(event.targetContract);
const receiveEvtOper = config.blockchains.fabric.fabricReceiveEventOperation;
await contract.submitTransaction(receiveEvtOper, JSON.stringify(event.event));
await contract.submitTransaction(receiveEvtOper, JSON.stringify(event.data));
}
sendEventToRouter(event) {
// sends an event to the router
const options = {
host: 'localhost',
host: config.router.endpoint,
path: '/',
port: config.router.port,
method: 'POST'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment