user746461
user746461

Reputation:

Constructor message for the chaincode in JSON format?

I'm looking at the tutorial on hyperledger fabric (https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html).

The tutorial mentions command peer chaincode invoke, which accepts

--ctor string                    Constructor message for the chaincode in JSON format (default "{}")

What's the specification of the JSON message? Is there a documentation available?

I know what JSON is, but what is the format required by the JSON?

The tutorial shows two usages, e.g. -c '{"function":"TransferAsset","Args":["asset6","gqq"]}' and -c '{"Args":["GetAllAssets"]}'

Besides "function" and "Args", can I do something else?

Upvotes: 0

Views: 158

Answers (1)

Li Xian
Li Xian

Reputation: 411

non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'

this are source code

if chaincodeCtorJSON != "{}" {
        var f interface{}
        err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
        if err != nil {
            return errors.Wrap(err, "chaincode argument error")
        }
        m := f.(map[string]interface{})
        sm := make(map[string]interface{})
        for k := range m {
            sm[strings.ToLower(k)] = m[k]
        }
        _, argsPresent := sm["args"]
        _, funcPresent := sm["function"]
        if !argsPresent || (len(m) == 2 && !funcPresent) || len(m) > 2 {
            return errors.New("non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
        }
    } else {
        if cmd == nil || (cmd != chaincodeInstallCmd && cmd != chaincodePackageCmd) {
            return errors.New("empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
        }
    }

Upvotes: 0

Related Questions