I am invoking a cross chaincode from the set method of my chaindode and it properly records the information I send. However, when I invoke the cross chaincode from the get method, then the data is not recorded.
To verify that it was not an implementation failure, I copied the function that goes in the get method into the set method as a test and it responded correctly, so I suspect that it is the fact of invoking the same cross-chaincode from another method.
Part of the set method code that works properly including the function copied from get method:
log.SetFlags(0)
uuid = uuidgen()
TxID = stub.GetTxID()
timestamp = timeNow()
log.Println("["+timestamp+"]["+uuid+"]["+CHANNEL_ENV+"]["+TxID+"][usecase_cc][Transaction] Transaction makes payment of X units from A to B")
re = captureOutput(func(){
log.Println("["+timestamp+"]["+uuid+"]["+CHANNEL_ENV+"]["+TxID+"][usecase_cc][Transaction] Transaction makes payment of X units from A to B")
})
invokeArgs = prepareToInvoke(uuid, re)
stub.InvokeChaincode("base_cc", invokeArgs, CHANNEL_ENV)
//IMPORTED FROM GET METHOD
Avalbytes, err = stub.GetState(A) // Get the state from the ledger
log.SetFlags(0)
uuid = uuidgen()
TxID = stub.GetTxID()
timestamp = timeNow()
jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}"
log.Println("["+timestamp+"]["+uuid+"]["+CHANNEL_ENV+"]["+TxID+"][Get] Query Response: "+jsonResp)
re = captureOutput(func(){
log.Println("["+timestamp+"]["+uuid+"]["+CHANNEL_ENV+"]["+TxID+"][Get] Query Response: "+jsonResp)
})
invokeArgs = prepareToInvoke(uuid, re)
stub.InvokeChaincode("base_cc", invokeArgs, CHANNEL_ENV)
//IMPORTED FROM GET METHOD
The failure is that when querying the cross chaincode it returns that the asset has not been inserted. The first four logs have been inserted from the set method and the last one that fails has been tried to insert from the get method:
response 3zjRkx5KXL65KPn4XGc9SjgWBRVS07i07ecWTMmCRf8=
response A+Mq4UjLrvTRyVXEgBsgA5Pvk2WTUjKYa0NYKxMwtG0=
response vlstiHrCz2tw3t8Ba4C9GbHo/nYrVwstP8JnEPhRAJc=
response KYE+acbDesekYslXT87EEZ546eVSIUREJlHI+8f8ZNY=
Traceback (most recent call last):
File "query.py", line 91, in <module>
response = loop.run_until_complete(cli.chaincode_query(
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/usr/local/lib/python3.8/dist-packages/fabric_sdk_py-0.9.0-py3.8.egg/hfc/fabric/client.py",
line 1328, in chaincode_query
return await chaincode.query(requestor, channel_name, peers, args,
File "/usr/local/lib/python3.8/dist-packages/fabric_sdk_py-0.9.0-py3.8.egg/hfc/fabric/chaincode.py",
line 316, in query
raise Exception(res)
Exception: [response {
status: 500
message: "Asset not found: 3280ca60-0352-40c4-83ab-b9c8e25d0f1f"
To clarify the error, I have created this image where: Cross-Chaincode
1A) Invoke the transaction (usecase chaincode) via Python SDK and set the method to add the peer (A, Aval) in the blockchain.
2A) Add the peer (A, Aval) through the put state API (usecase chaincode). This action generates a log.
3A) Collect the log on-chain and send it to another chaincode through a cross-chain invocation (from the usecase chaincode to the base chaincode).
4A) Add the pair (logUUID, base64(sha256(log(SET(A)))) through the put state API (Base Chaincode).
5A) Query the use case chaincode via the get method to retrieve Aval from A.
6A) Query Aval of A through the get state API in usecase chaincode. This action generates a new record.
7A) Collect the log in chaincode and send it to another chaincode via cross chaincode invocation.
8A) Adds the pair (logUUID, base64(sha256(log(GET(A)))) via the put state API (chaincode base).
1B) Query base chaincode via get method to retrieve base64(sha256(log(SET(A))).
2B) Retrieve base64(sha256(log(SET(A))) from logUUID via get state API in chaincode base.
3B) Query base chaincode via get method to retrieve base64(sha256(log(GET(A)))).
4B) Retrieve base64(sha256(log(GET(A))) from logUUID via get state API in chaincode base (Here happens the error).
The error was produced by Python SDK function chaincode_query.
I have oppened an issue in the Hyperledger Fabric Python SDK. However, to solve the issue I am using chaincode_invoke instead of chaincode_query.
Now, I can generate and retrieve logs from [get] method.
... and also verify it: