【问题标题】:Hyperledger Fabric: Calling Python script from chain code written using Node SDKHyperledger Fabric:从使用 Node SDK 编写的链码中调用 Python 脚本
【发布时间】:2019-10-14 08:35:01
【问题描述】:

我正在使用 Hyperledger Fabric 开发一个应用程序,其中一个用 nodeJS 编写的应用程序调用一个也用 nodeJS 编写的链代码函数。这个链码函数应该调用一个 Python 脚本,做一些事情并将结果写入链码函数。该链码函数应该将 Python 脚本返回的结果存储在账本上,并将成功存储状态返回给调用应用程序。 我尝试通过以下方式使用 nodeJS 提供的子进程模块来执行此操作 -

async mergeModel(ctx, modelNumber1, modelNumber2) {
    console.info('============= START : Merge Model ===========');
    const modelAsBytes1 = await ctx.stub.getState(modelNumber1); // get the model from chaincode state
    const modelAsBytes2 = await ctx.stub.getState(modelNumber2); // get the model from chaincode state

    if (!modelAsBytes1 || modelAsBytes1.length === 0) {
        throw new Error(`${modelNumber1} does not exist`);
    }
    if (!modelAsBytes2 || modelAsBytes2.length === 0) {
        throw new Error(`${modelNumber2} does not exist`);
    }
    const spawn = require('child_process').spawn;
    const pythonProcess = spawn('python',['mergeModel.py', modelAsBytes1, modelAsBytes2]);
    pythonProcess.stdout.on('data', (data) => {
        console.log(data);
    });
}

python 脚本 mergeModel.py 存储在与链代码相同的目录中。 但是,这并没有按预期调用 python 脚本。 有什么我想念的吗。 谢谢。

【问题讨论】:

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


【解决方案1】:
> This chain code function should call a Python script, do something and
  written the results to the chaincode function.

这是非常糟糕的做法,请不要做这样的事情 影响交易执行。尝试在 Nodejs AppServer,一旦你得到结果,然后调用链代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    相关资源
    最近更新 更多