allow multiple outputs to the proposal validator

... upon creation of the proposal. Don't know if this is intended or
not.
This commit is contained in:
fanghr 2022-04-26 17:22:10 +08:00
parent 14b8d30d57
commit ec0c53db99

View file

@ -49,11 +49,12 @@ import Agora.Proposal (
PProposalThresholds, PProposalThresholds,
Proposal (..), Proposal (..),
ProposalId, ProposalId,
ProposalStatus (Draft, Executable),
ProposalThresholds, ProposalThresholds,
pnextProposalId, pnextProposalId,
proposalDatumValid, proposalDatumValid,
proposalPolicy, proposalPolicy,
proposalValidator,ProposalStatus (Draft, Executable) proposalValidator,
) )
import Agora.Utils ( import Agora.Utils (
findOutputsToAddress, findOutputsToAddress,
@ -380,21 +381,32 @@ governorValidator gov =
passert "Exactly one proposal token must be minted" $ passert "Exactly one proposal token must be minted" $
hasOnlyOneTokenOfCurrencySymbol # pproposalSymbol # txInfo.mint hasOnlyOneTokenOfCurrencySymbol # pproposalSymbol # txInfo.mint
outputs <- plet $ findOutputsToAddress # ctx.txInfo # pproposalValidatorAddress filteredOutputs <-
passert "Exactly one utxo should be sent to the proposal validator" $ plet $
plength # outputs #== 1 pfilter
# ( phoistAcyclic $
plam
( \txOut' -> P.do
txOut <- pletFields @'["address", "value"] txOut'
output <- pletFields @'["value", "datumHash"] $ phead # outputs txOut.address #== pdata pproposalValidatorAddress
passert "The proposal state token must be sent to the proposal validator" $ #&& psymbolValueOf # pproposalSymbol # txOut.value #== 1
psymbolValueOf # pproposalSymbol # output.value #== 1 )
)
# pfromData txInfo.outputs
passert "Exactly one utxo with proposal state token should be sent to the proposal validator" $
plength # filteredOutputs #== 1
outputDatumHash <- plet $ pfield @"datumHash" #$ phead # filteredOutputs
passert "The utxo paid to the proposal validator must have datum" $ passert "The utxo paid to the proposal validator must have datum" $
pisDJust # output.datumHash pisDJust # outputDatumHash
outputProposalDatum' <- outputProposalDatum' <-
plet $ plet $
mustFindDatum' @PProposalDatum mustFindDatum' @PProposalDatum
# output.datumHash # outputDatumHash
# ctx.txInfo # ctx.txInfo
passert "Proposal datum must be valid" $ passert "Proposal datum must be valid" $
@ -473,8 +485,8 @@ governorValidator gov =
pletFields @'["id", "effects", "status", "cosigners", "thresholds", "votes"] pletFields @'["id", "effects", "status", "cosigners", "thresholds", "votes"]
inputProposalDatum' inputProposalDatum'
passert "Proposal must be in executable state in order to execute effects" $ passert "Proposal must be in executable state in order to execute effects" $
inputProposalDatum.status #== pconstantData Executable inputProposalDatum.status #== pconstantData Executable
let expectedOutputProposalDatum = let expectedOutputProposalDatum =
pforgetData $ pforgetData $