DAML:应用表达式条件但缺少必需的授权者

DAML: Applying expression conditions but absence of required authorizers

作为 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

之所以要求所有选民授权 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 选择有效,同时仍将结果告知所有可能的选民。