当我部署新的 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/