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

module Cardano.Ledger.Babbage.TxWits (
  module BabbageTxWitsReExport,
)
where

import Cardano.Ledger.Alonzo.TxWits (
  AlonzoEraTxWits (..),
  AlonzoTxWits (..),
  addrAlonzoTxWitsL,
  bootAddrAlonzoTxWitsL,
  datsAlonzoTxWitsL,
  rdmrsAlonzoTxWitsL,
  scriptAlonzoTxWitsL,
 )
import Cardano.Ledger.Alonzo.TxWits as BabbageTxWitsReExport (
  AlonzoEraTxWits (..),
  AlonzoTxWits (..),
  upgradeRedeemers,
  upgradeTxDats,
 )
import Cardano.Ledger.Babbage.Era (BabbageEra)
import Cardano.Ledger.Babbage.TxBody ()
import Cardano.Ledger.Core

instance EraTxWits BabbageEra where
  type TxWits BabbageEra = AlonzoTxWits BabbageEra

  mkBasicTxWits :: TxWits BabbageEra
mkBasicTxWits = forall a. Monoid a => a
mempty

  addrTxWitsL :: Lens' (TxWits BabbageEra) (Set (WitVKey 'Witness))
addrTxWitsL = forall era.
AlonzoEraScript era =>
Lens' (AlonzoTxWits era) (Set (WitVKey 'Witness))
addrAlonzoTxWitsL
  {-# INLINE addrTxWitsL #-}

  bootAddrTxWitsL :: Lens' (TxWits BabbageEra) (Set BootstrapWitness)
bootAddrTxWitsL = forall era.
AlonzoEraScript era =>
Lens' (AlonzoTxWits era) (Set BootstrapWitness)
bootAddrAlonzoTxWitsL
  {-# INLINE bootAddrTxWitsL #-}

  scriptTxWitsL :: Lens' (TxWits BabbageEra) (Map ScriptHash (Script BabbageEra))
scriptTxWitsL = forall era.
AlonzoEraScript era =>
Lens' (AlonzoTxWits era) (Map ScriptHash (Script era))
scriptAlonzoTxWitsL
  {-# INLINE scriptTxWitsL #-}

  upgradeTxWits :: EraTxWits (PreviousEra BabbageEra) =>
TxWits (PreviousEra BabbageEra) -> TxWits BabbageEra
upgradeTxWits TxWits (PreviousEra BabbageEra)
atw =
    AlonzoTxWits
      { txwitsVKey :: Set (WitVKey 'Witness)
txwitsVKey = forall era.
AlonzoEraScript era =>
AlonzoTxWits era -> Set (WitVKey 'Witness)
txwitsVKey TxWits (PreviousEra BabbageEra)
atw
      , txwitsBoot :: Set BootstrapWitness
txwitsBoot = forall era.
AlonzoEraScript era =>
AlonzoTxWits era -> Set BootstrapWitness
txwitsBoot TxWits (PreviousEra BabbageEra)
atw
      , txscripts :: Map ScriptHash (Script BabbageEra)
txscripts = 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
<$> forall era.
AlonzoEraScript era =>
AlonzoTxWits era -> Map ScriptHash (Script era)
txscripts TxWits (PreviousEra BabbageEra)
atw
      , txdats :: TxDats BabbageEra
txdats = forall era1 era2.
(Era era1, Era era2) =>
TxDats era1 -> TxDats era2
upgradeTxDats (forall era. AlonzoEraScript era => AlonzoTxWits era -> TxDats era
txdats TxWits (PreviousEra BabbageEra)
atw)
      , txrdmrs :: Redeemers BabbageEra
txrdmrs = forall era.
(AlonzoEraScript (PreviousEra era), AlonzoEraScript era) =>
Redeemers (PreviousEra era) -> Redeemers era
upgradeRedeemers (forall era.
AlonzoEraScript era =>
AlonzoTxWits era -> Redeemers era
txrdmrs TxWits (PreviousEra BabbageEra)
atw)
      }

instance AlonzoEraTxWits BabbageEra where
  datsTxWitsL :: Lens' (TxWits BabbageEra) (TxDats BabbageEra)
datsTxWitsL = forall era.
AlonzoEraScript era =>
Lens' (AlonzoTxWits era) (TxDats era)
datsAlonzoTxWitsL
  {-# INLINE datsTxWitsL #-}

  rdmrsTxWitsL :: Lens' (TxWits BabbageEra) (Redeemers BabbageEra)
rdmrsTxWitsL = forall era.
AlonzoEraScript era =>
Lens' (AlonzoTxWits era) (Redeemers era)
rdmrsAlonzoTxWitsL
  {-# INLINE rdmrsTxWitsL #-}