使用Hyperledger Fabric Node JS创建频道时出错

时间:2019-01-17 16:17:30

标签: node.js hyperledger-fabric hyperledger-fabric-sdk-js

我正在尝试使用Fabric SDK node.js创建一个频道。当我通过bash命令创建通道时,没有任何问题(您可以看到下面的代码),但是当我使用node.js SDK时,出现了一些错误。 我正在使用TLS和客户端身份验证。我不知道该错误意味着什么以及如何解决。任何帮助将不胜感激。

用于创建Channel的Node JS代码,它已在主机上执行:

var Fabric_Client = require('fabric-client');
var fs=require('fs');
var fabric_client = new Fabric_Client();

// Obtain tls cert and key from client.
let clientcert = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/tls/peer1-org1-cli-client.crt');
let clientkey = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/tls/peer1-org1-cli-client.key');
fabric_client.setTlsClientCertAndKey(clientcert.toString(),clientkey.toString())



//Orderer configuration
let pem1 = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/org0-ca-chain.pem');
const connectionopts = {
    pem: pem1.toString()
};
var order = fabric_client.newOrderer('grpcs://localhost:9101', connectionopts)


//setup identity admin
let cert = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/orgs/org1/admin/msp/signcerts/cert.pem');
let pk = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/orgs/org1/admin/msp/keystore/b17b8a06b4928a037e621cc784cac4f8a4913087c95c68162ecae6189993a1fa_sk');
const  mspid = 'org1MSP';
fabric_client.setAdminSigningIdentity(pk, cert, mspid);


// Setup create channel
var chanelName = 'mychannel';
const envelope = fs.readFileSync('/home/rosalva40/Documentos/Own2/Own/data/channel.tx');
channelConfig = fabric_client.extractChannelConfig(envelope);
signature = fabric_client.signChannelConfig(channelConfig);

const request = {
    name: chanelName,
    orderer: order,
    config: channelConfig,
    signatures : [signature],
    txId : fabric_client.newTransactionID(true)
};


//Create chanel
fabric_client.createChannel(request);

运行createChannel.js时,在控制台中出现以下错误:

  

2019-01-17T14:30:42.278Z-错误:[Remote.js]:错误:未能   在截止日期URL之前连接:grpcs:// localhost:9101   2019-01-17T14:30:42.283Z-错误:[Orderer.js]:订购者   grpcs:// localhost:9101出现错误错误:之前无法连接   截止日期URL:grpcs:// localhost:9101(node:31051)   UnhandledPromiseRejectionWarning:错误:在连接之前无法连接   截止期限URL:grpcs:// localhost:9101       在checkState(/home/rosalva40/fabric-samples/vote/node_modules/fabric-client/node_modules/grpc/src/client.js:720:16)   (节点:31051)UnhandledPromiseRejectionWarning:未处理的承诺   拒绝。该错误是由抛出异步内部引起的   没有捕获块或拒绝承诺   未使用.catch()处理。 (拒绝ID:2)(节点:31051)[DEP0018]   DeprecationWarning:已弃用未处理的承诺拒绝。在   未来,未处理的承诺拒绝将终止   具有非零退出代码的Node.js进程。

这是订购者节点日志:

  

2019-01-17 16:08:40.977 UTC [grpc] Println-> DEBU 13a grpc:   Server.Serve无法创建ServerTransport:连接错误:desc   =“传输:http2Server.HandleStreams无法从客户端收到引言:EOF” 2019-01-17 16:08:41.987 UTC [grpc] Println-> DEBU   13b grpc:Server.Serve无法创建ServerTransport:连接   错误:desc =“传输:http2Server.HandleStreams无法接收   客户序言:EOF“ 2019-01-17 16:08:43.572 UTC [grpc]   Println-> DEBU 13c grpc:Server.Serve创建失败   ServerTransport:连接错误:desc =“ transport:   http2Server.HandleStreams无法从客户端收到前言:   EOF”

这是在容器中执行的bash代码:

DATA=data
CHANNEL_TX_FILE=/$DATA/channel.tx
CHANNEL_NAME=mychannel 

# ORDERER CONNECTION ARGUMENTS
ORDERER_HOST=orderer1-org0
ORDERER_PORT_INT=7050
INT_CA_CHAINFILE=/${DATA}/org0-ca-chain.pem
ORDERER_PORT_ARGS="-o $ORDERER_HOST:$ORDERER_PORT_INT --tls --cafile $INT_CA_CHAINFILE --clientauth"

export CORE_PEER_TLS_CLIENTCERT_FILE=/$DATA/tls/peer1-org1-cli-client.crt
export CORE_PEER_TLS_CLIENTKEY_FILE=/$DATA/tls/peer1-org1-cli-client.key

ORDERER_CONN_ARGS="$ORDERER_PORT_ARGS --keyfile $CORE_PEER_TLS_CLIENTKEY_FILE --certfile $CORE_PEER_TLS_CLIENTCERT_FILE"

#ORGANIZATION ADMIN ENVIROMENT ARGUMENTS
ORG_ADMIN_HOME=/${DATA}/orgs/org1/admin
export CORE_PEER_MSPCONFIGPATH=$ORG_ADMIN_HOME/msp
export CORE_PEER_LOCALMSPID=org1MSP

#CHANNEL CREATE COMMAND
peer channel create --logging-level=DEBUG -c $CHANNEL_NAME -f $CHANNEL_TX_FILE $ORDERER_CONN_ARGS

1 个答案:

答案 0 :(得分:0)

该应用似乎无法连接到订购者。尝试使用此方法:

var Client = require('fabric-client');
var Channel = require('fabric-client').Channel;
const fs = require('fs');
var client = Client.loadFromConfig("config/configfile.yaml");
/**
 * @param {String} channelName Channel name used in configtxgen to create the channel transaction (mychannel)
 * @param {String} channelConfigPath Path of the channel transaction (/home/root/channel-artifacts/channel.tx)
 * @param {String} orderer Orderer name (orderer.example.com)
 * @description Create channel
 */
async createChannel(channelName,orderer, channelConfigPath) {
    var envelope = fs.readFileSync(channelConfigPath);
    var channelConfig = client.extractChannelConfig(envelope);
    let signature = client.signChannelConfig(channelConfig);
    let request = {
        config: channelConfig,
        orderer: client.getOrderer(orderer),
        signatures: [signature],
        name: channelName,
        txId: client.newTransactionID(true)
    };
    const result = await client.createChannel(request)
    return result;
}

您可以在此link中检查configfile.yaml的结构。 不要忘记在您的configfile.yaml中设置客户端标头