【问题标题】:passing arguments for chaincode invocation as bytes将链码调用的参数作为字节传递
【发布时间】:2019-06-13 06:41:53
【问题描述】:

调用链码时,有 -c 选项用于传递参数。据我了解(另见Hyperledger fabric: Error: chaincode argument error: json: cannot unmarshal array into Go struct field strArgs.Args of type string),这些参数需要作为字符串数组传递。 例如:

-c '{"Args":["add", "peter", "6"]}'

有一个 GetArgs()function (https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.GetArgs) 以字节数组的形式返回参数。 在上述情况下,这意味着第三个参数(“6”)作为长度为 1 的字节数组返回,其中 54 作为第一个条目。 但我想在长度为 1 的字节数组中表示第三个参数(“6”),第一个条目为 6(00000110)。 根本不可能将字节/数字类型作为参数传递吗?

【问题讨论】:

    标签: hyperledger-fabric


    【解决方案1】:

    您需要做的是将第三个参数作为 json 传递并从链码中的字符串解组。

        '{"Args": ["add", "peter", "[6]"]}'
    

    然后类似

        var arr []byte
        err := json.Unmarshal(args[2], &arr) // args[2] is the third argument from the list
        fmt.Println(arr)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      相关资源
      最近更新 更多