hyperledger-fabric-node-chaincode-utils icon indicating copy to clipboard operation
hyperledger-fabric-node-chaincode-utils copied to clipboard

parseParameters requires a parameter to be JSON

Open kueckermann opened this issue 6 years ago • 3 comments

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.
}

kueckermann avatar May 23 '18 14:05 kueckermann

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 avatar May 24 '18 18:05 janb87

@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?

daanporon avatar May 28 '18 15:05 daanporon

Thanks @daanporon You can PR when you guys are ready, its not an urgent fix.

kueckermann avatar May 28 '18 17:05 kueckermann