{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Shelley.TreeDiff (
  module Test.Cardano.Ledger.TreeDiff,
) where

import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Core
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Ledger.Shelley.AdaPots (AdaPots)
import Cardano.Ledger.Shelley.Governance
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.PParams
import Cardano.Ledger.Shelley.PoolRank
import Cardano.Ledger.Shelley.Rules
import Cardano.Ledger.Shelley.Scripts
import Cardano.Ledger.Shelley.State
import Cardano.Ledger.Shelley.Tx
import Cardano.Ledger.Shelley.TxAuxData
import Cardano.Ledger.Shelley.TxBody
import Cardano.Ledger.Shelley.TxCert
import Cardano.Ledger.Shelley.TxOut
import Cardano.Ledger.Shelley.TxWits
import Cardano.Ledger.Shelley.UTxO
import Data.TreeDiff.OMap as OMap
import Test.Cardano.Ledger.TreeDiff

-- PParams
instance ToExpr (PParamsUpdate era) => ToExpr (ProposedPPUpdates era)

instance ToExpr (ShelleyPParams StrictMaybe era)

instance ToExpr (ShelleyPParams Identity era)

instance ToExpr (PParamsUpdate era) => ToExpr (Update era)

-- Scripts
instance ToExpr (MultiSigRaw era)

instance ToExpr (MultiSig era)

-- TxAuxData
instance ToExpr Metadatum

instance ToExpr (ShelleyTxAuxDataRaw era)

instance ToExpr (ShelleyTxAuxData era)

-- Governance

instance ToExpr (PParams era) => ToExpr (FuturePParams era)

instance
  ( ToExpr (PParamsUpdate era)
  , ToExpr (PParams era)
  ) =>
  ToExpr (ShelleyGovState era)

-- TxCert
instance ToExpr GenesisDelegCert

instance ToExpr MIRPot

instance ToExpr MIRTarget

instance ToExpr MIRCert

instance ToExpr (ShelleyTxCert era)

instance ToExpr ShelleyDelegCert

-- TxWits
instance (Era era, ToExpr (Script era)) => ToExpr (ShelleyTxWits era)

instance (Era era, ToExpr (Script era)) => ToExpr (ShelleyTxWitsRaw era)

-- Rules/Ppup
instance ToExpr VotingPeriod

instance ToExpr (ShelleyPpupPredFailure era)

-- TxOut
instance (EraTxOut era, ToExpr (Value era)) => ToExpr (ShelleyTxOut era) where
  toExpr :: ShelleyTxOut era -> Expr
toExpr (ShelleyTxOut Addr
x Value era
y) = ConstructorName -> [Expr] -> Expr
App ConstructorName
"ShelleyTxOut" [Addr -> Expr
forall a. ToExpr a => a -> Expr
toExpr Addr
x, Value era -> Expr
forall a. ToExpr a => a -> Expr
toExpr Value era
y]

-- TxBody
instance ToExpr (ShelleyTxBodyRaw TopTx ShelleyEra) where
  toExpr :: ShelleyTxBodyRaw TopTx ShelleyEra -> Expr
toExpr ShelleyTxBodyRaw {Set TxIn
StrictMaybe TxAuxDataHash
StrictMaybe (Update ShelleyEra)
SlotNo
Coin
Withdrawals
StrictSeq (TxCert ShelleyEra)
StrictSeq (TxOut ShelleyEra)
stbrInputs :: Set TxIn
stbrOutputs :: StrictSeq (TxOut ShelleyEra)
stbrCerts :: StrictSeq (TxCert ShelleyEra)
stbrWithdrawals :: Withdrawals
stbrFee :: Coin
stbrTtl :: SlotNo
stbrUpdate :: StrictMaybe (Update ShelleyEra)
stbrAuxDataHash :: StrictMaybe TxAuxDataHash
stbrAuxDataHash :: forall era. ShelleyTxBodyRaw TopTx era -> StrictMaybe TxAuxDataHash
stbrUpdate :: forall era. ShelleyTxBodyRaw TopTx era -> StrictMaybe (Update era)
stbrTtl :: forall era. ShelleyTxBodyRaw TopTx era -> SlotNo
stbrFee :: forall era. ShelleyTxBodyRaw TopTx era -> Coin
stbrWithdrawals :: forall era. ShelleyTxBodyRaw TopTx era -> Withdrawals
stbrCerts :: forall era. ShelleyTxBodyRaw TopTx era -> StrictSeq (TxCert era)
stbrOutputs :: forall era. ShelleyTxBodyRaw TopTx era -> StrictSeq (TxOut era)
stbrInputs :: forall era. ShelleyTxBodyRaw TopTx era -> Set TxIn
..} =
    ConstructorName -> OMap ConstructorName Expr -> Expr
Rec ConstructorName
"ShelleyTxBodyRaw" (OMap ConstructorName Expr -> Expr)
-> OMap ConstructorName Expr -> Expr
forall a b. (a -> b) -> a -> b
$
      [(ConstructorName, Expr)] -> OMap ConstructorName Expr
forall k v. Ord k => [(k, v)] -> OMap k v
OMap.fromList
        [ (ConstructorName
"inputs", Set TxIn -> Expr
forall a. ToExpr a => a -> Expr
toExpr Set TxIn
stbrInputs)
        , (ConstructorName
"outputs", StrictSeq (ShelleyTxOut ShelleyEra) -> Expr
forall a. ToExpr a => a -> Expr
toExpr StrictSeq (TxOut ShelleyEra)
StrictSeq (ShelleyTxOut ShelleyEra)
stbrOutputs)
        , (ConstructorName
"certs", StrictSeq (ShelleyTxCert ShelleyEra) -> Expr
forall a. ToExpr a => a -> Expr
toExpr StrictSeq (TxCert ShelleyEra)
StrictSeq (ShelleyTxCert ShelleyEra)
stbrCerts)
        , (ConstructorName
"withdrawals", Withdrawals -> Expr
forall a. ToExpr a => a -> Expr
toExpr Withdrawals
stbrWithdrawals)
        , (ConstructorName
"fee", Coin -> Expr
forall a. ToExpr a => a -> Expr
toExpr Coin
stbrFee)
        , (ConstructorName
"ttl", SlotNo -> Expr
forall a. ToExpr a => a -> Expr
toExpr SlotNo
stbrTtl)
        , (ConstructorName
"update", StrictMaybe (Update ShelleyEra) -> Expr
forall a. ToExpr a => a -> Expr
toExpr StrictMaybe (Update ShelleyEra)
stbrUpdate)
        , (ConstructorName
"auxDataHash", StrictMaybe TxAuxDataHash -> Expr
forall a. ToExpr a => a -> Expr
toExpr StrictMaybe TxAuxDataHash
stbrAuxDataHash)
        ]

instance ToExpr (TxBody TopTx ShelleyEra)

-- PoolRank
instance ToExpr Likelihood

instance ToExpr LogWeight

instance ToExpr NonMyopic

instance
  ( ToExpr (TxAuxData era)
  , ToExpr (TxBody TopTx era)
  , ToExpr (TxWits era)
  ) =>
  ToExpr (ShelleyTx TopTx era)
  where
  toExpr :: ShelleyTx TopTx era -> Expr
toExpr ShelleyTx {StrictMaybe (TxAuxData era)
TxWits era
TxBody TopTx era
stBody :: TxBody TopTx era
stWits :: TxWits era
stAuxData :: StrictMaybe (TxAuxData era)
stAuxData :: forall era. ShelleyTx TopTx era -> StrictMaybe (TxAuxData era)
stWits :: forall era. ShelleyTx TopTx era -> TxWits era
stBody :: forall era. ShelleyTx TopTx era -> TxBody TopTx era
..} =
    ConstructorName -> OMap ConstructorName Expr -> Expr
Rec ConstructorName
"ShelleyTx" (OMap ConstructorName Expr -> Expr)
-> OMap ConstructorName Expr -> Expr
forall a b. (a -> b) -> a -> b
$
      [(ConstructorName, Expr)] -> OMap ConstructorName Expr
forall k v. Ord k => [(k, v)] -> OMap k v
OMap.fromList
        [ (ConstructorName
"body", TxBody TopTx era -> Expr
forall a. ToExpr a => a -> Expr
toExpr TxBody TopTx era
stBody)
        , (ConstructorName
"wits", TxWits era -> Expr
forall a. ToExpr a => a -> Expr
toExpr TxWits era
stWits)
        , (ConstructorName
"auxData", StrictMaybe (TxAuxData era) -> Expr
forall a. ToExpr a => a -> Expr
toExpr StrictMaybe (TxAuxData era)
stAuxData)
        ]

-- RewardUpdate

-- | You really don't want to see what is inside this.
instance ToExpr PulsingRewUpdate where
  toExpr :: PulsingRewUpdate -> Expr
toExpr PulsingRewUpdate
_ = ConstructorName -> [Expr] -> Expr
App ConstructorName
"PulsingRewUpdate..." []

instance ToExpr RewardUpdate

-- LedgerState/Types

instance
  ( ToExpr (TxOut era)
  , ToExpr (PParams era)
  , ToExpr (StashedAVVMAddresses era)
  , ToExpr (GovState era)
  , ToExpr (CertState era)
  , ToExpr (InstantStake era)
  ) =>
  ToExpr (NewEpochState era)

instance
  ( ToExpr (TxOut era)
  , ToExpr (PParams era)
  , ToExpr (GovState era)
  , ToExpr (CertState era)
  , ToExpr (InstantStake era)
  ) =>
  ToExpr (EpochState era)

instance
  ( ToExpr (TxOut era)
  , ToExpr (GovState era)
  , ToExpr (CertState era)
  , ToExpr (InstantStake era)
  ) =>
  ToExpr (LedgerState era)

instance
  ( ToExpr (TxOut era)
  , ToExpr (GovState era)
  , ToExpr (InstantStake era)
  ) =>
  ToExpr (UTxOState era)

instance ToExpr (ShelleyInstantStake era)

instance ToExpr (ShelleyScriptsNeeded era)

-- Rules/Utxo
instance
  ( ToExpr (EraRuleFailure "PPUP" era)
  , ToExpr (Value era)
  , ToExpr (TxOut era)
  ) =>
  ToExpr (ShelleyUtxoPredFailure era)

-- Rules/Pool
instance ToExpr (ShelleyPoolPredFailure era)

-- Rules/Deleg
instance ToExpr (ShelleyDelegPredFailure era)

-- Rules/Utxow
instance
  ( Era era
  , ToExpr (PredicateFailure (EraRule "UTXO" era))
  ) =>
  ToExpr (ShelleyUtxowPredFailure era)

-- Rules/Delpl
instance
  ( ToExpr (PredicateFailure (EraRule "DELEG" era))
  , ToExpr (PredicateFailure (EraRule "POOL" era))
  ) =>
  ToExpr (ShelleyDelplPredFailure era)

-- Rules/Delegs
instance
  ToExpr (PredicateFailure (EraRule "DELPL" era)) =>
  ToExpr (ShelleyDelegsPredFailure era)

-- Rules/Ledger
instance
  ( ToExpr (PredicateFailure (EraRule "UTXOW" era))
  , ToExpr (PredicateFailure (EraRule "DELEGS" era))
  ) =>
  ToExpr (ShelleyLedgerPredFailure era)

instance ToExpr Obligations

instance ToExpr AdaPots

-- Events
instance
  ( ToExpr (Event (EraRule "UTXOW" era))
  , ToExpr (Event (EraRule "DELEGS" era))
  ) =>
  ToExpr (ShelleyLedgerEvent era)

instance
  ToExpr (Event (EraRule "LEDGER" era)) =>
  ToExpr (ShelleyLedgersEvent era)

instance
  ToExpr (Event (EraRule "LEDGERS" era)) =>
  ToExpr (ShelleyBbodyEvent era)

instance
  ToExpr (Event (EraRule "UTXO" era)) =>
  ToExpr (ShelleyUtxowEvent era)

instance
  ( ToExpr (Event (EraRule "PPUP" era))
  , ToExpr (TxOut era)
  ) =>
  ToExpr (UtxoEvent era)

instance ToExpr (PpupEvent era)

instance ToExpr (Event (EraRule "DELPL" era)) => ToExpr (ShelleyDelegsEvent era)

instance
  ( ToExpr (Event (EraRule "DELEG" era))
  , ToExpr (Event (EraRule "POOL" era))
  ) =>
  ToExpr (ShelleyDelplEvent era)

instance ToExpr (ShelleyDelegEvent era)

instance ToExpr (PoolEvent era)

instance ToExpr (PParamsHKD Identity era) => ToExpr (PoolEnv era)

instance
  ( ToExpr (Event (EraRule "NEWEPOCH" era))
  , ToExpr (Event (EraRule "RUPD" era))
  ) =>
  ToExpr (ShelleyTickEvent era)

instance ToExpr RewardType

instance ToExpr Reward

instance
  ( ToExpr (Event (EraRule "EPOCH" era))
  , ToExpr (Event (EraRule "MIR" era))
  , ToExpr (Event (EraRule "RUPD" era))
  ) =>
  ToExpr (ShelleyNewEpochEvent era)

instance
  ( ToExpr (Event (EraRule "POOLREAP" era))
  , ToExpr (Event (EraRule "SNAP" era))
  , ToExpr (Event (EraRule "UPEC" era))
  ) =>
  ToExpr (ShelleyEpochEvent era)

instance ToExpr (ShelleyPoolreapEvent era)

instance ToExpr (SnapEvent era)

instance ToExpr (ShelleyMirEvent era)

instance ToExpr RupdEvent

instance (ToExpr (PParamsHKD Identity era), ToExpr (CertState era)) => ToExpr (UtxoEnv era)

instance ToExpr (PParamsHKD Identity era) => ToExpr (LedgerEnv era)

instance ToExpr (PParamsHKD Identity era) => ToExpr (ShelleyLedgersEnv era)

instance
  ToExpr (PredicateFailure (EraRule "LEDGER" era)) =>
  ToExpr (ShelleyLedgersPredFailure era)

instance (EraCertState era, ToExpr (Accounts era)) => ToExpr (ShelleyCertState era)

instance ToExpr (ShelleyAccountState era)

instance ToExpr (ShelleyAccounts era)

instance
  ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
  ToExpr (ShelleyBbodyPredFailure era)

instance
  ToExpr (State (EraRule "LEDGERS" era)) =>
  ToExpr (ShelleyBbodyState era)

instance ToExpr (Tx TopTx ShelleyEra)