hyperledger-fabric-node-chaincode-utils
hyperledger-fabric-node-chaincode-utils copied to clipboard
parseParameters requires a parameter to be JSON
TL;DR parseParameters shouldn't write a error level log for failure to JSON parse an arg. Make it debug level.
parseParameters works fine if you are sending your chaincode arguments as JSON objects or numbers. But litters error logs if you don't... which seems unnecessary.
Example: ['changeOwner', 'asset_1', 'user_2'] would result in 2 error logs
- "failed to parse param user_1"
- "failed to parse param user_2"
I guess the assumption is that developers will send those arguments as an array:
['changeOwner', ['asset_1', 'user_2']]
However, doing this makes destructing parsedParameters in ChaincodeBase.js:105 less useful
let payload = await method.call(this, stub, this.getTransactionHelperFor(stub), ...parsedParameters);
Example ideal use case:
// In chaincode
function changeOwner(asset, new_owner){
// Change the asset owner.
}
I also agree on this. It should not be required to pass an argument as an object.
@daanporon Can we change https://github.com/Kunstmaan/hyperledger-fabric-node-chaincode-utils/blob/master/src/lib/ChaincodeBase.js#L58 to use logger.debug
?
@janb87 @kueckermann i agree it's a bit weird that we are throwing an error there, while we are actually resolving the issue. It's ok for me to replace this with just a debug log.
@kueckermann do you want to provide a PR for this?
Thanks @daanporon You can PR when you guys are ready, its not an urgent fix.