我构建了一个启用了多个orgs和tls的Fabric网络。 Crypto材料是用cryptogen构建的。我不打算在我的例子中使用fabric-ca。
我通过CLI安装并实例化了fabcar。使用CLI命令调用和查询可以作为魅力。
现在,为了使用nodejs脚本query.js和invoke.js,我连接了私钥和公钥,以便为Fabcar创建PeerAdmin凭证。我还改变了.js文件中的配置,以针对具有grpcs的同行和订购者。
每当我执行任何.js脚本时,我都会遇到以下错误:
Create a client and set the wallet location
Set wallet path, and associate user PeerAdmin with application
Check user is enrolled, and set a query URL in the network
Caught Error Error: PEM encoded certificate is required.
at new Endpoint (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:146:11)
at new Remote (/home/hl/fabcar/node_modules/fabric-client/lib/Remote.js:95:20)
at new Peer (/home/hl/fabcar/node_modules/fabric-client/lib/Peer.js:53:3)
at Client.newPeer (/home/hl/fabcar/node_modules/fabric-client/lib/Client.js:173:14)
at Promise.resolve.then.then.then (/home/hl/fabcar/query.js:39:28)
at <anonymous>
当我尝试在没有grpcs的情况下查询链代码时,我收到以下错误:
Create a client and set the wallet location
Set wallet path, and associate user PeerAdmin with application
Check user is enrolled, and set a query URL in the network
Make query
Assigning transaction_id: 9cbf355cda03db2b1971fe10af27d66686ea9b913eda80f667cac48bada015bf
error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: Endpoint read failed
at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15
returned from query
Query result count = 1
error from query = { Error: Endpoint read failed
at /home/hl/fabcar/node_modules/grpc/src/client.js:554:15 code: 14, metadata: Metadata { _internal_repr: {} } }
Response is Error: Endpoint read failed
PeerAdmin内容:
{"name":"PeerAdmin","mspid":"PeerOrgMSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"[...]","identity":{"certificate":"-----BEGIN CERTIFICATE-----\n[...]-----END CERTIFICATE-----\n"}}}
任何帮助我指出正确的程序或使用上述方法进行故障排除都将非常感激。
答案 0 :(得分:0)
据我所知,您将在没有Fabric CA的情况下进行fabcar。 如果是这样,您就无法使用Node.js应用程序,因为它正在使用用户上下文而您没有注册用户上下文。
但是你想在没有CA的情况下使用fabcar,你可以调用或查询事务为cli。
docker exec -it cli bash
peer chaincode query -C mychannel -n fabcar -c'{“Args”:[“queryAllCars”,“”]}'
peer chaincode query -C mychannel -n fabcar -c'{“Args”:[“queryCar”,“CAR4”]}'
调用事务是相同的
答案 1 :(得分:0)
启用gRPC时,必须将pem作为参数传递给各种Hyperledger元素对象(例如peer,orderer)的实例化。在fabcar示例(invoke.js
):
// This is a new line
var options = {
tls_cert: {
pem: fs.readFileSync(path.join(__dirname, './network/tls') + '/peer.cert').toString(),
}
};
...
// Replace the original instantiation by adding the pem option
var peer = fabric_client.newPeer('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:26268', {
pem: options.tls_cert.pem
});
channel.addPeer(peer);
// Replace the original instantiation by adding the pem option
var order = fabric_client.newOrderer('grpcs://fft-zbc03b.4.secure.blockchain.ibm.com:20161', {
pem: options.tls_cert.pem
})
...
// Replace the original instantiation by adding the pem option
event_hub.setPeerAddr('grpcs://fft-zbc03a.4.secure.blockchain.ibm.com:23972', {
pem: options.tls_cert.pem
});
上面的代码假定您已将正确的证书下载到network/tls/
。可以通过向CA发送请求来下载这些证书。有关完整示例,请参阅Bluemix文档here。