是否可以使用 invokeChaincode 方法从不同通道上的链码中检索数据

Is it possible to use invokeChaincode method to retrieve data from the chaincode that is on different channel

我目前 运行 一个项目有 2 个链代码、2 个通道和 2 个组织。我想在由 org1 和 org2 组成的第一个通道 (channel-1) 上安装我的第一个链代码 (CC1)。第二个链代码 (CC2) 将安装在仅由 org2 组成的通道 2 上。

我想从第一个链码中检索数据,检索到的数据将用于第二个链码。是否可以使用 invokeChaincode 方法从不同通道上的链代码检索数据?

如果不可能,那么从安装在不同通道上的其他链代码检索数据的方法是什么?

我正在使用 hyperledger fabric 2.0 版和节点 js 来构建我的链代码。

您可以使用 invokeChaincode 函数从不同的通道调用链码:

//get data from channel 1
const cc1Args = ['arg1', 'arg2'];
const cc1Res = await ctx.stub.invokeChaincode('CC1', cc1Args, 'channel-1');
if (cc1Res.status !== 200) {
    throw new Error(cc1Res.message);
}
const cc1Asset = JSON.parse(cc1Res.payload.toString('utf8'));

//save data to channel 2
const cc2Args = [cc1Asset.arg1, cc1Asset.arg2];
const cc2Res = await ctx.stub.invokeChaincode('CC2', cc2Args, 'channel-2');
if (cc2Res.status !== 200) {
    throw new Error(cc2Res.message);
}
const cc2ResObj = JSON.parse(cc1Res.payload.toString('utf8'));

您还可以阅读invokeChaincode的文档:https://hyperledger.github.io/fabric-chaincode-node/master/api/fabric-shim.ChaincodeStub.html#invokeChaincode__anchor

是的,您可以使用 invokechaincode 方法调用其他链代码,但您的对等方应加入该频道。有关更多信息,请访问这些链接

https://kctheservant.medium.com/cross-chaincode-invoking-in-hyperledger-fabric-8b8df1183c04

https://github.com/hyperledger-archives/fabric/blob/master/examples/chaincode/go/chaincode_example04/chaincode_example04.go

https://golang.hotexamples.com/examples/github.com.hyperledger.fabric.core.chaincode.shim/ChaincodeStubInterface/InvokeChaincode/golang-chaincodestubinterface-invokechaincode-method-examples.html