我当前正在使用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);
但是,我的目标是将此代码包含在节点红色的节点中(请检查here。
有点上下文:当前这些节点不处理发现,这可能是需要的。我的工作目的是将其包含在这些节点中。
结果,我试图将上面的代码插入到我的节点代码中,该代码提供了以下内容:(相同的代码,它只是一个复制/粘贴)
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
有人知道什么可能是不同的,和/或是什么导致此错误的线索吗?
编辑:
在测试软件包时,通过npm install PATH
而不是使用npm link
将其链接到node-red时,出现以下错误:
{ 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日志的更多信息。您可以找到整个日志here
出于安全性考虑,除本地主机地址外,所有地址均已更改为ADDRESS
或ADDRESS:PORT
(取决于所写内容)。
答案 0 :(得分:1)
使用发现时的当前默认值(1.4.0-1.4.4)用于将所有返回的IP地址转换为本地主机。您需要明确禁用它。在您的代码中,我看到您已经尝试过,但是属性名称略有错误。它应该是FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /opt/project_name
COPY project_name/project_name.csproj project_name/project_name.csproj
RUN dotnet restore project_name/project_name.csproj
COPY project_name.UnitTests/project_name.UnitTests.csproj project_name.UnitTests/project_name.UnitTests.csproj
RUN dotnet restore project_name.UnitTests/project_name.UnitTests.csproj
COPY . .
RUN dotnet test project_name.UnitTests/project_name.UnitTests.csproj -f netcoreapp2.0 -c Release --no-restore
RUN dotnet publish project_name/project_name.csproj -f netcoreapp2.0 -c Release -o ../EmployerAccount/ea-api
FROM mcr.microsoft.com/dotnet/core/runtime:2.1 AS runtime
WORKDIR /opt/project_name
COPY --from=build /opt/project_name/project_name/project_name ./
COPY --from=build /opt/project_name/project_name/project_name/appsettings/testing/testing-1.json appsettings.json
ENV COMPUTERNAME company-test
ENV ClusterContentIp /opt
ENV ASPNETCORE_ENVIRONMENT Staging
ENV WorkingDirectory /opt/project_name
ENTRYPOINT ["dotnet", "project_name.dll"]
,带有一个小的asLocalhost
,而您使用的是大写字母h