@xdx24
2018-11-12T03:24:31.000000Z
字数 2006
阅读 396
fabric
$ git clone https://github.com/hyperledger/fabric-sdk-py.git
$ cd fabric-sdk-py
$ make install
安装后可以检测sdk版本
$ python
>>> import hfc
>>> print(hfc.VERSION)
0.7.0
使用以下命令开启一个Fabric Network
$ docker pull hyperledger/fabric-peer:1.3.0
$ docker pull hyperledger/fabric-orderer:1.3.0
$ docker pull hyperledger/fabric-ca:1.3.0
$ docker pull hyperledger/fabric-ccenv:1.3.0
$ 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
路径下
一个网络连接配置文件通过提供跟网络交互所需要的所有信息帮助SDK连接到Fabric网络中,其中包括:
* peer, orderer, ca的服务端点
* 客户端身份的认证证书
一个例子是 network.json
Use sdk to create a new channel and let peers joinit.
使用sdk建立新的Channel并让peers
from hfc.fabric import Client
cli = Client(net_profile="test/fixtures/network.json")
org1_admin = cli.get_user(org_name='org1.example.com', name='Admin')
# Create a New Channel, the response should be true if succeed
response = cli.channel_create(
orderer_name='orderer.example.com',
channel_name='businesschannel',
requestor=org1_admin,
config_yaml='test/fixtures/e2e_cli/',
channel_profile='TwoOrgsChannel'
)
print(response==True)
# Join Peers into Channel, the response should be true if succeed
response = cli.channel_join(
requestor=org1_admin,
channel_name='businesschannel',
peer_names=['peer0.org1.example.com',
'peer1.org1.example.com']
orderer_name='orderer.example.com'
)
print(response==True)
# Join Peers from a different MSP into Channel
org2_admin = cli.get_user(org_name='org2.example.com', name='Admin')
# For operations on peers from org2.example.com, org2_admin is required as requestor
response = cli.channel_join(
requestor=org2_admin,
channel_name='businesschannel',
peer_names=['peer0.org2.example.com',
'peer1.org2.example.com']
orderer_name='orderer.example.com'
)
print(response==True)
configtxgen
加入到PATH
路径下