nicolapaoli
nicolapaoli

Reputation: 55

Hyperledger Fabric Chaincode - Failed to read data from another chaincode using InvokeChaincode. Status 200 but Payload is Empty

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?

Upvotes: 1

Views: 354

Answers (1)

Josh Smith
Josh Smith

Reputation: 153

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.

Upvotes: 1

Related Questions