“基于区块链的智慧医疗系统”毕设项目的链码部分仓库
peer.Response
结构response.status
:200/400/500response.payload
:base64
编码后的返回response.message
:错误信息,由shim.Error
指定
- 布置链码
教程参考:Fabric官方教程 - 英文版
- 开启
./network.sh up
- 建立频道
./network.sh createChannel -c <channelName> ./network.sh createChannel -c fa-jason
- 安装链码
./network.sh deployCC -ccn <chaincode-name> -ccp <chaincode-filepath> -ccl <chaincode-language> ./network.sh deployCC -ccn MedicalSystem -ccp ../chaincode/MedicalSystem -ccl go -c fa-jason
- 调用函数
peer chaincode instantiate -C fa-jason peer chaincode invoke -C fa-jason -c '{"function":"initLedger","Args":[]}' peer chaincode query -C fa-jason -c '...'
- 使用结束
./network.sh down
需要从go代码目录执行下列命令
- 打包:
GO111MODULE=on go mod vendor
cd ../../test-network
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
peer lifecycle chaincode package ms.tar.gz --path ../chaincode/MedicalSystem --lang golang --label ms_1.0
- 安装:
- 节点1名义
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 lifecycle chaincode install ms.tar.gz
- 节点2名义
export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp export CORE_PEER_ADDRESS=localhost:9051 peer lifecycle chaincode install ms.tar.gz
- 接受链码定义:
peer lifecycle chaincode queryinstalled
export CC_PACKAGE_ID=<pkgid from last order>
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID fa-jason --name MedicalSystem --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
需切换至节点1,继续运行
approveformyorg
命令
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID fa-jason --name MedicalSystem --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
- 提交链码定义至频道
peer lifecycle chaincode checkcommitreadiness --channelID fa-jason --name MedicalSystem --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --output json
输出应均为
true
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID fa-jason --name MedicalSystem --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --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"
- 检验提交状态
peer lifecycle chaincode querycommitted --channelID fa-jason --name MedicalSystem --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"