{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Mary.Scripts (
  module Cardano.Ledger.Allegra.Scripts,
)
where

import Cardano.Ledger.Allegra.Scripts
import Cardano.Ledger.Core
import Cardano.Ledger.Mary.Era (MaryEra)
import Cardano.Ledger.Shelley.Scripts (
  ShelleyEraScript (..),
  nativeMultiSigTag,
 )

-- | Since Timelock scripts are a strictly backwards compatible extension of
-- MultiSig scripts, we can use the same 'scriptPrefixTag' tag here as we did
-- for the ValidateScript instance in MultiSig
instance EraScript MaryEra where
  type Script MaryEra = Timelock MaryEra
  type NativeScript MaryEra = Timelock MaryEra

  upgradeScript :: EraScript (PreviousEra MaryEra) =>
Script (PreviousEra MaryEra) -> Script MaryEra
upgradeScript = forall era1 era2.
(Era era1, Era era2) =>
Timelock era1 -> Timelock era2
translateTimelock

  scriptPrefixTag :: Script MaryEra -> ByteString
scriptPrefixTag Script MaryEra
_script = ByteString
nativeMultiSigTag -- "\x00"

  getNativeScript :: Script MaryEra -> Maybe (NativeScript MaryEra)
getNativeScript = forall a. a -> Maybe a
Just

  fromNativeScript :: NativeScript MaryEra -> Script MaryEra
fromNativeScript = forall a. a -> a
id

instance ShelleyEraScript MaryEra where
  mkRequireSignature :: KeyHash 'Witness -> NativeScript MaryEra
mkRequireSignature = forall era. Era era => KeyHash 'Witness -> Timelock era
mkRequireSignatureTimelock
  getRequireSignature :: NativeScript MaryEra -> Maybe (KeyHash 'Witness)
getRequireSignature = forall era. Era era => Timelock era -> Maybe (KeyHash 'Witness)
getRequireSignatureTimelock

  mkRequireAllOf :: StrictSeq (NativeScript MaryEra) -> NativeScript MaryEra
mkRequireAllOf = forall era. Era era => StrictSeq (Timelock era) -> Timelock era
mkRequireAllOfTimelock
  getRequireAllOf :: NativeScript MaryEra -> Maybe (StrictSeq (NativeScript MaryEra))
getRequireAllOf = forall era.
Era era =>
Timelock era -> Maybe (StrictSeq (Timelock era))
getRequireAllOfTimelock

  mkRequireAnyOf :: StrictSeq (NativeScript MaryEra) -> NativeScript MaryEra
mkRequireAnyOf = forall era. Era era => StrictSeq (Timelock era) -> Timelock era
mkRequireAnyOfTimelock
  getRequireAnyOf :: NativeScript MaryEra -> Maybe (StrictSeq (NativeScript MaryEra))
getRequireAnyOf = forall era.
Era era =>
Timelock era -> Maybe (StrictSeq (Timelock era))
getRequireAnyOfTimelock

  mkRequireMOf :: Int -> StrictSeq (NativeScript MaryEra) -> NativeScript MaryEra
mkRequireMOf = forall era.
Era era =>
Int -> StrictSeq (Timelock era) -> Timelock era
mkRequireMOfTimelock
  getRequireMOf :: NativeScript MaryEra
-> Maybe (Int, StrictSeq (NativeScript MaryEra))
getRequireMOf = forall era.
Era era =>
Timelock era -> Maybe (Int, StrictSeq (Timelock era))
getRequireMOfTimelock

instance AllegraEraScript MaryEra where
  mkTimeStart :: SlotNo -> NativeScript MaryEra
mkTimeStart = forall era. Era era => SlotNo -> Timelock era
mkTimeStartTimelock
  getTimeStart :: NativeScript MaryEra -> Maybe SlotNo
getTimeStart = forall era. Era era => Timelock era -> Maybe SlotNo
getTimeStartTimelock

  mkTimeExpire :: SlotNo -> NativeScript MaryEra
mkTimeExpire = forall era. Era era => SlotNo -> Timelock era
mkTimeExpireTimelock
  getTimeExpire :: NativeScript MaryEra -> Maybe SlotNo
getTimeExpire = forall era. Era era => Timelock era -> Maybe SlotNo
getTimeExpireTimelock