Reputation: 2972
I am currently using IBM Blockchain Platform 2.0. I am connecting to it with fabric-network 1.4.0
and fabric-client 1.4.0
.
When I listen for events from a simple node.js script on my machine, it works perfectly well. Here is the sample script:
const ccpPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/node-red/fabric-server/config/org1/ibp2/user1/connection.json');
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
const walletPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/IBP2/CHAINCODE/public-resource/profile/wallet');
const wallet = new FileSystemWallet(walletPath);
const gateway = new Gateway();
const options = { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: false } };
await gateway.connect(ccp, options);
const network = await gateway.getNetwork('CHANNELNAME');
const contract = network.getContract('CCNAME');
const channel = network.getChannel();
const eventHub = channel.newChannelEventHub('IP:PORT');
let event = eventHub.registerChaincodeEvent('CCNAME', 'EVENTREGEX', (event, number, txid, status) => {
console.log(event);
console.log(event.payload.toString());
console.log(number);
}, (error) => {
console.log(error);
}, { startBlock: 0 });
eventHub.connect(true);
However, my goal is to include this code into node-red nodes (check here.
A bit of context: currently these nodes do not handle discovery, which may be needed. The purpose of my work is to include this into these nodes.
As a consequence, I tried to insert the code above into my nodes code, which gives the following: (same code, it is just a copy/paste)
else if (actionType === 'event') {
node.log('EVENT');
const ccPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/node-red/fabric-server/config/org1/ibp2/user1/connection.json');
const ccp = JSON.parse(fs.readFileSync(ccPath, 'utf8'));
const walletPath = path.resolve('C:/Users/FlorianCastelain/Documents/GitHub/blockchain-code/IBP2/CHAINCODE/public-resource/profile/wallet');
const wallet = new FileSystemWallet(walletPath);
const gateway = new Gateway();
const options = { wallet, identity: 'user1', discovery: { enabled: true, asLocalHost: false } };
await gateway.connect(ccp, options);
const network = await gateway.getNetwork('CHANEL NAME');
const channel = network.getChannel();
const eventHub = channel.newChannelEventHub('IP:PORT');
let event = eventHub.registerChaincodeEvent('CCNAME', 'REGEX', (event, number, txid, status) => {
console.log(event);
console.log(event.payload.toString());
console.log(number);
}, (error) => {
console.log(error);
}, { startBlock: 0 });
eventHub.connect(true);
// const networkInfo = await connect(identityName, node.connection.discoveryEnabled, node.connection.discoveryAsLocalhost, channelName, contractName, node);
// const channel = networkInfo.network.getChannel();
// await subscribeToEvent(channel, contractName, msg.payload.peerName, msg.payload.startBlock,
// msg.payload.endBlock, msg.payload.timeout, msg.payload.eventName, node, msg);
} else if
It produces the following error:
{ Error: 14 UNAVAILABLE: Connect Failed
at Object.exports.createStatusError (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\common.js:91:15)
at ClientDuplexStream._emitStatusIfDone (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client.js:233:26)
at ClientDuplexStream._receiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client.js:211:8)
at Object.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:1306:15)
at InterceptingListener._callNext (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:618:8)
at C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\grpc\src\client_interceptors.js:1123:18
code: 14, metadata: Metadata { _internal_repr: {} }, details:
'Connect Failed' }
I checked fabric-network
version on both "environment", it is 1.4.0
Does anyone has a clue on what can be the difference and/or what can cause this error?
Edit:
When testing the package when linking it to node-red via npm install PATH
instead of using npm link
, I get the following error:
{ Error: 14 UNAVAILABLE: failed to connect to all addresses
at Object.exports.createStatusError (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\common.js:91:15)
at ClientDuplexStream._emitStatusIfDone (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client.js:233:26)
at ClientDuplexStream._receiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client.js:211:8)
at Object.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:1306:15)
at InterceptingListener._callNext (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:618:8)
at C:\Users\FlorianCastelain\Documents\GitHub\node-red-contrib-fabric\node_modules\fabric-network\node_modules\fabric-client\node_modules\grpc\src\client_interceptors.js:1123:18
code: 14,
metadata: Metadata { _internal_repr: {} },
details: 'failed to connect to all addresses' }
Edit: More info from HLF logging. You can find the entire logs here
All addresses have been changed to ADDRESS
or ADDRESS:PORT
(depending on what was written), except localhost addresses, for security.
Upvotes: 0
Views: 228
Reputation: 5868
The current default (1.4.0-1.4.4) when discovery is used is for all returned ip addresses to be converted to localhost. You need to explicitly disable this. In your code I see you have tried but got the property name slightly wrong. It should be asLocalhost
with a small h
whereas you have used a capital H
Upvotes: 1