{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Mary.Translation where

import Cardano.Ledger.Binary (DecoderError)
import Cardano.Ledger.CertState (CommitteeState (..))
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.Genesis (NoGenesis (..))
import Cardano.Ledger.Mary.Core
import Cardano.Ledger.Mary.Era (MaryEra)
import Cardano.Ledger.Mary.Scripts (Timelock, translateTimelock)
import Cardano.Ledger.Mary.TxAuxData (AllegraTxAuxData (..))
import Cardano.Ledger.Shelley.LedgerState (
  CertState (..),
  DState (..),
  EpochState (..),
  LedgerState (..),
  NewEpochState (..),
  PState (..),
  UTxOState (..),
  VState (..),
 )
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..), Update (..))
import Cardano.Ledger.Shelley.Tx (ShelleyTx)
import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut)
import Cardano.Ledger.Shelley.TxWits (ShelleyTxWits)
import Cardano.Ledger.UTxO (UTxO (..))
import Data.Coerce (coerce)
import qualified Data.Map.Strict as Map

--------------------------------------------------------------------------------
-- Translation from Allegra to Mary
--
-- The instances below are needed by the consensus layer. Do not remove any of
-- them without coordinating with consensus.
--
-- Please add auxiliary instances and other declarations at the bottom of this
-- module, not in the list below so that it remains clear which instances the
-- consensus layer needs.
--
-- WARNING: when a translation instance currently uses the default
-- 'TranslationError', i.e., 'Void', it means the consensus layer relies on it
-- being total. Do not change it!
--------------------------------------------------------------------------------

instance Crypto c => TranslateEra (MaryEra c) NewEpochState where
  translateEra :: TranslationContext (MaryEra c)
-> NewEpochState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) NewEpochState)
     (NewEpochState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt NewEpochState (PreviousEra (MaryEra c))
nes =
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
      NewEpochState
        { nesEL :: EpochNo
nesEL = forall era. NewEpochState era -> EpochNo
nesEL NewEpochState (PreviousEra (MaryEra c))
nes
        , nesBprev :: BlocksMade (EraCrypto (MaryEra c))
nesBprev = forall era. NewEpochState era -> BlocksMade (EraCrypto era)
nesBprev NewEpochState (PreviousEra (MaryEra c))
nes
        , nesBcur :: BlocksMade (EraCrypto (MaryEra c))
nesBcur = forall era. NewEpochState era -> BlocksMade (EraCrypto era)
nesBcur NewEpochState (PreviousEra (MaryEra c))
nes
        , nesEs :: EpochState (MaryEra c)
nesEs = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. NewEpochState era -> EpochState era
nesEs NewEpochState (PreviousEra (MaryEra c))
nes
        , nesRu :: StrictMaybe (PulsingRewUpdate (EraCrypto (MaryEra c)))
nesRu = forall era.
NewEpochState era -> StrictMaybe (PulsingRewUpdate (EraCrypto era))
nesRu NewEpochState (PreviousEra (MaryEra c))
nes
        , nesPd :: PoolDistr (EraCrypto (MaryEra c))
nesPd = forall era. NewEpochState era -> PoolDistr (EraCrypto era)
nesPd NewEpochState (PreviousEra (MaryEra c))
nes
        , stashedAVVMAddresses :: StashedAVVMAddresses (MaryEra c)
stashedAVVMAddresses = ()
        }

instance (Crypto c, EraTx (MaryEra c)) => TranslateEra (MaryEra c) ShelleyTx where
  type TranslationError (MaryEra c) ShelleyTx = DecoderError
  translateEra :: TranslationContext (MaryEra c)
-> ShelleyTx (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) ShelleyTx) (ShelleyTx (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ctx = forall era (ti :: * -> *) (to :: * -> *).
(Era era, ToCBOR (ti (PreviousEra era)),
 DecCBOR (Annotator (to era))) =>
Text -> ti (PreviousEra era) -> Except DecoderError (to era)
translateEraThroughCBOR Text
"ShelleyTx"

--------------------------------------------------------------------------------
-- Auxiliary instances and functions
--------------------------------------------------------------------------------

instance Crypto c => TranslateEra (MaryEra c) PParams

instance Crypto c => TranslateEra (MaryEra c) PParamsUpdate

instance Crypto c => TranslateEra (MaryEra c) FuturePParams where
  translateEra :: TranslationContext (MaryEra c)
-> FuturePParams (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) FuturePParams)
     (FuturePParams (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt = \case
    FuturePParams (PreviousEra (MaryEra c))
NoPParamsUpdate -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall era. FuturePParams era
NoPParamsUpdate
    DefinitePParamsUpdate PParams (PreviousEra (MaryEra c))
pp -> forall era. PParams era -> FuturePParams era
DefinitePParamsUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
translateEra TranslationContext (MaryEra c)
ctxt PParams (PreviousEra (MaryEra c))
pp
    PotentialPParamsUpdate Maybe (PParams (PreviousEra (MaryEra c)))
mpp -> forall era. Maybe (PParams era) -> FuturePParams era
PotentialPParamsUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
translateEra TranslationContext (MaryEra c)
ctxt) Maybe (PParams (PreviousEra (MaryEra c)))
mpp

instance Crypto c => TranslateEra (MaryEra c) EpochState where
  translateEra :: TranslationContext (MaryEra c)
-> EpochState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) EpochState) (EpochState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt EpochState (PreviousEra (MaryEra c))
es =
    forall (m :: * -> *) a. Monad m => a -> m a
return
      EpochState
        { esAccountState :: AccountState
esAccountState = forall era. EpochState era -> AccountState
esAccountState EpochState (PreviousEra (MaryEra c))
es
        , esSnapshots :: SnapShots (EraCrypto (MaryEra c))
esSnapshots = forall era. EpochState era -> SnapShots (EraCrypto era)
esSnapshots EpochState (PreviousEra (MaryEra c))
es
        , esLState :: LedgerState (MaryEra c)
esLState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. EpochState era -> LedgerState era
esLState EpochState (PreviousEra (MaryEra c))
es
        , esNonMyopic :: NonMyopic (EraCrypto (MaryEra c))
esNonMyopic = forall era. EpochState era -> NonMyopic (EraCrypto era)
esNonMyopic EpochState (PreviousEra (MaryEra c))
es
        }

instance Crypto c => TranslateEra (MaryEra c) DState where
  translateEra :: TranslationContext (MaryEra c)
-> DState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) DState) (DState (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ DState {Map
  (FutureGenDeleg (EraCrypto (PreviousEra (MaryEra c))))
  (GenDelegPair (EraCrypto (PreviousEra (MaryEra c))))
InstantaneousRewards (EraCrypto (PreviousEra (MaryEra c)))
UMap (EraCrypto (PreviousEra (MaryEra c)))
GenDelegs (EraCrypto (PreviousEra (MaryEra c)))
dsUnified :: forall era. DState era -> UMap (EraCrypto era)
dsFutureGenDelegs :: forall era.
DState era
-> Map
     (FutureGenDeleg (EraCrypto era)) (GenDelegPair (EraCrypto era))
dsGenDelegs :: forall era. DState era -> GenDelegs (EraCrypto era)
dsIRewards :: forall era. DState era -> InstantaneousRewards (EraCrypto era)
dsIRewards :: InstantaneousRewards (EraCrypto (PreviousEra (MaryEra c)))
dsGenDelegs :: GenDelegs (EraCrypto (PreviousEra (MaryEra c)))
dsFutureGenDelegs :: Map
  (FutureGenDeleg (EraCrypto (PreviousEra (MaryEra c))))
  (GenDelegPair (EraCrypto (PreviousEra (MaryEra c))))
dsUnified :: UMap (EraCrypto (PreviousEra (MaryEra c)))
..} = forall (f :: * -> *) a. Applicative f => a -> f a
pure DState {Map
  (FutureGenDeleg (EraCrypto (PreviousEra (MaryEra c))))
  (GenDelegPair (EraCrypto (PreviousEra (MaryEra c))))
InstantaneousRewards (EraCrypto (PreviousEra (MaryEra c)))
UMap (EraCrypto (PreviousEra (MaryEra c)))
GenDelegs (EraCrypto (PreviousEra (MaryEra c)))
dsUnified :: UMap (EraCrypto (MaryEra c))
dsFutureGenDelegs :: Map
  (FutureGenDeleg (EraCrypto (MaryEra c)))
  (GenDelegPair (EraCrypto (MaryEra c)))
dsGenDelegs :: GenDelegs (EraCrypto (MaryEra c))
dsIRewards :: InstantaneousRewards (EraCrypto (MaryEra c))
dsIRewards :: InstantaneousRewards (EraCrypto (PreviousEra (MaryEra c)))
dsGenDelegs :: GenDelegs (EraCrypto (PreviousEra (MaryEra c)))
dsFutureGenDelegs :: Map
  (FutureGenDeleg (EraCrypto (PreviousEra (MaryEra c))))
  (GenDelegPair (EraCrypto (PreviousEra (MaryEra c))))
dsUnified :: UMap (EraCrypto (PreviousEra (MaryEra c)))
..}

instance Crypto c => TranslateEra (MaryEra c) CommitteeState where
  translateEra :: TranslationContext (MaryEra c)
-> CommitteeState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) CommitteeState)
     (CommitteeState (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ CommitteeState {Map
  (Credential
     'ColdCommitteeRole (EraCrypto (PreviousEra (MaryEra c))))
  (CommitteeAuthorization (EraCrypto (PreviousEra (MaryEra c))))
csCommitteeCreds :: forall era.
CommitteeState era
-> Map
     (Credential 'ColdCommitteeRole (EraCrypto era))
     (CommitteeAuthorization (EraCrypto era))
csCommitteeCreds :: Map
  (Credential
     'ColdCommitteeRole (EraCrypto (PreviousEra (MaryEra c))))
  (CommitteeAuthorization (EraCrypto (PreviousEra (MaryEra c))))
..} = forall (f :: * -> *) a. Applicative f => a -> f a
pure CommitteeState {Map
  (Credential
     'ColdCommitteeRole (EraCrypto (PreviousEra (MaryEra c))))
  (CommitteeAuthorization (EraCrypto (PreviousEra (MaryEra c))))
csCommitteeCreds :: Map
  (Credential 'ColdCommitteeRole (EraCrypto (MaryEra c)))
  (CommitteeAuthorization (EraCrypto (MaryEra c)))
csCommitteeCreds :: Map
  (Credential
     'ColdCommitteeRole (EraCrypto (PreviousEra (MaryEra c))))
  (CommitteeAuthorization (EraCrypto (PreviousEra (MaryEra c))))
..}

instance Crypto c => TranslateEra (MaryEra c) VState where
  translateEra :: TranslationContext (MaryEra c)
-> VState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) VState) (VState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctx VState {Map
  (Credential 'DRepRole (EraCrypto (PreviousEra (MaryEra c))))
  (DRepState (EraCrypto (PreviousEra (MaryEra c))))
CommitteeState (PreviousEra (MaryEra c))
EpochNo
vsDReps :: forall era.
VState era
-> Map
     (Credential 'DRepRole (EraCrypto era)) (DRepState (EraCrypto era))
vsCommitteeState :: forall era. VState era -> CommitteeState era
vsNumDormantEpochs :: forall era. VState era -> EpochNo
vsNumDormantEpochs :: EpochNo
vsCommitteeState :: CommitteeState (PreviousEra (MaryEra c))
vsDReps :: Map
  (Credential 'DRepRole (EraCrypto (PreviousEra (MaryEra c))))
  (DRepState (EraCrypto (PreviousEra (MaryEra c))))
..} = do
    CommitteeState (MaryEra c)
committeeState <- forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
translateEra TranslationContext (MaryEra c)
ctx CommitteeState (PreviousEra (MaryEra c))
vsCommitteeState
    forall (f :: * -> *) a. Applicative f => a -> f a
pure VState {vsCommitteeState :: CommitteeState (MaryEra c)
vsCommitteeState = CommitteeState (MaryEra c)
committeeState, Map
  (Credential 'DRepRole (EraCrypto (PreviousEra (MaryEra c))))
  (DRepState (EraCrypto (PreviousEra (MaryEra c))))
EpochNo
vsDReps :: Map
  (Credential 'DRepRole (EraCrypto (MaryEra c)))
  (DRepState (EraCrypto (MaryEra c)))
vsNumDormantEpochs :: EpochNo
vsNumDormantEpochs :: EpochNo
vsDReps :: Map
  (Credential 'DRepRole (EraCrypto (PreviousEra (MaryEra c))))
  (DRepState (EraCrypto (PreviousEra (MaryEra c))))
..}

instance Crypto c => TranslateEra (MaryEra c) PState where
  translateEra :: TranslationContext (MaryEra c)
-> PState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) PState) (PState (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ PState {Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
Map (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) Coin
Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) EpochNo
psStakePoolParams :: forall era.
PState era
-> Map
     (KeyHash 'StakePool (EraCrypto era)) (PoolParams (EraCrypto era))
psFutureStakePoolParams :: forall era.
PState era
-> Map
     (KeyHash 'StakePool (EraCrypto era)) (PoolParams (EraCrypto era))
psRetiring :: forall era.
PState era -> Map (KeyHash 'StakePool (EraCrypto era)) EpochNo
psDeposits :: forall era.
PState era -> Map (KeyHash 'StakePool (EraCrypto era)) Coin
psDeposits :: Map (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) Coin
psRetiring :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) EpochNo
psFutureStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
psStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
..} = forall (f :: * -> *) a. Applicative f => a -> f a
pure PState {Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
Map (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) Coin
Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) EpochNo
psStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (MaryEra c)))
  (PoolParams (EraCrypto (MaryEra c)))
psFutureStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (MaryEra c)))
  (PoolParams (EraCrypto (MaryEra c)))
psRetiring :: Map (KeyHash 'StakePool (EraCrypto (MaryEra c))) EpochNo
psDeposits :: Map (KeyHash 'StakePool (EraCrypto (MaryEra c))) Coin
psDeposits :: Map (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) Coin
psRetiring :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c)))) EpochNo
psFutureStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
psStakePoolParams :: Map
  (KeyHash 'StakePool (EraCrypto (PreviousEra (MaryEra c))))
  (PoolParams (EraCrypto (PreviousEra (MaryEra c))))
..}

instance Crypto c => TranslateEra (MaryEra c) CertState where
  translateEra :: TranslationContext (MaryEra c)
-> CertState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) CertState) (CertState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt CertState (PreviousEra (MaryEra c))
ls =
    forall (f :: * -> *) a. Applicative f => a -> f a
pure
      CertState
        { certDState :: DState (MaryEra c)
certDState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. CertState era -> DState era
certDState CertState (PreviousEra (MaryEra c))
ls
        , certPState :: PState (MaryEra c)
certPState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. CertState era -> PState era
certPState CertState (PreviousEra (MaryEra c))
ls
        , certVState :: VState (MaryEra c)
certVState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. CertState era -> VState era
certVState CertState (PreviousEra (MaryEra c))
ls
        }

instance Crypto c => TranslateEra (MaryEra c) LedgerState where
  translateEra :: TranslationContext (MaryEra c)
-> LedgerState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) LedgerState)
     (LedgerState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt LedgerState (PreviousEra (MaryEra c))
ls =
    forall (m :: * -> *) a. Monad m => a -> m a
return
      LedgerState
        { lsUTxOState :: UTxOState (MaryEra c)
lsUTxOState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. LedgerState era -> UTxOState era
lsUTxOState LedgerState (PreviousEra (MaryEra c))
ls
        , lsCertState :: CertState (MaryEra c)
lsCertState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. LedgerState era -> CertState era
lsCertState LedgerState (PreviousEra (MaryEra c))
ls
        }

instance Crypto c => TranslateEra (MaryEra c) ProposedPPUpdates where
  translateEra :: TranslationContext (MaryEra c)
-> ProposedPPUpdates (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) ProposedPPUpdates)
     (ProposedPPUpdates (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt (ProposedPPUpdates Map
  (KeyHash 'Genesis (EraCrypto (PreviousEra (MaryEra c))))
  (PParamsUpdate (PreviousEra (MaryEra c)))
ppup) =
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall era.
Map (KeyHash 'Genesis (EraCrypto era)) (PParamsUpdate era)
-> ProposedPPUpdates era
ProposedPPUpdates forall a b. (a -> b) -> a -> b
$ forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt) Map
  (KeyHash 'Genesis (EraCrypto (PreviousEra (MaryEra c))))
  (PParamsUpdate (PreviousEra (MaryEra c)))
ppup

instance Crypto c => TranslateEra (MaryEra c) ShelleyGovState where
  translateEra :: TranslationContext (MaryEra c)
-> ShelleyGovState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) ShelleyGovState)
     (ShelleyGovState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt ShelleyGovState (PreviousEra (MaryEra c))
ps =
    forall (m :: * -> *) a. Monad m => a -> m a
return
      ShelleyGovState
        { sgsCurProposals :: ProposedPPUpdates (MaryEra c)
sgsCurProposals = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. ShelleyGovState era -> ProposedPPUpdates era
sgsCurProposals ShelleyGovState (PreviousEra (MaryEra c))
ps
        , sgsFutureProposals :: ProposedPPUpdates (MaryEra c)
sgsFutureProposals = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. ShelleyGovState era -> ProposedPPUpdates era
sgsFutureProposals ShelleyGovState (PreviousEra (MaryEra c))
ps
        , sgsCurPParams :: PParams (MaryEra c)
sgsCurPParams = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. ShelleyGovState era -> PParams era
sgsCurPParams ShelleyGovState (PreviousEra (MaryEra c))
ps
        , sgsPrevPParams :: PParams (MaryEra c)
sgsPrevPParams = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. ShelleyGovState era -> PParams era
sgsPrevPParams ShelleyGovState (PreviousEra (MaryEra c))
ps
        , sgsFuturePParams :: FuturePParams (MaryEra c)
sgsFuturePParams = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. ShelleyGovState era -> FuturePParams era
sgsFuturePParams ShelleyGovState (PreviousEra (MaryEra c))
ps
        }

instance Crypto c => TranslateEra (MaryEra c) UTxOState where
  translateEra :: TranslationContext (MaryEra c)
-> UTxOState (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) UTxOState) (UTxOState (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt UTxOState (PreviousEra (MaryEra c))
us =
    forall (m :: * -> *) a. Monad m => a -> m a
return
      UTxOState
        { utxosUtxo :: UTxO (MaryEra c)
utxosUtxo = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. UTxOState era -> UTxO era
utxosUtxo UTxOState (PreviousEra (MaryEra c))
us
        , utxosDeposited :: Coin
utxosDeposited = forall era. UTxOState era -> Coin
utxosDeposited UTxOState (PreviousEra (MaryEra c))
us
        , utxosFees :: Coin
utxosFees = forall era. UTxOState era -> Coin
utxosFees UTxOState (PreviousEra (MaryEra c))
us
        , utxosGovState :: GovState (MaryEra c)
utxosGovState = forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b. (a -> b) -> a -> b
$ forall era. UTxOState era -> GovState era
utxosGovState UTxOState (PreviousEra (MaryEra c))
us
        , utxosStakeDistr :: IncrementalStake (EraCrypto (MaryEra c))
utxosStakeDistr = forall era. UTxOState era -> IncrementalStake (EraCrypto era)
utxosStakeDistr UTxOState (PreviousEra (MaryEra c))
us
        , utxosDonation :: Coin
utxosDonation = forall era. UTxOState era -> Coin
utxosDonation UTxOState (PreviousEra (MaryEra c))
us
        }

instance Crypto c => TranslateEra (MaryEra c) ShelleyTxOut where
  translateEra :: TranslationContext (MaryEra c)
-> ShelleyTxOut (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) ShelleyTxOut)
     (ShelleyTxOut (MaryEra c))
translateEra TranslationContext (MaryEra c)
NoGenesis (MaryEra c)
NoGenesis = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era.
(EraTxOut era, EraTxOut (PreviousEra era)) =>
TxOut (PreviousEra era) -> TxOut era
upgradeTxOut

instance Crypto c => TranslateEra (MaryEra c) UTxO where
  translateEra :: TranslationContext (MaryEra c)
-> UTxO (PreviousEra (MaryEra c))
-> Except (TranslationError (MaryEra c) UTxO) (UTxO (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctxt UTxO (PreviousEra (MaryEra c))
utxo =
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall era. Map (TxIn (EraCrypto era)) (TxOut era) -> UTxO era
UTxO (forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctxt forall a b k. (a -> b) -> Map k a -> Map k b
`Map.map` forall era. UTxO era -> Map (TxIn (EraCrypto era)) (TxOut era)
unUTxO UTxO (PreviousEra (MaryEra c))
utxo)

instance Crypto c => TranslateEra (MaryEra c) ShelleyTxWits where
  type TranslationError (MaryEra c) ShelleyTxWits = DecoderError
  translateEra :: TranslationContext (MaryEra c)
-> ShelleyTxWits (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) ShelleyTxWits)
     (ShelleyTxWits (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ctx = forall era (ti :: * -> *) (to :: * -> *).
(Era era, ToCBOR (ti (PreviousEra era)),
 DecCBOR (Annotator (to era))) =>
Text -> ti (PreviousEra era) -> Except DecoderError (to era)
translateEraThroughCBOR Text
"ShelleyTxWits"

instance Crypto c => TranslateEra (MaryEra c) Update where
  translateEra :: TranslationContext (MaryEra c)
-> Update (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) Update) (Update (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ (Update ProposedPPUpdates (PreviousEra (MaryEra c))
pp EpochNo
en) = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall era. ProposedPPUpdates era -> EpochNo -> Update era
Update (coerce :: forall a b. Coercible a b => a -> b
coerce ProposedPPUpdates (PreviousEra (MaryEra c))
pp) EpochNo
en

instance Crypto c => TranslateEra (MaryEra c) Timelock where
  translateEra :: TranslationContext (MaryEra c)
-> Timelock (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) Timelock) (Timelock (MaryEra c))
translateEra TranslationContext (MaryEra c)
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era1 era2.
(Era era1, Era era2, EraCrypto era1 ~ EraCrypto era2) =>
Timelock era1 -> Timelock era2
translateTimelock

instance Crypto c => TranslateEra (MaryEra c) AllegraTxAuxData where
  translateEra :: TranslationContext (MaryEra c)
-> AllegraTxAuxData (PreviousEra (MaryEra c))
-> Except
     (TranslationError (MaryEra c) AllegraTxAuxData)
     (AllegraTxAuxData (MaryEra c))
translateEra TranslationContext (MaryEra c)
ctx (AllegraTxAuxData Map Word64 Metadatum
md StrictSeq (Timelock (AllegraEra c))
as) =
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall era.
Era era =>
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxData era
AllegraTxAuxData Map Word64 Metadatum
md forall a b. (a -> b) -> a -> b
$ forall era (f :: * -> *).
(TranslateEra era f, TranslationError era f ~ Void) =>
TranslationContext era -> f (PreviousEra era) -> f era
translateEra' TranslationContext (MaryEra c)
ctx forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock (AllegraEra c))
as