一、启动测试网络
请参考Hyperledger Fabric2.3 环境搭建及Fabric 测试网络使用_xiaohanshasha的博客-CSDN博客
二、addOrg3
Adding an Org to a Channel — hyperledger-fabricdocs main documentation
1、执行./addOrg3.sh up
./addOrg3.sh up
出现下图则表示成功
2、配置领导选举
注意:在初始通道配置完成后,将组织添加到网络时,本节作为了解领导者选举设置的参考。此示例为动态领导者选举,需要所有peer在网络中共同设置。
1.选用动态选举模式
CORE_PEER_GOSSIP_USELEADERELECTION=true
CORE_PEER_GOSSIP_ORGLEADER=false
2.选择静态领导模式,配置一个peer成为组织的领导:
CORE_PEER_GOSSIP_USELEADERELECTION=false
CORE_PEER_GOSSIP_ORGLEADER=true
3、安装,定义和调用链码
脚本会在Org1和Org2上安装Fabcar,为Org1和Org2审议了链码定义,然后提交链码定义到通道。一旦链码定义被提交到通道,链码会初始化并调用账本数据。下面的命令假设我们仍在使用通道mychannel。
链码部署后我们可以使用以下几步来作为以Org3身份调用链码。这些步骤全都在目录test-network中,不必非进入Org3CLI容器中,复制和黏贴接下来的环境变量
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
export CORE_PEER_ADDRESS=localhost:11051
第一步是打包 Basic 链码:
peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic
此命令将创建一个名为 的链代码包basic.tar.gz ,我们可以将其安装在 Org3 对等节点上。如果通道正在运行用 Java 或 Node.js 编写的链代码,请相应地修改命令。发出以下命令来安装链码包peer0.org3.example.com
peer lifecycle chaincode install basic.tar.gz
下一步是审议链码定义。Org3需要审议和Org1和Org2一样的链码定义并提交到通道中。为了调用链码,Org3需要包含定义标识在链码定义中。你可以通过peer查询来找链码标识?
peer lifecycle chaincode queryinstalled
您应该会看到类似于以下内容的输出:
?以后会用到package ID,所以将其放入环境变量中,注意更换成你自己的Packge?ID
export CC_PACKAGE_ID=basic_1.0:2a4f0075e234f0b69dd4fb68310e033023187fe1c4b4619c25d8d5730c13616c
Org3审议链码定义
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 2022-03-11 19:47:56.801 PST [chaincodeCmd] ClientWait -> INFO 001 txid [4abb1d6a02c40703b27ff001c5adf82374db8ddee9c1cf2ed7d9eef1433f5779] committed with status (VALID) at localhost:11051 root@ubuntu:/home/hanlw/go/src/hyperleger/fabric-2.3.0/scripts/fabric-samples/test-network# peer lifecycle chaincode queryinstalled Installed chaincodes on peer: Package ID: basic_1.0:2a4f0075e234f0b69dd4fb68310e033023187fe1c4b4619c25d8d5730c13616c, Label: basic_1.0
?使用peer?lifecycle?chaincode?querycommitted命令查询审议过的链码定义是否以被提交到通道。
peer lifecycle chaincode querycommitted --channelID mychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
peer lifecycle chaincode querycommitted --channelID mychannel --name basic --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" Committed chaincode definition for chaincode 'basic' on channel 'mychannel': Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true, Org3MSP: true]
Org3可以使用自己已经审议且链码定义早已提交到通道的链码,链码定义使用默认的背书策略,需要大多数组织认可一项交易。这意味着,如果将组织添加到通道或从通道中删除,则会自动更新背书策略。之前需要Org1和Org2背书(2/2),现在需要三个组织中的两个(2/3).
查询账本确保链码已经在Org3节点运行。注意我们此时需要链码容器启动
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --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" -c '{"function":"InitLedger","Args":[]}'
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" --peerAddresses localhost:11051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt" -c '{"function":"InitPeople","Args":[]}' 2022-03-11 19:50:22.905 PST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200?
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllPeoples"]}' [{"ID":"1","name":"韩帅","Sex":"男","age":29},{"ID":"2","name":"田色","Sex":"男","age":90},{"ID":"3","name":"曾博士","Sex":"女","age":23},{"ID":"4","name":"李世民","Sex":"男","age":23},{"ID":"5","name":"李世民s","Sex":"男","age":23},{"ID":"6","name":"李ddd世民s","Sex":"男","age":23},{"ID":"7","name":"wwd世民s","Sex":"男","age":23}] ?
|