hyperledger-fabric - 如何在 Hyperledger Composer 项目中加载示例数据

标签 hyperledger-fabric hyperledger-composer

当我部署新的 Hyperledger Composer 项目时,它完全是空的。有没有办法加载某种种子/赛程数据?

最佳答案

我过去为此所做的是编写一个名为 setup 的事务,只允许管理员运行。此函数使用大量可用于测试的模拟数据来初始化您的链。例如:

型号:

transaction Setup {
}

交易脚本:

/**
 * Seed chain with mock data for testing
 * @param {com.your.namespace} tx - set up request
 * @transaction
 */
async function setup(tx) {
  const factory = getFactory();

  const exampleRegistry = await getParticipantRegistry(`${namespace}.example`);

  const exampleResource= factory.newResource(namespace, "Example", "ExampleResourceName");
  example.exampleProperty = 2000;

  await exampleRegistry.add(exampleResource);

  const otherExample = factory.newResource(namespace, "OtherExample", "OtherExampleName");
  otherExample.exampleProperty = 0;
  const otherExampleRef = factory.newRelationship(namespace, "OtherExample", "OtherExampleName");

  await otherExampleRegistry.addAll([otherExample]);

  const thirdExample = factory.newResource(namespace, "ThirdExample", "ThirdExampleName");
  thirdExample.exampleRelationshipProperty = otherExampleRef
  thirdExample.exampleProperty = 0;

  await thirdExampleRegistry.addAll([thirdExample]);
}

然后,您的.ACL:

rule SetupTransaction {
    description: "Deny anyone but admin access to call Setup transaction"
    participant: "com.your.namespace.**"
    operation: ALL
    resource: "com.your.namespace.Setup"
    action: DENY
}

关于hyperledger-fabric - 如何在 Hyperledger Composer 项目中加载示例数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54419494/

相关文章:

kubernetes - 有没有人尝试过 HLF 2.0 功能 "External Builders and Launchers"并希望取得联系?

docker - 无法设置 IP 表 : Unable to enable NAT rule

php - 有没有办法将 Hyperledger Fabric Composer 命令从 'composer' 重命名为其他名称?

yaml - Hyperledger Fabric configtxgen - 读取配置时出错 : map merge requires map or sequence of maps as the value

hyperledger-fabric - Hyperledger 结构错误 : 14 UNAVAILABLE: TCP Write failed

mongodb - 用于 hyperledger composer API 的 Passport JWt 身份验证

hyperledger - Fabric Composer 对比 -->

hyperledger-composer - 需要替换本地主机 :3000 with realip:3000 in composer-rest-server

hyperledger-fabric - Hyperledger 具有与 Fabric CA 不同的 PKI

node.js - Hyperledger - 编写 REST API 或提交交易来添加/修改 Assets ?