1.如何在超级账本作曲家中为参与者存储多个屁股



嗨,我是区块链的新手..请帮忙。

1.我有客户参与者应该能够存储多个资产。 2. 如何查询客户的所有产品

namespace demo  
participant Customer identified by customerId {
o String customerId
o String firstName
o String lastName
o String email
o String phone
o Address address optional
--> Product[] product optional // here i need to store multiple products that belongs to this customer
}

asset Product identified by productId{
o String productId
o productType producttype
o String productName
o String model
--> Customer owner optional
}

1-我认为在您的商业案例中,为每个产品添加所有者是没有意义的,因为您已经拥有属于每个客户的资产(产品(数组。

1.1-要在产品数组中保存多个资产,这将在逻辑.js文件中的事务处理函数中完成 在下面的文档链接中,您将找到有关如何实现它的非常有用的信息: https://hyperledger.github.io/composer/latest/reference/js_scripts

1.2-作为查询解决方案 您将通过 customerId 查询此参与者注册表,在结果中您将找到您的产品数组。 如下所示。

in the queries.qry file
query CurrentCustomer {
description: "Returns Certain Customer Details in This Registry"
statement:  
SELECT  demo.Customer
WHERE (customerId == _$customerId)
}

为了更好地了解查询,您可以查看下面的文档链接: https://hyperledger.github.io/composer/latest/tutorials/queries

2-这里的问题是,每次客户购买产品时,您都要向此阵列添加新产品吗? 因此,假设您的客户购买了 10,000 种产品,并且有多个客户以这种速度,您的应用程序性能将不是最好的,因为检索这么多数据并对其进行更改,然后更新您的参与者(客户(。 相反,您可以在客户和发票之间建立关系,并且每张发票都包含产品的枚举,将表示为包含所有产品属性的概念,在这种情况下,每张发票都有所有者,因此您可以查询特定客户的所有发票。

最新更新