fabric 1.4 byfn.sh的手动部署过程
- 为每个节点生成证书文件
- 生成系统通道创世区块
- 生成channel配置信息
- 生成锚节点配置信息
- 启动网络 peer0.org1、peer1.org1、peer0.org2、 peer1.org2、 orderer、 cli
- docker exec -it cli bash 进入到docker 的cli 的bash 中进行执行
- create channel
- peer0.org1 peer1.org1 peer0.org2、 peer1.org2 加入channel
- 更新锚节点
- 安装链码
- 实例化链码,并且确定背书策略
- 查询链码中数据
- 调用链码 a 转b 10 元
具体实现
0.导入环境变量
cd fabric-samples/first-network/
export PATH=../bin:$PATH
# 因为当前的目录是 /fabric-samples/first-network 但是命令都在/fabric-samples/bin
1.为每个节点生成证书文件
crypto-config.yaml 文件定义orderer组织 和Peer节点配置 生成的oederer组织个数 组织内的节点个数
# - Name: Org2 // 组织名字
# Domain: org2.example.com
# EnableNodeOUs: true
# Template:
# Count: 2 生成 peer0 peer 1
# Users:
# Count: 1 用户数量
cryptogen generate --config=./crypto-config.yaml
#log
#[root@localhost first-network]# cryptogen generate --config=./crypto-config.yaml
#org1.example.com
#org2.example.com
2.生成创世区块
configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
#log
#[root@localhost first-network]# configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
#2021-04-13 17:08:18.528 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
#2021-04-13 17:08:18.563 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: solo
#2021-04-13 17:08:18.563 CST 0003 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
#2021-04-13 17:08:18.566 CST 0004 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
#2021-04-13 17:08:18.566 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Creating system channel genesis block
#2021-04-13 17:08:18.567 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block
# 将会在./channel-artifacts 生成 genesis.block
3.生成channel配置信息文件
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
# log
# [root@localhost first-network]# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
# 2021-04-13 17:18:32.723 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
# 2021-04-13 17:18:32.761 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
# 2021-04-13 17:18:32.761 CST 0003 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Generating new channel configtx
# 2021-04-13 17:18:32.765 CST 0004 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Writing new channel tx
# 将会在./channel-artifacts 生成 channel.tx
4.更新锚节点配置信息
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
#log
# [root@localhost first-network]# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
# 2021-04-13 17:14:34.892 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
# 2021-04-13 17:14:34.929 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
# 2021-04-13 17:14:34.929 CST 0003 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Generating anchor peer update
# 2021-04-13 17:14:34.932 CST 0004 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Writing anchor peer update
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
# log
# [root@localhost first-network]# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
# 2021-04-13 17:21:36.822 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
# 2021-04-13 17:21:36.858 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
# 2021-04-13 17:21:36.858 CST 0003 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Generating anchor peer update
# 2021-04-13 17:21:36.862 CST 0004 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Writing anchor peer update
# 将会在./channel-artifacts 生成 Org2MSPanchors.tx 和 Org1MSPanchors.tx
5. 启动网络
docker-compose -f docker-compose-cli.yaml up -d
# -f 指定模版文件 up 启动 -d 在后台
# log
# [root@localhost first-network]# docker-compose -f docker-compose-cli.yaml up -d
# Creating network "net_byfn" with the default driver
# Creating volume "net_peer0.org2.example.com" with default driver
# Creating volume "net_peer1.org2.example.com" with default driver
# Creating volume "net_peer1.org1.example.com" with default driver
# Creating volume "net_peer0.org1.example.com" with default driver
# Creating peer0.org1.example.com ... done
# Creating cli ... done
# Creating peer1.org2.example.com ...
# Creating peer0.org1.example.com ...
# Creating peer0.org2.example.com ...
# Creating peer1.org1.example.com ...
# Creating cli ...
执行docker ps,命令查看当前创建的镜像,如果orderer节点未启动 执行以下命令
docker ps
# log
# [root@localhost first-network]# docker ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# dea1e2dad8be hyperledger/fabric-tools:latest "/bin/bash" 2 minutes ago Up 2 minutes cli
# 7bf029636aba hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:8051->8051/tcp peer1.org1.example.com
# b846fc9ae209 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:7051->7051/tcp peer0.org1.example.com
# 4972796c60b7 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:9051->9051/tcp peer0.org2.example.com
# b2dbff1b7bbb hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:10051->10051/tcp peer1.org2.example.com
# ddca3d022fc6 hyperledger/fabric-orderer:latest "orderer" 2 minutes ago Up 2 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
docker-compose -f docker-compose-cli.yaml down --volumes --remove-orphans
docker rm -f $(docker ps -a | grep "hyperledger/*" | awk "{print \$1}")
docker volume prune
6.进入cli 后台操作
docker exec -it cli bash
# log
# [root@localhost first-network]# docker exec -it cli bash
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer#
7.创建channel
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --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
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --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
# 2021-04-13 09:36:39.768 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 09:36:39.802 UTC [cli.common] readBlock -> INFO 002 Received block: 0
8.配置channel
1.将mychannel.block 拷贝到channel-artifacts文件下 cp mychannel.block ./channel-artifacts
此时有网络中有两个组织,每两个组织下面有两个peer
peer0.org1
peer1.org1
peer0.org2
peer1.org2
2.env | grep CORE 查看当前的节点信息
env | grep CORE
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# env | grep CORE
# CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# CORE_PEER_LOCALMSPID=Org1MSP
# CORE_PEER_TLS_ENABLED=true
# CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# CORE_PEER_ID=cli
# CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
# CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
# CORE_PEER_ADDRESS=peer0.org1.example.com:7051
# CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
3.如上现在是peer0.org1
peer channel join -b channel-artifacts/mychannel.block
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b channel-artifacts/mychannel.block
# 2021-04-13 09:47:49.006 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 09:47:49.056 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
4.切换成 peer1.org1
source scripts/utils.sh
setGlobals 1 1
env | gerp CORE
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# env |grep CORE
# CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# CORE_PEER_LOCALMSPID=Org1MSP
# CORE_PEER_TLS_ENABLED=true
# CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# CORE_PEER_ID=cli
# CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
# CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
# CORE_PEER_ADDRESS=peer1.org1.example.com:8051
# CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
peer channel join -b channel-artifacts/mychannel.block
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b channel-artifacts/mychannel.block
# 2021-04-13 09:58:19.306 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 09:58:19.386 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
5.切换为 peer0.org2
source scripts/utils.sh
setGlobals 0 2
env |grep CORE
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# env |grep CORE
# CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# CORE_PEER_LOCALMSPID=Org2MSP
# CORE_PEER_TLS_ENABLED=true
# CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# CORE_PEER_ID=cli
# CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
# 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
# CORE_PEER_ADDRESS=peer0.org2.example.com:9051
# CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
peer channel join -b channel-artifacts/mychannel.block
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b channel-artifacts/mychannel.block
# 2021-04-13 10:02:01.462 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 10:02:01.510 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
6.切换为 peer1.org2
source scripts/utils.sh
setGlobals 1 2
env |grep CORE
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# env |grep CORE
# CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
# CORE_PEER_LOCALMSPID=Org2MSP
# CORE_PEER_TLS_ENABLED=true
# CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
# CORE_PEER_ID=cli
# CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
# 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
# CORE_PEER_ADDRESS=peer1.org2.example.com:10051
# CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
peer channel join -b channel-artifacts/mychannel.block
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b channel-artifacts/mychannel.block
# 2021-04-13 10:04:11.511 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 10:04:11.552 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
9.更新锚节点,锚节点作用(用来和不同组织的进行通信)
1.切换到 peer0.org1
source scripts/utils.sh
setGlobals 0 1
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --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
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --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
#2021-04-13 10:09:22.616 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
#2021-04-13 10:09:22.646 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
2.切换到 peer0.org2
source scripts/utils.sh
setGlobals 0 2
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --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
# log
# root@dea1e2dad8be:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --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
# 2021-04-13 10:05:56.057 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
# 2021-04-13 10:05:56.087 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
10. 安装链码
# 切换到 peer0.org1
setGlobals 0 1
# 安装链码
peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
# log
# root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
# 2021-04-14 10:41:48.938 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
# 2021-04-14 10:41:48.938 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
# 2021-04-14 10:41:49.898 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
# 切换到peer0.org2
setGlobals 0 2
# 安装链码
peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
#log
# root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
# 2021-04-14 10:44:57.219 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
# 2021-04-14 10:44:57.219 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
# 2021-04-14 10:44:57.547 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
11.实例化链码并且确定背书策略
在peer0.org2上初始化链码并指定背书策略 需要两个组织同时背书才能完成交易
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
#log
#root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
#2021-04-14 10:57:26.252 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
#2021-04-14 10:57:26.252 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
12.peer0.org1上进行查询
查询a 的值是100
setGlobals 0 1
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#log
#root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#100
#查询的结果是100
13.将b 的10元钱转给a 交易验证
1.根据背书策略需要两个组织共同背书才能完成交易 peer0.org1
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -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","b","a","10"]}'
# log
#root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -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","b","a","10"]}'
#2021-04-14 11:10:19.285 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
2.在peer0.org2 查询验证
setGlobals 0 2
# 查询a 的money
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
# log
# root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#110 a 有110元钱
# 查询b 的money
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
#root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
#190
14.加入新的节点,在新节点上安装链码
在peer1.org2上安装链码
# 切换到 peer1.org2
setGlobals 1 2
# 安装链码
peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
# log
# root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
# 2021-04-14 11:18:33.865 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
# 2021-04-14 11:18:33.865 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
# 2021-04-14 11:18:34.422 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
# 查询 a 和 b 的余额
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
#log
# root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
# 190
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#root@416a56c9f044:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
#110
ps:setGlobals 切换环境
setGlobals 切换环境其实是使用的utils.sh 的方法,如果不使用这个方法,比较直接的是如下操作,通过更改环境变量进行操作
# org1 peer0
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
# peer1.org1
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer1.org1.example.com:8051
# peer0.org2
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
# peer1.org2
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer1.org2.example.com:10051
网友评论