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

module Cardano.Ledger.Alonzo.TxCert () where

import Cardano.Ledger.Alonzo.Era (AlonzoEra)
import Cardano.Ledger.Alonzo.PParams ()
import Cardano.Ledger.Shelley.TxCert

instance EraTxCert AlonzoEra where
  type TxCert AlonzoEra = ShelleyTxCert AlonzoEra

  upgradeTxCert :: EraTxCert (PreviousEra AlonzoEra) =>
TxCert (PreviousEra AlonzoEra)
-> Either (TxCertUpgradeError AlonzoEra) (TxCert AlonzoEra)
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 AlonzoEra -> Maybe (KeyHash 'Witness)
getVKeyWitnessTxCert = forall era. ShelleyTxCert era -> Maybe (KeyHash 'Witness)
getVKeyWitnessShelleyTxCert

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

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

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

  mkRetirePoolTxCert :: KeyHash 'StakePool -> EpochNo -> TxCert AlonzoEra
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 AlonzoEra -> 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 AlonzoEra
_ = forall a. Maybe a
Nothing

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

  getTotalDepositsTxCerts :: forall (f :: * -> *).
Foldable f =>
PParams AlonzoEra
-> (KeyHash 'StakePool -> Bool) -> f (TxCert AlonzoEra) -> 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 AlonzoEra
-> (Credential 'Staking -> Maybe Coin)
-> (Credential 'DRepRole -> Maybe Coin)
-> f (TxCert AlonzoEra)
-> Coin
getTotalRefundsTxCerts PParams AlonzoEra
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 AlonzoEra
pp Credential 'Staking -> Maybe Coin
lookupStakeDeposit

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

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

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

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

  mkDelegStakeTxCert :: Credential 'Staking -> KeyHash 'StakePool -> TxCert AlonzoEra
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 AlonzoEra -> 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 AlonzoEra
_ = forall a. Maybe a
Nothing

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

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

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

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