{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Dijkstra (DijkstraEra, ApplyTxError (..)) where

import Cardano.Ledger.BaseTypes (Inject (inject))
import Cardano.Ledger.Conway.Governance (RunConwayRatify)
import Cardano.Ledger.Dijkstra.BlockBody ()
import Cardano.Ledger.Dijkstra.Era
import Cardano.Ledger.Dijkstra.Genesis ()
import Cardano.Ledger.Dijkstra.Governance ()
import Cardano.Ledger.Dijkstra.Rules (
  DijkstraLedgerPredFailure,
  DijkstraMempoolPredFailure (LedgerFailure),
 )
import Cardano.Ledger.Dijkstra.Scripts ()
import Cardano.Ledger.Dijkstra.State.CertState ()
import Cardano.Ledger.Dijkstra.State.Stake ()
import Cardano.Ledger.Dijkstra.Transition ()
import Cardano.Ledger.Dijkstra.Translation ()
import Cardano.Ledger.Dijkstra.Tx ()
import Cardano.Ledger.Dijkstra.TxBody ()
import Cardano.Ledger.Dijkstra.TxInfo ()
import Cardano.Ledger.Dijkstra.TxWits ()
import Cardano.Ledger.Dijkstra.UTxO ()
import Cardano.Ledger.Shelley.API (ApplyBlock, ApplyTx (..), ruleApplyTxValidation)
import Data.Bifunctor (Bifunctor (first))
import Data.List.NonEmpty (NonEmpty)

instance ApplyTx DijkstraEra where
  newtype ApplyTxError DijkstraEra = DijkstraApplyTxError (NonEmpty (DijkstraMempoolPredFailure DijkstraEra))
    deriving (ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool
(ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool)
-> (ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool)
-> Eq (ApplyTxError DijkstraEra)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool
== :: ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool
$c/= :: ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool
/= :: ApplyTxError DijkstraEra -> ApplyTxError DijkstraEra -> Bool
Eq, Int -> ApplyTxError DijkstraEra -> ShowS
[ApplyTxError DijkstraEra] -> ShowS
ApplyTxError DijkstraEra -> String
(Int -> ApplyTxError DijkstraEra -> ShowS)
-> (ApplyTxError DijkstraEra -> String)
-> ([ApplyTxError DijkstraEra] -> ShowS)
-> Show (ApplyTxError DijkstraEra)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ApplyTxError DijkstraEra -> ShowS
showsPrec :: Int -> ApplyTxError DijkstraEra -> ShowS
$cshow :: ApplyTxError DijkstraEra -> String
show :: ApplyTxError DijkstraEra -> String
$cshowList :: [ApplyTxError DijkstraEra] -> ShowS
showList :: [ApplyTxError DijkstraEra] -> ShowS
Show)
  applyTxValidation :: ValidationPolicy
-> Globals
-> MempoolEnv DijkstraEra
-> MempoolState DijkstraEra
-> Tx TopTx DijkstraEra
-> Either
     (ApplyTxError DijkstraEra)
     (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
applyTxValidation ValidationPolicy
validationPolicy Globals
globals MempoolEnv DijkstraEra
env MempoolState DijkstraEra
state Tx TopTx DijkstraEra
tx =
    (NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
 -> ApplyTxError DijkstraEra)
-> Either
     (NonEmpty (DijkstraMempoolPredFailure DijkstraEra))
     (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
-> Either
     (ApplyTxError DijkstraEra)
     (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
DijkstraApplyTxError (Either
   (NonEmpty (DijkstraMempoolPredFailure DijkstraEra))
   (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
 -> Either
      (ApplyTxError DijkstraEra)
      (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra)))
-> Either
     (NonEmpty (DijkstraMempoolPredFailure DijkstraEra))
     (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
-> Either
     (ApplyTxError DijkstraEra)
     (MempoolState DijkstraEra, Validated (Tx TopTx DijkstraEra))
forall a b. (a -> b) -> a -> b
$
      forall (rule :: Symbol) era.
(STS (EraRule rule era), BaseM (EraRule rule era) ~ ShelleyBase,
 Environment (EraRule rule era) ~ LedgerEnv era,
 State (EraRule rule era) ~ MempoolState era,
 Signal (EraRule rule era) ~ Tx TopTx era) =>
ValidationPolicy
-> Globals
-> LedgerEnv era
-> MempoolState era
-> Tx TopTx era
-> Either
     (NonEmpty (PredicateFailure (EraRule rule era)))
     (MempoolState era, Validated (Tx TopTx era))
ruleApplyTxValidation @"MEMPOOL" ValidationPolicy
validationPolicy Globals
globals MempoolEnv DijkstraEra
env MempoolState DijkstraEra
state Tx TopTx DijkstraEra
tx

instance ApplyBlock DijkstraEra

instance RunConwayRatify DijkstraEra

instance Inject (NonEmpty (DijkstraMempoolPredFailure DijkstraEra)) (ApplyTxError DijkstraEra) where
  inject :: NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
inject = NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
DijkstraApplyTxError

instance Inject (NonEmpty (DijkstraLedgerPredFailure DijkstraEra)) (ApplyTxError DijkstraEra) where
  inject :: NonEmpty (DijkstraLedgerPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
inject = NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
DijkstraApplyTxError (NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
 -> ApplyTxError DijkstraEra)
-> (NonEmpty (DijkstraLedgerPredFailure DijkstraEra)
    -> NonEmpty (DijkstraMempoolPredFailure DijkstraEra))
-> NonEmpty (DijkstraLedgerPredFailure DijkstraEra)
-> ApplyTxError DijkstraEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DijkstraLedgerPredFailure DijkstraEra
 -> DijkstraMempoolPredFailure DijkstraEra)
-> NonEmpty (DijkstraLedgerPredFailure DijkstraEra)
-> NonEmpty (DijkstraMempoolPredFailure DijkstraEra)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PredicateFailure (EraRule "LEDGER" DijkstraEra)
-> DijkstraMempoolPredFailure DijkstraEra
DijkstraLedgerPredFailure DijkstraEra
-> DijkstraMempoolPredFailure DijkstraEra
forall era.
PredicateFailure (EraRule "LEDGER" era)
-> DijkstraMempoolPredFailure era
LedgerFailure