You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varrequest=self._httpClient.request(requestOptions,function(response){constresponseBody=[];response.on('data',function(chunk){responseBody.push(chunk);});response.on('end',function(){varpayload=responseBody.join('');if(!payload){reject(newError(util.format('Enrollment failed with HTTP status code ',response.statusCode)));}//response should be JSONtry{varres=JSON.parse(payload);if(res.success){//we want the result field which is Base64-encoded PEMvarenrollResponse=newObject();// Cert field is Base64-encoded PEMenrollResponse.enrollmentCert=Buffer.from(res.result.Cert,'base64').toString();enrollResponse.caCertChain=Buffer.from(res.result.ServerInfo.CAChain,'base64').toString();returnresolve(enrollResponse);}else{returnreject(newError(util.format('Enrollment failed with errors [%s]',JSON.stringify(res.errors))));}}catch(err){reject(newError(util.format('Could not parse enrollment response [%s] as JSON due to error [%s]',payload,err)));}});});request.on('error',function(err){reject(newError(util.format('Calling enrollment endpoint failed with error [%s]',err)));});letbody=JSON.stringify(enrollRequest);request.write(body);request.end();
certificateAuthorities:
ca0.chainplaza.com:
url: http://localhost:7054# the properties specified under this object are passed to the 'http' client verbatim when# making the request to the Fabric-CA serverhttpOptions:
verify: truetlsCACerts:
path: ../network/crypto-config/peerOrganizations/org0.chainplaza.com/ca/ca.org0.chainplaza.com-cert.pem# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is# needed to enroll and invoke new users.registrar:
- enrollId: adminenrollSecret: adminpw# [Optional] The optional name of the CA.caName: ca0.chainplaza.comca1.chainplaza.com:
url: http://localhost:8054httpOptions:
verify: truetlsCACerts:
path: ../network/crypto-config/peerOrganizations/org1.chainplaza.com/ca/ca.org1.chainplaza.com-cert.pemregistrar:
- enrollId: adminenrollSecret: adminpw# [Optional] The optional name of the CA.caName: ca1.chainplaza.comca2.chainplaza.com:
url: http://localhost:9054httpOptions:
verify: truetlsCACerts:
path: ../network/crypto-config/peerOrganizations/org2.chainplaza.com/ca/ca.org2.chainplaza.com-cert.pemregistrar:
- enrollId: adminenrollSecret: adminpw# [Optional] The optional name of the CA.caName: ca2.chainplaza.com
E0702 16:48:37.113124000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0702 16:48:37.117412000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
error: [Orderer.js]: sendBroadcast - on error: "Error: Connect Failed\n at ClientDuplexStream._emitStatusIfDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:255:19)\n at ClientDuplexStream._readsDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:221:8)\n at readCallback (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:283:12)"
[2018-07-02 16:48:37.124] [ERROR] Create-Channel - Error: SERVICE_UNAVAILABLE
at ClientDuplexStream.<anonymous> (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/fabric-client/lib/Orderer.js:136:21)
at emitOne (events.js:116:13)
at ClientDuplexStream.emit (events.js:211:7)
at ClientDuplexStream._emitStatusIfDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:258:12)
at ClientDuplexStream._readsDone (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:221:8)
at readCallback (/Users/guanpengchn/Code/chain_plaza/balance-transfer/node_modules/grpc/src/node/src/client.js:283:12)
(node:28483) UnhandledPromiseRejectionWarning: Error: Failed to initialize the channel: Error: SERVICE_UNAVAILABLE
at Object.createChannel (/Users/guanpengchn/Code/chain_plaza/balance-transfer/app/create-channel.js:65:9)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:28483) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing insideof an async functionwithout a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:28483) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
E0702 16:48:57.113731000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0702 16:48:57.120118000 140735804384128 ssl_transport_security.c:921] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
{"success":false,"message":"failed Error: fabric-ca request register failed with errors [[{\"code\":63,\"message\":\"Failed to get Affiliation: sql: no rows in result set\"}]]"}%
varcreateAffiliation=asyncfunction(affiliationName){try{varclient=awaitgetClientForOrg(affiliationName);logger.debug('Successfully initialized the credential stores');varadmins=hfc.getConfigSetting('admins');letadminUserObj=awaitclient.setUserContext({username: admins[0].username,password: admins[0].secret});letcaClient=client.getCertificateAuthority();lettmp=awaitcaClient.newAffiliationService().create({name: affiliationName},adminUserObj);logger.debug('Successfully create affiliation');varresponse={success: true,message: affiliationName+' create Successfully',};returnresponse;}catch(error){logger.error('Failed to create affiliation with error: %s',error.toString());logger.error(error.stack.toString());return'failed '+error.toString();}};
app.js中添加代码如下
// Create Affiliationapp.post('/affiliations',asyncfunction(req,res){logger.info('<<<<<<<<<<<<<<<<< C R E A T E A F F I L I A T I O N >>>>>>>>>>>>>>>>>');logger.debug('End point : /affiliation');varorgName=req.body.orgName;logger.debug('Affiliation name : '+orgName);if(!orgName){res.json(getErrorMessage('\'orgName\''));return;}letresponse=awaithelper.createAffiliation(orgName);if(response&&typeofresponse!=='string'){logger.debug('Successfully create affiliation %s ',orgName);res.json(response);}else{logger.debug('Failed to create affiliation %s with::%s',orgName,response);res.json({success: false,message: response});}});
这样实现了rest接口,能够create affiliation,执行
$ fabric-ca-client affiliation list
即可看添加结果,最后一行
5、使用balance-transfer遇到无效网络配置
问题描述
Error: Invalid network configuration due to missing configuration data
varutil=require('util');varpath=require('path');varhfc=require('fabric-client');varfile='network-config%s.yaml';varenv=process.env.TARGET_NETWORK;if(env)file=util.format(file,'-'+env);elsefile=util.format(file,'');// indicate to the application where the setup file is located so it able// to have the hfc load it to initalize the fabric client instancehfc.setConfigSetting('network-connection-profile-path',path.join(__dirname,'artifacts',file));hfc.setConfigSetting('Org1-connection-profile-path',path.join(__dirname,'artifacts','org1.yaml'));hfc.setConfigSetting('Org2-connection-profile-path',path.join(__dirname,'artifacts','org2.yaml'));// some other settings the application might need to knowhfc.addConfigFile(path.join(__dirname,'config.json'));
// get a fabric client loaded with a connection profile for this orgletconfig='-connection-profile-path';// build a client context and load it with a connection profile// lets only load the network settings and save the client for laterletclient=hfc.loadFromConfig(hfc.getConfigSetting('network'+config));
6、create Affiliation后依然报错Failed to get Affiliation
/* * Internal method to handle both chaincode calls */_sendChaincodeProposal(request,command,timeout){leterrorMsg=null;//validate the incoming requestif(!errorMsg)errorMsg=clientUtils.checkProposalRequest(request);if(!errorMsg)errorMsg=clientUtils.checkInstallRequest(request);if(errorMsg){logger.error('sendChainCodeProposal error '+errorMsg);returnPromise.reject(newError(errorMsg));}constpeers=this._getTargets(request.targets,Constants.NetworkConfig.ENDORSING_PEER_ROLE);// args is optional because some chaincode may not need any input parameters during initializationif(!request.args){request.args=[];}// step 1: construct a ChaincodeSpecconstargs=[];//args.push(Buffer.from(request.fcn ? request.fcn : 'init', 'utf8'));for(letargofrequest.args)args.push(Buffer.from(arg,'utf8'));constccSpec={type: clientUtils.translateCCType(request.chaincodeType),chaincode_id: {name: request.chaincodeId,version: request.chaincodeVersion},input: {args: args}};// step 2: construct the ChaincodeDeploymentSpecconstchaincodeDeploymentSpec=new_ccProto.ChaincodeDeploymentSpec();chaincodeDeploymentSpec.setChaincodeSpec(ccSpec);constsigner=this._clientContext._getSigningIdentity(request.txId.isAdmin());constlcccSpec_args=[Buffer.from(command),Buffer.from(this._name),chaincodeDeploymentSpec.toBuffer()];if(request['endorsement-policy']){lcccSpec_args[3]=this._buildEndorsementPolicy(request['endorsement-policy']);}constlcccSpec={// type: _ccProto.ChaincodeSpec.Type.GOLANG,type: clientUtils.translateCCType(request.chaincodeType),chaincode_id: {name: Constants.LSCC},input: {args: lcccSpec_args}};constchannelHeader=clientUtils.buildChannelHeader(_commonProto.HeaderType.ENDORSER_TRANSACTION,this._name,request.txId.getTransactionID(),null,Constants.LSCC,clientUtils.buildCurrentTimestamp(),peers[0].getClientCertHash());constheader=clientUtils.buildHeader(signer,channelHeader,request.txId.getNonce());constproposal=clientUtils.buildProposal(lcccSpec,header,request.transientMap);constsigned_proposal=clientUtils.signProposal(signer,proposal);returnclientUtils.sendPeersProposal(peers,signed_proposal,timeout).then(function(responses){return[responses,proposal];});}
The text was updated successfully, but these errors were encountered:
1.创建用户报错SSL
问题描述
大概上周一周的时间都在调这个bug,今天总算知道原因了,先把情况列出来,首先是使用了Fabric官网的Node SDK例子balance_transfer,在第一步发请求注册的时候出现的问题
/balance-transfer/node_modules/fabric-ca-client/lib/FabricCAClientImpl.js
的844行代码上,代码段如下:其中
_httpClient
值为https
,也就是nodejs自带的模块,通过require('https')
引入的,也就是相当于在发送https请求的时候报错该错误在网上搜了很久,也用了github上很多人提到的解决方案,但是并不奏效,最后发现是在fabric的基本docker-compose.yaml配置文件和base.yaml配置文件中有相关配置
也就是
TLS_ENABLED
相关字段的配置,被配置成了false,尤其是CA部分的,会导致存在https无法请求的问题,换成http就成功了解决方案
修改network_config.yaml文件
将
certificateAuthories
处的ca都由https
配置成http
的,并且打开httpOptions
配置为true
,配置修改如下2.创建channel报错SSL
问题描述
解决方案
修改network_config.yaml文件
将所有
grpcs
配置成grpc
然后创建channel就成功了3.创建用户报错Failed to get Affiliation
问题描述
org1.department1
org1.department2
org2.department1
,所以此处使用Org0报错解决方案
fabric-ca-client
在fabric-samples/bin
中,其中7054是ca0的端口,相对应关系$ fabric-ca-client enroll -u http://admin:adminpw@localhost:7054 2018/07/02 17:51:00 [INFO] Created a default configuration file at /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml 2018/07/02 17:51:00 [INFO] generating key: &{A:ecdsa S:256} 2018/07/02 17:51:00 [INFO] encoded CSR 2018/07/02 17:51:00 [INFO] Stored client certificate at /Users/guanpengchn/.fabric-ca-client/msp/signcerts/cert.pem 2018/07/02 17:51:00 [INFO] Stored root CA certificate at /Users/guanpengchn/.fabric-ca-client/msp/cacerts/localhost-7054.pem 2018/07/02 17:51:00 [INFO] Stored intermediate CA certificates at /Users/guanpengchn/.fabric-ca-client/msp/intermediatecerts/localhost-7054.pem $ fabric-ca-client affiliation add org0 2018/07/02 17:51:09 [INFO] Configuration file location: /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml Successfully added affiliation: org0 $ fabric-ca-client affiliation add org0.department1 2018/07/02 17:51:15 [INFO] Configuration file location: /Users/guanpengchn/.fabric-ca-client/fabric-ca-client-config.yaml Successfully added affiliation: org0.department1
这时候再注册就成功了
4、create Affiliation的rest接口实现
问题描述
解决方案
于是通过debug后发现
helper.js
的getRegisteredUser
函数中,在enroll了admin之后的caClient变量有newAffiliationService函数仿照fabcar中的调用方式和helper.js的
getRegisteredUser
函数写法,做了如下实现helper.js
添加代码如下app.js
中添加代码如下这样实现了rest接口,能够create affiliation,执行
即可看添加结果,最后一行
5、使用balance-transfer遇到无效网络配置
问题描述
解决方案
原因就是在artifacts下的yaml文件缺失,所以找不到,涉及到的文件为
artifacts/network-config.yaml
,artifacts/org1.yaml
,artifacts/org2.yaml
等,文件所在目录其中在config.js文件中配有文件查询的代码
'Org1-connection-profile-path'
中的前面Org1
来做文件查找的,在代码里体现就是代码位置
6、create Affiliation后依然报错Failed to get Affiliation
问题描述
解决方案
修改后的代码
7、instantiate chaincode时args参数为空报错
问题描述
其中args:[]这里参数为空,结果报错
"Incorrect arguments. Expecting no initial arguments"
解决方案
The text was updated successfully, but these errors were encountered: