Fabric开发(一)ubuntu下快速搭建fabric1.4.3

1、安装前准备:
安装 git、curl、pip

sudo apt-get install git
sudo apt-get install curl
sudo apt-get install python-pip
pip install --upgrade pip

2、安装go
我这次安装的是go12.5

wget https://storage.googleapis.com/golang/go1.14.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz

接下来编辑当前用户的环境变量:

vi ~/.profile

添加如下:

export PATH=$PATH:/usr/local/go/bin 
export GOROOT=/usr/local/go 
export GOPATH=$HOME/go 
export PATH=$PATH:$HOME/go/bin

编辑保存并退出vi后,记得把这些环境载入:

source ~/.profile

我们把go的目录GOPATH设置为当前用户的文件夹下,所以记得创建go文件夹

cd ~
mkdir go

3.Docker安装
卸载旧版本docker

sudo apt-get remove docker docker-engine docker.io

更新系统软件

sudo apt-get update

安装依赖包

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加官方密钥
执行该命令时,如遇到长时间没有响应说明网络连接不到docker网站,需要使用代-理进行。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

显示OK,表示添加成功.
添加仓库

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

再次更新软件

sudo apt-get update

安装docker
如果想指定安装某一版本,可使用 sudo apt-get install docker-ce= 命令,把替换为具体版本即可。

以下命令没有指定版本,默认就会安装最新版

sudo apt-get install docker-ce

查看docker版本

docker -v

安装完成后需要修改当前用户(我使用的用户叫cuijb)权限:

sudo gpasswd -a cuijb docker
正在将用户“cuijb”加入到“docker”组中
newgrp docker #更新用户组

4.docker-compose安装
下载docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

授权

sudo chmod +x /usr/local/bin/docker-compose

查看版本信息

docker-compose --version

5.下载 fabric源码、fabric-samples源码、fabric镜像
我们可以使用Git命令下载源码,首先需要建立对应的目录,然后进入该目录,Git下载源码:

mkdir -p ~/go/src/github.com/hyperledger 
cd ~/go/src/github.com/hyperledger 
git clone https://github.com/hyperledger/fabric.git

由于Fabric一直在更新,所有我们并不需要最新最新的源码,需要切换到v1.4.3版本的源码即可:

cd ~/go/src/github.com/hyperledger/fabric
git checkout v1.4.3

Fabric Docker镜像的下载

cd ~/go/src/github.com/hyperledger/fabric/script
./bootstrap.sh

下载完成后,会列出所下载的 docker 镜像,具体如下所示:

root@yufabu:~# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-tools       1.4.3               18ed4db0cd57        4 months ago        1.55GB
hyperledger/fabric-tools       latest              18ed4db0cd57        4 months ago        1.55GB
hyperledger/fabric-ca          1.4.3               c18a0d3cc958        4 months ago        253MB
hyperledger/fabric-ca          latest              c18a0d3cc958        4 months ago        253MB
hyperledger/fabric-ccenv       1.4.3               3d31661a812a        4 months ago        1.45GB
hyperledger/fabric-ccenv       latest              3d31661a812a        4 months ago        1.45GB
hyperledger/fabric-orderer     1.4.3               b666a6ebbe09        4 months ago        173MB
hyperledger/fabric-orderer     latest              b666a6ebbe09        4 months ago        173MB
hyperledger/fabric-peer        1.4.3               fa87ccaed0ef        4 months ago        179MB
hyperledger/fabric-peer        latest              fa87ccaed0ef        4 months ago        179MB
hyperledger/fabric-javaenv     1.4.3               5ba5ba09db8f        4 months ago        1.76GB
hyperledger/fabric-javaenv     latest              5ba5ba09db8f        4 months ago        1.76GB
wurstmeister/kafka             latest              988f4a6ca13c        5 months ago        421MB
wil0/php-fpm                   v2                  89b437e8ebd2        7 months ago        403MB
hyperledger/fabric-zookeeper   0.4.15              20c6045930c8        9 months ago        1.43GB
hyperledger/fabric-zookeeper   latest              20c6045930c8        9 months ago        1.43GB
hyperledger/fabric-kafka       0.4.15              b4ab82bbaf2f        9 months ago        1.44GB
hyperledger/fabric-kafka       latest              b4ab82bbaf2f        9 months ago        1.44GB
hyperledger/fabric-couchdb     0.4.15              8de128a55539        9 months ago        1.5GB
hyperledger/fabric-couchdb     latest              8de128a55539        9 months ago        1.5GB

至此,下载 fabric 源码、fabric-samples 源码、fabric 镜像的工作已经完成
执行 ls 命令,查看在当前目录下多了 fabric-samples 目录:

6.first-network 的创建、first-network 的启动、cli 客户端的操作、first-network 的停止、注意事项

6.1、first-network 的创建
切换到 first-network 目录下

cd fabric-samples
cd first-network

创建第一个 channel(myfirstchannel 为通道名称,不写默认为 mychannel,可以自己定义):

./byfn.sh -m generate -c mychannel

自动创建过程如下:

 ./byfn.sh -m generate -c myfirstchannel
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/../bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
#####            使用cryptogen工具生成证书        #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x

Generate CCP files for Org1 and Org2
/root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/../bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
#########         生成 orderer 创世块        ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2019-12-26 13:46:40.228 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-26 13:46:40.291 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-12-26 13:46:40.292 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.349 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-12-26 13:46:40.349 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.355 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-12-26 13:46:40.356 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
###				生成通道配置事务'channel.tx'					  ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID myfirsitchannel
2019-12-26 13:46:40.381 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-26 13:46:40.439 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.497 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-12-26 13:46:40.497 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.497 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-12-26 13:46:40.498 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#######  	  生成指定一个peer节点,并更新到Org1MSP	   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID myfirsitchannel -asOrg Org1MSP
2019-12-26 13:46:40.524 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-26 13:46:40.582 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.641 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-12-26 13:46:40.641 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.641 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-12-26 13:46:40.641 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#######  	  生成指定一个peer节点,并更新到Org1MSP	   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID myfirsitchannel -asOrg Org2MSP
2019-12-26 13:46:40.666 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-26 13:46:40.726 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.784 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-12-26 13:46:40.784 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-26 13:46:40.784 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-12-26 13:46:40.784 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

6.2、first-network 的启动
指定通道名,启动网络:

./byfn.sh -m up -c mychannel

显示如下:

cuijb@cuijb-VirtualBox:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network$ ./byfn.sh -m up -c mychannel
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.4.3
DOCKER_IMAGE_VERSION=1.4.3
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 volume "net_orderer.example.com" with default driver
Creating peer1.org2.example.com
Creating peer0.org1.example.com
Creating peer1.org1.example.com
Creating orderer.example.com
Creating peer0.org2.example.com
Creating cli
CONTAINER ID        IMAGE                               COMMAND             CREATED             STATUS                  PORTS                      NAMES
bad91d6708e9        hyperledger/fabric-tools:latest     "/bin/bash"         3 seconds ago       Up Less than a second                              cli
fde805cdd9a9        hyperledger/fabric-orderer:latest   "orderer"           16 seconds ago      Up 5 seconds            0.0.0.0:7050->7050/tcp     orderer.example.com
6d65447fb84c        hyperledger/fabric-peer:latest      "peer node start"   16 seconds ago      Up 3 seconds            0.0.0.0:9051->9051/tcp     peer0.org2.example.com
56b7e58f1374        hyperledger/fabric-peer:latest      "peer node start"   16 seconds ago      Up 7 seconds            0.0.0.0:7051->7051/tcp     peer0.org1.example.com
fb03d8e4dd2f        hyperledger/fabric-peer:latest      "peer node start"   16 seconds ago      Up 3 seconds            0.0.0.0:10051->10051/tcp   peer1.org2.example.com
96b66a7d468b        hyperledger/fabric-peer:latest      "peer node start"   16 seconds ago      Up 7 seconds            0.0.0.0:8051->8051/tcp     peer1.org1.example.com

 ____    _____      _      ____    _____
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |
 ___) |   | |    / ___ \  |  _ <    | |
|____/    |_|   /_/   \_\ |_| \_\   |_|

Build your first network (BYFN) end-to-end test

Channel name : mychannel
Creating 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
+ res=0
+ set +x
2019-12-28 03:22:42.100 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:42.467 UTC [cli.common] readBlock -> INFO 002 Received block: 0
===================== Channel 'mychannel' created =====================

Having all peers join the channel...
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-12-28 03:22:42.564 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:43.043 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-12-28 03:22:46.167 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:47.249 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-12-28 03:22:50.323 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:51.214 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-12-28 03:22:54.286 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:55.442 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' =====================

Updating anchor peers for org1...
+ 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
+ res=0
+ set +x
2019-12-28 03:22:58.694 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:22:58.824 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================
+ 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

Updating anchor peers for org2...
+ res=0
+ set +x
2019-12-28 03:23:01.943 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-28 03:23:01.958 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================

Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
2019-12-28 03:23:05.061 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-12-28 03:23:05.062 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-12-28 03:23:12.474 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org1 =====================

Install chaincode on peer0.org2...
+ res=0
+ set +x
2019-12-28 03:23:12.594 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-12-28 03:23:12.594 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-12-28 03:23:12.861 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org2 =====================

Instantiating chaincode on 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/orderers/orderer.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'\'')'
+ res=0
+ set +x
2019-12-28 03:23:13.059 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-12-28 03:23:13.060 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================

Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Sending invoke transaction on peer0.org1 peer0.org2...
+ 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 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","a","b","10"]}'
+ res=0
+ set +x
2019-12-28 03:24:16.833 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================

Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2019-12-28 03:24:16.884 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-12-28 03:24:16.884 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-12-28 03:24:16.993 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer1.org2 =====================

Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
Attempting to Query peer1.org2 ...4 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

90
===================== Query successful on peer1.org2 on channel 'mychannel' =====================

========= All GOOD, BYFN execution completed ===========
 _____   _   _   ____
| ____| | \ | | |  _ \
|  _|   |  \| | | | | |
| |___  | |\  | | |_| |
|_____| |_| \_| |____/

当出现上面的信息,说明网络启动成功。

6.3客户端的操作
进入 cli 容器:

docker exec -it cli bash

查询 a 的余额:

root@bad91d6708e9:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
90

查询 b 的余额:

root@bad91d6708e9:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
210

a 向 b 转账 20 并查询各自的余额:

root@bad91d6708e9:/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/orderers/orderer.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","a","b","20"]}'
2019-12-28 04:02:31.158 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200

注意:此处再补充一下 1.4.3 中关于交易转账的命令构成( 1.1.x 版本和 1.4.x 版本的转账命令有点区别):

peer chaincode invoke [flags], 常用参数为:
	`-o, --orderer: orderer节点的地址
	`-C,--channelID:当前命令运行的通道,默认值是“testchainid"
	`-c, --ctor:JSON格式的构造参数,默认值是“{}"
	`-n,--name:Chaincode的名字
	`--tls: 通信时是否使用tls加密
	`--cafile: 当前orderer节点pem格式的tls证书文件, 要使用绝对路径.
	`--peerAddresses: 指定要连接的peer节点的地址
	`--tlsRootCertFiles: 连接的peer节点的TLS根证书
# 连接的peer节点的TLS根证书查找路径参考:
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.itcast.com/peers/peer0.orggo.itcast.com/tls/ca.crt
# example
# -c '{"Args":["invoke","a","b","10"]}'
$ peer chaincode invoke -o orderer节点地址:端口 --tls true --cafile orderer节点pem格式的证书文件 -C 通道名称 -n 链码名称 --peerAddresses 背书节点1:端口 --tlsRootCertFiles 背书节点1的TLS根证书    --peerAddresses 背书节点2:端口 --tlsRootCertFiles 背书节点2的TLS根证书 -c 交易链码调用

6.4.first-network 的关闭
关闭网络:

./byfn.sh -m down

执行 docker ps -a 可以看到 容器情况:

cuijb@cuijb-VirtualBox:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network$ docker ps -a
CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                      NAMES
b609b3d98436        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   41 minutes ago      Up 41 minutes                                  dev-peer1.org2.example.com-mycc-1.0
f24c5f7fdf6b        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   42 minutes ago      Up 42 minutes                                  dev-peer0.org1.example.com-mycc-1.0
eb1dbb4a9269        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   42 minutes ago      Up 42 minutes                                  dev-peer0.org2.example.com-mycc-1.0
bad91d6708e9        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              44 minutes ago      Up 43 minutes                                  cli
fde805cdd9a9        hyperledger/fabric-orderer:latest                                                                      "orderer"                44 minutes ago      Up 44 minutes       0.0.0.0:7050->7050/tcp     orderer.example.com
6d65447fb84c        hyperledger/fabric-peer:latest                                                                         "peer node start"        44 minutes ago      Up 44 minutes       0.0.0.0:9051->9051/tcp     peer0.org2.example.com
56b7e58f1374        hyperledger/fabric-peer:latest                                                                         "peer node start"        44 minutes ago      Up 44 minutes       0.0.0.0:7051->7051/tcp     peer0.org1.example.com
fb03d8e4dd2f        hyperledger/fabric-peer:latest                                                                         "peer node start"        44 minutes ago      Up 44 minutes       0.0.0.0:10051->10051/tcp   peer1.org2.example.com
96b66a7d468b        hyperledger/fabric-peer:latest                                                                         "peer node start"        44 minutes ago      Up 44 minutes       0.0.0.0:8051->8051/tcp     peer1.org1.example.com

6.5.注意事项
若上次启动网络后没有关闭,下次启动网络之前一定要先执行 ./byfn.sh -m down
然后再次启动网络,只需执行 ./byfn.sh -m up -c myfirstchannel 即可。
再次,关闭所有 docker 容器的命令(如果用得到的话):

docker rm -f $(docker ps -aq)

现在我们整个FabricV1.4.3的环境已经测试完毕,恭喜,一切正常。

2019年12月28日整理于深圳

猜你喜欢

转载自blog.csdn.net/jambeau/article/details/103712408