{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

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

import Cardano.Ledger.Allegra.TxAuxData (
  AllegraEraTxAuxData (..),
  AllegraTxAuxData (..),
  metadataAllegraTxAuxDataL,
  timelockScriptsAllegraTxAuxDataL,
 )
import Cardano.Ledger.Core
import Cardano.Ledger.Mary.Era (MaryEra)
import Cardano.Ledger.Mary.Scripts ()
import Cardano.Ledger.Shelley.TxAuxData (validMetadatum)
import Control.DeepSeq (deepseq)

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

instance EraTxAuxData MaryEra where
  type TxAuxData MaryEra = AllegraTxAuxData MaryEra

  mkBasicTxAuxData :: TxAuxData MaryEra
mkBasicTxAuxData = forall era.
Era era =>
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxData era
AllegraTxAuxData forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty

  metadataTxAuxDataL :: Lens' (TxAuxData MaryEra) (Map Word64 Metadatum)
metadataTxAuxDataL = forall era.
Era era =>
Lens' (AllegraTxAuxData era) (Map Word64 Metadatum)
metadataAllegraTxAuxDataL

  upgradeTxAuxData :: EraTxAuxData (PreviousEra MaryEra) =>
TxAuxData (PreviousEra MaryEra) -> TxAuxData MaryEra
upgradeTxAuxData (AllegraTxAuxData Map Word64 Metadatum
md StrictSeq (Timelock AllegraEra)
scripts) = forall era.
Era era =>
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxData era
AllegraTxAuxData Map Word64 Metadatum
md forall a b. (a -> b) -> a -> b
$ forall era.
(EraScript era, EraScript (PreviousEra era)) =>
Script (PreviousEra era) -> Script era
upgradeScript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock AllegraEra)
scripts

  validateTxAuxData :: ProtVer -> TxAuxData MaryEra -> Bool
validateTxAuxData ProtVer
_ (AllegraTxAuxData Map Word64 Metadatum
md StrictSeq (Timelock MaryEra)
as) = StrictSeq (Timelock MaryEra)
as forall a b. NFData a => a -> b -> b
`deepseq` forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Metadatum -> Bool
validMetadatum Map Word64 Metadatum
md

instance AllegraEraTxAuxData MaryEra where
  timelockScriptsTxAuxDataL :: Lens' (TxAuxData MaryEra) (StrictSeq (Timelock MaryEra))
timelockScriptsTxAuxDataL = forall era.
Era era =>
Lens' (AllegraTxAuxData era) (StrictSeq (Timelock era))
timelockScriptsAllegraTxAuxDataL