链码可以与其他链码互动吗?

时间:2017-09-24 01:54:24

标签: blockchain hyperledger-fabric hyperledger

我正在尝试用超级分类帐编写应用程序,我正在寻找一种与来自另一个链代码的链代码进行通信的方法。超级分类账可以吗?

我知道在以太网中可能与其他智能合约进行通信,但在超级联盟中也是如此。我找不到与之相关的任何相关链接。任何有关如何处理此问题的建议都会非常有用。

我检查了Writing Your First Application,但我找不到合适的解释。

1 个答案:

答案 0 :(得分:3)

Chaincode可以通过利用现有的ChaincodeStubInterface // 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 来与其他链码互动,例如:

response := stub.InvokeChaincode(chaincodeName, chainCodeArgs, channelName)

以下是如何使用它的示例:

images

当然,peer应该安装权限和链代码。

相关问题