add 'makeEffect' template stub

This commit is contained in:
Emily Martins 2022-03-28 13:12:16 +02:00
parent 8534405920
commit 64d006d025
3 changed files with 34 additions and 4 deletions

View file

@ -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'
--------------------------------------------------------------------------------

View file

@ -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)

View file

@ -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