以编程方式生成.bna文件

问题描述 投票:0回答:1

所以我知道如何使用composer archive create -t dir -n .并找到它的代码over here。在进行单元测试时,我能够生成businessNetworkDefinition并使用composer-embedded运行它们,但现在我正在尝试以编程方式生成.bna文件。似乎无法找到允许它发生的API。

我试过using this,但它只是抛出一个错误说unable to find lastIndexOf()

用例是,编辑了.cto文件,现在必须创建一个新的.bna文件。

hyperledger hyperledger-composer
1个回答
0
投票

所以这个particular line解决了我的问题。我使用的是版本0.20.x。我将版本更改为0.19.14并编辑了部分代码。似乎0.20.x可能存在问题

我的package.json

"dependencies": {
    "body-parser": "^1.18.3",
    "composer-client": "^0.19.14",
    "composer-common": "^0.19.14",
    "composer-admin": "^0.19.14",
    "composer-connector-embedded": "^0.19.14",
    "compression": "^1.7.3",
    "cookie-parser": "^1.4.4",
    "express": "^4.16.4",
    "helmet": "^3.15.1",
    "nodemon": "^1.18.10",
    "shelljs": "^0.8.3"
  }

和代码

const BusinessNetworkDefinition = require('composer-common').BusinessNetworkDefinition;
const path = require('path');
const fs = require('fs');

async function main() {
  const businessNetworkDefinition = await BusinessNetworkDefinition.fromDirectory(path.resolve(__dirname, '../tests/chaincode'));
  businessNetworkName = businessNetworkDefinition.getName();
  console.log(businessNetworkName);
  fs.writeFileSync('my-special.bna', await businessNetworkDefinition.toArchive());
};
main();

chaincode文件夹是

- chaincode
  - lib
    - logic.js
  - models
    - base.cto
  - package.json
  - permissions.acl
  - queries.qry

希望这有助于任何人尝试实现同样的目标!

© www.soinside.com 2019 - 2024. All rights reserved.