{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableSuperClasses #-}

module Test.Cardano.Ledger.Generic.Scriptic where

import Cardano.Ledger.Allegra.Scripts (
  pattern RequireTimeExpire,
  pattern RequireTimeStart,
 )
import Cardano.Ledger.Core
import Cardano.Ledger.Mary.Value (AssetName (..), MultiAsset (..), PolicyID (..))
import Cardano.Ledger.Plutus.Language (Language (..))
import Cardano.Ledger.Shelley.Scripts (
  pattern RequireAllOf,
  pattern RequireAnyOf,
  pattern RequireMOf,
  pattern RequireSignature,
 )
import Cardano.Slotting.Slot (SlotNo (..))
import qualified Data.Map.Strict as Map
import qualified Data.Sequence.Strict as Seq (fromList)
import Numeric.Natural (Natural)
import Test.Cardano.Ledger.Alonzo.Arbitrary (alwaysFails, alwaysSucceeds)
import Test.Cardano.Ledger.Generic.Indexed (theKeyHash)
import Test.Cardano.Ledger.Generic.Proof

-- =============================================
-- Making era parameterized Scripts

theSlot :: Int -> SlotNo
theSlot :: Int -> SlotNo
theSlot Int
n = Word64 -> SlotNo
SlotNo (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)

class (EraScript era, Show (Script era)) => Scriptic era where
  always :: Natural -> Proof era -> Script era
  alwaysAlt :: Natural -> Proof era -> Script era
  never :: Natural -> Proof era -> Script era
  require :: KeyHash 'Witness -> Proof era -> NativeScript era
  allOf :: [Proof era -> NativeScript era] -> Proof era -> NativeScript era
  anyOf :: [Proof era -> NativeScript era] -> Proof era -> NativeScript era
  mOf :: Int -> [Proof era -> NativeScript era] -> Proof era -> NativeScript era

class Scriptic era => PostShelley era where
  before :: Int -> Proof era -> NativeScript era
  after :: Int -> Proof era -> NativeScript era

class HasTokens era where
  forge :: Integer -> Script era -> MultiAsset

instance Scriptic ShelleyEra where
  never :: Natural -> Proof ShelleyEra -> Script ShelleyEra
never Natural
_ Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf forall a. Monoid a => a
mempty -- always False
  always :: Natural -> Proof ShelleyEra -> Script ShelleyEra
always Natural
_ Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  alwaysAlt :: Natural -> Proof ShelleyEra -> Script ShelleyEra
alwaysAlt Natural
_ Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  require :: KeyHash 'Witness -> Proof ShelleyEra -> NativeScript ShelleyEra
require KeyHash 'Witness
key Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof ShelleyEra -> NativeScript ShelleyEra]
-> Proof ShelleyEra -> NativeScript ShelleyEra
allOf [Proof ShelleyEra -> NativeScript ShelleyEra]
xs Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof ShelleyEra
Shelley) [Proof ShelleyEra -> NativeScript ShelleyEra]
xs))
  anyOf :: [Proof ShelleyEra -> NativeScript ShelleyEra]
-> Proof ShelleyEra -> NativeScript ShelleyEra
anyOf [Proof ShelleyEra -> NativeScript ShelleyEra]
xs Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof ShelleyEra
Shelley) [Proof ShelleyEra -> NativeScript ShelleyEra]
xs))
  mOf :: Int
-> [Proof ShelleyEra -> NativeScript ShelleyEra]
-> Proof ShelleyEra
-> NativeScript ShelleyEra
mOf Int
n [Proof ShelleyEra -> NativeScript ShelleyEra]
xs Proof ShelleyEra
Shelley = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof ShelleyEra
Shelley) [Proof ShelleyEra -> NativeScript ShelleyEra]
xs))

-- Make Scripts in AllegraEra

instance Scriptic AllegraEra where
  never :: Natural -> Proof AllegraEra -> Script AllegraEra
never Natural
_ Proof AllegraEra
Allegra = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf forall a. Monoid a => a
mempty -- always False
  always :: Natural -> Proof AllegraEra -> Script AllegraEra
always Natural
_ Proof AllegraEra
Allegra = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  alwaysAlt :: Natural -> Proof AllegraEra -> Script AllegraEra
alwaysAlt Natural
_ Proof AllegraEra
Allegra = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  require :: KeyHash 'Witness -> Proof AllegraEra -> NativeScript AllegraEra
require KeyHash 'Witness
key Proof AllegraEra
Allegra = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof AllegraEra -> NativeScript AllegraEra]
-> Proof AllegraEra -> NativeScript AllegraEra
allOf [Proof AllegraEra -> NativeScript AllegraEra]
xs Proof AllegraEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof AllegraEra
proof) [Proof AllegraEra -> NativeScript AllegraEra]
xs))
  anyOf :: [Proof AllegraEra -> NativeScript AllegraEra]
-> Proof AllegraEra -> NativeScript AllegraEra
anyOf [Proof AllegraEra -> NativeScript AllegraEra]
xs Proof AllegraEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof AllegraEra
proof) [Proof AllegraEra -> NativeScript AllegraEra]
xs))
  mOf :: Int
-> [Proof AllegraEra -> NativeScript AllegraEra]
-> Proof AllegraEra
-> NativeScript AllegraEra
mOf Int
n [Proof AllegraEra -> NativeScript AllegraEra]
xs Proof AllegraEra
proof = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof AllegraEra
proof) [Proof AllegraEra -> NativeScript AllegraEra]
xs))

instance PostShelley AllegraEra where
  before :: Int -> Proof AllegraEra -> NativeScript AllegraEra
before Int
n Proof AllegraEra
Allegra = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeStart (Int -> SlotNo
theSlot Int
n)
  after :: Int -> Proof AllegraEra -> NativeScript AllegraEra
after Int
n Proof AllegraEra
Allegra = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeExpire (Int -> SlotNo
theSlot Int
n)

-- Make Scripts in Mary era

instance Scriptic MaryEra where
  never :: Natural -> Proof MaryEra -> Script MaryEra
never Natural
_ Proof MaryEra
Mary = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf forall a. Monoid a => a
mempty -- always False
  always :: Natural -> Proof MaryEra -> Script MaryEra
always Natural
_ Proof MaryEra
Mary = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  alwaysAlt :: Natural -> Proof MaryEra -> Script MaryEra
alwaysAlt Natural
_ Proof MaryEra
Mary = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf forall a. Monoid a => a
mempty -- always True
  require :: KeyHash 'Witness -> Proof MaryEra -> NativeScript MaryEra
require KeyHash 'Witness
key Proof MaryEra
Mary = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof MaryEra -> NativeScript MaryEra]
-> Proof MaryEra -> NativeScript MaryEra
allOf [Proof MaryEra -> NativeScript MaryEra]
xs Proof MaryEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof MaryEra
proof) [Proof MaryEra -> NativeScript MaryEra]
xs))
  anyOf :: [Proof MaryEra -> NativeScript MaryEra]
-> Proof MaryEra -> NativeScript MaryEra
anyOf [Proof MaryEra -> NativeScript MaryEra]
xs Proof MaryEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof MaryEra
proof) [Proof MaryEra -> NativeScript MaryEra]
xs))
  mOf :: Int
-> [Proof MaryEra -> NativeScript MaryEra]
-> Proof MaryEra
-> NativeScript MaryEra
mOf Int
n [Proof MaryEra -> NativeScript MaryEra]
xs Proof MaryEra
proof = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> a -> b
$ Proof MaryEra
proof) [Proof MaryEra -> NativeScript MaryEra]
xs))

instance PostShelley MaryEra where
  before :: Int -> Proof MaryEra -> NativeScript MaryEra
before Int
n Proof MaryEra
Mary = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeStart (Int -> SlotNo
theSlot Int
n)
  after :: Int -> Proof MaryEra -> NativeScript MaryEra
after Int
n Proof MaryEra
Mary = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeExpire (Int -> SlotNo
theSlot Int
n)

instance HasTokens MaryEra where
  forge :: Integer -> Script MaryEra -> MultiAsset
forge Integer
n Script MaryEra
s = Map PolicyID (Map AssetName Integer) -> MultiAsset
MultiAsset forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> Map k a
Map.singleton PolicyID
pid (forall k a. k -> a -> Map k a
Map.singleton AssetName
an Integer
n)
    where
      pid :: PolicyID
pid = ScriptHash -> PolicyID
PolicyID (forall era. EraScript era => Script era -> ScriptHash
hashScript @MaryEra Script MaryEra
s)
      an :: AssetName
an = ShortByteString -> AssetName
AssetName ShortByteString
"an"

instance HasTokens AlonzoEra where
  forge :: Integer -> Script AlonzoEra -> MultiAsset
forge Integer
n Script AlonzoEra
s = Map PolicyID (Map AssetName Integer) -> MultiAsset
MultiAsset forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> Map k a
Map.singleton PolicyID
pid (forall k a. k -> a -> Map k a
Map.singleton AssetName
an Integer
n)
    where
      pid :: PolicyID
pid = ScriptHash -> PolicyID
PolicyID (forall era. EraScript era => Script era -> ScriptHash
hashScript @AlonzoEra Script AlonzoEra
s)
      an :: AssetName
an = ShortByteString -> AssetName
AssetName ShortByteString
"an"

instance HasTokens BabbageEra where
  forge :: Integer -> Script BabbageEra -> MultiAsset
forge Integer
n Script BabbageEra
s = Map PolicyID (Map AssetName Integer) -> MultiAsset
MultiAsset forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> Map k a
Map.singleton PolicyID
pid (forall k a. k -> a -> Map k a
Map.singleton AssetName
an Integer
n)
    where
      pid :: PolicyID
pid = ScriptHash -> PolicyID
PolicyID (forall era. EraScript era => Script era -> ScriptHash
hashScript @BabbageEra Script BabbageEra
s)
      an :: AssetName
an = ShortByteString -> AssetName
AssetName ShortByteString
"an"

instance HasTokens ConwayEra where
  forge :: Integer -> Script ConwayEra -> MultiAsset
forge Integer
n Script ConwayEra
s = Map PolicyID (Map AssetName Integer) -> MultiAsset
MultiAsset forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> Map k a
Map.singleton PolicyID
pid (forall k a. k -> a -> Map k a
Map.singleton AssetName
an Integer
n)
    where
      pid :: PolicyID
pid = ScriptHash -> PolicyID
PolicyID (forall era. EraScript era => Script era -> ScriptHash
hashScript @ConwayEra Script ConwayEra
s)
      an :: AssetName
an = ShortByteString -> AssetName
AssetName ShortByteString
"an"

-- =================================
-- Make Scripts in Alonzo era

instance Scriptic AlonzoEra where
  never :: Natural -> Proof AlonzoEra -> Script AlonzoEra
never Natural
n Proof AlonzoEra
Alonzo = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysFails @'PlutusV1 Natural
n -- always False
  always :: Natural -> Proof AlonzoEra -> Script AlonzoEra
always Natural
n Proof AlonzoEra
Alonzo = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV1 Natural
n -- always True
  alwaysAlt :: Natural -> Proof AlonzoEra -> Script AlonzoEra
alwaysAlt Natural
n Proof AlonzoEra
Alonzo = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV1 Natural
n -- always True
  require :: KeyHash 'Witness -> Proof AlonzoEra -> NativeScript AlonzoEra
require KeyHash 'Witness
key Proof AlonzoEra
Alonzo = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof AlonzoEra -> NativeScript AlonzoEra]
-> Proof AlonzoEra -> NativeScript AlonzoEra
allOf [Proof AlonzoEra -> NativeScript AlonzoEra]
xs Proof AlonzoEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof AlonzoEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof AlonzoEra -> NativeScript AlonzoEra]
xs))
  anyOf :: [Proof AlonzoEra -> NativeScript AlonzoEra]
-> Proof AlonzoEra -> NativeScript AlonzoEra
anyOf [Proof AlonzoEra -> NativeScript AlonzoEra]
xs Proof AlonzoEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof AlonzoEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof AlonzoEra -> NativeScript AlonzoEra]
xs))
  mOf :: Int
-> [Proof AlonzoEra -> NativeScript AlonzoEra]
-> Proof AlonzoEra
-> NativeScript AlonzoEra
mOf Int
n [Proof AlonzoEra -> NativeScript AlonzoEra]
xs Proof AlonzoEra
proof = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof AlonzoEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof AlonzoEra -> NativeScript AlonzoEra]
xs))

instance PostShelley AlonzoEra where
  before :: Int -> Proof AlonzoEra -> NativeScript AlonzoEra
before Int
n Proof AlonzoEra
Alonzo = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeStart (Int -> SlotNo
theSlot Int
n)
  after :: Int -> Proof AlonzoEra -> NativeScript AlonzoEra
after Int
n Proof AlonzoEra
Alonzo = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeExpire (Int -> SlotNo
theSlot Int
n)

-- =================================

instance Scriptic BabbageEra where
  never :: Natural -> Proof BabbageEra -> Script BabbageEra
never Natural
n Proof BabbageEra
Babbage = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysFails @'PlutusV1 Natural
n -- always False
  always :: Natural -> Proof BabbageEra -> Script BabbageEra
always Natural
n Proof BabbageEra
Babbage = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV1 Natural
n -- always True
  alwaysAlt :: Natural -> Proof BabbageEra -> Script BabbageEra
alwaysAlt Natural
n Proof BabbageEra
Babbage = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV2 Natural
n -- always True
  require :: KeyHash 'Witness -> Proof BabbageEra -> NativeScript BabbageEra
require KeyHash 'Witness
key Proof BabbageEra
Babbage = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof BabbageEra -> NativeScript BabbageEra]
-> Proof BabbageEra -> NativeScript BabbageEra
allOf [Proof BabbageEra -> NativeScript BabbageEra]
xs Proof BabbageEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof BabbageEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof BabbageEra -> NativeScript BabbageEra]
xs))
  anyOf :: [Proof BabbageEra -> NativeScript BabbageEra]
-> Proof BabbageEra -> NativeScript BabbageEra
anyOf [Proof BabbageEra -> NativeScript BabbageEra]
xs Proof BabbageEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof BabbageEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof BabbageEra -> NativeScript BabbageEra]
xs))
  mOf :: Int
-> [Proof BabbageEra -> NativeScript BabbageEra]
-> Proof BabbageEra
-> NativeScript BabbageEra
mOf Int
n [Proof BabbageEra -> NativeScript BabbageEra]
xs Proof BabbageEra
proof = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof BabbageEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof BabbageEra -> NativeScript BabbageEra]
xs))

instance PostShelley BabbageEra where
  before :: Int -> Proof BabbageEra -> NativeScript BabbageEra
before Int
n Proof BabbageEra
Babbage = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeStart (Int -> SlotNo
theSlot Int
n)
  after :: Int -> Proof BabbageEra -> NativeScript BabbageEra
after Int
n Proof BabbageEra
Babbage = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeExpire (Int -> SlotNo
theSlot Int
n)

-- =================================

instance Scriptic ConwayEra where
  never :: Natural -> Proof ConwayEra -> Script ConwayEra
never Natural
n Proof ConwayEra
Conway = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysFails @'PlutusV1 Natural
n -- always False
  always :: Natural -> Proof ConwayEra -> Script ConwayEra
always Natural
n Proof ConwayEra
Conway = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV1 Natural
n -- always True
  alwaysAlt :: Natural -> Proof ConwayEra -> Script ConwayEra
alwaysAlt Natural
n Proof ConwayEra
Conway = forall (l :: Language) era.
(HasCallStack, PlutusLanguage l, AlonzoEraScript era) =>
Natural -> Script era
alwaysSucceeds @'PlutusV2 Natural
n -- always True
  require :: KeyHash 'Witness -> Proof ConwayEra -> NativeScript ConwayEra
require KeyHash 'Witness
key Proof ConwayEra
Conway = forall era.
ShelleyEraScript era =>
KeyHash 'Witness -> NativeScript era
RequireSignature KeyHash 'Witness
key
  allOf :: [Proof ConwayEra -> NativeScript ConwayEra]
-> Proof ConwayEra -> NativeScript ConwayEra
allOf [Proof ConwayEra -> NativeScript ConwayEra]
xs Proof ConwayEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAllOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof ConwayEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof ConwayEra -> NativeScript ConwayEra]
xs))
  anyOf :: [Proof ConwayEra -> NativeScript ConwayEra]
-> Proof ConwayEra -> NativeScript ConwayEra
anyOf [Proof ConwayEra -> NativeScript ConwayEra]
xs Proof ConwayEra
proof = forall era.
ShelleyEraScript era =>
StrictSeq (NativeScript era) -> NativeScript era
RequireAnyOf (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof ConwayEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof ConwayEra -> NativeScript ConwayEra]
xs))
  mOf :: Int
-> [Proof ConwayEra -> NativeScript ConwayEra]
-> Proof ConwayEra
-> NativeScript ConwayEra
mOf Int
n [Proof ConwayEra -> NativeScript ConwayEra]
xs Proof ConwayEra
proof = forall era.
ShelleyEraScript era =>
Int -> StrictSeq (NativeScript era) -> NativeScript era
RequireMOf Int
n (forall a. [a] -> StrictSeq a
Seq.fromList ((forall a b. (a -> b) -> a -> b
$ Proof ConwayEra
proof) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Proof ConwayEra -> NativeScript ConwayEra]
xs))

instance PostShelley ConwayEra where
  before :: Int -> Proof ConwayEra -> NativeScript ConwayEra
before Int
n Proof ConwayEra
Conway = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeStart (Int -> SlotNo
theSlot Int
n)
  after :: Int -> Proof ConwayEra -> NativeScript ConwayEra
after Int
n Proof ConwayEra
Conway = forall era. AllegraEraScript era => SlotNo -> NativeScript era
RequireTimeExpire (Int -> SlotNo
theSlot Int
n)

-- =======================================
-- Some examples that work in multiple Eras
matchkey :: Scriptic era => Int -> Proof era -> NativeScript era
matchkey :: forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
n Proof era
era = forall era.
Scriptic era =>
KeyHash 'Witness -> Proof era -> NativeScript era
require (forall (kr :: KeyRole). Int -> KeyHash kr
theKeyHash Int
n) Proof era
era

test21 :: Scriptic era => Proof era -> Script era
test21 :: forall era. Scriptic era => Proof era -> Script era
test21 Proof era
wit = forall era. EraScript era => NativeScript era -> Script era
fromNativeScript forall a b. (a -> b) -> a -> b
$ forall era.
Scriptic era =>
[Proof era -> NativeScript era] -> Proof era -> NativeScript era
allOf [forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
1, forall era.
Scriptic era =>
[Proof era -> NativeScript era] -> Proof era -> NativeScript era
anyOf [forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
2, forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
3]] Proof era
wit

test22 :: PostShelley era => Proof era -> Script era
test22 :: forall era. PostShelley era => Proof era -> Script era
test22 Proof era
wit = forall era. EraScript era => NativeScript era -> Script era
fromNativeScript forall a b. (a -> b) -> a -> b
$ forall era.
Scriptic era =>
Int
-> [Proof era -> NativeScript era] -> Proof era -> NativeScript era
mOf Int
2 [forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
1, forall era. PostShelley era => Int -> Proof era -> NativeScript era
before Int
100, forall era.
Scriptic era =>
[Proof era -> NativeScript era] -> Proof era -> NativeScript era
anyOf [forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
2, forall era. Scriptic era => Int -> Proof era -> NativeScript era
matchkey Int
3]] Proof era
wit