Beispiel #1
0
    ))
    print(response)

    # Query by block number
    response = loop.run_until_complete(cli.query_block(
        requestor=org1_admin,
        channel_name='businesschannel',
        peers=['peer0.org1.example.com', 'peer1.org1.example.com'],
        block_number='0'
    ))
    print(response)

    # Query instantiated chaincodes
    responses = loop.run_until_complete(cli.query_instantiated_chaincodes(
        requestor=org1_admin,
        channel_name='businesschannel',
        peers=['peer0.org1.example.com', 'peer1.org1.example.com']
    ))
    print(responses)

    # Get Channel configuration
    responses = loop.run_until_complete(cli.get_channel_config(
        requestor=org1_admin,
        channel_name='businesschannel',
        peers=['peer0.org1.example.com', 'peer1.org1.example.com']
    ))
    print(responses)

    # Get channel config from orderer
    response = loop.run_until_complete(cli.get_channel_config_with_orderer(
        orderer='orderer.example.com',
Beispiel #2
0
            tx_id=tx_id))
    print(response)

    # Query by block number
    response = loop.run_until_complete(
        cli.query_block(
            requestor=org1_admin,
            channel_name='businesschannel',
            peers=['peer0.org1.example.com', 'peer1.org1.example.com'],
            block_number='0'))
    print(response)

    # Query instantiated chaincodes
    responses = loop.run_until_complete(
        cli.query_instantiated_chaincodes(
            requestor=org1_admin,
            channel_name='businesschannel',
            peers=['peer0.org1.example.com', 'peer1.org1.example.com']))
    print(responses)

    # Get Channel configuration
    responses = loop.run_until_complete(
        cli.get_channel_config(
            requestor=org1_admin,
            channel_name='businesschannel',
            peers=['peer0.org1.example.com', 'peer1.org1.example.com']))
    print(responses)

    # Get channel config from orderer
    response = loop.run_until_complete(
        cli.get_channel_config_with_orderer(
            orderer='orderer.example.com',
Beispiel #3
0
def get_hfc_client():

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    client = Client()

    # Add peer from backend ledger config file
    peer = Peer(name=LEDGER['peer']['name'])
    peer.init_with_bundle({
        'url': f'{LEDGER["peer"]["host"]}:{PEER_PORT}',
        'grpcOptions': LEDGER['peer']['grpcOptions'],
        'tlsCACerts': {
            'path': LEDGER['peer']['tlsCACerts']
        },
        'clientKey': {
            'path': LEDGER['peer']['clientKey']
        },
        'clientCert': {
            'path': LEDGER['peer']['clientCert']
        },
    })
    client._peers[LEDGER['peer']['name']] = peer

    # Check peer has joined channel

    response = loop.run_until_complete(
        client.query_channels(requestor=LEDGER['requestor'],
                              peers=[peer],
                              decode=True))

    channels = [ch.channel_id for ch in response.channels]

    if not LEDGER['channel_name'] in channels:
        raise Exception(
            f'Peer has not joined channel: {LEDGER["channel_name"]}')

    channel = client.new_channel(LEDGER['channel_name'])

    # Check chaincode is instantiated in the channel

    responses = loop.run_until_complete(
        client.query_instantiated_chaincodes(
            requestor=LEDGER['requestor'],
            channel_name=LEDGER['channel_name'],
            peers=[peer],
            decode=True))

    chaincodes = [cc.name for resp in responses for cc in resp.chaincodes]

    if not LEDGER['chaincode_name'] in chaincodes:
        raise Exception(
            f'Chaincode : {LEDGER["chaincode_name"]}'
            f' is not instantiated in the channel :  {LEDGER["channel_name"]}')

    # Discover orderers and peers from channel discovery
    results = loop.run_until_complete(
        channel._discovery(LEDGER['requestor'],
                           peer,
                           config=True,
                           local=False,
                           interests=[{
                               'chaincodes': [{
                                   'name': LEDGER['chaincode_name']
                               }]
                           }]))

    results = deserialize_discovery(results)

    update_client_with_discovery(client, results)

    return loop, client
Beispiel #4
0
loop = asyncio.get_event_loop()
cli = Client(net_profile="./network.json")

print(cli.organizations)  # orgs in the network
print(cli.peers)  # peers in the network
print(cli.orderers)  # orderers in the network
print(cli.CAs)  # ca nodes in the network
cli.new_channel('mychannel')
org1_admin = cli.get_user(org_name='org1.example.com', name='Admin') # get the admin user from local path
args = ["212344", "red", "202", "Jack"]
#args2 = ["GetBlockByTxID", "mychannel", "64caff9786483d0d56f6d7ba738ece33328c2559b7b4093547018bcd22e42986"]
# The response should be true if succeed
response = loop.run_until_complete(cli.query_instantiated_chaincodes(
               requestor=org1_admin,
               channel_name='mychannel',
               peers=['peer0.org1.example.com'],
               decode=True
               ))
"""
# This part is used to check the channel information
response = loop.run_until_complete(cli.query_peers(
               requestor=org1_admin,
               peer='peer0.org1.example.com',
               channel='mychannel',
               local=True,
               decode=True
               ))
print("response=", response)
"""

for i in range(400000000, 5000000000):