{-# 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 Cardano.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 Ouroboros.Consensus.Byron.Ledger as Consensus
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
import           Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch)
import qualified Ouroboros.Consensus.HardFork.Combinator.Degenerate as Consensus
import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus

import           Cardano.Api.Eras
import           Cardano.Api.Modes
import           Cardano.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 'CardanoMode' 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

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

deriving instance Show (TxInMode mode)


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

toConsensusGenTx (TxInMode (ByronTx ATxAux ByteString
tx) EraInMode era mode
ByronEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ByronBlock
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ByronBlock
tx'))
  where
    tx' :: GenTx ByronBlock
tx' = TxId -> ATxAux ByteString -> GenTx ByronBlock
Consensus.ByronTx (ATxAux ByteString -> TxId
Consensus.byronIdTx ATxAux ByteString
tx) ATxAux ByteString
tx
    --TODO: add the above as mkByronTx to the consensus code,
    -- matching mkShelleyTx below

toConsensusGenTx (TxInByronSpecial GenTx ByronBlock
gtx EraInMode ByronEra mode
ByronEraInByronMode) =
    OneEraGenTx '[ByronBlock] -> GenTx (HardForkBlock '[ByronBlock])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS GenTx '[ByronBlock] -> OneEraGenTx '[ByronBlock]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ByronBlock -> NS GenTx '[ByronBlock]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ByronBlock
gtx))

toConsensusGenTx (TxInByronSpecial GenTx ByronBlock
gtx EraInMode ByronEra mode
ByronEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx ByronBlock
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx ByronBlock
gtx))

toConsensusGenTx (TxInMode (ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
tx) EraInMode era mode
ShelleyEraInShelleyMode) =
    OneEraGenTx '[ShelleyBlock (ShelleyEra StandardCrypto)]
-> GenTx
     (HardForkBlock '[ShelleyBlock (ShelleyEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS GenTx '[ShelleyBlock (ShelleyEra StandardCrypto)]
-> OneEraGenTx '[ShelleyBlock (ShelleyEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
-> NS GenTx '[ShelleyBlock (ShelleyEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
tx'))
  where
    tx' :: GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
tx' = Tx (ShelleyEra StandardCrypto)
-> GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
Consensus.mkShelleyTx Tx (ShelleyEra StandardCrypto)
Tx (ShelleyLedgerEra era)
tx

toConsensusGenTx (TxInMode (ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
tx) EraInMode era mode
ShelleyEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
-> NS
     GenTx
     '[ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
tx')))
  where
    tx' :: GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
tx' = Tx (ShelleyEra StandardCrypto)
-> GenTx (ShelleyBlock (ShelleyEra StandardCrypto))
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
Consensus.mkShelleyTx Tx (ShelleyEra StandardCrypto)
Tx (ShelleyLedgerEra era)
tx

toConsensusGenTx (TxInMode (ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
tx) EraInMode era mode
AllegraEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (ShelleyBlock (AllegraEra StandardCrypto))
-> NS
     GenTx
     '[ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (ShelleyBlock (AllegraEra StandardCrypto))
tx'))))
  where
    tx' :: GenTx (ShelleyBlock (AllegraEra StandardCrypto))
tx' = Tx (AllegraEra StandardCrypto)
-> GenTx (ShelleyBlock (AllegraEra StandardCrypto))
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
Consensus.mkShelleyTx Tx (AllegraEra StandardCrypto)
Tx (ShelleyLedgerEra era)
tx

toConsensusGenTx (TxInMode (ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
tx) EraInMode era mode
MaryEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (ShelleyBlock (MaryEra StandardCrypto))
-> NS
     GenTx
     '[ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (ShelleyBlock (MaryEra StandardCrypto))
tx')))))
  where
    tx' :: GenTx (ShelleyBlock (MaryEra StandardCrypto))
tx' = Tx (MaryEra StandardCrypto)
-> GenTx (ShelleyBlock (MaryEra StandardCrypto))
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
Consensus.mkShelleyTx Tx (MaryEra StandardCrypto)
Tx (ShelleyLedgerEra era)
tx

toConsensusGenTx (TxInMode (ShelleyTx ShelleyBasedEra era
_ Tx (ShelleyLedgerEra era)
tx) EraInMode era mode
AlonzoEraInCardanoMode) =
    OneEraGenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> GenTx
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
Consensus.HardForkGenTx (NS
  GenTx
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> OneEraGenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
Consensus.OneEraGenTx (NS
  GenTx
  '[ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS
  GenTx
  '[ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (NS GenTx '[ShelleyBlock (AlonzoEra StandardCrypto)]
-> NS
     GenTx
     '[ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (xs :: [k]) (x :: k).
NS a xs -> NS a (x : xs)
S (GenTx (ShelleyBlock (AlonzoEra StandardCrypto))
-> NS GenTx '[ShelleyBlock (AlonzoEra StandardCrypto)]
forall k (a :: k -> *) (x :: k) (xs :: [k]). a x -> NS a (x : xs)
Z GenTx (ShelleyBlock (AlonzoEra StandardCrypto))
tx'))))))
  where
    tx' :: GenTx (ShelleyBlock (AlonzoEra StandardCrypto))
tx' = Tx (AlonzoEra StandardCrypto)
-> GenTx (ShelleyBlock (AlonzoEra StandardCrypto))
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
Consensus.mkShelleyTx Tx (AlonzoEra StandardCrypto)
Tx (ShelleyLedgerEra 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

     ByronTxValidationError
       :: Consensus.ApplyTxErr Consensus.ByronBlock
       -> TxValidationError ByronEra

     ShelleyTxValidationError
       :: ShelleyBasedEra era
       -> Consensus.ApplyTxErr (Consensus.ShelleyBlock (ShelleyLedgerEra era))
       -> TxValidationError era

-- The GADT in the ShelleyTxValidationError case requires a custom instance
instance Show (TxValidationError era) where
    showsPrec :: Int -> TxValidationError era -> ShowS
showsPrec Int
p (ByronTxValidationError ApplyTxErr ByronBlock
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ByronTxValidationError "
        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 ByronBlock
ApplyMempoolPayloadErr
err
        )

    showsPrec Int
p (ShelleyTxValidationError ShelleyBasedEra era
ShelleyBasedEraShelley ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxValidationError ShelleyBasedEraShelley "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (ShelleyEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (ShelleyEra StandardCrypto)
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err
        )

    showsPrec Int
p (ShelleyTxValidationError ShelleyBasedEra era
ShelleyBasedEraAllegra ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxValidationError ShelleyBasedEraAllegra "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (AllegraEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (AllegraEra StandardCrypto)
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err
        )

    showsPrec Int
p (ShelleyTxValidationError ShelleyBasedEra era
ShelleyBasedEraMary ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxValidationError ShelleyBasedEraMary "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (MaryEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (MaryEra StandardCrypto)
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err
        )

    showsPrec Int
p (ShelleyTxValidationError ShelleyBasedEra era
ShelleyBasedEraAlonzo ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
err) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxValidationError ShelleyBasedEraAlonzo "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ApplyTxError (AlonzoEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ApplyTxError (AlonzoEra StandardCrypto)
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra 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
ByronMode (Consensus.DegenApplyTxErr err) =
    TxValidationError ByronEra
-> EraInMode ByronEra ByronMode
-> TxValidationErrorInMode ByronMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ApplyTxErr ByronBlock -> TxValidationError ByronEra
ByronTxValidationError ApplyTxErr ByronBlock
err)
      EraInMode ByronEra ByronMode
ByronEraInByronMode

fromConsensusApplyTxErr ConsensusMode mode
ShelleyMode (Consensus.DegenApplyTxErr err) =
    TxValidationError ShelleyEra
-> EraInMode ShelleyEra ShelleyMode
-> TxValidationErrorInMode ShelleyMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ShelleyBasedEra ShelleyEra
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra ShelleyEra))
-> TxValidationError ShelleyEra
forall era.
ShelleyBasedEra era
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
-> TxValidationError era
ShelleyTxValidationError ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley ApplyTxErr (ShelleyBlock (ShelleyEra StandardCrypto))
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra ShelleyEra))
err)
      EraInMode ShelleyEra ShelleyMode
ShelleyEraInShelleyMode

fromConsensusApplyTxErr ConsensusMode mode
CardanoMode (Consensus.ApplyTxErrByron err) =
    TxValidationError ByronEra
-> EraInMode ByronEra CardanoMode
-> TxValidationErrorInMode CardanoMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ApplyTxErr ByronBlock -> TxValidationError ByronEra
ByronTxValidationError ApplyTxErr ByronBlock
err)
      EraInMode ByronEra CardanoMode
ByronEraInCardanoMode

fromConsensusApplyTxErr ConsensusMode mode
CardanoMode (Consensus.ApplyTxErrShelley err) =
    TxValidationError ShelleyEra
-> EraInMode ShelleyEra CardanoMode
-> TxValidationErrorInMode CardanoMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ShelleyBasedEra ShelleyEra
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra ShelleyEra))
-> TxValidationError ShelleyEra
forall era.
ShelleyBasedEra era
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
-> TxValidationError era
ShelleyTxValidationError ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley ApplyTxErr (ShelleyBlock (ShelleyEra StandardCrypto))
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra ShelleyEra))
err)
      EraInMode ShelleyEra CardanoMode
ShelleyEraInCardanoMode

fromConsensusApplyTxErr ConsensusMode mode
CardanoMode (Consensus.ApplyTxErrAllegra err) =
    TxValidationError AllegraEra
-> EraInMode AllegraEra CardanoMode
-> TxValidationErrorInMode CardanoMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ShelleyBasedEra AllegraEra
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra AllegraEra))
-> TxValidationError AllegraEra
forall era.
ShelleyBasedEra era
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
-> TxValidationError era
ShelleyTxValidationError ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra ApplyTxErr (ShelleyBlock (AllegraEra StandardCrypto))
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra AllegraEra))
err)
      EraInMode AllegraEra CardanoMode
AllegraEraInCardanoMode

fromConsensusApplyTxErr ConsensusMode mode
CardanoMode (Consensus.ApplyTxErrMary err) =
    TxValidationError MaryEra
-> EraInMode MaryEra CardanoMode
-> TxValidationErrorInMode CardanoMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ShelleyBasedEra MaryEra
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra MaryEra))
-> TxValidationError MaryEra
forall era.
ShelleyBasedEra era
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
-> TxValidationError era
ShelleyTxValidationError ShelleyBasedEra MaryEra
ShelleyBasedEraMary ApplyTxErr (ShelleyBlock (MaryEra StandardCrypto))
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra MaryEra))
err)
      EraInMode MaryEra CardanoMode
MaryEraInCardanoMode

fromConsensusApplyTxErr ConsensusMode mode
CardanoMode (Consensus.ApplyTxErrAlonzo err) =
    TxValidationError AlonzoEra
-> EraInMode AlonzoEra CardanoMode
-> TxValidationErrorInMode CardanoMode
forall era mode.
TxValidationError era
-> EraInMode era mode -> TxValidationErrorInMode mode
TxValidationErrorInMode
      (ShelleyBasedEra AlonzoEra
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra AlonzoEra))
-> TxValidationError AlonzoEra
forall era.
ShelleyBasedEra era
-> ApplyTxErr (ShelleyBlock (ShelleyLedgerEra era))
-> TxValidationError era
ShelleyTxValidationError ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo ApplyTxErr (ShelleyBlock (AlonzoEra StandardCrypto))
ApplyTxErr (ShelleyBlock (ShelleyLedgerEra AlonzoEra))
err)
      EraInMode AlonzoEra CardanoMode
AlonzoEraInCardanoMode

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