我们如何在Fabric 1.0中从另一个链码中调用一个链码?如果有人有例子请分享 [英] how we can call one chaincode from another chaincode in fabric 1.0 ?? if anyone having example please share

查看:288
本文介绍了我们如何在Fabric 1.0中从另一个链码中调用一个链码?如果有人有例子请分享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to call one chaincode from another chaincode in fabric 1.0 so I have some questions: 1) can we install two chaincode on single peer 2) if we install two chaincode on different peer, how we can call one into another? 3)if anybody having sample example please share.

推荐答案

这应该很容易实现,下面是一个示例:

This is should be pretty straight forward to achieve, here is an example:

// 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,请在注释中正确指出:

As @Gari, correctly stated in the comment:

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

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

请考虑阅读以下内容:

  1. https://github.com. 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/版本1.0/chaincode.html
  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

这篇关于我们如何在Fabric 1.0中从另一个链码中调用一个链码?如果有人有例子请分享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆