I am trying to perform a query on a chaincode(cc02
) from another chaincode (cc01
), both residing on the same channel. When I try invoking the query function by calling stub.invokeChaincode(...)
, the command is returning a [Object object]
instead of the result of the query. Can someone please tell what the mistake in this is?
More details
Minimal version of the querying function in cc01
reads:
async queryOtherContract(stub, args) {
let chaincodeName = args[0]; //cc02
let fcn = args[1]; //query
let fcnArgs = args[2]; //key
let channel = args[3]; //defaultchannel
let queryResponse = await stub.invokeChaincode(chaincodeName, [fcn, fcnArgs], channel);
console.log('Query response: ', JSON.stringify(queryResponse));
}
Output:
Query response: {"status":200,"message":"","payload":{"buffer":{"type":"Buffer","data":[8,6...108]},"offset":9,"markedOffset":-1,"limit":59,"littleEndian":true,"noAssert":false}}
The payload Buffer decodes to [Object object]
The queried function from cc02
is as follows:
async query(stub, args) {
let key = args[0]; //key
let valueAsBytes = await stub.getState(key);
let valString = valueAsBytes.toString('utf8');
console.log('Value String: ', valString);
return shim.success(Buffer.from(valString));
}
Output: Value String: Value001
I have tried different variations as well including sending valueAsBytes
directly as well as returning valString
directly instead of wrapping it in the shim function. What am I doing wrong in this?