I'm new to DAML and have been scratching my head over this for two solid days. In this voting system specified in "template Voting", an actor has the ability to add a voter party to a list of voters specified as "choice Add". This voters list (I presume a list) is defined as "voters : Set Party", (of which I can't seem to find the definition), and some conditions are defined in "Choice Vote" and "Choice Decide".
I'm trying to remove the "Choice Add" ability and instead pre-define all voters in a list defined in a separate template. If I understand correctly these predefined voters must be declared as a list: [Party] I created a template called "Creation" containing some variables in conjunction with a custom type called "CreationRights" containing the to be voters list which must be referenced from the voting template. However, I can't seem to refer to this list in any way. Changing the voters data type to [Party] also gives an error for "voters" in Choice Decide and Choice Vote. rendering the conditions specified unusable:
Couldn't match expected type 'Set a1' with actual type '[Party]'
How can I reference to the predefined voters (votingRight) list while still applying the condition set? Any tips are very welcome!
Code:
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