6.3.2 Hyperledger Fabric接入说明
使用fabric-tools与节点进行交互
示例:
1.启动cli
#docker-compose-cli.yaml文件如下: $ cat docker-compose-cli.yaml version: '2' services: cli: container_name: fabric_peercli image: hyperledger/fabric-tools:2.3.2 restart: always tty: true stdin_open: true environment: - FABRIC_LOGGING_SPEC=DEBUG - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt - CORE_PEER_ADDRESS=peer1.org1.example.com:1051 - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp - CORE_PEER_LOCALMSPID=Org1MSP - ORDERER_CA=/etc/hyperledger/fabric/orderer/tlsca/tlsca.orderer.example.com-cert.pem - ORDERER_ADDRESS=orderer1.orderer.example.com:7050 working_dir: /etc/hyperledger/fabric command: /bin/bash volumes: - /var/run/:/host/var/run/ - ./certs/ordererOrganizations/orderer.example.com:/etc/hyperledger/fabric/orderer - ./certs/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp:/etc/hyperledger/fabric/msp - ./certs/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls - ./sharedfiles/chaincode:/etc/hyperledger/fabric/src extra_hosts: - "orderer1.orderer.example.com:161.189.69.75" - "peer1.org1.example.com:161.189.69.75"
2.进入容器进行链码部署以及调用
#链码部署 // package peer lifecycle chaincode package basic414.tar.gz --path ./asset-transfer-basic/chaincode-javascript/ --lang node --label basic414 // install peer lifecycle chaincode install basic414.tar.gz // queryinstalled peer lifecycle chaincode queryinstalled // approveformyorg peer lifecycle chaincode approveformyorg --name basic414 --package-id basic414:16bf72ced8451fc6fd94bd139de1532adfdd190af075c2e84a87513915a97365 -o $ORDERER_ADDRESS --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE --cafile $ORDERER_CA --version 1.0 --channelID netchannel --sequence 1 --connTimeout 30s // queryapproved peer lifecycle chaincode queryapproved --channelID netchannel -n basic414 // checkcommitreadiness peer lifecycle chaincode checkcommitreadiness --channelID netchannel --name basic414 --version 1.0 --sequence 1 --output json // commit peer lifecycle chaincode commit -o $ORDERER_ADDRESS --cafile $ORDERER_CA --channelID netchannel --name basic414 --version 1.0 --sequence 1 --peerAddresses $CORE_PEER_ADDRESS --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE // querycommitted peer lifecycle chaincode querycommitted -o $ORDERER_ADDRESS --channelID netchannel --tls --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE --cafile $ORDERER_CA #调用链码 // InitLedger peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["InitLedger"]}' // GetAllAssets peer chaincode query -C netchannel -n basic414 -c '{"Args":["GetAllAssets"]}' // CreateAsset peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["CreateAsset","asset7","white", "15", "zxl", "800"]}' //UpdateAsset peer chaincode invoke -o $ORDERER_ADDRESS --tls --cafile $ORDERER_CA -C netchannel -n basic414 --peerAddresses $CORE_PEER_ADDRESS --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE -c '{"Args":["UpdateAsset","asset7","zxl", "1218", "zxl", "1218"]}' //ReadAsset peer chaincode query -C netchannel -n basic414 -c '{"Args":["ReadAsset","asset7"]}'