JSON 格式的链代码的构造函数消息?
Constructor message for the chaincode in JSON format?
我正在查看有关 hyperledger fabric (https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html) 的教程。
教程提到了命令peer chaincode invoke
,它接受
--ctor string Constructor message for the chaincode in JSON format (default "{}")
JSON 消息的规格是什么?有可用的文档吗?
我知道JSON是什么,但是JSON要求的格式是什么?
教程展示了两种用法,例如 -c '{"function":"TransferAsset","Args":["asset6","gqq"]}'
和 -c '{"Args":["GetAllAssets"]}'
除了“function”和“Args”,我还能做点别的吗?
非空 JSON 链代码参数必须包含以下键:'Args' 或 'Function' 和 'Args'
这是源代码
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'")
}
}
我正在查看有关 hyperledger fabric (https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html) 的教程。
教程提到了命令peer chaincode invoke
,它接受
--ctor string Constructor message for the chaincode in JSON format (default "{}")
JSON 消息的规格是什么?有可用的文档吗?
我知道JSON是什么,但是JSON要求的格式是什么?
教程展示了两种用法,例如 -c '{"function":"TransferAsset","Args":["asset6","gqq"]}'
和 -c '{"Args":["GetAllAssets"]}'
除了“function”和“Args”,我还能做点别的吗?
非空 JSON 链代码参数必须包含以下键:'Args' 或 'Function' 和 'Args'
这是源代码
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'")
}
}