在mac上部署HyperLedger Fabric 1.0

最近在学习区块链框架HyperLedger Fabric,其当前的最新版本为1.0.0 Beta。为方便体验,需要在本地的mac上先部署起来。由于目前相关的中文资料很少,主要参考的是官方文档,还有网上一些零星的文章。


先将Fabric工程下载一份到本地(这里为方便说明,存在个人目录)

1
2
cd ~
git clone git@github.com:hyperledger/fabric.git


环境搭建

为了方便部署,Fabric提供了Docker镜像,但我们得先将Docker环境搭建起来。Mac上搭建Docker环境,可以通过Docker ToolBox来安装,其中会包括一些列的工具,感兴趣的朋友可以关注下其文档。由于是初学,我准备不使用该工具,而是从基础开始一步步来搭建。

安装VirtualBox、Vagrant

由于Docker是基于Linux容器技术LXC, 不能直接部署在mac的OS X系统上,因此在mac上需要先搭建一个Linux的虚拟环境。

  • 这就要借助VirtualBox虚拟出一个Linux环境,下载VirtualBoxOS X版本并安装即可。

  • Vagrant是虚拟机管理工具,底层支持VirtualBox作为虚拟机系统,可以在参考这里做些了解。下载Vagrant的OS X版本安装即可。

还有个工具boot2docker可以更方便的直接mac下用命令管理docker(当然前提也得安装VirtualBox),感兴趣可以关注下,这里我也没有安装这个工具,而是进入到VirtualBox中使用docker。

启动虚拟机


进入git clone到本地个人目录的fabric工程下devenv目录,会看到有个Vagrantfile文件,在该目录下执行以下命令。

1
2
3
cd fabric/devenv
vagrant up
vagrant ssh

其中`vagrant up`命令执行时间会很长,它会现在ubuntu虚拟机,将其启动后进行初始化环境,包括go、docker等安装,需要耐心等待。

执行成功就会看到以下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
➜ devenv git:(v1.0.0-preview) vagrant ssh
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-59-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 packages can be updated.
0 updates are security updates.
Last login: Thu Jun 22 05:15:17 2017 from 10.0.2.2
vagrant@hyperledger-devenv:v0.3.0-c7b3fe0:/opt/gopath/src/github.com/hyperledger/fabric$


Fabric部署

由于在部署过程中需要下载大量fabric相关的docker镜像,国外镜像源是在没法忍,一定要先将源切换到国内,阿里云上有:

在虚拟机内部:

1
2
3
4
sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service
sudo sed -i "s|ExecStart=/usr/bin/dockerd|ExecStart=/usr/bin/dockerd --registry-mirror=https://pee6w651.mirror.aliyuncs.com|g" /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo service docker restart

然后执行:

1
2
3
4
cd ~
mkdir fabric-sample
cd fabric-sample
sh /opt/gopath/src/github.com/hyperledger/fabric/scripts/bootstrap-1.0.0-beta.sh

执行后会下载fabric相关的docker镜像,非一般的速度,也需要耐心等待。

以上下载完成后,可以看下docker镜像情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vagrant@hyperledger-devenv:v0.3.0-c7b3fe0:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-tools latest ae6b0f53cb70 14 hours ago 1.32 GB
hyperledger/fabric-tools x86_64-1.0.0-beta ae6b0f53cb70 14 hours ago 1.32 GB
hyperledger/fabric-couchdb latest 31bbbec3d853 14 hours ago 1.48 GB
hyperledger/fabric-couchdb x86_64-1.0.0-beta 31bbbec3d853 14 hours ago 1.48 GB
hyperledger/fabric-kafka latest c4ac1c9a4797 14 hours ago 1.3 GB
hyperledger/fabric-kafka x86_64-1.0.0-beta c4ac1c9a4797 14 hours ago 1.3 GB
hyperledger/fabric-zookeeper latest 2c4ebacb6f00 14 hours ago 1.31 GB
hyperledger/fabric-zookeeper x86_64-1.0.0-beta 2c4ebacb6f00 14 hours ago 1.31 GB
hyperledger/fabric-orderer latest 11ff350dd297 14 hours ago 179 MB
hyperledger/fabric-orderer x86_64-1.0.0-beta 11ff350dd297 14 hours ago 179 MB
hyperledger/fabric-peer latest e01c2b645f11 14 hours ago 182 MB
hyperledger/fabric-peer x86_64-1.0.0-beta e01c2b645f11 14 hours ago 182 MB
hyperledger/fabric-javaenv latest 61c188dca542 14 hours ago 1.42 GB
hyperledger/fabric-javaenv x86_64-1.0.0-beta 61c188dca542 14 hours ago 1.42 GB
hyperledger/fabric-ccenv latest 7034cca1918d 14 hours ago 1.29 GB
hyperledger/fabric-ccenv x86_64-1.0.0-beta 7034cca1918d 14 hours ago 1.29 GB
hyperledger/fabric-ca latest e549e8c53c2e 15 hours ago 238 MB
hyperledger/fabric-ca x86_64-1.0.0-beta e549e8c53c2e 15 hours ago 238 MB

Fabric启动

在上述fabric-sample目录下,cd release/linux-amd64/,然后执行./network_setup.sh up,就可以将fabric启动起来,以下为启动过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
vagrant@hyperledger-devenv:v0.3.0-c7b3fe0:~/fabric-sample/release/linux-amd64$ ./network_setup.sh up
setting to default channel 'mychannel'
mychannel
Using cryptogen -> /home/vagrant/fabric-sample/release/linux-amd64/../../release/linux-amd64/bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
2017-06-23 05:47:17.467 UTC [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.563 UTC [bccsp] GetDefault -> WARN 002 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.565 UTC [bccsp] GetDefault -> WARN 003 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.569 UTC [bccsp] GetDefault -> WARN 004 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.572 UTC [bccsp] GetDefault -> WARN 005 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
org2.example.com
2017-06-23 05:47:17.577 UTC [bccsp] GetDefault -> WARN 006 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.579 UTC [bccsp] GetDefault -> WARN 007 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.582 UTC [bccsp] GetDefault -> WARN 008 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.585 UTC [bccsp] GetDefault -> WARN 009 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.588 UTC [bccsp] GetDefault -> WARN 00a Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.591 UTC [bccsp] GetDefault -> WARN 00b Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.594 UTC [bccsp] GetDefault -> WARN 00c Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2017-06-23 05:47:17.597 UTC [bccsp] GetDefault -> WARN 00d Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
Using configtxgen -> /home/vagrant/fabric-sample/release/linux-amd64/../../release/linux-amd64/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
2017-06-23 05:47:17.837 UTC [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-23 05:47:17.848 UTC [msp] getMspConfig -> INFO 002 intermediate certs folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:47:17.849 UTC [msp] getMspConfig -> INFO 003 crls folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/crls: no such file or directory]
2017-06-23 05:47:17.849 UTC [msp] getMspConfig -> INFO 004 MSP configuration file not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/config.yaml]: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/ordererOrganizations/example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:47:17.915 UTC [msp] getMspConfig -> INFO 005 intermediate certs folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:47:17.916 UTC [msp] getMspConfig -> INFO 006 crls folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:47:17.917 UTC [msp] getMspConfig -> INFO 007 MSP configuration file not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/config.yaml]: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:47:17.921 UTC [msp] getMspConfig -> INFO 008 intermediate certs folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:47:17.922 UTC [msp] getMspConfig -> INFO 009 crls folder not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/intermediatecerts]. Skipping.: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/crls: no such file or directory]
2017-06-23 05:47:17.923 UTC [msp] getMspConfig -> INFO 00a MSP configuration file not found at [/home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/config.yaml]: [stat /home/vagrant/fabric-sample/release/linux-amd64/crypto-config/peerOrganizations/org2.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:47:17.930 UTC [common/configtx/tool] doOutputBlock -> INFO 00b Generating genesis block
2017-06-23 05:47:17.935 UTC [common/configtx/tool] doOutputBlock -> INFO 00c Writing genesis block
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2017-06-23 05:47:18.140 UTC [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-23 05:47:18.162 UTC [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2017-06-23 05:47:18.163 UTC [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
2017-06-23 05:47:18.186 UTC [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-23 05:47:18.206 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-23 05:47:18.207 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
2017-06-23 05:47:18.447 UTC [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-23 05:47:18.453 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-23 05:47:18.454 UTC [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
Creating network "linuxamd64_default" with the default driver
Creating orderer.example.com
Creating peer1.org1.example.com
Creating peer0.org1.example.com
Creating peer0.org2.example.com
Creating peer1.org2.example.com
Creating cli
____ _____ _ ____ _____ _____ ____ _____
/ ___| |_ _| / \ | _ \ |_ _| | ____| |___ \ | ____|
\___ \ | | / _ \ | |_) | | | _____ | _| __) | | _|
___) | | | / ___ \ | _ < | | |_____| | |___ / __/ | |___
|____/ |_| /_/ \_\ |_| \_\ |_| |_____| |_____| |_____|
Channel name : mychannel
Creating channel...
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_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_VM_ENDPOINT=unix:///host/var/run/docker.sock
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_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
...
中间省略大量打印信息
...
2017-06-23 05:48:37.821 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:48:37.821 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:48:37.821 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB1070A6708031A0C08B5D7B2CA0510...6D7963631A0A0A0571756572790A0161
2017-06-23 05:48:37.821 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: D0AAC30B596F344FE392560914150033874236831DEDB76E4A45904722E9921B
Query Result: 90
2017-06-23 05:49:00.486 UTC [main] main -> INFO 008 Exiting.....
===================== Query on PEER3 on channel 'mychannel' is successful =====================
===================== All GOOD, End-2-End execution completed =====================
_____ _ _ ____ _____ ____ _____
| ____| | \ | | | _ \ | ____| |___ \ | ____|
| _| | \| | | | | | _____ | _| __) | | _|
| |___ | |\ | | |_| | |_____| | |___ / __/ | |___
|_____| |_| \_| |____/ |_____| |_____| |_____|

Fabric测试&体验

在打开一个shell并执行vagrant ssh登录到虚拟机,然后进入Fabric CLI容器

1
docker exec -it cli bash

可以进入容器

1
root@2b646a798400:/opt/gopath/src/github.com/hyperledger/fabric/peer#

再安装示例:

1
2
cd /opt/gopath/src
peer chaincode install -n devincc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

得到以下输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2017-06-23 05:50:27.050 UTC [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:50:27.050 UTC [msp] getMspConfig -> INFO 002 crls folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:50:27.052 UTC [msp] getMspConfig -> INFO 003 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:50:27.110 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:50:27.110 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:50:27.111 UTC [golang-platform] getCodeFromFS -> DEBU 006 getCodeFromFS github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
2017-06-23 05:50:27.286 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package fmt
2017-06-23 05:50:27.286 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
2017-06-23 05:50:27.286 UTC [golang-platform] func1 -> DEBU 009 Discarding provided package github.com/hyperledger/fabric/protos/peer
2017-06-23 05:50:27.286 UTC [golang-platform] func1 -> DEBU 00a Discarding GOROOT package strconv
2017-06-23 05:50:27.286 UTC [golang-platform] func1 -> DEBU 00b Discarding GOROOT package
2017-06-23 05:50:27.286 UTC [golang-platform] GetDeploymentPayload -> DEBU 00c done
2017-06-23 05:50:27.289 UTC [msp/identity] Sign -> DEBU 00d Sign: plaintext: 0AA2070A5C08031A0C08A3D8B2CA0510...3C66FC330000FFFF7FCF700C001C0000
2017-06-23 05:50:27.289 UTC [msp/identity] Sign -> DEBU 00e Sign: digest: 83B87FD053CA12C412CC9850DBFB94E7EAE1983E91B04270B6352FA2EC3ECB15
2017-06-23 05:50:27.297 UTC [chaincodeCmd] install -> DEBU 00f Installed remotely response:<status:200 payload:"OK" >
2017-06-23 05:50:27.297 UTC [main] main -> INFO 010 Exiting.....

初始化实例,设置a账户100,b账户200

1
root@2b646a798400:/opt/gopath/src# peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -C mychannel -n devincc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

输出:

1
2
3
4
5
6
7
8
9
10
11
12
2017-06-23 05:50:47.220 UTC [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:50:47.220 UTC [msp] getMspConfig -> INFO 002 crls folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:50:47.220 UTC [msp] getMspConfig -> INFO 003 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:50:47.277 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:50:47.277 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:50:47.287 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 006 Using default escc
2017-06-23 05:50:47.288 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 007 Using default vscc
2017-06-23 05:50:47.290 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AAD070A6708031A0C08B7D8B2CA0510...324D53500A04657363630A0476736363
2017-06-23 05:50:47.290 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 36E49FE181ADCF03088E5D0AE710B30B67E4803F4E37B73078380A9DB5CF9603
2017-06-23 05:51:08.178 UTC [msp/identity] Sign -> DEBU 00a Sign: plaintext: 0AAD070A6708031A0C08B7D8B2CA0510...F07E3760D46961FE57B9D38F8D1BABFE
2017-06-23 05:51:08.178 UTC [msp/identity] Sign -> DEBU 00b Sign: digest: A93AA322F299B468CA2F6089598854F9601691F90336927FEFFA24D16342DDDE
2017-06-23 05:51:08.193 UTC [main] main -> INFO 00c Exiting.....

查询a账户余额,query命令,输出Query Result: 100

1
peer chaincode query -C mychannel -n devincc -c '{"Args":["query","a"]}'

输出:

1
2
3
4
5
6
7
8
9
2017-06-23 05:51:15.084 UTC [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:51:15.084 UTC [msp] getMspConfig -> INFO 002 crls folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:51:15.084 UTC [msp] getMspConfig -> INFO 003 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:51:15.146 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:51:15.146 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:51:15.149 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AAF070A6908031A0B08D3D8B2CA0510...696E63631A0A0A0571756572790A0161
2017-06-23 05:51:15.149 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 2317DA8BAB41C5D03745C63F7B621B3D016690BF96B6BB33C02B30634005AD7F
Query Result: 100
2017-06-23 05:51:15.170 UTC [main] main -> INFO 008 Exiting.....

a账户转账10到b账户,invoke命令,得到输出Chaincode invoke successful. result: status:200

1
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem -C mychannel -n devincc -c '{"Args":["invoke","a","b","10"]}'

输出

1
2
3
4
5
6
7
8
9
10
11
12
2017-06-23 05:51:29.234 UTC [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:51:29.235 UTC [msp] getMspConfig -> INFO 002 crls folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:51:29.235 UTC [msp] getMspConfig -> INFO 003 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:51:29.283 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:51:29.283 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:51:29.295 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB0070A6A08031A0C08E1D8B2CA0510...696E766F6B650A01610A01620A023130
2017-06-23 05:51:29.295 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: E3DE55FFD249EEA6DB16F3ABB2E7A66E4212E1461A2A104F2F70E0761899EB09
2017-06-23 05:51:29.316 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AB0070A6A08031A0C08E1D8B2CA0510...31099F7A27E2D77D827DFEE23F077555
2017-06-23 05:51:29.316 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 7A328CBD52B5C50E9A3708C8AA09377130E50732D4232AEA0A5526D814DC958C
2017-06-23 05:51:29.325 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response:<status:200 message:"OK" > payload:"\n \326\336\010\327\324\206\265\254c#\203\323l\251E\026\204Z\305\232\3141'\346\372\206\007Sb\366W7\022b\nK\0220\n\007devincc\022%\n\007\n\001a\022\002\010\005\n\007\n\001b\022\002\010\005\032\007\n\001a\032\00290\032\010\n\001b\032\003210\022\027\n\004lscc\022\017\n\r\n\007devincc\022\002\010\005\032\003\010\310\001\"\016\022\007devincc\032\0031.0" endorsement:<endorser:"\n\007Org1MSP\022\325\006-----BEGIN -----\nMIICWjCCAgCgAwIBAgIQJhewne/nukiq1+AtoiUsWzAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMwNTQ3MTdaFw0yNzA2MjEwNTQ3MTda\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7eNBnsC+FkNNnHRjNNnmA3FaUQt6vvo9\ncl/wnSVfRi1SbqNLzc7plpmikybLLau7So3OVOHKNpLQUobijl6VtaOBjTCBijAO\nBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIw\nADArBgNVHSMEJDAigCCSzU2vv1K0hTxMdt1HJwxyNZ3Dw7up9DwGtbWtgfDX+jAo\nBgNVHREEITAfghZwZWVyMC5vcmcxLmV4YW1wbGUuY29tggVwZWVyMDAKBggqhkjO\nPQQDAgNIADBFAiEAn7ULKvs4XvFdTTCcp0VWnc27USs7Co03yIpWGXY/A7oCIAEp\nMpdCNyLZoRvPjdaSd91fnfbeHQh8Rrh5JzI4/KNL\n-----END -----\n" signature:"0E\002!\000\204N$\211\321\370U5\340\347F\262\306Z\247\311\217\271z\355\245\326J*\242r\0073\207\341\336\332\002 ZT\335\325L\321\373\203\204`!^\021\276k\0031\t\237z'\342\327}\202}\376\342?\007uU" >
2017-06-23 05:51:29.326 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200
2017-06-23 05:51:29.330 UTC [main] main -> INFO 00c Exiting.....

查询b账户余额,query命令,得到结果Query Result: 210

1
peer chaincode query -C mychannel -n devincc -c '{"Args":["query","b"]}'

输出

1
2
3
4
5
6
7
8
9
2017-06-23 05:51:35.774 UTC [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts: no such file or directory]
2017-06-23 05:51:35.774 UTC [msp] getMspConfig -> INFO 002 crls folder not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/intermediatecerts]. Skipping.: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/crls: no such file or directory]
2017-06-23 05:51:35.774 UTC [msp] getMspConfig -> INFO 003 MSP configuration file not found at [/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml]: [stat /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml: no such file or directory]
2017-06-23 05:51:35.824 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2017-06-23 05:51:35.824 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2017-06-23 05:51:35.824 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB0070A6A08031A0C08E7D8B2CA0510...696E63631A0A0A0571756572790A0162
2017-06-23 05:51:35.824 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 69ABA8F17D0B2287C38E50249BE1138995F98875A16FB783D0AD00D57680066D
Query Result: 210
2017-06-23 05:51:35.842 UTC [main] main -> INFO 008 Exiting.....


参考资料

由于在虚拟机启动的时候,已经自动帮我们做了很多初始化工作,比如go、docker、java、node等很多依赖的安装与初始化,对于其启动细节还不够了解,因此在下一篇文章中,我们会介绍在一台CentOS上如何部署Fabric。

坚持原创技术分享,您的支持将鼓励我继续创作!