class FabricInitializer: """This provides the proper fabric client wrapper """ def __init__(self, net_profile=None, channel_name=None, cc_name=None, cc_version=None, org_name=None, user_name=None, peer_name=None): self.client = Client(net_profile=net_profile) assert self.client print("---client---") print(self.client.orderers) print(self.client.peers) print("---client---") self.channel_name = channel_name self.channel = self.client.new_channel(channel_name) print("---channel---") print("client channels: ", self.client._channels) print("channel: ", self.client.get_channel(channel_name)) print("channel name: ", self.client.get_channel(channel_name).name) print("channel peers: ", self.client.get_channel(channel_name).peers) print("channel orderers: ", self.client.get_channel(channel_name).orderers) print("---channel---") assert self.channel self.cc_name = cc_name self.cc_version = cc_version self.user = self.client.get_user(org_name, user_name) assert self.user self.peers = [self.client.get_peer(peer_name)] assert self.peers print("---parameters---") print("User: "******"Peers: ", self.peers) print("cc name:", self.cc_name) print("---parameters---") self.hub = None self.reg_nub = None async def get_height(self): info = await self.client.query_info(self.user, self.channel_name, self.peers) return info.height
peers=['peer0.org1.example.com'], args=args, cc_name='example_cc')) print("Query chaincode done.") print(response) ############################################################################## # Query Peer installed chaincodes response = loop.run_until_complete( cli.query_installed_chaincodes(requestor=org1_admin, peers=['peer0.org1.example.com'])) print("Query installed chaincode.") print(response) # check if channel named "businesschannel" is already exists response = cli.get_channel(name="businesschannel") print("Channel named `businesschannel`: ", response) # query channels joined in by given peers response = loop.run_until_complete( cli.query_channels(requestor=org1_admin, peers=['peer0.org1.example.com'])) print("Channels: ", response) # query channel info of a given channel named "businesschannel" response = loop.run_until_complete( cli.query_info(requestor=org1_admin, channel_name="businesschannel", peers=['peer0.org1.example.com'])) print("Channels: ", response)
peers=['peer0.org1.example.com'] )) print("Get channel config done.") print(response) # Channel event hub def getBlocks(blocks): # On event complition the block is appended to the list of blocks def onEvent(block): blocks.append(block) # Returns an instance of the onEvent function return onEvent blocks = [] # empty list channel = cli.get_channel('businesschannel') channel_event_hub = channel.newChannelEventHub(cli.get_peer('peer0.org1.example.com'), org1_admin) channel_event_hub.registerBlockEvent(start=0, onEvent=getBlocks(blocks)) stream = channel_event_hub.connect() print(blocks) # Query Channel response = cli.query_channels( requestor=org1_admin, peers=['peer0.org1.example.com', 'peer1.org1.example.com'] ) print(response) # Query Info response = loop.run_until_complete(cli.query_info(