Closed chrc closed 6 years ago
You should be perfectly able to do this. Can you provide your full code?
import {Chaincode, ChaincodeError, Helpers, StubHelper} from '@theledger/fabric-chaincode-utils';
import * as Yup from 'yup';
...
export class MyChaincode extends Chaincode {
//args: [ 'KEY01', '', '' ]
async postIntoFabric(stubHelper: StubHelper, args: string[]) {
const verifiedArgs = await Helpers.checkArgs<any>(args, Yup.object()
.shape({
key: Yup.string().required(),
title: Yup.string().notRequired(),
name: Yup.string().nullable(true),
})
);
...
}
I got this error :
error: [MyChaincode] Error: ValidationError: title is a required field
at /...../node/node_modules/@theledger/fabric-chaincode-utils/src/utils/helpers.ts:63:19
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
error: [MyChaincode] Data of error ValidationError: title is a required field: undefined
I'm trying to use:
@types/yup: "^0.24.2",
typescript: "^2.7.2"
Did you send your args as a string array or as a json object? If so, can you log your args and paste a copy of the output? The verifiedArgs method will compose a js object based on the string array you send to the chaincode (['arg1','arg2','arg3',...], for example in this case, this could be sth like: ['key1', 'director', 'john'], and the Yup schema. The method will iterate over the keys in the yup schema and insert the values from the string array top down. Additionally, it will return an error if the rendered object doesn't match the Yup schema: https://github.com/wearetheledger/fabric-node-chaincode-utils/blob/master/src/utils/helpers.ts
Hi, With last versions it's ok now :) Thanks!
There's still a bug with error handling, you shouldn't be seeing "[undefined]". I'll keep this issue open to track this.
Hello,
I use @theledger/fabric-chaincode-utils to write my chaincode, and do stubHelper.putState(verifiedArgs.key, myObject).
I have a json object with a empty value, like: { name: 'HOME', firstname: 'John', foo: '', age: 30 } When I want to do channel.sendTransactionProposal() I got a error "Calling chaincode Invoke() returned error response [undefined]. Sending ERROR message back to peer"
How It is possible to put/send a json with some empty values?
Thanks by advance 🙂