ensure that the voting op is within a valid period
This commit is contained in:
parent
fc48709c07
commit
3741759717
1 changed files with 17 additions and 2 deletions
|
|
@ -17,6 +17,7 @@ import Agora.Proposal (
|
||||||
Proposal (governorSTAssetClass, stakeSTAssetClass),
|
Proposal (governorSTAssetClass, stakeSTAssetClass),
|
||||||
ProposalStatus (VotingReady),
|
ProposalStatus (VotingReady),
|
||||||
)
|
)
|
||||||
|
import Agora.Proposal.Time (currentProposalTime, isVotingPeriod)
|
||||||
import Agora.Record (mkRecordConstr, (.&), (.=))
|
import Agora.Record (mkRecordConstr, (.&), (.=))
|
||||||
import Agora.Stake (PProposalLock (..), PStakeDatum (..), findStakeOwnedBy)
|
import Agora.Stake (PProposalLock (..), PStakeDatum (..), findStakeOwnedBy)
|
||||||
import Agora.Utils (
|
import Agora.Utils (
|
||||||
|
|
@ -131,7 +132,17 @@ proposalValidator proposal =
|
||||||
ctx <- tcont $ pletFields @'["txInfo", "purpose"] ctx'
|
ctx <- tcont $ pletFields @'["txInfo", "purpose"] ctx'
|
||||||
txInfo <- tclet $ pfromData ctx.txInfo
|
txInfo <- tclet $ pfromData ctx.txInfo
|
||||||
PTxInfo txInfo' <- tcmatch 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
|
PSpending ((pfield @"_0" #) -> txOutRef) <- tcmatch $ pfromData ctx.purpose
|
||||||
|
|
||||||
PJust txOut <- tcmatch $ findTxOutByTxOutRef # txOutRef # txInfoF.inputs
|
PJust txOut <- tcmatch $ findTxOutByTxOutRef # txOutRef # txInfoF.inputs
|
||||||
|
|
@ -173,13 +184,17 @@ proposalValidator proposal =
|
||||||
|
|
||||||
tcassert "ST at inputs must be 1" (spentST #== 1)
|
tcassert "ST at inputs must be 1" (spentST #== 1)
|
||||||
|
|
||||||
|
currentTime <- tclet $ currentProposalTime # txInfoF.validRange
|
||||||
|
|
||||||
pure $
|
pure $
|
||||||
pmatch proposalRedeemer $ \case
|
pmatch proposalRedeemer $ \case
|
||||||
PVote r -> unTermCont $ do
|
PVote r -> unTermCont $ do
|
||||||
-- TODO: do we have to check the timing here?
|
|
||||||
tcassert "Input proposal must be in VotingReady state" $
|
tcassert "Input proposal must be in VotingReady state" $
|
||||||
proposalF.status #== pconstant VotingReady
|
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).
|
-- Ensure the transaction is voting to a valid 'ResultTag'(outcome).
|
||||||
PProposalVotes voteMap <- tcmatch proposalF.votes
|
PProposalVotes voteMap <- tcmatch proposalF.votes
|
||||||
voteFor <- tclet $ pfromData $ pfield @"resultTag" # r
|
voteFor <- tclet $ pfromData $ pfield @"resultTag" # r
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue