我编写了一个chaincode1(部署在ORG1的一个对等体上),它接受来自用户的详细信息并将其存储到账本中。现在我想编写一个chaincode2(部署在ORG2的对等体上),它从chaincode1获取一些数据进行计算。此chaincode2应由chaincode1调用,并包含计算所需的特定细节。我如何实现这个功能,我应该在哪里测试它?
发布于 2018-05-12 07:17:37
首先,有几个前提条件,例如:
接下来,您需要利用以下API:
// 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下面是一个示例:
chainCodeArgs := util.ToChaincodeArgs("arg1", "arg2")
response := stub.InvokeChaincode("chaincodeName", chainCodeArgs, "channelID")
if response.Status != shim.OK {
return shim.Error(response.Message)
}发布于 2018-05-12 05:08:19
下面是可用于从另一个链码调用链码的函数
func (stub *TestAPIStub) InvokeChaincode(chaincode1 string, args [][]byte, channel string) pb.Response {
return pb.Response{}
}您可以参考this document来了解智能合约调用或“链码”如何调用另一个智能合约。
https://stackoverflow.com/questions/50291575
复制相似问题