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

时间:2019-01-29 10:57:58

标签: hyperledger-fabric hyperledger-composer

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

1 个答案:

答案 0 :(得分:2)

我过去为此所做的是编写一个名为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
}