{- | Module: Caradno.YTxP.Control.Stubs
Description: Development stubs. Use these when you don't
have some scripts fully implemented yet.
-}
module Cardano.YTxP.Control.Stubs (
  alwaysSucceedsValidator,
  alwaysSucceedsTwoArgumentScript,
  noncedValidatorWrapper,
  noncedTwoArgumentScriptWrapper,
) where

import Plutarch.LedgerApi.V2 (PScriptContext)

--------------------------------------------------------------------------------
-- Validator stubs

-- | A validator that will never fail
alwaysSucceedsValidator ::
  forall (s :: S).
  Term s (PData :--> PData :--> PScriptContext :--> POpaque)
alwaysSucceedsValidator :: forall (s :: S).
Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
alwaysSucceedsValidator = (Term s PData
 -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a (b :: PType) (s :: S) (c :: PType).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: PType).
HasCallStack =>
(Term s c
 -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (c :--> (PData :--> (PScriptContext :--> POpaque)))
plam ((Term s PData
  -> Term s PData -> Term s PScriptContext -> Term s POpaque)
 -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
-> (Term s PData
    -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a b. (a -> b) -> a -> b
$ \Term s PData
_ Term s PData
_ Term s PScriptContext
_ -> Term s (PUnit @S) -> Term s POpaque
forall (s :: S) (a :: PType). Term s a -> Term s POpaque
popaque (PLifted (PUnit @S) -> Term s (PUnit @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant ())

{- | Compile a nonce into the script, changing the script hash. This can be useful if you need
many stubbed validators with different addresses.
-}
noncedValidatorWrapper ::
  forall (nonceType :: S -> Type) (s :: S).
  Term s nonceType ->
  Term s (PData :--> PData :--> PScriptContext :--> POpaque) ->
  Term s (PData :--> PData :--> PScriptContext :--> POpaque)
noncedValidatorWrapper :: forall (nonceType :: PType) (s :: S).
Term s nonceType
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
noncedValidatorWrapper Term s nonceType
nonce Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
wrappedScript =
  Term s nonceType
-> (Term s nonceType
    -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall (s :: S) (a :: PType) (b :: PType).
Term s a -> (Term s a -> Term s b) -> Term s b
plet Term s nonceType
nonce ((Term s nonceType
  -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
 -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
-> (Term s nonceType
    -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a b. (a -> b) -> a -> b
$
    Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
-> Term s nonceType
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a b. a -> b -> a
const
      ((Term s PData
 -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a (b :: PType) (s :: S) (c :: PType).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: PType).
HasCallStack =>
(Term s c
 -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (c :--> (PData :--> (PScriptContext :--> POpaque)))
plam ((Term s PData
  -> Term s PData -> Term s PScriptContext -> Term s POpaque)
 -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque))))
-> (Term s PData
    -> Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
forall a b. (a -> b) -> a -> b
$ \Term s PData
datum Term s PData
redeemer Term s PScriptContext
ctx -> Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
wrappedScript Term s (PData :--> (PData :--> (PScriptContext :--> POpaque)))
-> Term s PData
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PData
datum Term s (PData :--> (PScriptContext :--> POpaque))
-> Term s PData -> Term s (PScriptContext :--> POpaque)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PData
redeemer Term s (PScriptContext :--> POpaque)
-> Term s PScriptContext -> Term s POpaque
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PScriptContext
ctx)

--------------------------------------------------------------------------------
-- Two argument script (minting policies and staking validator) stubs

-- | A two argument script (minting policy or staking validator) that will never fail
alwaysSucceedsTwoArgumentScript ::
  forall (s :: S).
  Term s (PData :--> PScriptContext :--> POpaque)
alwaysSucceedsTwoArgumentScript :: forall (s :: S). Term s (PData :--> (PScriptContext :--> POpaque))
alwaysSucceedsTwoArgumentScript = (Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a (b :: PType) (s :: S) (c :: PType).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: PType).
HasCallStack =>
(Term s c -> Term s PScriptContext -> Term s POpaque)
-> Term s (c :--> (PScriptContext :--> POpaque))
plam ((Term s PData -> Term s PScriptContext -> Term s POpaque)
 -> Term s (PData :--> (PScriptContext :--> POpaque)))
-> (Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a b. (a -> b) -> a -> b
$ \Term s PData
_ Term s PScriptContext
_ -> Term s (PUnit @S) -> Term s POpaque
forall (s :: S) (a :: PType). Term s a -> Term s POpaque
popaque (PLifted (PUnit @S) -> Term s (PUnit @S)
forall (p :: PType) (s :: S). PLift p => PLifted p -> Term s p
pconstant ())

{- | Compiles a nonce into the script, changing the script hashes.
This is useful if you need many stubbed validators with different addresses
-}
noncedTwoArgumentScriptWrapper ::
  forall (nonceType :: S -> Type) (s :: S).
  Term s nonceType ->
  Term s (PData :--> PScriptContext :--> POpaque) ->
  Term s (PData :--> PScriptContext :--> POpaque)
noncedTwoArgumentScriptWrapper :: forall (nonceType :: PType) (s :: S).
Term s nonceType
-> Term s (PData :--> (PScriptContext :--> POpaque))
-> Term s (PData :--> (PScriptContext :--> POpaque))
noncedTwoArgumentScriptWrapper Term s nonceType
nonce Term s (PData :--> (PScriptContext :--> POpaque))
wrappedScript =
  Term s nonceType
-> (Term s nonceType
    -> Term s (PData :--> (PScriptContext :--> POpaque)))
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall (s :: S) (a :: PType) (b :: PType).
Term s a -> (Term s a -> Term s b) -> Term s b
plet Term s nonceType
nonce ((Term s nonceType
  -> Term s (PData :--> (PScriptContext :--> POpaque)))
 -> Term s (PData :--> (PScriptContext :--> POpaque)))
-> (Term s nonceType
    -> Term s (PData :--> (PScriptContext :--> POpaque)))
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a b. (a -> b) -> a -> b
$
    Term s (PData :--> (PScriptContext :--> POpaque))
-> Term s nonceType
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a b. a -> b -> a
const
      ((Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a (b :: PType) (s :: S) (c :: PType).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
forall (c :: PType).
HasCallStack =>
(Term s c -> Term s PScriptContext -> Term s POpaque)
-> Term s (c :--> (PScriptContext :--> POpaque))
plam ((Term s PData -> Term s PScriptContext -> Term s POpaque)
 -> Term s (PData :--> (PScriptContext :--> POpaque)))
-> (Term s PData -> Term s PScriptContext -> Term s POpaque)
-> Term s (PData :--> (PScriptContext :--> POpaque))
forall a b. (a -> b) -> a -> b
$ \Term s PData
redeemer Term s PScriptContext
ctx -> Term s (PData :--> (PScriptContext :--> POpaque))
wrappedScript Term s (PData :--> (PScriptContext :--> POpaque))
-> Term s PData -> Term s (PScriptContext :--> POpaque)
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PData
redeemer Term s (PScriptContext :--> POpaque)
-> Term s PScriptContext -> Term s POpaque
forall (s :: S) (a :: PType) (b :: PType).
Term s (a :--> b) -> Term s a -> Term s b
# Term s PScriptContext
ctx)