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

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?

图片转代码服务由CSDN问答提供 功能建议

我正在研究一个链码,需要从另一个链中读取先前存储的数据。

它们在同一通道上实例化,我可以分别使用它们分别读取和写入数据。

您可以使用 marble 链码复制它,并将其以不同的名称安装在同一对等节点上。

其中(A)我实现了invokeChaincode(B),以这种方式读取B存储的数据:

  func(chaincode * SimpleChaincode)queryMarblesFromAnotherChaincode(stub shim.ChaincodeStubInterface,args  [] string)peer.Response {
 
 queryMarble:=“ queryMarble” 
 
如果len(args)!= 3 {
返回shim.Error(“参数数目不正确。应为3”)
  } 
 
 chaincodeName:= args [0] 
 chaincodeArgs:= toChaincodeArgs(queryMarble,args [1])
 chaincodeChannel:= args [2] 
 
响应:= stub.InvokeChaincode(chaincodeName,chaincodeArgs,  chaincodeChannel)
 if response.Status!= shim.OK {
返回shim.Error(fmt.Sprintf(“无法查询链码:%s”,response.Payload))
} 
返回shim.Success(  response.Payload)
} 
   
 
 

使用对等链代码调用.. 运行该方法, 我收到状态:200 ,但是有效负载为空。

您能告诉我我在做什么错吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题