calculate the starting time of a proposal upon creation

This commit is contained in:
fanghr 2022-05-24 23:31:26 +08:00
parent 2820831dad
commit 9bc2acb9ca
5 changed files with 77 additions and 31 deletions

View file

@ -30,6 +30,7 @@ module Agora.Proposal (
-- * Plutarch helpers
proposalDatumValid,
pemptyVotesFor,
) where
import GHC.Generics qualified as GHC
@ -47,7 +48,7 @@ import PlutusTx.AssocMap qualified as AssocMap
import Agora.Proposal.Time (PProposalStartingTime, PProposalTimingConfig, ProposalStartingTime, ProposalTimingConfig)
import Agora.SafeMoney (GTTag)
import Agora.Utils (pkeysEqual, pnotNull)
import Agora.Utils (pkeysEqual, pmapMap, pnotNull)
import Control.Applicative (Const)
import Control.Arrow (first)
import Plutarch.DataRepr (DerivePConstantViaData (..), PDataFields, PIsDataReprInstances (..))
@ -348,6 +349,16 @@ deriving via
instance
(PConstantDecl ProposalVotes)
-- Plutarch version of 'pemptyVotesFor'.
pemptyVotesFor :: forall s a. (PIsData a) => Term s (PMap PResultTag a :--> PProposalVotes)
pemptyVotesFor =
phoistAcyclic $
plam
( \m ->
pcon $
PProposalVotes $ pmapMap # plam (const $ pconstant 0) # m
)
-- | Plutarch-level version of 'ProposalDatum'.
newtype PProposalDatum (s :: S) = PProposalDatum
{ getProposalDatum ::