在我的网络中,模型的相关部分如下。
asset Farm identified by farmId{
o String farmId
o String FarmLocation
o String[] images optional
o String[] waterSources
o String[] nearFactories
o String otherDescription optional
o Certification certification
--> Stakeholder owner
o String[] farmers
}
participant Stakeholder identified by stakeholderId{
o String stakeholderId
o String name
o Address address
o String email optional
o String telephone optional
o Certification certification optional
o String[] images optional
o Company company
o String username
o String password
o StakeholderType type
o String description optional
o String authPerson
o String vehicleNo optional
o DistType distributionType optional
o String branchNo optional
}
在“农场”资产中,我将相关的“农民”参与者的标识符存储为“农民”属性下的字符串数组。我只允许ID包含在此数组中的农民访问Farm资产。为此,我尝试了以下访问规则。但是它似乎没有按预期工作。
rule FarmersHasAccessToTheirFarms {
description: "Allow all participants full access to their assets"
participant(p): "org.ucsc.agriblockchain.Stakeholder"
operation: ALL
resource(r): "org.ucsc.agriblockchain.Farm"
condition: (p.type == "FARMER" && p.stakeholderId in r.farmers)
action: ALLOW
}
如何实现此要求?有什么建议吗?
答案 0 :(得分:0)
您可以使用.some
功能-有人已经在此处发布了答案-> Includes function in ACL condition,与您要实现的目标类似。
例如类似
condition: (p.type == "FARMER" && (r.farmers.some(function (checkstake) {
return checkstake === p.stakeholderId;
} ))