os.environ['GOPATH'] = os.path.abspath(gopath) # The response should be true if succeed response = loop.run_until_complete(cli.chaincode_install( requestor=org1_admin, peers=['peer0.org1.example.com', 'peer1.org1.example.com'], cc_path=CC_PATH, cc_name=CC_NAME, cc_version=CC_VERSION)) # Instantiate Chaincode in Channel, the response should be true if succeed args = ['a', '200', 'b', '300'] response = loop.run_until_complete(cli.chaincode_instantiate( requestor=org1_admin, channel_name='businesschannel', peers=['peer0.org1.example.com'], args=args, cc_name=CC_NAME, cc_version=CC_VERSION)) if response: print("Instantiate chaincode successful") else: print("Instantiate chaincode failed") exit(-1) # Invoke a chaincode args = ['a', 'b', '100'] # The response should be true if succeed response = loop.run_until_complete(cli.chaincode_invoke( requestor=org1_admin, channel_name='businesschannel',
peers=['peer0.org1.example.com', 'peer1.org1.example.com'], cc_path='github.com/example_cc', cc_name='example_cc', cc_version='v1.0')) if response: print("Install chaincode successful") else: print("Install chaincode failed") exit(-1) # Instantiate Chaincode in Channel, the response should be true if succeed args = ['a', '200', 'b', '300'] response = loop.run_until_complete( cli.chaincode_instantiate(requestor=org1_admin, channel_name='businesschannel', peers=['peer0.org1.example.com'], args=args, cc_name='example_cc', cc_version='v1.0')) if response: print("Instantiate chaincode successful") else: print("Instantiate chaincode failed") exit(-1) # The instantiate command after all is a transaction which has to be endorsed, ordered and committed. # What probably confuses you is the fact that peer cli succeeded to endorse instantiate transaction and submit it to the ordering service. # While it might not be committed, hence chaincode container not started and as a result you are not able to query your chaincode. print( ">--- WAITING FOR chaincode container to start after Instantiate! ---<" ) time.sleep(15)
cc_name=cc_name, transient_map=None, wait_for_event=True)) responses = loop.run_until_complete( cli.chaincode_install( requestor=org1_admin, peers=['peer0.org1.example.com', 'peer1.org1.example.com'], cc_path='github.com/example_cc', cc_name='mycc', cc_version='v1.0')) response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name='mychannel', peers=['peer0.org1.example.com'], args=args, cc_name='mycc', cc_version='1.0', collections_config=None, wait_for_event=True # optional, for being sure chaincode is instantiated )) response = loop.run_until_complete( cli.chaincode_query(requestor=org1_admin, channel_name='mychannel', peers=['peer0.org1.example.com'], fcn='Query', args=['170020031'], cc_name='mycc'))
"identities": [{ "role": { "name": "member", "mspId": "PeerOrg1MSP" } }], "policy": { "1-of": [{ "signed-by": 0 }] }, } response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name='secondchannel', peers=[ 'peer0.org1.dz', 'peer1.org1.dz', 'peer2.org1.dz', 'peer3.org1.dz' ], args=args, cc_name='test_cc2', cc_version='v1.0', cc_endorsement_policy=policy, # optional, but recommended collections_config=None, # optional, for private data policy transient_map=None, # optional, for private data wait_for_event=True # optional, for being sure chaincode is instantiated )) print(response)
# policy, see https://hyperledger-fabric.readthedocs.io/en/release-1.4/endorsement-policies.html policy = { 'identities': [ { 'role': { 'name': 'member', 'mspId': 'Org1MSP' } }, ], 'policy': { '1-of': [ { 'signed-by': 0 }, ] } } response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name='channel1', peers=['peer0.org1.example.com'], #, 'peer0.org2.example.com' args=args, cc_name='usecase_cc', cc_version='v1.0', collections_config=None, # optional, for private data policy transient_map=None, # optional, for private data wait_for_event=True # optional, for being sure chaincode is instantiated )) print("response", response)
], 'policy': { '1-of': [ { 'signed-by': 0 }, ] } } response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name='modbuschannel', peers=['peer0.org1.example.com'], args=args, cc_name='example_cc', cc_version='v1.0', # cc_endorsement_policy=policy, # optional, but recommended collections_config=None, # optional, for private data policy transient_map=None, # optional, for private data wait_for_event=True # optional, for being sure chaincode is instantiated )) print("response", response) # Query a chaincode, [a] args = ['a'] # The response should be true if succeed response = loop.run_until_complete( cli.chaincode_query(requestor=org1_admin, channel_name='modbuschannel', peers=['peer0.org1.example.com'], args=args,
######################## cli.new_channel("firstchannel") cli.new_channel("secondchannel") args = ["data1", "value1"] response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name="firstchannel", peers=["peer0.org1.dz", "peer1.org1.dz", "peer2.org1.dz"], args=args, # fcn="NewData", cc_name="firstcc", cc_version="v1.0", cc_endorsement_policy=policy, # optional, but recommended collections_config=None, # optional, for private data policy transient_map=None, # optional, for private data wait_for_event= True, # optional, for being sure chaincode is → instantiated )) response = loop.run_until_complete( cli.chaincode_instantiate( requestor=org1_admin, channel_name="secondchannel", peers=["peer0.org1.dz", "peer1.org1.dz", "peer2.org1.dz"], args=args, # fcn="NewData", cc_name="secondcc",