【自用版】Fabric 2.2.3添加org3组织后初始化网络及安装合约等命令

  • 生成证书文件
cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations"
cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations"
cryptogen generate --config=./organizations/cryptogen/crypto-config-org3.yaml --output="organizations"
cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations"
  • 生成创世块
export FABRIC_CFG_PATH=${PWD}/configtx
configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
  • 开启orderer和三个组织的节点
orderer start
peer node start
  • 生成通道文件并更新锚节点
export FABRIC_CFG_PATH=${PWD}/configtx
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID mychannel -asOrg Org3MSP
  • 创建通道并加入
    打开终端1切换环境:
export FABRIC_CFG_PATH=/home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/peer1

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_ADDRESS=localhost:7051
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

打开终端2切换环境:

export FABRIC_CFG_PATH=$PWD/peer2
export CORE_PEER_TLS_ENABLED=true
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_ADDRESS=localhost:9051
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp

打开终端3切换环境:

export FABRIC_CFG_PATH=$PWD/peer3
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_ADDRESS=localhost:9551
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp

创建通道:

peer channel create -o localhost:7050 -c mychannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/mychannel.tx --outputBlock ./channel-artifacts/mychannel.block --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

加入通道:

sudo peer channel join -b ./channel-artifacts/mychannel.block
  • 打包处理智能合约
    在合约文件夹内打开终端:
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go mod init PqCa
go mod tidy
go mod vendor

打包合约:

sudo peer lifecycle chaincode package chaincode/PqCa.tar.gz --path chaincode/PqCa --lang golang --label PqCa_1.0
sudo peer lifecycle chaincode package chaincode/PqUser.tar.gz --path chaincode/PqUser --lang golang --label PqUser_1.0

安装合约:

sudo peer lifecycle chaincode install chaincode/PqCa.tar.gz
sudo peer lifecycle chaincode install chaincode/PqUser.tar.gz

💚可以查询一下安装过的合约

peer lifecycle chaincode queryinstalled
  • 各组织审议合约:
export CC_PACKAGE_ID=
peer lifecycle chaincode approveformyorg -o localhost:7050  --channelID mychannel  --ordererTLSHostnameOverride orderer.example.com --name PqCa --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"
peer lifecycle chaincode approveformyorg -o localhost:7050  --channelID mychannel  --ordererTLSHostnameOverride orderer.example.com --name PqUser --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"
  • 通道审议:
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name PqCa --version 1.0 --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem  --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name PqUser --version 1.0 --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem  --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"
  • 向通道提交链码定义:
peer lifecycle chaincode commit -o localhost:7050 --channelID mychannel --ordererTLSHostnameOverride orderer.example.com  --name PqCa --version 1.0 --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --peerAddresses peer0.org3.example.com:9551 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt    --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"
peer lifecycle chaincode commit -o localhost:7050 --channelID mychannel --ordererTLSHostnameOverride orderer.example.com  --name PqUser --version 1.0 --sequence 1 --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt   --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --peerAddresses peer0.org3.example.com:9551 --tlsRootCertFiles   /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt   --signature-policy  "OR('Org1MSP.member','Org2MSP.member','Org3MSP.member')"

🤎查看通道上已经提交的合约:

peer lifecycle chaincode querycommitted --channelID mychannel --name PqCa --output json
peer lifecycle chaincode querycommitted --channelID mychannel --name PqUser --output json
  • 更新一下锚节点
peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel -f ./channel-artifacts/Org3MSPanchors.tx --tls --cafile /home/zmh/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

接下来就可以调用合约了balabla~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值