首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从部署在使用hyperledger-fabric中的单个通道连接的两个不同组织对等节点上的另一个链代码调用链代码?

如何从部署在使用hyperledger-fabric中的单个通道连接的两个不同组织对等节点上的另一个链代码调用链代码?
EN

Stack Overflow用户
提问于 2018-05-11 19:41:17
回答 2查看 1.5K关注 0票数 3

我编写了一个chaincode1(部署在ORG1的一个对等体上),它接受来自用户的详细信息并将其存储到账本中。现在我想编写一个chaincode2(部署在ORG2的对等体上),它从chaincode1获取一些数据进行计算。此chaincode2应由chaincode1调用,并包含计算所需的特定细节。我如何实现这个功能,我应该在哪里测试它?

EN

回答 2

Stack Overflow用户

发布于 2018-05-12 07:17:37

首先,有几个前提条件,例如:

  1. 如果您想让chaincode1调用chaincode2,您需要将两个链码安装在同一个peer中,并且
  2. 需要确保这两个通道的此peer部分

接下来,您需要利用以下API:

代码语言:javascript
复制
// InvokeChaincode locally calls the specified chaincode `Invoke` using the
// same transaction context; that is, chaincode calling chaincode doesn't
// create a new transaction message.
// If the called chaincode is on the same channel, it simply adds the called
// chaincode read set and write set to the calling transaction.
// If the called chaincode is on a different channel,
// only the Response is returned to the calling chaincode; any PutState calls
// from the called chaincode will not have any effect on the ledger; that is,
// the called chaincode on a different channel will not have its read set
// and write set applied to the transaction. Only the calling chaincode's
// read set and write set will be applied to the transaction. Effectively
// the called chaincode on a different channel is a `Query`, which does not
// participate in state validation checks in subsequent commit phase.
// If `channel` is empty, the caller's channel is assumed.
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

下面是一个示例:

代码语言:javascript
复制
chainCodeArgs := util.ToChaincodeArgs("arg1", "arg2")
response := stub.InvokeChaincode("chaincodeName", chainCodeArgs, "channelID")

if response.Status != shim.OK {
    return shim.Error(response.Message)
}
票数 2
EN

Stack Overflow用户

发布于 2018-05-12 05:08:19

下面是可用于从另一个链码调用链码的函数

代码语言:javascript
复制
func (stub *TestAPIStub) InvokeChaincode(chaincode1 string, args [][]byte, channel string) pb.Response {
   return pb.Response{}
}

您可以参考this document来了解智能合约调用或“链码”如何调用另一个智能合约。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50291575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档