fabric-sample 2.2.0 test-network实战

家住魔仙堡 提交于 2020-10-28 03:01:05

相比于fabricv2.0.0v2.2.0的部分指令作出了小更改

1.下载fabric-sample及fabric2.2.0二进制文件和镜像

cd /home/yujialing/go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
git checkout 22393b629bcac7f7807cc6998aa44e06ecc77426
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.2.0 1.4.8 -s

配置环境变量

vim ~/.bashrc

将以下内容复制到bashrc文件中(路径中用户名需要改成你们的用户名),按“I”插入,插入完成后按ESC退出插入,输出:wq!保存退出,如下图所示(pwdfabric-sample的路径)

export PATH=$PATH:/home/yujialing/go/src/github.com/hyperledger/fabric-samples/bin
export FABRIC_CFG_PATH=/home/yujialing/go/src/github.com/hyperledger/fabric-samples/config

退出后在命令行输入以下命令刷新配置文件

source ~/.bashrc

2.创建并初始化Fabric网络

cd test-network
./network.sh up -ca
./network.sh createChannel
./network.sh deployCC

./network.sh up -ca执行完毕后如下图所示

./network.sh createChannel执行完毕后如下图所示

./network.sh deployCC执行完毕后如下图所示


3.账本交互

Org1Peer0的身份进行账本交互

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${
   
      PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

创建资产

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${
   
      PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"CreateAsset","Args":["asset6","black","20","Jack","630"]}'

在这里插入图片描述

查询刚刚创建的资产

peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'

在这里插入图片描述
更新资产,将颜色改为blue蓝色,价值改为680

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${
   
      PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"UpdateAsset","Args":["asset6","blue","20","Jack","680"]}'

查询资产是否更新成功

peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'

在这里插入图片描述
查询资产是否存在

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${
   
      PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"AssetExists","Args":["asset6"]}'

在这里插入图片描述
资产转移,将asset6资产由Jack转给Michel

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${
   
      PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"TransferAsset","Args":["asset6","Michel"]}'

在这里插入图片描述
删除资产,将asset6资产删除

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${
   
      PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${
   
      PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"DeleteAsset","Args":["asset6"]}'

在这里插入图片描述
欢迎小伙伴的讨论,若有问题请在评论区评论或私信,谢谢你。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!