facar单机与多机部署
可以和我之前写的多机部署文章一起看,有些问题重复的
大佬的多机部署博客链接:https://blog.csdn.net/bean_business/article/details/110100669
单机部署
因为我之前把fabcar文件更改过,所以需要重新下载fabric-sample内容覆盖掉fabcar文件夹
链接:https://github.com/hyperledger/fabric-samples/tree/master
需要在linux上下载,在win10下载后复制过去似乎编码啥的有问题,运行会报错
单机部署的js版(运行过没问题)
https://hyperledger-fabric.readthedocs.io/zh_CN/release-2.2/write_first_app.html
ps:感觉js版的链码写得比较清楚易懂
多机部署
仍然是用multiple-deployment文件夹中内容
先把两台机的mychannel.block,之前打包的链码压缩包删掉
建议开始前再检查一遍docker-compose-up.yaml文件中ip地址有没有错误 (两台都检查一下)
host也要检查 😡(浪费好长时间)
可能因为我更新了wmware导致和之前ip不一样了
以下是虚拟机1
的操作,复制fabric样例中的名为 fabcar 的链码(智能合约)到chaincode/go
下
cp -r ../chaincode/fabcar/go/* chaincode/go
go env -w GO111MODULE=on
go mod tidy
安装部署链码
在虚拟机1打包链码前需要在cli1内执行
go env -w GO111MODULE=auto
安装链码的操作直接复制多机部署博客就可以(不改名字之类的话)
(如果试着改下名字可以熟练下那些参数)
操作可以参考
https://blog.csdn.net/bean_business/article/details/108015490
https://hyperledger-fabric.readthedocs.io/zh_CN/release-2.2/commands/peerlifecycle.html
主要看前两个
初始化链码
args里的就是参数。(表明调用哪个函数,传进什么参数)
peer chaincode invoke -o [orderer0.example.com:7050](http://orderer0.example.com:7050/) --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses [peer0.org1.example.com:7051](http://peer0.org1.example.com:7051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses [peer0.org2.example.com:7051](http://peer0.org2.example.com:7051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["InitLedger"]}' --waitForEvent
查询所有车辆 (query查询)
peer chaincode query -C mychannel -n mycc -c '{"Args":["QueryAllCars"]}'
创建新车
与初始化链码的指令差别就在args
peer chaincode invoke -o [orderer.example.com:7050](http://orderer.example.com:7050/) --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses [peer0.org1.example.com:7051](http://peer0.org1.example.com:7051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses [peer0.org2.example.com:7051](http://peer0.org2.example.com:9051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"Args":["CreateCar","CAR10","GEELY","Borui","Blue","Yujialing"]}'
查询具体的车
peer chaincode query -C mychannel -n mycc -c '{"Args":["QueryCar","CAR10"]}'
更改车辆所有者(调用ChangeCarOwner函数)
peer chaincode invoke -o [orderer0.example.com:7050](http://orderer0.example.com:7050/) --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses [peer0.org1.example.com:7051](http://peer0.org1.example.com:7051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses [peer0.org2.example.com:7051](http://peer0.org2.example.com:7051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["ChangeCarOwner","CAR10","广东靓仔"]}' --waitForEvent
更改并同步成功