目录
1.创建fabric网络所需的组织结构及各节点对应的证书、密钥等加密组件
4. 进入 cli 容器,创建应用通道,将 peer 节点加入至通道中
1.创建fabric网络所需的组织结构及各节点对应的证书、密钥等加密组件
generate: 指定创建fabric网络所需的组织结构(包含fabric网络所有的节点及各节点所包含的证书、密钥等)
--config: 指定生成组织结构所使用的配置文件
../bin/cryptogen generate --config=./crypto-config.yaml
2. 创建三种类型的配置文件
(1) 初始区块配置文件
- ../bin/configtxgen -profile TwoOrgsOrdererGenesis -outpuptBlock ./channel-artifacts/genesis.block
-profile: 指定所需的配置信息来源于默认配置文件中的哪一项
-outputBlock: 指定生成的初始区块存储路径及文件名
(2) 应用通道交易配置文件
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
(3) 锚节点更新配置文件
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
3. 启动fabric网络
docker-compose -f docker-compose-cli.yaml up -d
4. 进入 cli 容器,创建应用通道,将 peer 节点加入至通道中
(1)进入 cli 容器
docker exec -it cli bash
(2) 创建应用通道
peer channel create -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 mychannel -f ./channel-artifacts/channel.tx
(3) 将Peer节点加入至通道中
peer channel join -b mychannel.block
(4) 更新锚节点
peer channel update -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 mychannel -f ./channel-artifacts/Org1MSPanchors.tx
-o: 指定orderer节点名称及端口号
--tls: 开启TLS验证
--cafile:指定TLSCA证书
-c: 指定通道唯一标识ID
-f: 指定要使用的配置文件
(5) 查询当前节点加入的通道信息
peer channel list
5. 测试链码
(1)部署链码
a.安装链码
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
-n: 指定链码的名称
-v: 指定链码的版本号
-p: 指定要安装的链码所在目录
b. 实例化链码
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 -n mycc -v 1.0 -C mychannel -c '{"Args":["ini", "a", "100", "b", "200"]}' -P "OR('Org1MSP.peer','Org2MSP.peer')"
-o: 指定要链接的Orderer节点地址及端口号
--tls: 开启TLS验证
--cafile: 指定TLSCA证书
-C: 指定通道ID
-n: 要实例化的链码名称
-v: 链码的版本号
-c: 指定实例化链码时要传递的函数名及参数列表
-P: 指定背书策略
(2) 调用链码实现交易
a.查询(query)
peer chaincode query -C mychannel -n mycc -c '{"Args":["query", "a"]}'
b.调用(invoke)
peer chaincode invoke -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 mychannel -n mycc -c '{"Args":["invoke", "a", "b", "10"]}'
6.退出容器之后关闭网络
docker-compose -f docker-compose-cli.yaml down