Skip to content

Part of 'the design of a group-signature-based medical system', this is the code which will be deployed on nodes.(The code in this repository may not be complete)

Notifications You must be signed in to change notification settings

jasonren0403/medical-system-chaincode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

medical-system-chaincode

“基于区块链的智慧医疗系统”毕设项目的链码部分仓库

API笔记

  • peer.Response结构
    • response.status:200/400/500
    • response.payloadbase64编码后的返回
    • response.message:错误信息,由shim.Error指定
  • 布置链码

    教程参考:Fabric官方教程 - 英文版

    1. 开启
    ./network.sh up
    1. 建立频道
    ./network.sh createChannel -c <channelName>
    ./network.sh createChannel -c fa-jason
    1. 安装链码
    ./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
    1. 调用函数
    peer chaincode instantiate -C fa-jason
    peer chaincode invoke -C fa-jason -c '{"function":"initLedger","Args":[]}'
    peer chaincode query -C fa-jason -c '...'
    1. 使用结束
    ./network.sh down

手动安装合约

需要从go代码目录执行下列命令

  1. 打包:
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. 安装:
    1. 节点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
    1. 节点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
  2. 接受链码定义:
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"
  1. 提交链码定义至频道
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"
  1. 检验提交状态
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"

About

Part of 'the design of a group-signature-based medical system', this is the code which will be deployed on nodes.(The code in this repository may not be complete)

Topics

Resources

Stars

Watchers

Forks

Languages