【问题标题】:Is it possible to use invokeChaincode method to retrieve data from the chaincode that is on different channel是否可以使用 invokeChaincode 方法从不同通道上的链码中检索数据
【发布时间】:2020-05-13 15:11:12
【问题描述】:

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

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

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

我正在使用超级账本结构 2.0 版和节点 js 来构建我的链码。

【问题讨论】:

    标签: hyperledger-fabric hyperledger hyperledger-chaincode hyperledger-fabric-sdk-js


    【解决方案1】:

    您可以使用 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 方法的帮助。如何实现这个是fabric。
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 2012-12-10
    • 2019-09-12
    • 2015-08-15
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多