Fabric区块链Node.js开发详解Fabric区块链Java开发详解Fabric区块链Golang开发详解1、安装预编译的Hyperledger Fabric 2.0应用程序Hyperledger Fabric官方提供了以下2.0版本的预编译程序:
configtxgen:用于生成Fabric创世区块初始或更新配置文件configtxlator:用于编解码Fabric区块链配置文件cryptogen:用于快速生成节点、用户、客户端等所需的证书和密钥文件discover:用于Fabric网络的服务发现idemixgen:很少用到orderer:Fabric排序节点程序peer:Fabric对等节点程序fabric-ca-client:Fabric-CA服务程序的客户端,用于注册和添加用户首先创建一个Hyperledger Fabric 2.0的专用目录,然后进入 该目录:. o7 O7 d7 F' W. d$ ~( Z
1' n- B% X* U( w: I 29 @! F5 U+ H+ X0 x( n 3 | ~$ mkdir hubwiz-hf2% e8 @1 U3 u& u3 q' l ~$ cd hubwiz-hf2. s2 @0 b+ b$ v0 c$ m+ m5 d: K' ` ~/hubwiz-hf2$& i# N. S# ?3 t- _' I. H: g |
19 F0 N; A! n/ \# Y | ~/hubwiz-hf2$ curl -sSL https://bit.ly/2ysbOFE | bash -s -d -- 2.0.0 1.4.4 0.4.181 L* @" D) d7 I1 @3 T3 I |
2.0.0:表示Hyperledger Fabric的版本号1.4.4:表示Fabric CA的版本号0.4.18:表示第三方引用的版本号上述命令执行后,在当前目录的bin子目录下你就可以看到上述程序了:1 r0 b' K% u' R: D: ~) U; n0 T- y
1 _: g- ?+ ]& d% U | ~/huwbiz-hf2$ ls bin# d4 Y; a1 n: j" b; {5 r9 {6 A |
1+ K! Q7 t; V- L& f% [8 p | export PATH=$HOME/hubwiz-hf2/bin:$PATH |
1 | ~$ orderer version# d: V6 d0 R! C9 r* k |
2、安装Hyperledger Fabric 2.0示例程序代码在Hyperledger Fabric 2.0目录中执行如下命令安装官方提供的示例代码:
1$ P0 [4 I7 U' o. b5 L2 P | ~/hubwiz-hf2$ git clone https://github.com/hyperledger/fabric-samples |
使用如下命令查看并验证fabric-samples安装成功:8 |/ R4 V3 S3 c I; T
15 F9 ^7 x5 F# l# h2 o* I | ~/hubwiz-hf2$ tree fabric-samples -L 1 -d |
1$ z8 R, e( k" ], B* y# _1 ^8 A 2 3- X# b9 ^8 n: l1 l& L, {, x0 h+ q 4 58 d- @$ B0 Y6 j8 I( C. b 6 7 8 9 102 z$ b2 g& b! [6 _- Z 11 12 13 14) J( J$ U' e. G2 Y$ m0 a4 w | fabric-samples |- basic-network |- chaincode-docker-devmode. [. b) w u1 L$ l. N; Q |- chaincode |- ci I) z7 r5 y' Q) y) x8 G |- commercial-paper |- docs |- fabcar7 S2 }. L- \5 l- ]5 {. {2 K7 `5 N/ i |- first-network |- high-throughput, k% c. d$ `8 @9 ?! q2 n1 n4 F% t @ |- interest_rate_swaps/ {2 Q" Y8 W8 `% l B! Q- g: R |- off_chain_data3 p* w. [( o+ h8 g- K |- scripts* `2 q* i' W' C$ G' ^ |- test-network) i. ?% L( K" x& ~, d# Y |
3、预下载Hyperledger Fabric 2.0的docker镜像可以使用如下命令预下载Hyperledger Fabric 2.0的docker镜像, 这样在进行后续的测试时,会减少一些等待时间。
1& ?' O0 E+ _4 d/ J: S3 |2 a" T | ~/hubwiz-hf2$ curl -sSL https://bit.ly/2ysbOFE | bash -s -b -- 2.0.0 1.4.4 0.4.180 T9 n) K5 {/ C9 N& o5 V |
4、使用test-network测试Hyperledger Fabric 2.0进入fabric-samples目录启动Hyperledger Fabric 2.0新增加的测试网络test-network:- |. d3 _' X7 C3 N
1- Z3 J( N8 }* z0 b 2 | ~/hubwiz-hf2$ cd fabric-samples/test-network ~/hubwiz-hf2/fabric-samples/test-network$ ./network.sh up$ x$ e, ]8 R( } |
1% D; V5 m$ L' f* X' r- Q# ` 2& ^0 ~! F% x$ C2 v a" P! n 3 4 5# V* ^8 d z7 z0 a 6- s; X& L1 i# V0 O H& ~- X 7; n4 t5 R; ~7 F' U7 G8 r7 F 8 9 106 q. P) g- v8 @$ t+ a6 E 11 | Creating network "net_test" with the default driver Creating volume "net_orderer.example.com" with default driver9 x% s T6 \9 g Creating volume "net_peer0.org1.example.com" with default driver Creating volume "net_peer0.org2.example.com" with default driver Creating orderer.example.com ... done Creating peer0.org2.example.com ... done, J4 K+ B5 }+ n ? Creating peer0.org1.example.com ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9 z* f$ {- K4 ~: Q 8d0c74b9d6af hyperledger/fabric-orderer:latest "orderer" 4 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com( h4 D {4 J3 Z; C5 Z ea1cf82b5b99 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com cd8d9b23cb56 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com |