0

我目前正在使用 IBM Blockchain Platform 2.0。我用fabric-network 1.4.0和连接到它fabric-client 1.4.0

当我在我的机器上侦听来自简单 node.js 脚本的事件时,它运行良好。这是示例脚本:

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);

但是,我的目标是将此代码包含到节点红色节点中(查看此处.

一点上下文:目前这些节点不处理可能需要的发现。我工作的目的是将其包含到这些节点中。

结果,我尝试将上面的代码插入到我的节点代码中,它给出了以下内容:(相同的代码,它只是一个复制/粘贴)

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 

它产生以下错误:

{ 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' }

fabric-network我在两个“环境”上检查了版本,它是1.4.0

有没有人知道有什么区别和/或什么会导致这个错误?


编辑:

在将包链接到 node-red vianpm install PATH而不是 using时测试包时npm link,出现以下错误:

{ 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' }

编辑:来自 HLF 日志记录的更多信息。你可以在这里找到完整的日志

为了安全起见,除本地主机地址外,所有地址都已更改为ADDRESSADDRESS:PORT(取决于写入的内容)。

4

1 回答 1

1

使用发现时的当前默认值 (1.4.0-1.4.4) 是将所有返回的 IP 地址转换为 localhost。您需要明确禁用它。在您的代码中,我看到您已经尝试过,但属性名称略有错误。它应该是asLocalhost小的h,而您使用的是大写字母H

于 2019-07-15T09:19:51.763 回答