fabric-sample 2.2.0 test-network实战

avatar
avatar
云惠网小编
2077
文章
0
评论
2020年10月17日08:43:57 评论 12 次浏览 4359字阅读14分31秒
摘要

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

相比于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

fabric-sample 2.2.0 test-network实战

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

source ~/.bashrc

2.创建并初始化Fabric网络

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

./network.sh up -ca执行完毕后如下图所示
fabric-sample 2.2.0 test-network实战

./network.sh createChannel执行完毕后如下图所示
fabric-sample 2.2.0 test-network实战

./network.sh deployCC执行完毕后如下图所示
fabric-sample 2.2.0 test-network实战


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/[email protected].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"]}'

fabric-sample 2.2.0 test-network实战

查询刚刚创建的资产

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

fabric-sample 2.2.0 test-network实战
更新资产,将颜色改为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"]}'

fabric-sample 2.2.0 test-network实战
查询资产是否存在

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"]}'

fabric-sample 2.2.0 test-network实战
资产转移,将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"]}'

fabric-sample 2.2.0 test-network实战
删除资产,将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"]}'

fabric-sample 2.2.0 test-network实战
欢迎小伙伴的讨论,若有问题请在评论区评论或私信,谢谢你。

腾讯云618
avatar
2020年10月份自考总结 阿里云开发与运维

2020年10月份自考总结

  这次自考考了3科分别是英语,数据结构,C++。通过这段时间的学习,过不过的吧,尽力了。尽人事,听天命。过不了,下次继续努力,放平心态。分别说一下这三科的学习。
腾讯云618
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: