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

module Cardano.Ledger.Allegra.TxCert () where

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

instance EraTxCert AllegraEra where
  type TxCert AllegraEra = ShelleyTxCert AllegraEra

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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