我们如何从 fabric 1.0 中的另一个链代码调用一个链代码?如果有人有例子请分享

how we can call one chaincode from another chaincode in fabric 1.0 ?? if anyone having example please share

我想从 fabric 1.0 中的另一个链代码调用一个链代码 所以我有一些问题: 1)我们可以在单个节点上安装两个链码吗 2) 如果我们在不同的节点上安装两个链码,我们如何调用一个到另一个? 3) 如果有人有示例请分享。

这应该很容易实现,这里是一个例子:

// Invoke
func (am *accountManagement) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
    actionName, params := stub.GetFunctionAndParameters()

    if actionName == "callAnotherCC" {
        chainCodeArgs := util.ToChaincodeArgs("anotherCCFunc", "paramA")
        response := stub.InvokeChaincode("anotherCCName", chainCodeArgs, "channelName")

        if response.Status != shim.OK {
           return shim.Error(response.Message)
        }
        return shim.Success(nil)
    }

    // NOTE: This is an example, hence assuming only valid call is to call another chaincode
    return shim.Error(fmt.Sprintf("[ERROR] No <%s> action defined", actionName))
}


UPDTAE

作为@Gari,在评论中正确陈述:

It's very important to make sure that both chaincodes are installed on each endorsing peer

考虑阅读以下 material:

  1. https://github.com/asararatnakar/fabric_v1_Chaincode_instructions/blob/master/call-chaincode-to-chaincode-nondefault-chain.md
  2. https://jira.hyperledger.org/browse/FAB-1788
  3. http://hyperledger-fabric.readthedocs.io/en/release-1.0/chaincode.html