【问题标题】:how we can call one chaincode from another chaincode in fabric 1.0 ?? if anyone having example please share我们如何在 fabric 1.0 中从另一个链码调用一个链码?如果有人有例子请分享
【发布时间】:2018-03-19 10:34:14
【问题描述】:

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

【问题讨论】:

    标签: hyperledger-fabric hyperledger


    【解决方案1】:

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

    // 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,在评论中正确说明:

    确保两个链码都安装在每个背书节点上非常重要

    考虑阅读以下材料:

    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

    【讨论】:

    • @ArtemBarger 我可以调用其他频道的链码吗?
    • @AkshaySood 仅当对等方参与两个通道并安装了第二个链码时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多