Итак, я создаю простую систему голосования как новичок в 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