{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}

module Cardano.Api.Internal.LedgerEvents.ConvertLedgerEvent
  ( LedgerEvent (..)
  , toLedgerEvent
  )
where

import Cardano.Api.Internal.LedgerEvents.LedgerEvent
import Cardano.Api.Internal.LedgerEvents.Rule.BBODY.DELEGS
import Cardano.Api.Internal.LedgerEvents.Rule.BBODY.LEDGER
import Cardano.Api.Internal.LedgerEvents.Rule.BBODY.UTXOW
import Cardano.Api.Internal.LedgerEvents.Rule.TICK.NEWEPOCH
import Cardano.Api.Internal.LedgerEvents.Rule.TICK.RUPD

import Cardano.Ledger.Allegra.Rules qualified as Allegra
import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyEvent (..))
import Cardano.Ledger.Api.Era
  ( AllegraEra
  , AlonzoEra
  , BabbageEra
  , ConwayEra
  , MaryEra
  , ShelleyEra
  )
import Cardano.Ledger.Conway.Rules qualified as Conway
import Cardano.Ledger.Core
import Cardano.Ledger.Core qualified as Ledger.Core
import Cardano.Ledger.Shelley.Rules
  ( RupdEvent (..)
  , ShelleyBbodyEvent (LedgersEvent)
  , ShelleyNewEpochEvent (..)
  , ShelleyTickEvent (TickNewEpochEvent, TickRupdEvent)
  , ShelleyUtxowEvent (..)
  )
import Cardano.Ledger.Shelley.Rules qualified as Shelley
import Cardano.Protocol.Crypto (StandardCrypto)
import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)
import Ouroboros.Consensus.Cardano.Block (HardForkBlock)
import Ouroboros.Consensus.Cardano.Block qualified as Consensus
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (getOneEraLedgerEvent)
import Ouroboros.Consensus.Protocol.Praos qualified as Consensus
import Ouroboros.Consensus.Protocol.TPraos qualified as Consensus
import Ouroboros.Consensus.Shelley.Ledger
  ( ShelleyBlock
  , ShelleyLedgerEvent (ShelleyLedgerEventBBODY, ShelleyLedgerEventTICK)
  )
import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (unwrapLedgerEvent))

import Control.State.Transition (Event)
import Data.SOP.Strict

class ConvertLedgerEvent blk where
  toLedgerEvent :: WrapLedgerEvent blk -> Maybe LedgerEvent

instance ConvertLedgerEvent ByronBlock where
  toLedgerEvent :: WrapLedgerEvent ByronBlock -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent ByronBlock
_ = Maybe LedgerEvent
forall a. Maybe a
Nothing

instance ConvertLedgerEvent (ShelleyBlock protocol ShelleyEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol ShelleyEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol ShelleyEra)
-> Maybe LedgerEvent
forall ledgerera protocol.
(Event (EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera,
 Event (EraRule "NEWEPOCH" ledgerera)
 ~ ShelleyNewEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ShelleyEpochEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent,
 Event (EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera,
 Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ UtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toLedgerEventShelley

toLedgerEventShelley
  :: Event (Ledger.Core.EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera
  => Event (Ledger.Core.EraRule "NEWEPOCH" ledgerera) ~ ShelleyNewEpochEvent ledgerera
  => Event (Ledger.Core.EraRule "POOLREAP" ledgerera) ~ Shelley.ShelleyPoolreapEvent ledgerera
  => Event (Ledger.Core.EraRule "EPOCH" ledgerera) ~ Shelley.ShelleyEpochEvent ledgerera
  => Event (Ledger.Core.EraRule "RUPD" ledgerera) ~ RupdEvent
  => Event (Ledger.Core.EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGERS" ledgerera) ~ Shelley.ShelleyLedgersEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGER" ledgerera) ~ Shelley.ShelleyLedgerEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Shelley.UtxoEvent ledgerera
  => Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
  => Event (EraRule "DELEGS" ledgerera) ~ Shelley.ShelleyDelegsEvent ledgerera
  => WrapLedgerEvent (ShelleyBlock protocol ledgerera) -> Maybe LedgerEvent
toLedgerEventShelley :: forall ledgerera protocol.
(Event (EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera,
 Event (EraRule "NEWEPOCH" ledgerera)
 ~ ShelleyNewEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ShelleyEpochEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent,
 Event (EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera,
 Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ UtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toLedgerEventShelley WrapLedgerEvent (ShelleyBlock protocol ledgerera)
evt = case WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> AuxLedgerEvent (LedgerState (ShelleyBlock protocol ledgerera))
forall blk. WrapLedgerEvent blk -> AuxLedgerEvent (LedgerState blk)
unwrapLedgerEvent WrapLedgerEvent (ShelleyBlock protocol ledgerera)
evt of
  ShelleyLedgerEventTICK Event (EraRule "TICK" ledgerera)
e -> ShelleyTickEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
LatestTickEventConstraints ledgerera =>
ShelleyTickEvent ledgerera -> Maybe LedgerEvent
handleLedgerTICKEvents Event (EraRule "TICK" ledgerera)
ShelleyTickEvent ledgerera
e
  ShelleyLedgerEventBBODY Event (EraRule "BBODY" ledgerera)
e -> ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
(Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ UtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleShelleyLedgerBBODYEvents Event (EraRule "BBODY" ledgerera)
ShelleyBbodyEvent ledgerera
e

handleShelleyLedgerBBODYEvents
  :: Event (Ledger.Core.EraRule "LEDGERS" ledgerera) ~ Shelley.ShelleyLedgersEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGER" ledgerera) ~ Shelley.ShelleyLedgerEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Shelley.UtxoEvent ledgerera
  => Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
  => Event (EraRule "DELEGS" ledgerera) ~ Shelley.ShelleyDelegsEvent ledgerera
  => ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleShelleyLedgerBBODYEvents :: forall ledgerera.
(Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ UtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleShelleyLedgerBBODYEvents (LedgersEvent (Shelley.LedgerEvent Event (EraRule "LEDGER" ledgerera)
e)) =
  case Event (EraRule "LEDGER" ledgerera)
e of
    Shelley.UtxowEvent Event (EraRule "UTXOW" ledgerera)
ev -> ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
(Event (EraRule "UTXO" ledgerera) ~ UtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera) =>
ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
handlePreAlonzoUTxOWEvent Event (EraRule "UTXOW" ledgerera)
ShelleyUtxowEvent ledgerera
ev
    Shelley.DelegsEvent Event (EraRule "DELEGS" ledgerera)
ev -> ShelleyDelegsEvent ledgerera -> Maybe LedgerEvent
forall ledgerera. ShelleyDelegsEvent ledgerera -> Maybe LedgerEvent
handleShelleyDELEGSEvent Event (EraRule "DELEGS" ledgerera)
ShelleyDelegsEvent ledgerera
ev

instance ConvertLedgerEvent (ShelleyBlock protocol MaryEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol MaryEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol MaryEra)
-> Maybe LedgerEvent
forall ledgerera protocol.
(Event (EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera,
 Event (EraRule "NEWEPOCH" ledgerera)
 ~ ShelleyNewEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ShelleyEpochEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent,
 Event (EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera,
 Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toLedgerEventAllegraMary

instance ConvertLedgerEvent (ShelleyBlock protocol AllegraEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol AllegraEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol AllegraEra)
-> Maybe LedgerEvent
forall ledgerera protocol.
(Event (EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera,
 Event (EraRule "NEWEPOCH" ledgerera)
 ~ ShelleyNewEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ShelleyEpochEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent,
 Event (EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera,
 Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toLedgerEventAllegraMary

toLedgerEventAllegraMary
  :: Event (Ledger.Core.EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera
  => Event (Ledger.Core.EraRule "NEWEPOCH" ledgerera) ~ ShelleyNewEpochEvent ledgerera
  => Event (Ledger.Core.EraRule "POOLREAP" ledgerera) ~ Shelley.ShelleyPoolreapEvent ledgerera
  => Event (Ledger.Core.EraRule "EPOCH" ledgerera) ~ Shelley.ShelleyEpochEvent ledgerera
  => Event (Ledger.Core.EraRule "RUPD" ledgerera) ~ RupdEvent
  => Event (Ledger.Core.EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGERS" ledgerera) ~ Shelley.ShelleyLedgersEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGER" ledgerera) ~ Shelley.ShelleyLedgerEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Allegra.AllegraUtxoEvent ledgerera
  => Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
  => Event (Ledger.Core.EraRule "DELEGS" ledgerera) ~ Shelley.ShelleyDelegsEvent ledgerera
  => WrapLedgerEvent (ShelleyBlock protocol ledgerera)
  -> Maybe LedgerEvent
toLedgerEventAllegraMary :: forall ledgerera protocol.
(Event (EraRule "TICK" ledgerera) ~ ShelleyTickEvent ledgerera,
 Event (EraRule "NEWEPOCH" ledgerera)
 ~ ShelleyNewEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ShelleyEpochEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent,
 Event (EraRule "BBODY" ledgerera) ~ ShelleyBbodyEvent ledgerera,
 Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toLedgerEventAllegraMary WrapLedgerEvent (ShelleyBlock protocol ledgerera)
evt = case WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> AuxLedgerEvent (LedgerState (ShelleyBlock protocol ledgerera))
forall blk. WrapLedgerEvent blk -> AuxLedgerEvent (LedgerState blk)
unwrapLedgerEvent WrapLedgerEvent (ShelleyBlock protocol ledgerera)
evt of
  ShelleyLedgerEventTICK Event (EraRule "TICK" ledgerera)
e -> ShelleyTickEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
LatestTickEventConstraints ledgerera =>
ShelleyTickEvent ledgerera -> Maybe LedgerEvent
handleLedgerTICKEvents Event (EraRule "TICK" ledgerera)
ShelleyTickEvent ledgerera
e
  ShelleyLedgerEventBBODY Event (EraRule "BBODY" ledgerera)
e -> ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
(Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleAllegraMaryLedgerBBODYEvents Event (EraRule "BBODY" ledgerera)
ShelleyBbodyEvent ledgerera
e

handleAllegraMaryLedgerBBODYEvents
  :: Event (Ledger.Core.EraRule "LEDGERS" ledgerera) ~ Shelley.ShelleyLedgersEvent ledgerera
  => Event (Ledger.Core.EraRule "LEDGER" ledgerera) ~ Shelley.ShelleyLedgerEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera
  => Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Allegra.AllegraUtxoEvent ledgerera
  => Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
  => Event (Ledger.Core.EraRule "DELEGS" ledgerera) ~ Shelley.ShelleyDelegsEvent ledgerera
  => ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleAllegraMaryLedgerBBODYEvents :: forall ledgerera.
(Event (EraRule "LEDGERS" ledgerera)
 ~ ShelleyLedgersEvent ledgerera,
 Event (EraRule "LEDGER" ledgerera) ~ ShelleyLedgerEvent ledgerera,
 Event (EraRule "UTXOW" ledgerera) ~ ShelleyUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
ShelleyBbodyEvent ledgerera -> Maybe LedgerEvent
handleAllegraMaryLedgerBBODYEvents (LedgersEvent (Shelley.LedgerEvent Event (EraRule "LEDGER" ledgerera)
e)) =
  case Event (EraRule "LEDGER" ledgerera)
e of
    Shelley.UtxowEvent Event (EraRule "UTXOW" ledgerera)
ev -> ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
(Event (EraRule "UTXO" ledgerera) ~ AllegraUtxoEvent ledgerera,
 Event (EraRule "PPUP" ledgerera) ~ PpupEvent ledgerera) =>
ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
handleAllegraMaryUTxOWEvent Event (EraRule "UTXOW" ledgerera)
ShelleyUtxowEvent ledgerera
ev
    Shelley.DelegsEvent Event (EraRule "DELEGS" ledgerera)
ev -> ShelleyDelegsEvent ledgerera -> Maybe LedgerEvent
forall ledgerera. ShelleyDelegsEvent ledgerera -> Maybe LedgerEvent
handleShelleyDELEGSEvent Event (EraRule "DELEGS" ledgerera)
ShelleyDelegsEvent ledgerera
ev

instance ConvertLedgerEvent (ShelleyBlock protocol AlonzoEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol AlonzoEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol AlonzoEra)
-> Maybe LedgerEvent
forall ledgerera protocol.
(LatestTickEventConstraints ledgerera,
 LatestBBodyEventConstraints ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toAlonzoOrBabbageLedgerEvents

instance ConvertLedgerEvent (ShelleyBlock protocol BabbageEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol BabbageEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol BabbageEra)
-> Maybe LedgerEvent
forall ledgerera protocol.
(LatestTickEventConstraints ledgerera,
 LatestBBodyEventConstraints ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toAlonzoOrBabbageLedgerEvents

toAlonzoOrBabbageLedgerEvents
  :: LatestTickEventConstraints ledgerera
  => LatestBBodyEventConstraints ledgerera
  => WrapLedgerEvent (ShelleyBlock protocol ledgerera) -> Maybe LedgerEvent
toAlonzoOrBabbageLedgerEvents :: forall ledgerera protocol.
(LatestTickEventConstraints ledgerera,
 LatestBBodyEventConstraints ledgerera) =>
WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> Maybe LedgerEvent
toAlonzoOrBabbageLedgerEvents WrapLedgerEvent (ShelleyBlock protocol ledgerera)
e =
  case WrapLedgerEvent (ShelleyBlock protocol ledgerera)
-> AuxLedgerEvent (LedgerState (ShelleyBlock protocol ledgerera))
forall blk. WrapLedgerEvent blk -> AuxLedgerEvent (LedgerState blk)
unwrapLedgerEvent WrapLedgerEvent (ShelleyBlock protocol ledgerera)
e of
    ShelleyLedgerEventTICK Event (EraRule "TICK" ledgerera)
tickEvent -> ShelleyTickEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
LatestTickEventConstraints ledgerera =>
ShelleyTickEvent ledgerera -> Maybe LedgerEvent
handleLedgerTICKEvents Event (EraRule "TICK" ledgerera)
ShelleyTickEvent ledgerera
tickEvent
    ShelleyLedgerEventBBODY Event (EraRule "BBODY" ledgerera)
bbodyEvent -> AlonzoBbodyEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
LatestBBodyEventConstraints ledgerera =>
AlonzoBbodyEvent ledgerera -> Maybe LedgerEvent
handleAlonzoToBabbageLedgerBBODYEvents AlonzoBbodyEvent ledgerera
Event (EraRule "BBODY" ledgerera)
bbodyEvent

handleAlonzoToBabbageLedgerBBODYEvents
  :: LatestBBodyEventConstraints ledgerera
  => AlonzoBbodyEvent ledgerera -> Maybe LedgerEvent
handleAlonzoToBabbageLedgerBBODYEvents :: forall ledgerera.
LatestBBodyEventConstraints ledgerera =>
AlonzoBbodyEvent ledgerera -> Maybe LedgerEvent
handleAlonzoToBabbageLedgerBBODYEvents (ShelleyInAlonzoEvent (LedgersEvent (Shelley.LedgerEvent Event (EraRule "LEDGER" ledgerera)
ledgerEvent))) =
  ShelleyLedgerEvent ledgerera -> Maybe LedgerEvent
forall ledgerera.
(Event (EraRule "UTXOW" ledgerera) ~ AlonzoUtxowEvent ledgerera,
 Event (EraRule "UTXO" ledgerera) ~ AlonzoUtxoEvent ledgerera,
 Event (EraRule "UTXOS" ledgerera) ~ AlonzoUtxosEvent ledgerera,
 Event (EraRule "DELEGS" ledgerera)
 ~ ShelleyDelegsEvent ledgerera) =>
ShelleyLedgerEvent ledgerera -> Maybe LedgerEvent
handleShelleyLEDGEREvents Event (EraRule "LEDGER" ledgerera)
ShelleyLedgerEvent ledgerera
ledgerEvent

instance ConvertLedgerEvent (ShelleyBlock protocol ConwayEra) where
  toLedgerEvent :: WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
-> Maybe LedgerEvent
toLedgerEvent = WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
-> Maybe LedgerEvent
forall protocol.
WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
-> Maybe LedgerEvent
toLedgerEventConway

-- LEDGER rule is defined anew in Conway

toLedgerEventConway
  :: WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
  -> Maybe LedgerEvent
toLedgerEventConway :: forall protocol.
WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
-> Maybe LedgerEvent
toLedgerEventConway WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
evt =
  case WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
-> AuxLedgerEvent (LedgerState (ShelleyBlock protocol ConwayEra))
forall blk. WrapLedgerEvent blk -> AuxLedgerEvent (LedgerState blk)
unwrapLedgerEvent WrapLedgerEvent (ShelleyBlock protocol ConwayEra)
evt of
    ShelleyLedgerEventTICK (TickNewEpochEvent Event (EraRule "NEWEPOCH" ConwayEra)
newEpochEvent) -> ConwayNewEpochEvent ConwayEra -> Maybe LedgerEvent
forall ledgerera.
(EraPParams ledgerera,
 Event (EraRule "EPOCH" ledgerera) ~ ConwayEpochEvent ledgerera,
 Event (EraRule "POOLREAP" ledgerera)
 ~ ShelleyPoolreapEvent ledgerera,
 Event (EraRule "RUPD" ledgerera) ~ RupdEvent) =>
ConwayNewEpochEvent ledgerera -> Maybe LedgerEvent
handleConwayNEWEPOCHEvents ConwayNewEpochEvent ConwayEra
Event (EraRule "NEWEPOCH" ConwayEra)
newEpochEvent
    ShelleyLedgerEventTICK (TickRupdEvent Event (EraRule "RUPD" ConwayEra)
rewardUpdate) -> RupdEvent -> Maybe LedgerEvent
handleLedgerRUPDEvents Event (EraRule "RUPD" ConwayEra)
RupdEvent
rewardUpdate
    ShelleyLedgerEventBBODY
      (ShelleyInAlonzoEvent (LedgersEvent (Shelley.LedgerEvent Event (EraRule "LEDGER" ConwayEra)
conwayLedgerEvent))) ->
        case Event (EraRule "LEDGER" ConwayEra)
conwayLedgerEvent of
          Conway.UtxowEvent Event (EraRule "UTXOW" ConwayEra)
utxowEvent -> AlonzoUtxowEvent ConwayEra -> Maybe LedgerEvent
handleConwayUTxOWEvent AlonzoUtxowEvent ConwayEra
Event (EraRule "UTXOW" ConwayEra)
utxowEvent
          Conway.CertsEvent{} -> Maybe LedgerEvent
forall a. Maybe a
Nothing
          Conway.GovEvent Event (EraRule "GOV" ConwayEra)
govEvent ->
            case Event (EraRule "GOV" ConwayEra)
govEvent of
              Conway.GovNewProposals TxId
txid Proposals ConwayEra
props ->
                LedgerEvent -> Maybe LedgerEvent
forall a. a -> Maybe a
Just (LedgerEvent -> Maybe LedgerEvent)
-> LedgerEvent -> Maybe LedgerEvent
forall a b. (a -> b) -> a -> b
$ TxId -> AnyProposals -> LedgerEvent
NewGovernanceProposals TxId
txid (Proposals ConwayEra -> AnyProposals
forall era. EraPParams era => Proposals era -> AnyProposals
AnyProposals Proposals ConwayEra
props)
              Conway.GovRemovedVotes TxId
txid Set (Voter, GovActionId)
replacedVotes Set (Credential 'DRepRole)
unregisteredDReps ->
                LedgerEvent -> Maybe LedgerEvent
forall a. a -> Maybe a
Just (LedgerEvent -> Maybe LedgerEvent)
-> LedgerEvent -> Maybe LedgerEvent
forall a b. (a -> b) -> a -> b
$ TxId
-> Set (Voter, GovActionId)
-> Set (Credential 'DRepRole)
-> LedgerEvent
RemovedGovernanceVotes TxId
txid Set (Voter, GovActionId)
replacedVotes Set (Credential 'DRepRole)
unregisteredDReps

instance ConvertLedgerEvent (HardForkBlock (Consensus.CardanoEras StandardCrypto)) where
  toLedgerEvent :: WrapLedgerEvent (HardForkBlock (CardanoEras StandardCrypto))
-> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (HardForkBlock (CardanoEras StandardCrypto))
wrappedLedgerEvent =
    case OneEraLedgerEvent (CardanoEras StandardCrypto)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
forall (xs :: [*]). OneEraLedgerEvent xs -> NS WrapLedgerEvent xs
getOneEraLedgerEvent (OneEraLedgerEvent (CardanoEras StandardCrypto)
 -> NS WrapLedgerEvent (CardanoEras StandardCrypto))
-> OneEraLedgerEvent (CardanoEras StandardCrypto)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
forall a b. (a -> b) -> a -> b
$ WrapLedgerEvent (HardForkBlock (CardanoEras StandardCrypto))
-> AuxLedgerEvent
     (LedgerState (HardForkBlock (CardanoEras StandardCrypto)))
forall blk. WrapLedgerEvent blk -> AuxLedgerEvent (LedgerState blk)
unwrapLedgerEvent WrapLedgerEvent (HardForkBlock (CardanoEras StandardCrypto))
wrappedLedgerEvent of
      ShelleyLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) ShelleyEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) ShelleyEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) ShelleyEra)
ledgerEvent
      AllegraLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AllegraEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AllegraEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AllegraEra)
ledgerEvent
      MaryLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) MaryEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) MaryEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) MaryEra)
ledgerEvent
      AlonzoLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AlonzoEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AlonzoEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AlonzoEra)
ledgerEvent
      BabbageLedgerEvent WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) BabbageEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) BabbageEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) BabbageEra)
ledgerEvent
      ConwayLedgerEvent WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) ConwayEra)
ledgerEvent -> WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) ConwayEra)
-> Maybe LedgerEvent
forall blk.
ConvertLedgerEvent blk =>
WrapLedgerEvent blk -> Maybe LedgerEvent
toLedgerEvent WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) ConwayEra)
ledgerEvent

{-# COMPLETE
  ShelleyLedgerEvent
  , AllegraLedgerEvent
  , MaryLedgerEvent
  , AlonzoLedgerEvent
  , BabbageLedgerEvent
  , ConwayLedgerEvent
  #-}

pattern ShelleyLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.TPraos StandardCrypto) ShelleyEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bShelleyLedgerEvent :: WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) ShelleyEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mShelleyLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent
      (ShelleyBlock (TPraos StandardCrypto) ShelleyEra)
    -> r)
-> ((# #) -> r)
-> r
ShelleyLedgerEvent x = S (Z x)

pattern AllegraLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.TPraos StandardCrypto) AllegraEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bAllegraLedgerEvent :: WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AllegraEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mAllegraLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent
      (ShelleyBlock (TPraos StandardCrypto) AllegraEra)
    -> r)
-> ((# #) -> r)
-> r
AllegraLedgerEvent x = S (S (Z x))

pattern MaryLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.TPraos StandardCrypto) MaryEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bMaryLedgerEvent :: WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) MaryEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mMaryLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) MaryEra)
    -> r)
-> ((# #) -> r)
-> r
MaryLedgerEvent x = S (S (S (Z x)))

pattern AlonzoLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.TPraos StandardCrypto) AlonzoEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bAlonzoLedgerEvent :: WrapLedgerEvent (ShelleyBlock (TPraos StandardCrypto) AlonzoEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mAlonzoLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent
      (ShelleyBlock (TPraos StandardCrypto) AlonzoEra)
    -> r)
-> ((# #) -> r)
-> r
AlonzoLedgerEvent x = S (S (S (S (Z x))))

pattern BabbageLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.Praos StandardCrypto) BabbageEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bBabbageLedgerEvent :: WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) BabbageEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mBabbageLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent
      (ShelleyBlock (Praos StandardCrypto) BabbageEra)
    -> r)
-> ((# #) -> r)
-> r
BabbageLedgerEvent x = S (S (S (S (S (Z x)))))

pattern ConwayLedgerEvent
  :: WrapLedgerEvent (ShelleyBlock (Consensus.Praos StandardCrypto) ConwayEra)
  -> NS WrapLedgerEvent (Consensus.CardanoEras StandardCrypto)
pattern $bConwayLedgerEvent :: WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) ConwayEra)
-> NS WrapLedgerEvent (CardanoEras StandardCrypto)
$mConwayLedgerEvent :: forall {r}.
NS WrapLedgerEvent (CardanoEras StandardCrypto)
-> (WrapLedgerEvent (ShelleyBlock (Praos StandardCrypto) ConwayEra)
    -> r)
-> ((# #) -> r)
-> r
ConwayLedgerEvent x = S (S (S (S (S (S (Z x))))))