# HyperledgerFabricContractJava **Repository Path**: seu-blockchain/hyperledger-fabric-contract-java ## Basic Information - **Project Name**: HyperledgerFabricContractJava - **Description**: 该合约支持对数据的查增删改操作,使用java编写。 - **Primary Language**: Java - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2023-03-22 - **Last Updated**: 2023-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HyperledgerFabricContractJava # 介绍 该合约支持对数据的查增删改操作,使用java编写。 # 使用说明 `git clone https://gitee.com/seu-blockchain/hyperledger-fabric-contract-java.git` #### 创建链码包 `peer lifecycle chaincode package shuju.tar.gz --path ./hyperledger-fabric-contract-java/ --lang java --label shuju_1` #### 安装链码包 Org1 peer节点安装链码包 ``` export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.regulator.com/peers/peer0.org1.regulator.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.regulator.com/users/Admin@org1.regulator.com/msp export CORE_PEER_ADDRESS=peer0.org1.regulator.com:11051 ``` 使用peer lifecycle chaincode install命令在peer节点上安装链码 `peer lifecycle chaincode install shuju.tar.gz` 这一步有时比较慢 与网络状况有关 Org2 peer节点安装链码包 ``` export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.regulator.com/peers/peer0.org2.regulator.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.regulator.com/users/Admin@org2.regulator.com/msp export CORE_PEER_ADDRESS=peer0.org2.regulator.com:13051 ``` 使用peer lifecycle chaincode install命令在peer节点上安装链码 `peer lifecycle chaincode install shuju.tar.gz` #### 查询包ID `peer lifecycle chaincode queryinstalled` 下面将包ID保存为环境变量,将返回的包ID粘贴到下面命令中。 `export CC_PACKAGE_ID=` 如: export CC_PACKAGE_ID=shuju_1:36c9afb9bc33088fd64e3388a068f843eb8e9789565848ae33ec7bc742f5b21c Org1通过链码定义 ``` export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.regulator.com/peers/peer0.org1.regulator.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.regulator.com/users/Admin@org1.regulator.com/msp export CORE_PEER_ADDRESS=peer0.org1.regulator.com:11051 ``` ``` peer lifecycle chaincode approveformyorg -o orderer.regulator.com:11050 --ordererTLSHostnameOverride orderer.regulator.com --channelID regulatorchannel --name shuju --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/regulator.com/orderers/orderer.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem ``` Org2通过链码定义 ``` export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.regulator.com/peers/peer0.org2.regulator.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.regulator.com/users/Admin@org2.regulator.com/msp export CORE_PEER_ADDRESS=peer0.org2.regulator.com:13051 ``` ``` peer lifecycle chaincode approveformyorg -o orderer.regulator.com:11050 --ordererTLSHostnameOverride orderer.regulator.com --channelID regulatorchannel --name shuju --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/regulator.com/orderers/orderer.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem ``` #### 把链码提交到通道上 使用 peer lifecycle chaincode checkcommitreadiness 查看通道成员是否已经批准相同的链码定义 `peer lifecycle chaincode checkcommitreadiness --channelID regulatorchannel --name shuju --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem --output json` 返回两个true 使用 peer lifecycle chaincode commit 将链码定义提交到通道 ``` peer lifecycle chaincode commit -o orderer.regulator.com:11050 --ordererTLSHostnameOverride orderer.regulator.com --channelID regulatorchannel --name shuju --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/regulator.com/orderers/orderer.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem --peerAddresses peer0.org1.regulator.com:11051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.regulator.com/peers/peer0.org1.regulator.com/tls/ca.crt --peerAddresses peer0.org2.regulator.com:13051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.regulator.com/peers/peer0.org2.regulator.com/tls/ca.crt ``` 使用 peer lifecycle chaincode querycommitted 确定链码定义已经提交给通道 `peer lifecycle chaincode querycommitted --channelID regulatorchannel --name shuju --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/regulator.com/orderers/orderer.regulator.com/msp/tlscacerts/tlsca.regulator.com-cert.pem` #### 调用链码 支持查询、创建、更新、删除等操作,下以查询为例 查询链码 `peer chaincode query -C regulatorchannel -n shuju -c '{"Args":["queryShuJu","江苏四环生物股份有限公司-2021-03-31"]}'`