因此,作为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
答案 0 :(得分:1)
之所以要求所有选民批准Decide
选择,是因为它创建了Decision
合同,其中所有选民都被列为签字人。您可以将Decision
合同更改为
template Decision
with
actor : Party
claim : Claim
voted : Set Party
voters : Set Party
accept : Bool
where
signatory actor, voted
observers voters
这将使Decide
选择有效,同时仍将所有可能的选民告知投票结果。