duangan6133 2018-10-04 16:55
浏览 1125
已采纳

Hyperledger Fabric链码-无法使用InvokeChaincode从另一个链码读取数据。 状态200,但有效载荷为空

I am working on a chaincode where I need to read data previously stored from another one.

They are instantiated on the same channel and I can use them individually to read and write data separately.

You can replicate it using the marble chaincode, installing it with different names on the same peer.

In one of them (A) I implemented invokeChaincode(B), to read data stored by B in this way:

func (chaincode *SimpleChaincode) queryMarblesFromAnotherChaincode(stub shim.ChaincodeStubInterface, args []string) peer.Response {

    queryMarble := "queryMarble"

    if len(args) != 3 {
        return shim.Error("Incorrect number of arguments. Expecting 3")
    }

    chaincodeName := args[0]
    chaincodeArgs := toChaincodeArgs(queryMarble, args[1])
    chaincodeChannel := args[2]

    response := stub.InvokeChaincode(chaincodeName, chaincodeArgs, chaincodeChannel)
    if response.Status != shim.OK {
        return shim.Error(fmt.Sprintf("Failed to query chaincode: %s", response.Payload))
    }
    return shim.Success(response.Payload)
}

Running that method using peer chaincode invoke .. , I receive status: 200, but Payload is empty.

Could you advise on what I am doing wrong?

  • 写回答

1条回答 默认 最新

  • dseigqk7443 2018-10-05 17:03
    关注

    If shim.success(response.Payload) is empty its most likely that chaincode B is returning an empty payload. To be sure try logging what response.Payload here in chaincode A before returning.

    In addition, add some logging to chaincode B so you can see exactly what chaincode B is supposedly returning to chaincode A.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗