diff --git a/agora/Agora/Effect.hs b/agora/Agora/Effect.hs index b802044..fccb32e 100644 --- a/agora/Agora/Effect.hs +++ b/agora/Agora/Effect.hs @@ -5,4 +5,33 @@ Description: Helpers for constructing effects Helpers for constructing effects. -} -module Agora.Effect () where +module Agora.Effect (makeEffect) where + +import Plutarch.Api.V1 (PScriptPurpose (PSpending), PTxInfo, PTxOutRef, PValidator) +import Plutarch.Internal (punsafeCoerce) +import Plutarch.Monadic qualified as P + +-------------------------------------------------------------------------------- + +-- | Helper 'template' for creating effect validator. +makeEffect :: + forall (datum :: PType) (s :: S). + PIsData datum => + (Term s datum -> Term s PTxOutRef -> Term s PTxInfo -> Term s POpaque) -> + Term s PValidator +makeEffect f = + plam $ \datum _redeemer ctx' -> P.do + ctx <- pletFields @'["txInfo", "purpose"] ctx' + txInfo' <- plet ctx.txInfo + + let datum' :: Term _ datum + datum' = pfromData $ punsafeCoerce datum + + PSpending txOutRef <- pmatch $ pfromData ctx.purpose + txOutRef' <- plet (pfield @"_0" # txOutRef) + + -- TODO: Here, check that a *single* GAT is burned. + + f datum' txOutRef' txInfo' + +-------------------------------------------------------------------------------- diff --git a/agora/Agora/Governor.hs b/agora/Agora/Governor.hs index b4ad0bc..f44eda1 100644 --- a/agora/Agora/Governor.hs +++ b/agora/Agora/Governor.hs @@ -5,7 +5,7 @@ Description: Governor entity scripts acting as authority of entire system. Governor entity scripts acting as authority of entire system. -} -module Agora.Governor (GovernorDatum (..)) where +module Agora.Governor (GovernorDatum (..), GovernorRedeemer (..)) where import Agora.Proposal (ProposalThresholds) diff --git a/agora/PPrelude.hs b/agora/PPrelude.hs index 8fba4be..3232cf9 100644 --- a/agora/PPrelude.hs +++ b/agora/PPrelude.hs @@ -11,7 +11,8 @@ module PPrelude ( module Plutarch, ) where --- These are not exported by Plutarch.Prelude, for some reason. Maybe we can 'fix' this upstream? -import Plutarch (ClosedTerm, compile) +-- NOTE: These are not exported by Plutarch.Prelude, for some reason. +-- Maybe we can 'fix' this upstream? +import Plutarch (ClosedTerm, POpaque, compile) import Plutarch.Prelude import Prelude