Notice: The tutorial is still in-progress, feel free to ask question in the rktchat channel. Code can be found at e2e_test.py.
$ git clone https://github.com/hyperledger/fabric-sdk-py.git
$ cd fabric-sdk-py
$ make install
After installation, you can optionally verify the installation.
$ python
>>> import hfc
>>> print(hfc.VERSION)
0.7.0
SDK needs a targeted fabric network to operate with, if there is not a running one, need to start a network manually.
To start a fabric network you can simple up the docker-compose-2orgs-4peers-tls
under fixtures.
$ docker-compose -f test/fixtures/docker-compose-2orgs-4peers-tls.yaml up
Then you'll have 2 orgs (org1.example.com; org2.example.com) with 2 peers in each one and one orderer (orderer.example.com)
If you want to understand the fabric network and how to change the network configuration, feel free to follow the byfn tutorial, from crypto-generator section to start-the-network section. service on the yaml file either.
A network connection profile will include all information that SDK requires to operate with a fabric network, including:
- Service endpoints for peer, orderer, ca;
- Credentials for identities that clients may act as;
e.g., network1.json
.
SDK can load all network information from the profile, and check the resources in the network.
# TODO: update code
from hfc.fabric import Client
cli = Client(net_profile="test/fixtures/network.json")
cli.organizations # orgs in the network
cli.peers # peers in the network
cli.orderers # orderers in the network
cli.CAs # ca nodes in the network
After load the configuration, SDK can operate with the network.
from hfc.fabric import Client
cli = Client(net_profile="test/fixtures/network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')
# The response should be true if succeed
response = cli.channel_create(
'orderer.example.com',
'businesschannel',
org1_admin,
'test/fixtures/e2e_cli/channel-artifacts/channel.tx')
from hfc.fabric import Client
cli = Client(net_profile="test/fixtures/network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')
# The response should be true if succeed
response = cli.channel_join(
org1_admin,
'businesschannel',
['peer0.org1.example.com', 'peer1.org1.example.com'],
'orderer.example.com')
from hfc.fabric import Client
cli = Client(net_profile="test/fixtures/network.json")
org1_admin = cli.get_user('org1.example.com', 'Admin')
# The response should be true if succeed
response = cli.chaincode_install(
requestor=org1_admin,
peer_names=['peer0.org1.example.com'],
cc_path='github.com/example_cc',
cc_name='example_cc',
cc_version='v1.0' )
from hfc.fabric import Client
#TODO
from hfc.fabric import Client
#TODO
This document is licensed under a Creative Commons Attribution 4.0 International License.
Some notes on the query
after
we get
res
which is atuple
it has three layers
res[0] is a
list
res[1] is
hfc.protos.peer.proposal_pb2.Proposal
res[2] is
hfc.protos.common.common_pb2.Header
res[0][0] is
tuple
res[0][0][0] is
hfc.protos.peer.proposal_response_pb2.ProposalResponse
You can print the result as