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

module Cardano.Ledger.Babbage.TxCert () where

import Cardano.Ledger.Babbage.Era
import Cardano.Ledger.Babbage.PParams ()
import Cardano.Ledger.Shelley.TxCert

instance EraTxCert BabbageEra where
  type TxCert BabbageEra = ShelleyTxCert BabbageEra

  upgradeTxCert :: EraTxCert (PreviousEra BabbageEra) =>
TxCert (PreviousEra BabbageEra)
-> Either (TxCertUpgradeError BabbageEra) (TxCert BabbageEra)
upgradeTxCert = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era1 era2. ShelleyTxCert era1 -> ShelleyTxCert era2
upgradeShelleyTxCert

  getVKeyWitnessTxCert :: TxCert BabbageEra -> Maybe (KeyHash 'Witness)
getVKeyWitnessTxCert = forall era. ShelleyTxCert era -> Maybe (KeyHash 'Witness)
getVKeyWitnessShelleyTxCert

  getScriptWitnessTxCert :: TxCert BabbageEra -> Maybe ScriptHash
getScriptWitnessTxCert = forall era. ShelleyTxCert era -> Maybe ScriptHash
getScriptWitnessShelleyTxCert

  mkRegPoolTxCert :: PoolParams -> TxCert BabbageEra
mkRegPoolTxCert = forall era. PoolCert -> ShelleyTxCert era
ShelleyTxCertPool forall b c a. (b -> c) -> (a -> b) -> a -> c
. PoolParams -> PoolCert
RegPool

  getRegPoolTxCert :: TxCert BabbageEra -> Maybe PoolParams
getRegPoolTxCert (ShelleyTxCertPool (RegPool PoolParams
poolParams)) = forall a. a -> Maybe a
Just PoolParams
poolParams
  getRegPoolTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  mkRetirePoolTxCert :: KeyHash 'StakePool -> EpochNo -> TxCert BabbageEra
mkRetirePoolTxCert KeyHash 'StakePool
poolId EpochNo
epochNo = forall era. PoolCert -> ShelleyTxCert era
ShelleyTxCertPool forall a b. (a -> b) -> a -> b
$ KeyHash 'StakePool -> EpochNo -> PoolCert
RetirePool KeyHash 'StakePool
poolId EpochNo
epochNo

  getRetirePoolTxCert :: TxCert BabbageEra -> Maybe (KeyHash 'StakePool, EpochNo)
getRetirePoolTxCert (ShelleyTxCertPool (RetirePool KeyHash 'StakePool
poolId EpochNo
epochNo)) = forall a. a -> Maybe a
Just (KeyHash 'StakePool
poolId, EpochNo
epochNo)
  getRetirePoolTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  lookupRegStakeTxCert :: TxCert BabbageEra -> Maybe (Credential 'Staking)
lookupRegStakeTxCert = \case
    RegTxCert Credential 'Staking
c -> forall a. a -> Maybe a
Just Credential 'Staking
c
    TxCert BabbageEra
_ -> forall a. Maybe a
Nothing
  lookupUnRegStakeTxCert :: TxCert BabbageEra -> Maybe (Credential 'Staking)
lookupUnRegStakeTxCert = \case
    UnRegTxCert Credential 'Staking
c -> forall a. a -> Maybe a
Just Credential 'Staking
c
    TxCert BabbageEra
_ -> forall a. Maybe a
Nothing

  getTotalDepositsTxCerts :: forall (f :: * -> *).
Foldable f =>
PParams BabbageEra
-> (KeyHash 'StakePool -> Bool) -> f (TxCert BabbageEra) -> Coin
getTotalDepositsTxCerts = forall era (f :: * -> *).
(EraPParams era, Foldable f, EraTxCert era) =>
PParams era
-> (KeyHash 'StakePool -> Bool) -> f (TxCert era) -> Coin
shelleyTotalDepositsTxCerts

  getTotalRefundsTxCerts :: forall (f :: * -> *).
Foldable f =>
PParams BabbageEra
-> (Credential 'Staking -> Maybe Coin)
-> (Credential 'DRepRole -> Maybe Coin)
-> f (TxCert BabbageEra)
-> Coin
getTotalRefundsTxCerts PParams BabbageEra
pp Credential 'Staking -> Maybe Coin
lookupStakeDeposit Credential 'DRepRole -> Maybe Coin
_ = forall era (f :: * -> *).
(EraPParams era, Foldable f, EraTxCert era) =>
PParams era
-> (Credential 'Staking -> Maybe Coin) -> f (TxCert era) -> Coin
shelleyTotalRefundsTxCerts PParams BabbageEra
pp Credential 'Staking -> Maybe Coin
lookupStakeDeposit

instance ShelleyEraTxCert BabbageEra where
  mkRegTxCert :: Credential 'Staking -> TxCert BabbageEra
mkRegTxCert = forall era. ShelleyDelegCert -> ShelleyTxCert era
ShelleyTxCertDelegCert forall b c a. (b -> c) -> (a -> b) -> a -> c
. Credential 'Staking -> ShelleyDelegCert
ShelleyRegCert

  getRegTxCert :: TxCert BabbageEra -> Maybe (Credential 'Staking)
getRegTxCert (ShelleyTxCertDelegCert (ShelleyRegCert Credential 'Staking
c)) = forall a. a -> Maybe a
Just Credential 'Staking
c
  getRegTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  mkUnRegTxCert :: Credential 'Staking -> TxCert BabbageEra
mkUnRegTxCert = forall era. ShelleyDelegCert -> ShelleyTxCert era
ShelleyTxCertDelegCert forall b c a. (b -> c) -> (a -> b) -> a -> c
. Credential 'Staking -> ShelleyDelegCert
ShelleyUnRegCert

  getUnRegTxCert :: TxCert BabbageEra -> Maybe (Credential 'Staking)
getUnRegTxCert (ShelleyTxCertDelegCert (ShelleyUnRegCert Credential 'Staking
c)) = forall a. a -> Maybe a
Just Credential 'Staking
c
  getUnRegTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  mkDelegStakeTxCert :: Credential 'Staking -> KeyHash 'StakePool -> TxCert BabbageEra
mkDelegStakeTxCert Credential 'Staking
c KeyHash 'StakePool
kh = forall era. ShelleyDelegCert -> ShelleyTxCert era
ShelleyTxCertDelegCert forall a b. (a -> b) -> a -> b
$ Credential 'Staking -> KeyHash 'StakePool -> ShelleyDelegCert
ShelleyDelegCert Credential 'Staking
c KeyHash 'StakePool
kh

  getDelegStakeTxCert :: TxCert BabbageEra
-> Maybe (Credential 'Staking, KeyHash 'StakePool)
getDelegStakeTxCert (ShelleyTxCertDelegCert (ShelleyDelegCert Credential 'Staking
c KeyHash 'StakePool
kh)) = forall a. a -> Maybe a
Just (Credential 'Staking
c, KeyHash 'StakePool
kh)
  getDelegStakeTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  mkGenesisDelegTxCert :: ProtVerAtMost BabbageEra 8 => GenesisDelegCert -> TxCert BabbageEra
mkGenesisDelegTxCert = forall era. GenesisDelegCert -> ShelleyTxCert era
ShelleyTxCertGenesisDeleg

  getGenesisDelegTxCert :: ProtVerAtMost BabbageEra 8 =>
TxCert BabbageEra -> Maybe GenesisDelegCert
getGenesisDelegTxCert (ShelleyTxCertGenesisDeleg GenesisDelegCert
c) = forall a. a -> Maybe a
Just GenesisDelegCert
c
  getGenesisDelegTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing

  mkMirTxCert :: ProtVerAtMost BabbageEra 8 => MIRCert -> TxCert BabbageEra
mkMirTxCert = forall era. MIRCert -> ShelleyTxCert era
ShelleyTxCertMir

  getMirTxCert :: ProtVerAtMost BabbageEra 8 => TxCert BabbageEra -> Maybe MIRCert
getMirTxCert (ShelleyTxCertMir MIRCert
c) = forall a. a -> Maybe a
Just MIRCert
c
  getMirTxCert TxCert BabbageEra
_ = forall a. Maybe a
Nothing