所以我正在构建一个简单的投票系统作为 DAML 初学者,到目前为止它运行得很好。现在我设定条件,说明当 60% 的登记选民投票时允许做出决定(可以在下面的选择决定中找到)。但是,当我在满足 60% 的条件时忽略任何选民时,我会收到以下错误,指出缺少授权选民:
The following errors occured: node NodeId(1)
(Identifier(0ea886b25958c473b6ab9efaacc3f4eb79975d4eec82d08a9d7e1d3e6ab4c1bb,Voti
ng:Decision))
requires authorizers Approver 1,Approver 2,Approver 4,Music Rights
Association, but only Music Rights
Association,Approver 1,Approver 2 were given.
出于某种原因,所有选民都必须根据授权投票,即使选民是在观察员下登记的。我如何确保每个选民保留他们的投票选择权,但在 60% 投票后才能做出决定?
代码:
daml 1.2
module Voting where
import DA.Next.Set as S
import DA.List as L
import DA.Assert
type VotingCid = ContractId Create_Voting
type ActorCid = ContractId Actor
type CreationCid = ContractId Creation
data CreationRights = CreationRights
with
votingRight : [Party]
deriving (Eq, Show)
template Claim
with
proposer : Party
where
signatory proposer
type VotingKey = (Party, Claim)
template Creation
with
artist : Party
title : Text
votingRight : Set Party
where
signatory artist
template Voting
with
actor : Party
claim : Claim
select_creationid : ContractId Creation
artist : Party
title : Text
voters : Set Party
voted : Set Party
votes : [Bool]
where
signatory actor, voted
observer voters
key (actor, claim) : VotingKey
maintainer key._1
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 ()
choice Decide : ContractId Decision
controller actor
do
let votersdec : Decimal = intToDecimal(size voters)
let votesdec : Decimal = intToDecimal(length votes)
assertMsg "At least 60% must have voted" $ (votersdec * 0.6) < votesdec
let approvals = length $ L.filter (\v -> v) votes
let disapprovals = length $ L.filter (\v -> not v) votes
let accept = approvals > disapprovals
create Decision with actor = actor; claim = claim; voters = voters; accept = accept
template Create_Voting
with
actor : Party
claim : Claim
select_creationid : ContractId Creation
voters : Set Party
voted : Set Party
votes : [Bool]
where
signatory actor
choice Select_Creation : ContractId Voting
with
title : Text
votingRight : Set Party
controller actor
do
selectedCreation <- fetch select_creationid
--selectedActor === selectedCreation.actor
--selectedTitle === selectedCreation.title
--voters === selectedCreation.votingRight
create Voting with artist = selectedCreation.artist; title = selectedCreation.title; actor = actor; claim = claim; select_creationid = select_creationid; voters = selectedCreation.votingRight;voted = voted; votes = votes
--insertCreation <- exercise selectedCreation Create_Selected_Claim
--return(insertCreation)
template Decision
with
actor : Party
claim : Claim
voters : Set Party
accept : Bool
where
signatory actor, voters