[关闭]
@xdx24 2018-11-12T03:24:31.000000Z 字数 2006 阅读 396

fabric中channel的建立与加入

fabric


0.操作前准备

0.1 安装 Fabric SDK

  1. $ git clone https://github.com/hyperledger/fabric-sdk-py.git
  2. $ cd fabric-sdk-py
  3. $ make install

安装后可以检测sdk版本

  1. $ python
  2. >>> import hfc
  3. >>> print(hfc.VERSION)
  4. 0.7.0

0.2.开启一个 Fabric Network

使用以下命令开启一个Fabric Network

  1. $ docker pull hyperledger/fabric-peer:1.3.0
  2. $ docker pull hyperledger/fabric-orderer:1.3.0
  3. $ docker pull hyperledger/fabric-ca:1.3.0
  4. $ docker pull hyperledger/fabric-ccenv:1.3.0
  5. $ docker-compose -f test/fixtures/docker-compose-2orgs-4peers-tls.yaml up

然后你将有一个有3个组织的Fabric网络,网络拓扑结构如下:
* org1.example.com
* peer0.org1.example.com
* peer1.org1.example.com
* org2.example.com
* peer0.org2.example.com
* peer1.org2.example.com
* orderer.example.com
* orderer.example.com

*注意: configtxgen需要在PATH路径下

0.3. 建立连接配置文件

一个网络连接配置文件通过提供跟网络交互所需要的所有信息帮助SDK连接到Fabric网络中,其中包括:
* peer, orderer, ca的服务端点
* 客户端身份的认证证书
一个例子是 network.json

1. 在Fabric网络中Channel的操作

Use sdk to create a new channel and let peers joinit.
使用sdk建立新的Channel并让peers

  1. from hfc.fabric import Client
  2. cli = Client(net_profile="test/fixtures/network.json")
  3. org1_admin = cli.get_user(org_name='org1.example.com', name='Admin')
  4. # Create a New Channel, the response should be true if succeed
  5. response = cli.channel_create(
  6. orderer_name='orderer.example.com',
  7. channel_name='businesschannel',
  8. requestor=org1_admin,
  9. config_yaml='test/fixtures/e2e_cli/',
  10. channel_profile='TwoOrgsChannel'
  11. )
  12. print(response==True)
  13. # Join Peers into Channel, the response should be true if succeed
  14. response = cli.channel_join(
  15. requestor=org1_admin,
  16. channel_name='businesschannel',
  17. peer_names=['peer0.org1.example.com',
  18. 'peer1.org1.example.com']
  19. orderer_name='orderer.example.com'
  20. )
  21. print(response==True)
  22. # Join Peers from a different MSP into Channel
  23. org2_admin = cli.get_user(org_name='org2.example.com', name='Admin')
  24. # For operations on peers from org2.example.com, org2_admin is required as requestor
  25. response = cli.channel_join(
  26. requestor=org2_admin,
  27. channel_name='businesschannel',
  28. peer_names=['peer0.org2.example.com',
  29. 'peer1.org2.example.com']
  30. orderer_name='orderer.example.com'
  31. )
  32. print(response==True)

1.1 操作示范

  1. configtxgen加入到PATH路径下
    Screenshot_20181109_092539.png-15.7kB
  2. 开启fabric客户端,确认客户端里没有Channel
    Screenshot_20181109_092327.png-31.4kB
  3. 进行建立Channel操作
    Screenshot_20181109_092656.png-34.8kB
    再次查看客户端Channel,发现新的Channel已经建立
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注