fabric-1.4.x byfn.sh脚本启动网络解析

当运行 ./byfn up 命令时执行了以下步骤:

1,生成证书文件

cryptogen generate --config=./crypto-config.yaml

2,生成交易相关文件

2.1 生成创世块

export FABRIC_CFG_PATH=$PWD
configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
注:为了符合生产环境,上面使用Raft共识机制

2.2 生成通道配置文件

export CHANNEL_NAME=mychannel && configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME

2.3 生成锚节点交易文件

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

3,启动网络节点

docker-compose -f docker-compose-cli.yaml -f docker-compose-etcdraft2.yaml up

4,网络测试(打开一个新终端)

4.1 在Org1的peer0上安装链码

peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/

4.2 在Org2的peer0上安装链码

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
CORE_PEER_LOCALMSPID=“Org2MSP”
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/

4.3 实例化链码

peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -v 1.0 -c ‘{“Args”:[“init”,“a”, “100”, “b”,“200”]}’ -P “AND (‘Org1MSP.peer’,‘Org2MSP.peer’)”

4.4 查询

peer chaincode query -C $CHANNEL_NAME -n mycc -c ‘{“Args”:[“query”,“a”]}’

4.5 调用

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c ‘{“Args”:[“invoke”,“a”,“b”,“10”]}’

4.6 验证

peer chaincode query -C $CHANNEL_NAME -n mycc -c ‘{“Args”:[“query”,“a”]}’

你可能感兴趣的:(hyperledger,fabric)