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.12.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.12.5.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

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日整理於深圳

發佈了69 篇原創文章 · 獲贊 36 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章