From b4ca5747572c876d633e1eff342983a94c767804 Mon Sep 17 00:00:00 2001 From: fanghr Date: Wed, 18 May 2022 21:11:55 +0800 Subject: [PATCH] ensure that the voting op is within a valid period --- agora/Agora/Proposal/Scripts.hs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/agora/Agora/Proposal/Scripts.hs b/agora/Agora/Proposal/Scripts.hs index 44ab890..7656303 100644 --- a/agora/Agora/Proposal/Scripts.hs +++ b/agora/Agora/Proposal/Scripts.hs @@ -17,6 +17,7 @@ import Agora.Proposal ( Proposal (governorSTAssetClass, stakeSTAssetClass), ProposalStatus (VotingReady), ) +import Agora.Proposal.Time (currentProposalTime, isVotingPeriod) import Agora.Record (mkRecordConstr, (.&), (.=)) import Agora.Stake (PProposalLock (..), PStakeDatum (..), findStakeOwnedBy) import Agora.Utils ( @@ -131,7 +132,17 @@ proposalValidator proposal = ctx <- tcont $ pletFields @'["txInfo", "purpose"] ctx' txInfo <- tclet $ pfromData ctx.txInfo PTxInfo txInfo' <- tcmatch txInfo - txInfoF <- tcont $ pletFields @'["inputs", "outputs", "mint", "datums", "signatories"] txInfo' + txInfoF <- + tcont $ + pletFields + @'[ "inputs" + , "outputs" + , "mint" + , "datums" + , "signatories" + , "validRange" + ] + txInfo' PSpending ((pfield @"_0" #) -> txOutRef) <- tcmatch $ pfromData ctx.purpose PJust txOut <- tcmatch $ findTxOutByTxOutRef # txOutRef # txInfoF.inputs @@ -173,13 +184,17 @@ proposalValidator proposal = tcassert "ST at inputs must be 1" (spentST #== 1) + currentTime <- tclet $ currentProposalTime # txInfoF.validRange + pure $ pmatch proposalRedeemer $ \case PVote r -> unTermCont $ do - -- TODO: do we have to check the timing here? tcassert "Input proposal must be in VotingReady state" $ proposalF.status #== pconstant VotingReady + tcassert "Proposal time should be wthin the voting period" $ + isVotingPeriod # proposalF.timingConfig # proposalF.startingTime # currentTime + -- Ensure the transaction is voting to a valid 'ResultTag'(outcome). PProposalVotes voteMap <- tcmatch proposalF.votes voteFor <- tclet $ pfromData $ pfield @"resultTag" # r