【问题标题】:[Hyperledger-Composer]Attempt to get property owner on an InvalidRelationship is not allowed - ACL Issue[Hyperledger-Composer] 不允许尝试在 InvalidRelationship 上获取财产所有者 - ACL 问题
【发布时间】:2024-01-17 04:55:01
【问题描述】:

我在玩 Hyperledger Composer 时遇到以下错误。

{
  "$class": "org.property.registration.purchaseProperty",
  "propertyListing":
  "resource:org.property.registration.PropertyListing#PL001"
}

错误:不允许尝试获取 InvalidRelationship 上的属性所有者。由于 ID 为“Asset:org.property.registration.Property”的集合中 ID 为“1003”的对象不存在而创建了 InvalidRelationship; [cause=参与者 'org.property.registration.User#0001' 没有对资源 'org.property.registration.Property#1003' 的“读取”访问权限]

我正在尝试访问作为另一个资产 propertyListing 一部分的资产属性。

asset Property identified by PID {
  o String PID
  o Integer marketPrice
  o DateTime regDate
  o String propertyType
  o String location
  o String status default= "Registered"
  --> User owner
} 
asset PropertyListing identified by PLID {
  o String PLID
  --> Property property
}

我正在尝试访问 PropertyListing 资产并更改其中的属性资产的状态。 (我想从其他用户发布的propertyListing购买房产)

const registry = await getAssetRegistry(tx.propertyListing.property.getFullyQualifiedType());
    await registry.update(tx.propertyListing.property);
 // Remove the property from propertyListing()
    const registry2 =  await getAssetRegistry(tx.propertyListing.getFullyQualifiedType());
    await registry2.remove(tx.propertyListing); 

我希望并且根据错误消息,这似乎是一些权限问题,阻止我购买其他用户发布的房产。

// User can see all properties listed for sale
rule UserAccessAllSaleProperties {
    description: "Allow Users to access all properties listed for sale"
    participant: "org.property.registration.User"
    operation: ALL
    resource: "org.property.registration.PropertyListing"
    action: ALLOW
}

在这里,我想访问属于 PropertyListing 的属性。 我正在尝试找出我可以使用的 ACL 的不足之处。还在尝试。

欢迎大家提出建议!!!

【问题讨论】:

    标签: hyperledger-fabric blockchain hyperledger-composer hyperledger-chaincode chaincode


    【解决方案1】:

    试试,

    rule UserAccessAllSaleProperties {
        description: "Allow Users to access all properties listed for sale"
        participant: "org.property.registration.**"
        operation: READ
        resource: "org.property.registration.PropertyListing"
        action: ALLOW
    }
    

    这将允许所有参与者仅“阅读”更适合您的应用程序的 PropertyListing 资产。如果您介绍任何未来的参与者,这将是有益的。 (假设用户被定义为参与者而不是资产)。

    我还建议您将参与者文件和资产文件分开,因为您的应用程序很大。 喜欢

    org.property.registration.Property (-> Will only contain Assets)
    org.property.registration.Participants (-> Will only contain Participants)
    

    并将它们相互导入。

    所以你的规则会像

    rule UserAccessAllSaleProperties {
        description: "Allow Users to access all properties listed for sale"
        participant: "org.property.registration.Participants.**"
        operation: READ
        resource: "org.property.registration.PropertyListing"
        action: ALLOW
    }
    

    【讨论】:

    • 感谢您的回复。我已经更改了 ACL,它几乎和你提到的一样,它对我有用。