{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

-- | Transactions in the context of a consensus mode, and other types used in
-- the transaction submission protocol.
--
module Bcc.Api.TxInMode (

    -- * Transaction in a consensus mode
    TxInMode(..),
    toConsensusGenTx,

    -- * Transaction validation errors
    TxValidationError(..),
    TxValidationErrorInMode(..),
    fromConsensusApplyTxErr,
  ) where

import           Prelude

import           Data.SOP.Strict (NS (S, Z))

import qualified Shardagnostic.Consensus.Cole.Ledger as Consensus
import qualified Shardagnostic.Consensus.Bcc.Block as Consensus
import qualified Shardagnostic.Consensus.HardFork.Combinator as Consensus
import           Shardagnostic.Consensus.HardFork.Combinator.AcrossEras (EraMismatch)
import qualified Shardagnostic.Consensus.HardFork.Combinator.Degenerate as Consensus
import qualified Shardagnostic.Consensus.Ledger.SupportsMempool as Consensus
import qualified Shardagnostic.Consensus.Sophie.Ledger as Consensus

import           Bcc.Api.Eras
import           Bcc.Api.Modes
import           Bcc.Api.Tx


-- ----------------------------------------------------------------------------
-- Transactions in the context of a consensus mode
--

-- | A 'Tx' in one of the eras supported by a given protocol mode.
--
-- For multi-era modes such as the 'BccMode' this type is a sum of the
-- different transaction types for all the eras. It is used in the
-- LocalTxSubmission protocol.
--
data TxInMode mode where

     -- | Everything we consider a normal transaction.
     --
     TxInMode :: Tx era -> EraInMode era mode -> TxInMode mode

     -- | Cole has various things we can post to the chain which are not
     -- actually transactions. This covers: update proposals, votes and
     -- delegation certs.
     --
     TxInColeSpecial :: Consensus.GenTx Consensus.ColeBlock
                      -> EraInMode ColeEra mode -> TxInMode mode

deriving instance Show (TxInMode mode)


toConsensusGenTx :: ConsensusBlockForMode mode ~ block
                 => TxInMode mode
                 -> Consensus.GenTx block
toConsensusGenTx :: TxInMode mode -> GenTx block
toConsensusGenTx (TxInMode (ColeTx ATxAux ByteString
tx) EraInMode era mode
ColeEraInColeMode) =
    OneEraGenTx '[ColeBlock] -> GenTx (HardForkBlock '[ColeBlock])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS GenTx '[ColeBlock] -> OneEraGenTx '[ColeBlock]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ColeBlock -> NS GenTx '[ColeBlock]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ColeBlock
tx'))
  where
    tx' :: GenTx ColeBlock
tx' = TxId -> ATxAux ByteString -> GenTx ColeBlock
Consensus.ColeTx (ATxAux ByteString -> TxId
Consensus.coleIdTx ATxAux ByteString
tx) ATxAux ByteString
tx

toConsensusGenTx (TxInMode (ColeTx ATxAux ByteString
tx) EraInMode era mode
ColeEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ColeBlock
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ColeBlock
tx'))
  where
    tx' :: GenTx ColeBlock
tx' = TxId -> ATxAux ByteString -> GenTx ColeBlock
Consensus.ColeTx (ATxAux ByteString -> TxId
Consensus.coleIdTx ATxAux ByteString
tx) ATxAux ByteString
tx
    --TODO: add the above as mkColeTx to the consensus code,
    -- matching mkSophieTx below

toConsensusGenTx (TxInColeSpecial GenTx ColeBlock
gtx EraInMode ColeEra mode
ColeEraInColeMode) =
    OneEraGenTx '[ColeBlock] -> GenTx (HardForkBlock '[ColeBlock])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS GenTx '[ColeBlock] -> OneEraGenTx '[ColeBlock]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ColeBlock -> NS GenTx '[ColeBlock]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ColeBlock
gtx))

toConsensusGenTx (TxInColeSpecial GenTx ColeBlock
gtx EraInMode ColeEra mode
ColeEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ColeBlock
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ColeBlock
gtx))

toConsensusGenTx (TxInMode (SophieTx SophieBasedEra era
_ Tx (SophieLedgerEra era)
tx) EraInMode era mode
SophieEraInSophieMode) =
    OneEraGenTx '[SophieBlock (SophieEra StandardCrypto)]
-> GenTx (HardForkBlock '[SophieBlock (SophieEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS GenTx '[SophieBlock (SophieEra StandardCrypto)]
-> OneEraGenTx '[SophieBlock (SophieEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx (SophieBlock (SophieEra StandardCrypto))
-> NS GenTx '[SophieBlock (SophieEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (SophieBlock (SophieEra StandardCrypto))
tx'))
  where
    tx' :: GenTx (SophieBlock (SophieEra StandardCrypto))
tx' = Tx (SophieEra StandardCrypto)
-> GenTx (SophieBlock (SophieEra StandardCrypto))
forall era. SophieBasedEra era => Tx era -> GenTx (SophieBlock era)
Consensus.mkSophieTx Tx (SophieEra StandardCrypto)
Tx (SophieLedgerEra era)
tx

toConsensusGenTx (TxInMode (SophieTx SophieBasedEra era
_ Tx (SophieLedgerEra era)
tx) EraInMode era mode
SophieEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (SophieBlock (SophieEra StandardCrypto))
-> NS
     GenTx
     '[SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (SophieBlock (SophieEra StandardCrypto))
tx')))
  where
    tx' :: GenTx (SophieBlock (SophieEra StandardCrypto))
tx' = Tx (SophieEra StandardCrypto)
-> GenTx (SophieBlock (SophieEra StandardCrypto))
forall era. SophieBasedEra era => Tx era -> GenTx (SophieBlock era)
Consensus.mkSophieTx Tx (SophieEra StandardCrypto)
Tx (SophieLedgerEra era)
tx

toConsensusGenTx (TxInMode (SophieTx SophieBasedEra era
_ Tx (SophieLedgerEra era)
tx) EraInMode era mode
EvieEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (SophieBlock (EvieEra StandardCrypto))
-> NS
     GenTx
     '[SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (SophieBlock (EvieEra StandardCrypto))
tx'))))
  where
    tx' :: GenTx (SophieBlock (EvieEra StandardCrypto))
tx' = Tx (EvieEra StandardCrypto)
-> GenTx (SophieBlock (EvieEra StandardCrypto))
forall era. SophieBasedEra era => Tx era -> GenTx (SophieBlock era)
Consensus.mkSophieTx Tx (EvieEra StandardCrypto)
Tx (SophieLedgerEra era)
tx

toConsensusGenTx (TxInMode (SophieTx SophieBasedEra era
_ Tx (SophieLedgerEra era)
tx) EraInMode era mode
JenEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (SophieBlock (JenEra StandardCrypto))
-> NS
     GenTx
     '[SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (SophieBlock (JenEra StandardCrypto))
tx')))))
  where
    tx' :: GenTx (SophieBlock (JenEra StandardCrypto))
tx' = Tx (JenEra StandardCrypto)
-> GenTx (SophieBlock (JenEra StandardCrypto))
forall era. SophieBasedEra era => Tx era -> GenTx (SophieBlock era)
Consensus.mkSophieTx Tx (JenEra StandardCrypto)
Tx (SophieLedgerEra era)
tx

toConsensusGenTx (TxInMode (SophieTx SophieBasedEra era
_ Tx (SophieLedgerEra era)
tx) EraInMode era mode
AurumEraInBccMode) =
    OneEraGenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
          SophieBlock (EvieEra StandardCrypto),
          SophieBlock (JenEra StandardCrypto),
          SophieBlock (AurumEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> OneEraGenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[SophieBlock (SophieEra StandardCrypto),
    SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[ColeBlock, SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[SophieBlock (EvieEra StandardCrypto),
    SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (SophieEra StandardCrypto),
       SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[SophieBlock (JenEra StandardCrypto),
    SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (EvieEra StandardCrypto),
       SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS GenTx '[SophieBlock (AurumEra StandardCrypto)]
-> NS
     GenTx
     '[SophieBlock (JenEra StandardCrypto),
       SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (SophieBlock (AurumEra StandardCrypto))
-> NS GenTx '[SophieBlock (AurumEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (SophieBlock (AurumEra StandardCrypto))
tx'))))))
  where
    tx' :: GenTx (SophieBlock (AurumEra StandardCrypto))
tx' = Tx (AurumEra StandardCrypto)
-> GenTx (SophieBlock (AurumEra StandardCrypto))
forall era. SophieBasedEra era => Tx era -> GenTx (SophieBlock era)
Consensus.mkSophieTx Tx (AurumEra StandardCrypto)
Tx (SophieLedgerEra era)
tx



-- ----------------------------------------------------------------------------
-- Transaction validation errors in the context of eras and consensus modes
--

-- | The transaction validations errors that can occur from trying to submit a
-- transaction to a local node. The errors are specific to an era.
--
data TxValidationError era where

     ColeTxValidationError
       :: Consensus.ApplyTxErr Consensus.ColeBlock
       -> TxValidationError ColeEra

     SophieTxValidationError
       :: SophieBasedEra era
       -> Consensus.ApplyTxErr (Consensus.SophieBlock (SophieLedgerEra era))
       -> TxValidationError era

-- The GADT in the SophieTxValidationError case requires a custom instance
instance Show (TxValidationError era) where
    showsPrec :: Int -> TxValidationError era -> ShowS
showsPrec Int
p (ColeTxValidationError ApplyTxErr ColeBlock
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ColeTxValidationError "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyMempoolPayloadErr -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxErr ColeBlock
ApplyMempoolPayloadErr
err
        )

    showsPrec Int
p (SophieTxValidationError SophieBasedEra era
SophieBasedEraSophie ApplyTxErr (SophieBlock (SophieLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"SophieTxValidationError SophieBasedEraSophie "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (SophieEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (SophieEra StandardCrypto)
ApplyTxErr (SophieBlock (SophieLedgerEra era))
err
        )

    showsPrec Int
p (SophieTxValidationError SophieBasedEra era
SophieBasedEraEvie ApplyTxErr (SophieBlock (SophieLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"SophieTxValidationError SophieBasedEraEvie "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (EvieEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (EvieEra StandardCrypto)
ApplyTxErr (SophieBlock (SophieLedgerEra era))
err
        )

    showsPrec Int
p (SophieTxValidationError SophieBasedEra era
SophieBasedEraJen ApplyTxErr (SophieBlock (SophieLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"SophieTxValidationError SophieBasedEraJen "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (JenEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (JenEra StandardCrypto)
ApplyTxErr (SophieBlock (SophieLedgerEra era))
err
        )

    showsPrec Int
p (SophieTxValidationError SophieBasedEra era
SophieBasedEraAurum ApplyTxErr (SophieBlock (SophieLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"SophieTxValidationError SophieBasedEraAurum "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (AurumEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (AurumEra StandardCrypto)
ApplyTxErr (SophieBlock (SophieLedgerEra era))
err
        )


-- | A 'TxValidationError' in one of the eras supported by a given protocol
-- mode.
--
-- This is used in the LocalStateQuery protocol.
--
data TxValidationErrorInMode mode where
     TxValidationErrorInMode :: TxValidationError era
                             -> EraInMode era mode
                             -> TxValidationErrorInMode mode

     TxValidationEraMismatch :: EraMismatch
                             -> TxValidationErrorInMode mode

deriving instance Show (TxValidationErrorInMode mode)


fromConsensusApplyTxErr :: ConsensusBlockForMode mode ~ block
                        => ConsensusMode mode
                        -> Consensus.ApplyTxErr block
                        -> TxValidationErrorInMode mode
fromConsensusApplyTxErr :: ConsensusMode mode
-> ApplyTxErr block -> TxValidationErrorInMode mode
fromConsensusApplyTxErr ConsensusMode mode
ColeMode (Consensus.DegenApplyTxErr err) =
    TxValidationError ColeEra
-> EraInMode ColeEra ColeMode -> TxValidationErrorInMode ColeMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ApplyTxErr ColeBlock -> TxValidationError ColeEra
ColeTxValidationError ApplyTxErr ColeBlock
err)
      EraInMode ColeEra ColeMode
ColeEraInColeMode

fromConsensusApplyTxErr ConsensusMode mode
SophieMode (Consensus.DegenApplyTxErr err) =
    TxValidationError SophieEra
-> EraInMode SophieEra SophieMode
-> TxValidationErrorInMode SophieMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (SophieBasedEra SophieEra
-> ApplyTxErr (SophieBlock (SophieLedgerEra SophieEra))
-> TxValidationError SophieEra
forall era.
SophieBasedEra era
-> ApplyTxErr (SophieBlock (SophieLedgerEra era))
-> TxValidationError era
SophieTxValidationError SophieBasedEra SophieEra
SophieBasedEraSophie ApplyTxErr (SophieBlock (SophieEra StandardCrypto))
ApplyTxErr (SophieBlock (SophieLedgerEra SophieEra))
err)
      EraInMode SophieEra SophieMode
SophieEraInSophieMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrCole err) =
    TxValidationError ColeEra
-> EraInMode ColeEra BccMode -> TxValidationErrorInMode BccMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ApplyTxErr ColeBlock -> TxValidationError ColeEra
ColeTxValidationError ApplyTxErr ColeBlock
err)
      EraInMode ColeEra BccMode
ColeEraInBccMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrSophie err) =
    TxValidationError SophieEra
-> EraInMode SophieEra BccMode -> TxValidationErrorInMode BccMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (SophieBasedEra SophieEra
-> ApplyTxErr (SophieBlock (SophieLedgerEra SophieEra))
-> TxValidationError SophieEra
forall era.
SophieBasedEra era
-> ApplyTxErr (SophieBlock (SophieLedgerEra era))
-> TxValidationError era
SophieTxValidationError SophieBasedEra SophieEra
SophieBasedEraSophie ApplyTxErr (SophieBlock (SophieEra StandardCrypto))
ApplyTxErr (SophieBlock (SophieLedgerEra SophieEra))
err)
      EraInMode SophieEra BccMode
SophieEraInBccMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrEvie err) =
    TxValidationError EvieEra
-> EraInMode EvieEra BccMode -> TxValidationErrorInMode BccMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (SophieBasedEra EvieEra
-> ApplyTxErr (SophieBlock (SophieLedgerEra EvieEra))
-> TxValidationError EvieEra
forall era.
SophieBasedEra era
-> ApplyTxErr (SophieBlock (SophieLedgerEra era))
-> TxValidationError era
SophieTxValidationError SophieBasedEra EvieEra
SophieBasedEraEvie ApplyTxErr (SophieBlock (EvieEra StandardCrypto))
ApplyTxErr (SophieBlock (SophieLedgerEra EvieEra))
err)
      EraInMode EvieEra BccMode
EvieEraInBccMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrJen err) =
    TxValidationError JenEra
-> EraInMode JenEra BccMode -> TxValidationErrorInMode BccMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (SophieBasedEra JenEra
-> ApplyTxErr (SophieBlock (SophieLedgerEra JenEra))
-> TxValidationError JenEra
forall era.
SophieBasedEra era
-> ApplyTxErr (SophieBlock (SophieLedgerEra era))
-> TxValidationError era
SophieTxValidationError SophieBasedEra JenEra
SophieBasedEraJen ApplyTxErr (SophieBlock (JenEra StandardCrypto))
ApplyTxErr (SophieBlock (SophieLedgerEra JenEra))
err)
      EraInMode JenEra BccMode
JenEraInBccMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrAurum err) =
    TxValidationError AurumEra
-> EraInMode AurumEra BccMode -> TxValidationErrorInMode BccMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (SophieBasedEra AurumEra
-> ApplyTxErr (SophieBlock (SophieLedgerEra AurumEra))
-> TxValidationError AurumEra
forall era.
SophieBasedEra era
-> ApplyTxErr (SophieBlock (SophieLedgerEra era))
-> TxValidationError era
SophieTxValidationError SophieBasedEra AurumEra
SophieBasedEraAurum ApplyTxErr (SophieBlock (AurumEra StandardCrypto))
ApplyTxErr (SophieBlock (SophieLedgerEra AurumEra))
err)
      EraInMode AurumEra BccMode
AurumEraInBccMode

fromConsensusApplyTxErr ConsensusMode mode
BccMode (Consensus.ApplyTxErrWrongEra err) =
    EraMismatch -> TxValidationErrorInMode mode
forall mode. EraMismatch -> TxValidationErrorInMode mode
TxValidationEraMismatch EraMismatch
err