【问题标题】:Hyperledger Composer: how to define relationshipsHyperledger Composer:如何定义关系
【发布时间】:2018-04-06 11:02:01
【问题描述】:

我对如何在 Hyperledger Composer .cto 文件中定义关系感到有些困惑。请在下面查看我的具体问题:

我在这里粘贴了 .cto 文件的部分内容https://github.com/IBM/Decentralized-Energy-Composer/blob/master/models/model.cto

participant Resident identified by residentID {
    o String residentID
    o String firstName
    o String lastName
    --> Coins coins
    --> Cash cash
    --> Energy energy
}

asset Coins identified by coinsID {
    o String coinsID
    o Double value
    o String ownerID
    o OwnerEntity ownerEntity

}

asset Energy identified by energyID {
    o String energyID
    o String units
    o Double value
    o String ownerID
    o OwnerEntity ownerEntity
} 

asset Cash identified by cashID {
    o String cashID
    o String currency
    o Double value
    o String ownerID
    o OwnerEntity ownerEntity
} 

这应该读作a Resident owns assets which are Coins, Cash and Energy 吗?可以反过来写吗(见下文)?

participant Resident identified by residentID {
    o String residentID
    o String firstName
    o String lastName

}

asset Coins identified by coinsID {
    o String coinsID
    o Double value
    -->Resident owner

}

asset Energy identified by energyID {
    o String energyID
    o String units
    o Double value
    --> Resident owner
} 

asset Cash identified by cashID {
    o String cashID
    o String currency
    o Double value
    --> Resident owner
} 

所以,这基本上是说每项资产都归某人所有。哪种设计被认为更好,为什么?请解释一下。

【问题讨论】:

    标签: hyperledger-composer


    【解决方案1】:

    很可能是第二种设计,因为从设计的角度来看,它更像是normalized。 (应该想象当前的设计是针对示例演示的水平设置,而不是详尽的设计以准备更大的东西)。业务网络模型(除其他外)描述participantsassetstransactions - 建模网络 - 资源及其字段/属性/类型的声明 - 当然还有任何关系 - 即不太相似一般来说,old school 数据库设计。更好的解释here (scroll down)

    关系说:

    1. 此资源 - 与另一个资源有关系。
    2. 可以从“this”资源(例如。 代码方面,您可以检索字段值,而无需求助 直接到该注册表以搜索和检索记录)。

    在上面的设计 2 中:通常,owner 字段(在 assets 中)是一个关系字段 - 并映射到引用的参与者类中的 participant 记录(通过其标识字段)。在您的事务逻辑中,您可以检查相关参与者的owner.firstName 的值(一个示例)。

    这种关系是单向的。通过添加关系字段,参与者(在 #2 的情况下)可以从上述任何资产资源类型中引用(例如,从您的交易处理逻辑/代码中,您的智能合约的一部分)。不强制执行关系(它不是关系数据库),但您可以在添加/删除时自己添加逻辑以进行检查。希望这会有所帮助。

    【讨论】:

    • 感谢您的回答!还有一个问题:如果一项资产可以拥有所有者,但所有者可以是居民、银行或公司,该怎么办?在这种情况下,一项资产将与 3 个参与者建立关系,但其中两个关系将为 NULL,因为一项资产只能由 1 个参与者拥有。这合理吗?
    • 假设您的意思是与 3 个不同的参与者 types(在资产模型中)的关系并且“一次仅由 1 个参与者类型拥有”。但无论哪种方式 - 是的,如果分配了第 3 个(在您的场景中),则 2 可以为 NULL。
    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多