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

Tej*_*ale 8 hyperledger hyperledger-fabric

我想从Fabric 1.0中的另一个链代码调用一个链代码,所以我有一些问题:1)我们可以在单个对等端安装两个链代码2)如果我们在不同的对等端安装两个链代码,我们如何将一个代码调用到另一个?3)如果有样品示例请分享.

Art*_*ger 13

这应该是非常直接的实现,这是一个例子:

// 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))
}
Run Code Online (Sandbox Code Playgroud)


UPDTAE

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

确保在每个认可对等体上安装两个链代码非常重要

考虑阅读以下材料:

  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

  • 请注意,如果在每个签名对等体上安装了两个链代码,则只能对链代码进行链式代码调用. (2认同)