AddContractListener如何在HyperLeDger Fabric 1.4版本中起作用
我正在使用Fabric版本1.4
。我已经在第一个网络上部署了合同fabcar
。我已经对现有合同进行了一些修改,例如添加setEvent(“启动”,[] byte {“ test”})
。我想要的是使用以下代码来聆听这些事件,但无法提取事件。这是我的代码: -
代码
//connect to Fabric Network, but starting a new gateway
const gateway = new Gateway();
//use our config file, our peerIdentity, and our discovery options to connect to Fabric network.
await gateway.connect(ccpPath, { wallet, identity: peerIdentity, discovery: { enabled: true, asLocalhost: true } });
console.log('gateway connect');
//connect to our channel that has been created on IBM Blockchain Platform
const network = await gateway.getNetwork('mychannel');
//connect to our insurance contract that has been installed / instantiated on IBM Blockchain Platform
const contract = await network.getContract('fabcar');
await contract.addContractListener('my-contract-listener', 'InitLedger', (err, event, blockNumber, transactionId, status) => {
if (err) {
console.error(err);
return;
}
//convert event to something we can parse
event = event.payload.toString();
event = JSON.parse(event)
//where we output the TradeEvent
console.log('************************ Start Trade Event *******************************************************');
console.log(`make: ${event.type}`);
console.log(`model: ${event.ownerId}`);
console.log(`colour: ${event.id}`);
console.log(`owner: ${event.description}`);
console.log(`Block Number: ${blockNumber} Transaction ID: ${transactionId} Status: ${status}`);
console.log('************************ End Trade Event ************************************');
});
在我在控制台中运行此代码时,它不会打印。如果我缺少任何建议或任何建议,请欢迎或建议我。
I'm using fabric version 1.4
. I have deploy my contract fabcar
on first network. I have do some modification in that existing contract like add SetEvent("initLedger",[]byte{"test"})
. And what I want is to listen these events using my below code but not able to fetch events. Here is my code:-
CODE
//connect to Fabric Network, but starting a new gateway
const gateway = new Gateway();
//use our config file, our peerIdentity, and our discovery options to connect to Fabric network.
await gateway.connect(ccpPath, { wallet, identity: peerIdentity, discovery: { enabled: true, asLocalhost: true } });
console.log('gateway connect');
//connect to our channel that has been created on IBM Blockchain Platform
const network = await gateway.getNetwork('mychannel');
//connect to our insurance contract that has been installed / instantiated on IBM Blockchain Platform
const contract = await network.getContract('fabcar');
await contract.addContractListener('my-contract-listener', 'InitLedger', (err, event, blockNumber, transactionId, status) => {
if (err) {
console.error(err);
return;
}
//convert event to something we can parse
event = event.payload.toString();
event = JSON.parse(event)
//where we output the TradeEvent
console.log('************************ Start Trade Event *******************************************************');
console.log(`make: ${event.type}`);
console.log(`model: ${event.ownerId}`);
console.log(`colour: ${event.id}`);
console.log(`owner: ${event.description}`);
console.log(`Block Number: ${blockNumber} Transaction ID: ${transactionId} Status: ${status}`);
console.log('************************ End Trade Event ************************************');
});
While I'm running this code in console it will print nothing. If I'm missing something or any suggestions please welcome or suggest me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论