1

我正在尝试使用 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]:Orderer 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) (node:31051) UnhandledPromiseRejectionWarning: 未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。(拒绝 ID:2)(节点:31051)[DEP0018] 弃用警告:未处理的承诺拒绝已被弃用。将来,未处理的 Promise 拒绝将使用非零退出代码终止 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 =“传输: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
4

1 回答 1

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

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

于 2019-01-19T16:42:29.440 回答