简体   繁体   English

在Amazon Managed Blockchain Hyperledger Fabric 1.2上以REST API部署和公开Chaincode

[英]Deploy and expose chaincode as REST api on amazon managed blockchain hyperledger fabric 1.2

I have configured amazon managed blockchain setup with Hyperledger 1.2. 我已经使用Hyperledger 1.2配置了亚马逊托管的区块链设置。 The network is prepared with a single member and a single peer node. 该网络由一个成员和一个对等节点组成。 Hyperledger Fabric Client setup is with Golang 1.10.3. Hyperledger Fabric客户端设置与Golang 1.10.3一起使用。 I have installed, Instantiated, Queried and Invoked mycc chaincode example given in AWS tutorial. 我已经安装,实例化,查询和调用了AWS教程中给出的mycc链代码示例。 Which works perfectly. 哪个完美。 Complete exercise was done following this link. 通过链接完成了完整的练习。

I want to deploy and expose the chaincode as REST api. 我想将chaincode部署并公开为REST api。 There is a sample project Amazon Managed Blockchain Workshop . 有一个示例项目Amazon Managed Blockchain Workshop They have used RESTful API, running as a Node.js Express application, using the Hyperledger Fabric Client SDK to query and invoke chaincode. 他们使用了RESTful API(作为Node.js Express应用程序运行),并使用Hyperledger Fabric Client SDK查询和调用链码。 I want to run non-profit chaincode example on Hyperledger Fabric Client prepared for AWS managed Blockchain Hyper Ledger 1.2 我想在为AWS托管区块链Hyper Ledger 1.2准备的Hyperledger Fabric Client上运行非营利性链代码示例

I have performed below steps: 我执行了以下步骤:

Here are the steps how am I am running and testing the REST API. 以下是我如何运行和测试REST API的步骤。

cd ~/non-profit-blockchain/ngo-rest-api
nvm use lts/carbon
node app.js &

If I execute Register/enroll a user request 如果我执行注册/注册用户请求

curl -s -X POST http://localhost:3000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=john&orgName=Org1'

Instead of showing: response: 而不是显示:响应:

{"success":true,"secret":"","message":"michael enrolled Successfully"} {“成功”:true,“秘密”:“”,“消息”:“迈克尔已成功注册”}

It shows below error message. 它显示以下错误消息。

{"success":false,"message":"failed Error: Missing mspid parameter"} {“成功”:false,“消息”:“失败错误:缺少mspid参数”}

I have also tried by adding mspid in the request but the error message is still same. 我也尝试过在请求中添加mspid,但错误消息仍然相同。 What am I missing? 我想念什么?

Here are contents of ngo-connection-profile.yaml 这是ngo-connection-profile.yaml的内容

channels:
  mychannel:
    orderers:
      - orderer.com
    peers:
      peer1:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
<pre><code>
organizations:
  Org1:
    mspid:
    peers:
      - peer1
    certificateAuthorities:
      - ca-org1
orderers:
  orderer.com:
    url: grpcs://orderer.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.managedblockchain.us-east-1.amazonaws.com:30001
    grpcOptions:
      ssl-target-name-override: orderer.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.managedblockchain.us-east-1.amazonaws.com
    tlsCACerts:
      path: /opt/home/managedblockchain-tls-chain.pem
</pre></code>
peers:
  peer1:
    url: grpcs://nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS....
    eventUrl: grpcs://nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.....
    grpcOptions:
      ssl-target-name-override: nd-NDNDNDNDNDNDNDNDNDNDND.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS.xxx
    tlsCACerts:
      path: /opt/home/managedblockchain-tls-chain.pem

certificateAuthorities:
  ca-org1:
    url: https://ca.m-AAAAAAAAAAAAAAAAAAAAAAAAA.n-XDXDXDXDXDSXDSXDXSDXSDXDSXDSXDS....
    httpOptions:
      verify: false
    tlsCACerts:
      path: /opt/home/managedblockchain-tls-chain.pem
    registrar:
      - enrollId: aaaaaaaa
        enrollSecret: XXXXXXXXXXX
    caName: m-AAAAAAAAAAAAAAAAAAAAAAAAA

I am also exploring Amazon Managed Blockchain although its in preview. 我也在探索Amazon Managed Blockchain,尽管它处于预览阶段。 Hopefully I will be able to assist you in your issue. 希望我能在您的问题上为您提供帮助。 mspid is not a parameter to be sent in the request. mspid不是要在请求中发送的参数。 It looks that you are missing some-thing in the configuration file. 看来您在配置文件中缺少某些内容。 Can you send me the contents of below configuration file? 您可以将以下配置文件的内容发送给我吗?

cat ~/non-profit-blockchain/tmp/connection-profile/ngo-connection-profile.yaml

While looking at the contents of the configuration file, it is obvious that mspid value is missing in the configuration file. 在查看配置文件的内容时,很明显在配置文件中缺少mspid值。 Membership Service Providers (MSP) ID is a mandatory value to be set in the configuration. 成员资格服务提供商(MSP)ID是必须在配置中设置的必需值。 You can also confirm it with below command. 您也可以使用以下命令进行确认。

cat ~/non-profit-blockchain/tmp/connection-profile/ngo-connection-profile.yaml | grep mspid:
If it is showing empty value then you need to set mspid in the configuration file. 如果显示空值,则需要在配置文件中设置mspid。 Make sure that the environment variables mentioned in 确保在中提到的环境变量
 ~/non-profit-blockchain/ngo-fabric/fabric-exports.sh 
are properly set. 设置正确。 If this file is missing then use 如果缺少此文件,则使用
 ~/non-profit-blockchain/ngo-fabric/templates/exports-template.sh 
You need to set the value of environment variable ${MEMBERID} in mspid in ngo-connection-profile.yaml, also see if any other required field value is missing in the configuration file. 您需要在ngo-connection-profile.yaml中的mspid中设置环境变量$ {MEMBERID}的值,还请查看配置文件中是否缺少任何其他必需的字段值。 You can also see the detail of values required t be replacs in the configuration file from below script. 您还可以从下面的脚本在配置文件中查看需要替换的值的详细信息。
 ~/non-profit-blockchain/ngo-rest-api/connection-profile/gen-connection-profile.sh 
. Let me list down those as well. 让我也列出这些。
 sed -i "s|%PEERNODEID%|$PEERNODEID|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%MEMBERID%|$MEMBERID|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%CAFILE%|$LOCALCA|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%ORDERINGSERVICEENDPOINT%|$ORDERINGSERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%ORDERINGSERVICEENDPOINTNOPORT%|$ORDERINGSERVICEENDPOINTNOPORT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%PEERSERVICEENDPOINT%|$PEERSERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%PEERSERVICEENDPOINTNOPORT%|$PEERSERVICEENDPOINTNOPORT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%PEEREVENTENDPOINT%|$PEEREVENTENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%CASERVICEENDPOINT%|$CASERVICEENDPOINT|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%ADMINUSER%|$ADMINUSER|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml sed -i "s|%ADMINPWD%|$ADMINPWD|g" $REPODIR/tmp/connection-profile/ngo-connection-profile.yaml 

After setting the values and verifying, stop node or kill the process running on port 3000 and run node again. 设置值并验证后,停止节点或终止在端口3000上运行的进程,然后再次运行节点。 cd ~/non-profit-blockchain/ngo-rest-api cd〜/ non-profit-blockchain / ngo-rest-api

 nvm use lts/carbon node app.js & 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM