我是 DAML 的新手,并且已经为此苦苦思索了两天。在“模板投票”中指定的这个投票系统中,参与者有能力将投票方添加到指定为“选择添加”的投票者列表中。这个选民名单(我假设是一个名单)被定义为“voters : Set Party”,(我似乎找不到定义),并且在“Choice Vote”和“Choice Decide”中定义了一些条件。
我正在尝试删除“选择添加”功能,而是在单独模板中定义的列表中预定义所有选民。如果我理解正确,这些预定义的选民必须声明为一个列表:[Party] 我创建了一个名为“Creation”的模板,其中包含一些变量以及一个名为“CreationRights”的自定义类型,其中包含必须从投票模板。但是,我似乎无法以任何方式引用此列表。将 voters 数据类型更改为 [Party] 也会在 Choice Decide 和 Choice Vote 中为“voters”提供错误。使指定的条件不可用:
无法将预期类型“Set a1”与实际类型“[Party]”匹配
如何在仍然应用条件集的同时引用预定义的选民 (votingRight) 列表?非常欢迎任何提示!
代码:
data CreationRights = CreationRights
with
votingRight : [Party]
deriving (Eq, Show)
template Creation
with
actor : Party
creationId : Text
title : Text
votingRight : CreationRights
where
signatory actor
template Voting
with
actor : Party
claim : Claim
voters : Set Party
voted : Set Party
votes : [Bool]
where
signatory actor, voted
observer voters
key (actor, claim) : VotingKey
maintainer key._1
---choice Add : ()
---with voter : Party
---controller actor
---do
---create this with voters = S.insert voter voters
---pure ()
choice Decide : ContractId Decision
controller actor
do
assertMsg "At least 60% must have voted" $ ((size voters / 100) * 60) <= length votes
let approvals = length $ L.filter (\v -> v) votes
let disapprovals = length $ L.filter (\v -> not v) votes
let accept = approvals > disapprovals
create Decision with ..
choice Vote : ()
with
voter : Party
accept : Bool
controller voter
do
assertMsg "Voter not added" $ member voter voters
assertMsg "Voter already voted" $ not $ member voter voted
create this with voted = S.insert voter voted; votes = accept :: votes
pure ()
template Decision
with
actor : Party
claim : Claim
voters : Set Party
accept : Bool
where
signatory actor, voters