{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}


-- | Transaction bodies
--
module Cardano.Api.TxBody (
    parseTxId,
    -- * Transaction bodies
    TxBody(.., TxBody),
    makeTransactionBody,
    TxBodyContent(..),
    TxBodyError(..),
    TxBodyScriptData(..),
    TxScriptValidity(..),
    TxScriptValiditySupportedInEra(..),

    ScriptValidity(..),
    scriptValidityToIsValid,
    isValidToScriptValidity,
    scriptValidityToTxScriptValidity,
    txScriptValidityToIsValid,
    txScriptValidityToScriptValidity,

    -- * Transaction Ids
    TxId(..),
    getTxId,
    getTxIdShelley,

    -- * Transaction inputs
    TxIn(..),
    TxIx(..),
    genesisUTxOPseudoTxIn,

    -- * Transaction outputs
    CtxTx, CtxUTxO,
    TxOut(..),
    TxOutValue(..),
    TxOutDatum(TxOutDatumNone, TxOutDatumHash, TxOutDatumInTx, TxOutDatumInline),
    toCtxUTxOTxOut,
    lovelaceToTxOutValue,
    prettyRenderTxOut,
    txOutValueToLovelace,
    txOutValueToValue,
    parseHash,
    TxOutInAnyEra(..),
    txOutInAnyEra,

    -- * Other transaction body types
    TxInsCollateral(..),
    TxInsReference(..),
    TxReturnCollateral(..),
    TxTotalCollateral(..),
    TxFee(..),
    TxValidityLowerBound(..),
    TxValidityUpperBound(..),
    TxMetadataInEra(..),
    TxAuxScripts(..),
    TxExtraKeyWitnesses(..),
    TxWithdrawals(..),
    TxCertificates(..),
    TxUpdateProposal(..),
    TxMintValue(..),

    -- ** Building vs viewing transactions
    BuildTxWith(..),
    BuildTx,
    ViewTx,

    -- * Era-dependent transaction body features
    CollateralSupportedInEra(..),
    MultiAssetSupportedInEra(..),
    OnlyAdaSupportedInEra(..),
    TxFeesExplicitInEra(..),
    TxFeesImplicitInEra(..),
    ValidityUpperBoundSupportedInEra(..),
    ValidityNoUpperBoundSupportedInEra(..),
    ValidityLowerBoundSupportedInEra(..),
    TxMetadataSupportedInEra(..),
    AuxScriptsSupportedInEra(..),
    TxExtraKeyWitnessesSupportedInEra(..),
    ScriptDataSupportedInEra(..),
    WithdrawalsSupportedInEra(..),
    CertificatesSupportedInEra(..),
    UpdateProposalSupportedInEra(..),
    TxTotalAndReturnCollateralSupportedInEra(..),

    -- ** Feature availability functions
    collateralSupportedInEra,
    multiAssetSupportedInEra,
    txFeesExplicitInEra,
    validityUpperBoundSupportedInEra,
    validityNoUpperBoundSupportedInEra,
    validityLowerBoundSupportedInEra,
    txMetadataSupportedInEra,
    auxScriptsSupportedInEra,
    extraKeyWitnessesSupportedInEra,
    scriptDataSupportedInEra,
    withdrawalsSupportedInEra,
    certificatesSupportedInEra,
    updateProposalSupportedInEra,
    txScriptValiditySupportedInShelleyBasedEra,
    txScriptValiditySupportedInCardanoEra,
    totalAndReturnCollateralSupportedInEra,

    -- * Inspecting 'ScriptWitness'es
    AnyScriptWitness(..),
    ScriptWitnessIndex(..),
    renderScriptWitnessIndex,
    collectTxBodyScriptWitnesses,

    -- * Conversion to inline data
    scriptDataToInlineDatum,

    -- * Internal conversion functions & types
    toByronTxId,
    toShelleyTxId,
    toShelleyTxIn,
    toShelleyTxOut,
    toShelleyTxOutAny,
    fromShelleyTxId,
    fromShelleyTxIn,
    fromShelleyTxOut,
    toAlonzoRdmrPtr,
    fromAlonzoRdmrPtr,
    fromByronTxIn,
    fromLedgerTxOuts,
    renderTxIn,

    -- * Misc helpers
    calculateExecutionUnitsLovelace,
    orderStakeAddrs,
    orderTxIns,

    -- * Data family instances
    AsType(AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody, AsMaryTxBody),
  ) where

import           Prelude

import           Control.Applicative (some)
import           Control.Monad (guard)
import           Data.Aeson (object, withObject, (.:), (.:?), (.=))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.Aeson.Types as Aeson
import           Data.Bifunctor (first)
import           Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BSC
import qualified Data.ByteString.Lazy as LBS
import           Data.Foldable (for_, toList)
import           Data.Function (on)
import           Data.List (intercalate, sortBy)
import qualified Data.List.NonEmpty as NonEmpty
import           Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import           Data.Maybe (catMaybes, fromMaybe, maybeToList)
import           Data.Scientific (toBoundedInteger)
import qualified Data.Sequence.Strict as Seq
import           Data.Set (Set)
import qualified Data.Set as Set
import           Data.String
import           Data.Text (Text)
import qualified Data.Text as Text
import           Data.Type.Equality (TestEquality (..), (:~:) (Refl))
import           Data.Word (Word16, Word32, Word64)
import           GHC.Generics
import           GHC.Records (HasField (..))
import           Text.Parsec ((<?>))
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.String as Parsec

import           Cardano.Binary (Annotated (..), reAnnotate, recoverBytes)
import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Ledger.Serialization as CBOR (decodeNullMaybe, encodeNullMaybe, mkSized,
                   sizedValue)
import           Cardano.Slotting.Slot (SlotNo (..))

import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Chain.UTxO as Byron
import qualified Cardano.Crypto.Hashing as Byron

import qualified Cardano.Ledger.Address as Shelley
import qualified Cardano.Ledger.AuxiliaryData as Ledger (hashAuxiliaryData)
import           Cardano.Ledger.BaseTypes (StrictMaybe (..), maybeToStrictMaybe)
import qualified Cardano.Ledger.Coin as Ledger
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Credential as Shelley
import           Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.Keys as Shelley
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.Shelley.Constraints as Ledger

import qualified Cardano.Ledger.Shelley.Genesis as Shelley
import qualified Cardano.Ledger.Shelley.Metadata as Shelley
import qualified Cardano.Ledger.Shelley.Tx as Shelley
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
import qualified Cardano.Ledger.TxIn as Ledger

import qualified Cardano.Ledger.Mary.Value as Mary
import qualified Cardano.Ledger.ShelleyMA.AuxiliaryData as Allegra
import qualified Cardano.Ledger.ShelleyMA.AuxiliaryData as Mary
import qualified Cardano.Ledger.ShelleyMA.TxBody as Allegra
import qualified Cardano.Ledger.ShelleyMA.TxBody as Mary
import           Cardano.Ledger.Val (isZero)

import qualified Cardano.Ledger.Alonzo as Alonzo
import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Cardano.Ledger.Alonzo.Language as Alonzo
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo
import qualified Cardano.Ledger.Alonzo.TxWitness as Alonzo

import qualified Cardano.Ledger.Babbage as Babbage
import qualified Cardano.Ledger.Babbage.PParams as Babbage
import qualified Cardano.Ledger.Babbage.TxBody as Babbage
import           Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardAlonzo, StandardBabbage,
                   StandardMary, StandardShelley)

import           Cardano.Api.Address
import           Cardano.Api.Certificate
import           Cardano.Api.Eras
import           Cardano.Api.Error
import           Cardano.Api.HasTypeProxy
import           Cardano.Api.Hash
import           Cardano.Api.KeysByron
import           Cardano.Api.KeysShelley
import           Cardano.Api.NetworkId
import           Cardano.Api.ProtocolParameters
import           Cardano.Api.Script
import           Cardano.Api.ScriptData
import           Cardano.Api.SerialiseCBOR
import           Cardano.Api.SerialiseJSON
import           Cardano.Api.SerialiseRaw
import           Cardano.Api.SerialiseTextEnvelope
import           Cardano.Api.TxIn
import           Cardano.Api.TxMetadata
import           Cardano.Api.Utils
import           Cardano.Api.Value
import           Cardano.Api.ValueParser


{- HLINT ignore "Redundant flip" -}
{- HLINT ignore "Use section" -}

-- | Indicates whether a script is expected to fail or pass validation.
data ScriptValidity
  = ScriptInvalid -- ^ Script is expected to fail validation.
                  -- Transactions marked as such can include scripts that fail validation.
                  -- Such transactions may be submitted to the chain, in which case the
                  -- collateral will be taken upon on chain script validation failure.

  | ScriptValid   -- ^ Script is expected to pass validation.
                  -- Transactions marked as such cannot include scripts that fail validation.

  deriving (ScriptValidity -> ScriptValidity -> Bool
(ScriptValidity -> ScriptValidity -> Bool)
-> (ScriptValidity -> ScriptValidity -> Bool) -> Eq ScriptValidity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScriptValidity -> ScriptValidity -> Bool
$c/= :: ScriptValidity -> ScriptValidity -> Bool
== :: ScriptValidity -> ScriptValidity -> Bool
$c== :: ScriptValidity -> ScriptValidity -> Bool
Eq, Int -> ScriptValidity -> ShowS
[ScriptValidity] -> ShowS
ScriptValidity -> String
(Int -> ScriptValidity -> ShowS)
-> (ScriptValidity -> String)
-> ([ScriptValidity] -> ShowS)
-> Show ScriptValidity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScriptValidity] -> ShowS
$cshowList :: [ScriptValidity] -> ShowS
show :: ScriptValidity -> String
$cshow :: ScriptValidity -> String
showsPrec :: Int -> ScriptValidity -> ShowS
$cshowsPrec :: Int -> ScriptValidity -> ShowS
Show)

instance ToCBOR ScriptValidity where
  toCBOR :: ScriptValidity -> Encoding
toCBOR = IsValid -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (IsValid -> Encoding)
-> (ScriptValidity -> IsValid) -> ScriptValidity -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptValidity -> IsValid
scriptValidityToIsValid

instance FromCBOR ScriptValidity where
  fromCBOR :: Decoder s ScriptValidity
fromCBOR = IsValid -> ScriptValidity
isValidToScriptValidity (IsValid -> ScriptValidity)
-> Decoder s IsValid -> Decoder s ScriptValidity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s IsValid
forall a s. FromCBOR a => Decoder s a
fromCBOR

scriptValidityToIsValid :: ScriptValidity -> Alonzo.IsValid
scriptValidityToIsValid :: ScriptValidity -> IsValid
scriptValidityToIsValid ScriptValidity
ScriptInvalid = Bool -> IsValid
Alonzo.IsValid Bool
False
scriptValidityToIsValid ScriptValidity
ScriptValid = Bool -> IsValid
Alonzo.IsValid Bool
True

isValidToScriptValidity :: Alonzo.IsValid -> ScriptValidity
isValidToScriptValidity :: IsValid -> ScriptValidity
isValidToScriptValidity (Alonzo.IsValid Bool
False) = ScriptValidity
ScriptInvalid
isValidToScriptValidity (Alonzo.IsValid Bool
True) = ScriptValidity
ScriptValid

-- | A representation of whether the era supports tx script validity.
--
-- The Mary and subsequent eras support script validity.
--
data TxScriptValidity era where
  TxScriptValidityNone :: TxScriptValidity era

  -- | Tx script validity is supported in transactions in the 'Alonzo' era onwards.
  TxScriptValidity
    :: TxScriptValiditySupportedInEra era
    -> ScriptValidity
    -> TxScriptValidity era

deriving instance Eq   (TxScriptValiditySupportedInEra era)
deriving instance Show (TxScriptValiditySupportedInEra era)

data TxScriptValiditySupportedInEra era where
  TxScriptValiditySupportedInAlonzoEra  :: TxScriptValiditySupportedInEra AlonzoEra
  TxScriptValiditySupportedInBabbageEra :: TxScriptValiditySupportedInEra BabbageEra

deriving instance Eq   (TxScriptValidity era)
deriving instance Show (TxScriptValidity era)

txScriptValiditySupportedInCardanoEra :: CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInCardanoEra :: CardanoEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInCardanoEra CardanoEra era
ByronEra   = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInCardanoEra CardanoEra era
ShelleyEra = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInCardanoEra CardanoEra era
AllegraEra = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInCardanoEra CardanoEra era
MaryEra    = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInCardanoEra CardanoEra era
AlonzoEra  = TxScriptValiditySupportedInEra AlonzoEra
-> Maybe (TxScriptValiditySupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just TxScriptValiditySupportedInEra AlonzoEra
TxScriptValiditySupportedInAlonzoEra
txScriptValiditySupportedInCardanoEra CardanoEra era
BabbageEra = TxScriptValiditySupportedInEra BabbageEra
-> Maybe (TxScriptValiditySupportedInEra BabbageEra)
forall a. a -> Maybe a
Just TxScriptValiditySupportedInEra BabbageEra
TxScriptValiditySupportedInBabbageEra

txScriptValiditySupportedInShelleyBasedEra :: ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInShelleyBasedEra :: ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
ShelleyBasedEraShelley = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
ShelleyBasedEraAllegra = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
ShelleyBasedEraMary    = Maybe (TxScriptValiditySupportedInEra era)
forall a. Maybe a
Nothing
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
ShelleyBasedEraAlonzo  = TxScriptValiditySupportedInEra AlonzoEra
-> Maybe (TxScriptValiditySupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just TxScriptValiditySupportedInEra AlonzoEra
TxScriptValiditySupportedInAlonzoEra
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
ShelleyBasedEraBabbage = TxScriptValiditySupportedInEra BabbageEra
-> Maybe (TxScriptValiditySupportedInEra BabbageEra)
forall a. a -> Maybe a
Just TxScriptValiditySupportedInEra BabbageEra
TxScriptValiditySupportedInBabbageEra

txScriptValidityToScriptValidity :: TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity :: TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity TxScriptValidity era
TxScriptValidityNone = ScriptValidity
ScriptValid
txScriptValidityToScriptValidity (TxScriptValidity TxScriptValiditySupportedInEra era
_ ScriptValidity
scriptValidity) = ScriptValidity
scriptValidity

scriptValidityToTxScriptValidity :: ShelleyBasedEra era -> ScriptValidity -> TxScriptValidity era
scriptValidityToTxScriptValidity :: ShelleyBasedEra era -> ScriptValidity -> TxScriptValidity era
scriptValidityToTxScriptValidity ShelleyBasedEra era
era ScriptValidity
scriptValidity = case ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
forall era.
ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
era of
  Maybe (TxScriptValiditySupportedInEra era)
Nothing -> TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
  Just TxScriptValiditySupportedInEra era
witness -> TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
forall era.
TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
TxScriptValidity TxScriptValiditySupportedInEra era
witness ScriptValidity
scriptValidity

txScriptValidityToIsValid :: TxScriptValidity era -> Alonzo.IsValid
txScriptValidityToIsValid :: TxScriptValidity era -> IsValid
txScriptValidityToIsValid = ScriptValidity -> IsValid
scriptValidityToIsValid (ScriptValidity -> IsValid)
-> (TxScriptValidity era -> ScriptValidity)
-> TxScriptValidity era
-> IsValid
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxScriptValidity era -> ScriptValidity
forall era. TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity

-- ----------------------------------------------------------------------------
-- Transaction outputs
--

-- | The context is a transaction body
data CtxTx
-- | The context is the UTxO
data CtxUTxO

data TxOut ctx era = TxOut (AddressInEra    era)
                           (TxOutValue      era)
                           (TxOutDatum ctx  era)
                           (ReferenceScript era)

deriving instance Eq   (TxOut ctx era)
deriving instance Show (TxOut ctx era)

data TxOutInAnyEra where
     TxOutInAnyEra :: CardanoEra era
                   -> TxOut CtxTx era
                   -> TxOutInAnyEra

deriving instance Show TxOutInAnyEra

instance Eq TxOutInAnyEra where
  TxOutInAnyEra CardanoEra era
era1 TxOut CtxTx era
out1 == :: TxOutInAnyEra -> TxOutInAnyEra -> Bool
== TxOutInAnyEra CardanoEra era
era2 TxOut CtxTx era
out2 =
    case CardanoEra era -> CardanoEra era -> Maybe (era :~: era)
forall k (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality CardanoEra era
era1 CardanoEra era
era2 of
      Just era :~: era
Refl -> TxOut CtxTx era
out1 TxOut CtxTx era -> TxOut CtxTx era -> Bool
forall a. Eq a => a -> a -> Bool
== TxOut CtxTx era
TxOut CtxTx era
out2
      Maybe (era :~: era)
Nothing   -> Bool
False

-- | Convenience constructor for 'TxOutInAnyEra'
txOutInAnyEra :: IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra :: TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra = CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
forall era. CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
TxOutInAnyEra CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra

toCtxUTxOTxOut :: TxOut CtxTx  era -> TxOut CtxUTxO era
toCtxUTxOTxOut :: TxOut CtxTx era -> TxOut CtxUTxO era
toCtxUTxOTxOut (TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxTx era
d ReferenceScript era
refS) =
  let dat :: TxOutDatum CtxUTxO era
dat = case TxOutDatum CtxTx era
d of
              TxOutDatum CtxTx era
TxOutDatumNone -> TxOutDatum CtxUTxO era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
              TxOutDatumHash ScriptDataSupportedInEra era
s Hash ScriptData
h -> ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
s Hash ScriptData
h
              TxOutDatumInTx' ScriptDataSupportedInEra era
s Hash ScriptData
h ScriptData
_ -> ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
s Hash ScriptData
h
              TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
s ScriptData
sd -> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
s ScriptData
sd
  in AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxUTxO era
-> ReferenceScript era
-> TxOut CtxUTxO era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxUTxO era
dat ReferenceScript era
refS

instance IsCardanoEra era => ToJSON (TxOut ctx era) where
  toJSON :: TxOut ctx era -> Value
toJSON  = CardanoEra era -> TxOut ctx era -> Value
forall era ctx. CardanoEra era -> TxOut ctx era -> Value
txOutToJsonValue CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra

txOutToJsonValue :: CardanoEra era -> TxOut ctx era -> Aeson.Value
txOutToJsonValue :: CardanoEra era -> TxOut ctx era -> Value
txOutToJsonValue CardanoEra era
era (TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum ctx era
dat ReferenceScript era
refScript) =
  case CardanoEra era
era of
    CardanoEra era
ByronEra -> [Pair] -> Value
object [Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr, Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val]
    CardanoEra era
ShelleyEra -> [Pair] -> Value
object [Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr, Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val]
    CardanoEra era
AllegraEra -> [Pair] -> Value
object [Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr, Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val]
    CardanoEra era
MaryEra -> [Pair] -> Value
object [Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr, Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val]
    CardanoEra era
AlonzoEra -> [Pair] -> Value
object
                   [ Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr
                   , Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val
                   , TxOutDatum ctx era -> Pair
forall ctx era. TxOutDatum ctx era -> Pair
datHashJsonVal TxOutDatum ctx era
dat
                   , Key
"datum" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutDatum ctx era -> Value
forall ctx era. TxOutDatum ctx era -> Value
datJsonVal TxOutDatum ctx era
dat
                   ]
    CardanoEra era
BabbageEra ->
      [Pair] -> Value
object
        [ Key
"address" Key -> AddressInEra era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressInEra era
addr
        , Key
"value" Key -> TxOutValue era -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutValue era
val
        , TxOutDatum ctx era -> Pair
forall ctx era. TxOutDatum ctx era -> Pair
datHashJsonVal TxOutDatum ctx era
dat
        , Key
"datum" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutDatum ctx era -> Value
forall ctx era. TxOutDatum ctx era -> Value
datJsonVal TxOutDatum ctx era
dat
        , Key
"inlineDatum" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TxOutDatum ctx era -> Value
forall ctx era. TxOutDatum ctx era -> Value
inlineDatumJsonVal TxOutDatum ctx era
dat
        , Key
"referenceScript" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ReferenceScript era -> Value
forall era. ReferenceScript era -> Value
refScriptJsonVal ReferenceScript era
refScript
        ]
 where
   datHashJsonVal :: TxOutDatum ctx era -> Aeson.Pair
   datHashJsonVal :: TxOutDatum ctx era -> Pair
datHashJsonVal TxOutDatum ctx era
d =
     case TxOutDatum ctx era
d of
       TxOutDatum ctx era
TxOutDatumNone ->
         Key
"datumhash" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Value
Aeson.Null
       TxOutDatumHash ScriptDataSupportedInEra era
_ Hash ScriptData
h ->
         Key
"datumhash" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Hash ScriptData -> Value
forall a. ToJSON a => a -> Value
toJSON Hash ScriptData
h
       TxOutDatumInTx' ScriptDataSupportedInEra era
_ Hash ScriptData
h ScriptData
_ ->
         Key
"datumhash" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Hash ScriptData -> Value
forall a. ToJSON a => a -> Value
toJSON Hash ScriptData
h
       TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ ScriptData
datum ->
         Key
"inlineDatumhash"  Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Hash ScriptData -> Value
forall a. ToJSON a => a -> Value
toJSON (ScriptData -> Hash ScriptData
hashScriptData ScriptData
datum)

   datJsonVal :: TxOutDatum ctx era -> Aeson.Value
   datJsonVal :: TxOutDatum ctx era -> Value
datJsonVal TxOutDatum ctx era
d =
     case TxOutDatum ctx era
d of
       TxOutDatum ctx era
TxOutDatumNone -> Value
Aeson.Null
       TxOutDatumHash ScriptDataSupportedInEra era
_ Hash ScriptData
_ -> Value
Aeson.Null
       TxOutDatumInTx' ScriptDataSupportedInEra era
_ Hash ScriptData
_ ScriptData
datum -> ScriptDataJsonSchema -> ScriptData -> Value
scriptDataToJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema ScriptData
datum
       TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ ScriptData
_ -> Value
Aeson.Null

   inlineDatumJsonVal :: TxOutDatum ctx era -> Aeson.Value
   inlineDatumJsonVal :: TxOutDatum ctx era -> Value
inlineDatumJsonVal TxOutDatum ctx era
d =
     case TxOutDatum ctx era
d of
       TxOutDatum ctx era
TxOutDatumNone -> Value
Aeson.Null
       TxOutDatumHash {} -> Value
Aeson.Null
       TxOutDatumInTx'{} -> Value
Aeson.Null
       TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ ScriptData
datum -> ScriptDataJsonSchema -> ScriptData -> Value
scriptDataToJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema ScriptData
datum

   refScriptJsonVal :: ReferenceScript era -> Aeson.Value
   refScriptJsonVal :: ReferenceScript era -> Value
refScriptJsonVal ReferenceScript era
rScript =
     case ReferenceScript era
rScript of
       ReferenceScript ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ ScriptInAnyLang
s -> ScriptInAnyLang -> Value
forall a. ToJSON a => a -> Value
toJSON ScriptInAnyLang
s
       ReferenceScript era
ReferenceScriptNone -> Value
Aeson.Null

instance (IsShelleyBasedEra era, IsCardanoEra era)
  => FromJSON (TxOut CtxTx era) where
      parseJSON :: Value -> Parser (TxOut CtxTx era)
parseJSON = String
-> (Object -> Parser (TxOut CtxTx era))
-> Value
-> Parser (TxOut CtxTx era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TxOut" ((Object -> Parser (TxOut CtxTx era))
 -> Value -> Parser (TxOut CtxTx era))
-> (Object -> Parser (TxOut CtxTx era))
-> Value
-> Parser (TxOut CtxTx era)
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        case ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra :: ShelleyBasedEra era of
          ShelleyBasedEra era
ShelleyBasedEraShelley ->
            AddressInEra ShelleyEra
-> TxOutValue ShelleyEra
-> TxOutDatum CtxTx ShelleyEra
-> ReferenceScript ShelleyEra
-> TxOut CtxTx ShelleyEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra ShelleyEra
 -> TxOutValue ShelleyEra
 -> TxOutDatum CtxTx ShelleyEra
 -> ReferenceScript ShelleyEra
 -> TxOut CtxTx ShelleyEra)
-> Parser (AddressInEra ShelleyEra)
-> Parser
     (TxOutValue ShelleyEra
      -> TxOutDatum CtxTx ShelleyEra
      -> ReferenceScript ShelleyEra
      -> TxOut CtxTx ShelleyEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra ShelleyEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue ShelleyEra
   -> TxOutDatum CtxTx ShelleyEra
   -> ReferenceScript ShelleyEra
   -> TxOut CtxTx ShelleyEra)
-> Parser (TxOutValue ShelleyEra)
-> Parser
     (TxOutDatum CtxTx ShelleyEra
      -> ReferenceScript ShelleyEra -> TxOut CtxTx ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue ShelleyEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxTx ShelleyEra
   -> ReferenceScript ShelleyEra -> TxOut CtxTx ShelleyEra)
-> Parser (TxOutDatum CtxTx ShelleyEra)
-> Parser (ReferenceScript ShelleyEra -> TxOut CtxTx ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx ShelleyEra -> Parser (TxOutDatum CtxTx ShelleyEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx ShelleyEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript ShelleyEra -> TxOut CtxTx ShelleyEra)
-> Parser (ReferenceScript ShelleyEra)
-> Parser (TxOut CtxTx ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript ShelleyEra -> Parser (ReferenceScript ShelleyEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript ShelleyEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraMary ->
            AddressInEra MaryEra
-> TxOutValue MaryEra
-> TxOutDatum CtxTx MaryEra
-> ReferenceScript MaryEra
-> TxOut CtxTx MaryEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra MaryEra
 -> TxOutValue MaryEra
 -> TxOutDatum CtxTx MaryEra
 -> ReferenceScript MaryEra
 -> TxOut CtxTx MaryEra)
-> Parser (AddressInEra MaryEra)
-> Parser
     (TxOutValue MaryEra
      -> TxOutDatum CtxTx MaryEra
      -> ReferenceScript MaryEra
      -> TxOut CtxTx MaryEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra MaryEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue MaryEra
   -> TxOutDatum CtxTx MaryEra
   -> ReferenceScript MaryEra
   -> TxOut CtxTx MaryEra)
-> Parser (TxOutValue MaryEra)
-> Parser
     (TxOutDatum CtxTx MaryEra
      -> ReferenceScript MaryEra -> TxOut CtxTx MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue MaryEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxTx MaryEra
   -> ReferenceScript MaryEra -> TxOut CtxTx MaryEra)
-> Parser (TxOutDatum CtxTx MaryEra)
-> Parser (ReferenceScript MaryEra -> TxOut CtxTx MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx MaryEra -> Parser (TxOutDatum CtxTx MaryEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx MaryEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript MaryEra -> TxOut CtxTx MaryEra)
-> Parser (ReferenceScript MaryEra) -> Parser (TxOut CtxTx MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript MaryEra -> Parser (ReferenceScript MaryEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript MaryEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraAllegra ->
            AddressInEra AllegraEra
-> TxOutValue AllegraEra
-> TxOutDatum CtxTx AllegraEra
-> ReferenceScript AllegraEra
-> TxOut CtxTx AllegraEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra AllegraEra
 -> TxOutValue AllegraEra
 -> TxOutDatum CtxTx AllegraEra
 -> ReferenceScript AllegraEra
 -> TxOut CtxTx AllegraEra)
-> Parser (AddressInEra AllegraEra)
-> Parser
     (TxOutValue AllegraEra
      -> TxOutDatum CtxTx AllegraEra
      -> ReferenceScript AllegraEra
      -> TxOut CtxTx AllegraEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra AllegraEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue AllegraEra
   -> TxOutDatum CtxTx AllegraEra
   -> ReferenceScript AllegraEra
   -> TxOut CtxTx AllegraEra)
-> Parser (TxOutValue AllegraEra)
-> Parser
     (TxOutDatum CtxTx AllegraEra
      -> ReferenceScript AllegraEra -> TxOut CtxTx AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue AllegraEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxTx AllegraEra
   -> ReferenceScript AllegraEra -> TxOut CtxTx AllegraEra)
-> Parser (TxOutDatum CtxTx AllegraEra)
-> Parser (ReferenceScript AllegraEra -> TxOut CtxTx AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx AllegraEra -> Parser (TxOutDatum CtxTx AllegraEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx AllegraEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript AllegraEra -> TxOut CtxTx AllegraEra)
-> Parser (ReferenceScript AllegraEra)
-> Parser (TxOut CtxTx AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript AllegraEra -> Parser (ReferenceScript AllegraEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript AllegraEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraAlonzo -> ScriptDataSupportedInEra era -> Object -> Parser (TxOut CtxTx era)
alonzoTxOutParser ScriptDataSupportedInEra era
ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra Object
o

          ShelleyBasedEra era
ShelleyBasedEraBabbage -> do
            TxOut CtxTx era
alonzoTxOutInBabbage <- ScriptDataSupportedInEra era -> Object -> Parser (TxOut CtxTx era)
alonzoTxOutParser ScriptDataSupportedInEra era
ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra Object
o

            -- We check for the existence of inline datums
            Maybe (Hash ScriptData)
inlineDatumHash <- Object
o Object -> Key -> Parser (Maybe (Hash ScriptData))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inlineDatumhash"
            Maybe Value
inlineDatum <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inlineDatum"
            TxOutDatum CtxTx BabbageEra
mInlineDatum <-
              case (Maybe Value
inlineDatum, Maybe (Hash ScriptData)
inlineDatumHash) of
                (Just Value
dVal, Just Hash ScriptData
h) ->
                  case ScriptDataJsonSchema
-> Value -> Either ScriptDataJsonError ScriptData
scriptDataFromJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema Value
dVal of
                    Left ScriptDataJsonError
err ->
                      String -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (TxOutDatum CtxTx BabbageEra))
-> String -> Parser (TxOutDatum CtxTx BabbageEra)
forall a b. (a -> b) -> a -> b
$ String
"Error parsing TxOut JSON: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ScriptDataJsonError -> String
forall e. Error e => e -> String
displayError ScriptDataJsonError
err
                    Right ScriptData
sData ->
                      if ScriptData -> Hash ScriptData
hashScriptData ScriptData
sData Hash ScriptData -> Hash ScriptData -> Bool
forall a. Eq a => a -> a -> Bool
/= Hash ScriptData
h
                      then String -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Inline datum not equivalent to inline datum hash"
                      else TxOutDatum CtxTx BabbageEra -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxOutDatum CtxTx BabbageEra
 -> Parser (TxOutDatum CtxTx BabbageEra))
-> TxOutDatum CtxTx BabbageEra
-> Parser (TxOutDatum CtxTx BabbageEra)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> ScriptData -> TxOutDatum CtxTx BabbageEra
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra ScriptData
sData
                (Maybe Value
Nothing, Maybe (Hash ScriptData)
Nothing) -> TxOutDatum CtxTx BabbageEra -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx BabbageEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                (Maybe Value
_,Maybe (Hash ScriptData)
_) -> String -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Should not be possible to create a tx output with either an inline datum hash or an inline datum"

            Maybe ScriptInAnyLang
mReferenceScript <- Object
o Object -> Key -> Parser (Maybe ScriptInAnyLang)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"referenceScript"

            TxOut CtxTx BabbageEra
-> TxOutDatum CtxTx BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxTx BabbageEra)
reconcile TxOut CtxTx era
TxOut CtxTx BabbageEra
alonzoTxOutInBabbage TxOutDatum CtxTx BabbageEra
mInlineDatum Maybe ScriptInAnyLang
mReferenceScript
         where
           reconcile
             :: TxOut CtxTx BabbageEra -- ^ Alonzo era datum in Babbage era
             -> TxOutDatum CtxTx BabbageEra -- ^ Babbagae inline datum
             -> Maybe ScriptInAnyLang
             -> Aeson.Parser (TxOut CtxTx BabbageEra)
           reconcile :: TxOut CtxTx BabbageEra
-> TxOutDatum CtxTx BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxTx BabbageEra)
reconcile top :: TxOut CtxTx BabbageEra
top@(TxOut AddressInEra BabbageEra
addr TxOutValue BabbageEra
v TxOutDatum CtxTx BabbageEra
dat ReferenceScript BabbageEra
r) TxOutDatum CtxTx BabbageEra
babbageDatum Maybe ScriptInAnyLang
mBabRefScript = do
             -- We check for conflicting datums
             TxOutDatum CtxTx BabbageEra
finalDat <- case (TxOutDatum CtxTx BabbageEra
dat, TxOutDatum CtxTx BabbageEra
babbageDatum) of
                           (TxOutDatum CtxTx BabbageEra
TxOutDatumNone, TxOutDatum CtxTx BabbageEra
bDatum) -> TxOutDatum CtxTx BabbageEra -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx BabbageEra
bDatum
                           (TxOutDatum CtxTx BabbageEra
anyDat, TxOutDatum CtxTx BabbageEra
TxOutDatumNone) -> TxOutDatum CtxTx BabbageEra -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx BabbageEra
anyDat
                           (TxOutDatum CtxTx BabbageEra
alonzoDat, TxOutDatum CtxTx BabbageEra
babbageDat) ->
                             String -> Parser (TxOutDatum CtxTx BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (TxOutDatum CtxTx BabbageEra))
-> String -> Parser (TxOutDatum CtxTx BabbageEra)
forall a b. (a -> b) -> a -> b
$ String
"Parsed an Alonzo era datum and a Babbage era datum " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
                                    String
"TxOut: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TxOut CtxTx BabbageEra -> String
forall a. Show a => a -> String
show TxOut CtxTx BabbageEra
top String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
                                    String
"Alonzo datum: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TxOutDatum CtxTx BabbageEra -> String
forall a. Show a => a -> String
show TxOutDatum CtxTx BabbageEra
alonzoDat String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
                                    String
"Babbage dat: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TxOutDatum CtxTx BabbageEra -> String
forall a. Show a => a -> String
show TxOutDatum CtxTx BabbageEra
babbageDat
             ReferenceScript BabbageEra
finalRefScript <- case Maybe ScriptInAnyLang
mBabRefScript of
                                 Maybe ScriptInAnyLang
Nothing -> ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript BabbageEra
r
                                 Just ScriptInAnyLang
anyScript ->
                                   ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra))
-> ReferenceScript BabbageEra
-> Parser (ReferenceScript BabbageEra)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> ScriptInAnyLang -> ReferenceScript BabbageEra
forall era.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
ReferenceScript ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra ScriptInAnyLang
anyScript
             TxOut CtxTx BabbageEra -> Parser (TxOut CtxTx BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxOut CtxTx BabbageEra -> Parser (TxOut CtxTx BabbageEra))
-> TxOut CtxTx BabbageEra -> Parser (TxOut CtxTx BabbageEra)
forall a b. (a -> b) -> a -> b
$ AddressInEra BabbageEra
-> TxOutValue BabbageEra
-> TxOutDatum CtxTx BabbageEra
-> ReferenceScript BabbageEra
-> TxOut CtxTx BabbageEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra BabbageEra
addr TxOutValue BabbageEra
v TxOutDatum CtxTx BabbageEra
finalDat ReferenceScript BabbageEra
finalRefScript

           alonzoTxOutParser
             :: ScriptDataSupportedInEra era -> Aeson.Object -> Aeson.Parser (TxOut CtxTx era)
           alonzoTxOutParser :: ScriptDataSupportedInEra era -> Object -> Parser (TxOut CtxTx era)
alonzoTxOutParser ScriptDataSupportedInEra era
supp Object
o = do
            Maybe (Hash ScriptData)
mDatumHash <- Object
o Object -> Key -> Parser (Maybe (Hash ScriptData))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"datumhash"
            Maybe Value
mDatumVal <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"datum"
            case (Maybe Value
mDatumVal, Maybe (Hash ScriptData)
mDatumHash) of
               (Maybe Value
Nothing,Maybe (Hash ScriptData)
Nothing) -> AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum CtxTx era
 -> ReferenceScript era
 -> TxOut CtxTx era)
-> Parser (AddressInEra era)
-> Parser
     (TxOutValue era
      -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                                          Parser
  (TxOutValue era
   -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutValue era)
-> Parser
     (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                                          Parser
  (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutDatum CtxTx era)
-> Parser (ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx era -> Parser (TxOutDatum CtxTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                                          Parser (ReferenceScript era -> TxOut CtxTx era)
-> Parser (ReferenceScript era) -> Parser (TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era -> Parser (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
               (Just Value
dVal, Just Hash ScriptData
dHash) ->
                 case ScriptDataJsonSchema
-> Value -> Either ScriptDataJsonError ScriptData
scriptDataFromJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema Value
dVal of
                   Left ScriptDataJsonError
err ->
                     String -> Parser (TxOut CtxTx era)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (TxOut CtxTx era))
-> String -> Parser (TxOut CtxTx era)
forall a b. (a -> b) -> a -> b
$ String
"Error parsing TxOut JSON: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ScriptDataJsonError -> String
forall e. Error e => e -> String
displayError ScriptDataJsonError
err
                   Right ScriptData
sData -> AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum CtxTx era
 -> ReferenceScript era
 -> TxOut CtxTx era)
-> Parser (AddressInEra era)
-> Parser
     (TxOutValue era
      -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                                        Parser
  (TxOutValue era
   -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutValue era)
-> Parser
     (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                                        Parser
  (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutDatum CtxTx era)
-> Parser (ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx era -> Parser (TxOutDatum CtxTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx' ScriptDataSupportedInEra era
supp Hash ScriptData
dHash ScriptData
sData)
                                        Parser (ReferenceScript era -> TxOut CtxTx era)
-> Parser (ReferenceScript era) -> Parser (TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era -> Parser (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
               (Maybe Value
Nothing, Just Hash ScriptData
dHash) ->
                 AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum CtxTx era
 -> ReferenceScript era
 -> TxOut CtxTx era)
-> Parser (AddressInEra era)
-> Parser
     (TxOutValue era
      -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                       Parser
  (TxOutValue era
   -> TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutValue era)
-> Parser
     (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                       Parser
  (TxOutDatum CtxTx era -> ReferenceScript era -> TxOut CtxTx era)
-> Parser (TxOutDatum CtxTx era)
-> Parser (ReferenceScript era -> TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxTx era -> Parser (TxOutDatum CtxTx era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supp Hash ScriptData
dHash)
                       Parser (ReferenceScript era -> TxOut CtxTx era)
-> Parser (ReferenceScript era) -> Parser (TxOut CtxTx era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era -> Parser (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
               (Just Value
_dVal, Maybe (Hash ScriptData)
Nothing) -> String -> Parser (TxOut CtxTx era)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Only datum JSON was found, this should not be possible."

instance (IsShelleyBasedEra era, IsCardanoEra era)
  => FromJSON (TxOut CtxUTxO era) where
      parseJSON :: Value -> Parser (TxOut CtxUTxO era)
parseJSON = String
-> (Object -> Parser (TxOut CtxUTxO era))
-> Value
-> Parser (TxOut CtxUTxO era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TxOut" ((Object -> Parser (TxOut CtxUTxO era))
 -> Value -> Parser (TxOut CtxUTxO era))
-> (Object -> Parser (TxOut CtxUTxO era))
-> Value
-> Parser (TxOut CtxUTxO era)
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        case ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra :: ShelleyBasedEra era of
          ShelleyBasedEra era
ShelleyBasedEraShelley ->
            AddressInEra ShelleyEra
-> TxOutValue ShelleyEra
-> TxOutDatum CtxUTxO ShelleyEra
-> ReferenceScript ShelleyEra
-> TxOut CtxUTxO ShelleyEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra ShelleyEra
 -> TxOutValue ShelleyEra
 -> TxOutDatum CtxUTxO ShelleyEra
 -> ReferenceScript ShelleyEra
 -> TxOut CtxUTxO ShelleyEra)
-> Parser (AddressInEra ShelleyEra)
-> Parser
     (TxOutValue ShelleyEra
      -> TxOutDatum CtxUTxO ShelleyEra
      -> ReferenceScript ShelleyEra
      -> TxOut CtxUTxO ShelleyEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra ShelleyEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue ShelleyEra
   -> TxOutDatum CtxUTxO ShelleyEra
   -> ReferenceScript ShelleyEra
   -> TxOut CtxUTxO ShelleyEra)
-> Parser (TxOutValue ShelleyEra)
-> Parser
     (TxOutDatum CtxUTxO ShelleyEra
      -> ReferenceScript ShelleyEra -> TxOut CtxUTxO ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue ShelleyEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxUTxO ShelleyEra
   -> ReferenceScript ShelleyEra -> TxOut CtxUTxO ShelleyEra)
-> Parser (TxOutDatum CtxUTxO ShelleyEra)
-> Parser (ReferenceScript ShelleyEra -> TxOut CtxUTxO ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxUTxO ShelleyEra
-> Parser (TxOutDatum CtxUTxO ShelleyEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO ShelleyEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript ShelleyEra -> TxOut CtxUTxO ShelleyEra)
-> Parser (ReferenceScript ShelleyEra)
-> Parser (TxOut CtxUTxO ShelleyEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript ShelleyEra -> Parser (ReferenceScript ShelleyEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript ShelleyEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraMary ->
            AddressInEra MaryEra
-> TxOutValue MaryEra
-> TxOutDatum CtxUTxO MaryEra
-> ReferenceScript MaryEra
-> TxOut CtxUTxO MaryEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra MaryEra
 -> TxOutValue MaryEra
 -> TxOutDatum CtxUTxO MaryEra
 -> ReferenceScript MaryEra
 -> TxOut CtxUTxO MaryEra)
-> Parser (AddressInEra MaryEra)
-> Parser
     (TxOutValue MaryEra
      -> TxOutDatum CtxUTxO MaryEra
      -> ReferenceScript MaryEra
      -> TxOut CtxUTxO MaryEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra MaryEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue MaryEra
   -> TxOutDatum CtxUTxO MaryEra
   -> ReferenceScript MaryEra
   -> TxOut CtxUTxO MaryEra)
-> Parser (TxOutValue MaryEra)
-> Parser
     (TxOutDatum CtxUTxO MaryEra
      -> ReferenceScript MaryEra -> TxOut CtxUTxO MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue MaryEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxUTxO MaryEra
   -> ReferenceScript MaryEra -> TxOut CtxUTxO MaryEra)
-> Parser (TxOutDatum CtxUTxO MaryEra)
-> Parser (ReferenceScript MaryEra -> TxOut CtxUTxO MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxUTxO MaryEra -> Parser (TxOutDatum CtxUTxO MaryEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO MaryEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript MaryEra -> TxOut CtxUTxO MaryEra)
-> Parser (ReferenceScript MaryEra)
-> Parser (TxOut CtxUTxO MaryEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript MaryEra -> Parser (ReferenceScript MaryEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript MaryEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraAllegra ->
            AddressInEra AllegraEra
-> TxOutValue AllegraEra
-> TxOutDatum CtxUTxO AllegraEra
-> ReferenceScript AllegraEra
-> TxOut CtxUTxO AllegraEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra AllegraEra
 -> TxOutValue AllegraEra
 -> TxOutDatum CtxUTxO AllegraEra
 -> ReferenceScript AllegraEra
 -> TxOut CtxUTxO AllegraEra)
-> Parser (AddressInEra AllegraEra)
-> Parser
     (TxOutValue AllegraEra
      -> TxOutDatum CtxUTxO AllegraEra
      -> ReferenceScript AllegraEra
      -> TxOut CtxUTxO AllegraEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra AllegraEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                  Parser
  (TxOutValue AllegraEra
   -> TxOutDatum CtxUTxO AllegraEra
   -> ReferenceScript AllegraEra
   -> TxOut CtxUTxO AllegraEra)
-> Parser (TxOutValue AllegraEra)
-> Parser
     (TxOutDatum CtxUTxO AllegraEra
      -> ReferenceScript AllegraEra -> TxOut CtxUTxO AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue AllegraEra)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                  Parser
  (TxOutDatum CtxUTxO AllegraEra
   -> ReferenceScript AllegraEra -> TxOut CtxUTxO AllegraEra)
-> Parser (TxOutDatum CtxUTxO AllegraEra)
-> Parser (ReferenceScript AllegraEra -> TxOut CtxUTxO AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxUTxO AllegraEra
-> Parser (TxOutDatum CtxUTxO AllegraEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO AllegraEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                  Parser (ReferenceScript AllegraEra -> TxOut CtxUTxO AllegraEra)
-> Parser (ReferenceScript AllegraEra)
-> Parser (TxOut CtxUTxO AllegraEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript AllegraEra -> Parser (ReferenceScript AllegraEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript AllegraEra
forall era. ReferenceScript era
ReferenceScriptNone
          ShelleyBasedEra era
ShelleyBasedEraAlonzo -> ScriptDataSupportedInEra era
-> Object -> Parser (TxOut CtxUTxO era)
alonzoTxOutParser ScriptDataSupportedInEra era
ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra Object
o

          ShelleyBasedEra era
ShelleyBasedEraBabbage -> do
            TxOut CtxUTxO era
alonzoTxOutInBabbage <- ScriptDataSupportedInEra era
-> Object -> Parser (TxOut CtxUTxO era)
alonzoTxOutParser ScriptDataSupportedInEra era
ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra Object
o

            -- We check for the existence of inline datums
            Maybe (Hash ScriptData)
inlineDatumHash <- Object
o Object -> Key -> Parser (Maybe (Hash ScriptData))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inlineDatumhash"
            Maybe Value
inlineDatum <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inlineDatum"
            TxOutDatum CtxUTxO BabbageEra
mInlineDatum <-
              case (Maybe Value
inlineDatum, Maybe (Hash ScriptData)
inlineDatumHash) of
                (Just Value
dVal, Just Hash ScriptData
h) ->
                  case ScriptDataJsonSchema
-> Value -> Either ScriptDataJsonError ScriptData
scriptDataFromJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema Value
dVal of
                    Left ScriptDataJsonError
err ->
                      String -> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (TxOutDatum CtxUTxO BabbageEra))
-> String -> Parser (TxOutDatum CtxUTxO BabbageEra)
forall a b. (a -> b) -> a -> b
$ String
"Error parsing TxOut JSON: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ScriptDataJsonError -> String
forall e. Error e => e -> String
displayError ScriptDataJsonError
err
                    Right ScriptData
sData ->
                      if ScriptData -> Hash ScriptData
hashScriptData ScriptData
sData Hash ScriptData -> Hash ScriptData -> Bool
forall a. Eq a => a -> a -> Bool
/= Hash ScriptData
h
                      then String -> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Inline datum not equivalent to inline datum hash"
                      else TxOutDatum CtxUTxO BabbageEra
-> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxOutDatum CtxUTxO BabbageEra
 -> Parser (TxOutDatum CtxUTxO BabbageEra))
-> TxOutDatum CtxUTxO BabbageEra
-> Parser (TxOutDatum CtxUTxO BabbageEra)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> ScriptData -> TxOutDatum CtxUTxO BabbageEra
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra ScriptData
sData
                (Maybe Value
Nothing, Maybe (Hash ScriptData)
Nothing) -> TxOutDatum CtxUTxO BabbageEra
-> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO BabbageEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                (Maybe Value
_,Maybe (Hash ScriptData)
_) -> String -> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Should not be possible to create a tx output with either an inline datum hash or an inline datum"

            -- We check for a reference script
            Maybe ScriptInAnyLang
mReferenceScript <- Object
o Object -> Key -> Parser (Maybe ScriptInAnyLang)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"referenceScript"

            TxOut CtxUTxO BabbageEra
-> TxOutDatum CtxUTxO BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxUTxO BabbageEra)
reconcile TxOut CtxUTxO era
TxOut CtxUTxO BabbageEra
alonzoTxOutInBabbage TxOutDatum CtxUTxO BabbageEra
mInlineDatum Maybe ScriptInAnyLang
mReferenceScript
         where
           reconcile
             :: TxOut CtxUTxO BabbageEra -- ^ Alonzo era datum in Babbage era
             -> TxOutDatum CtxUTxO BabbageEra -- ^ Babbagae inline datum
             -> Maybe ScriptInAnyLang
             -> Aeson.Parser (TxOut CtxUTxO BabbageEra)
           reconcile :: TxOut CtxUTxO BabbageEra
-> TxOutDatum CtxUTxO BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxUTxO BabbageEra)
reconcile (TxOut AddressInEra BabbageEra
addr TxOutValue BabbageEra
v TxOutDatum CtxUTxO BabbageEra
dat ReferenceScript BabbageEra
r) TxOutDatum CtxUTxO BabbageEra
babbageDatum Maybe ScriptInAnyLang
mBabRefScript = do
             -- We check for conflicting datums
             TxOutDatum CtxUTxO BabbageEra
finalDat <- case (TxOutDatum CtxUTxO BabbageEra
dat, TxOutDatum CtxUTxO BabbageEra
babbageDatum) of
                           (TxOutDatum CtxUTxO BabbageEra
TxOutDatumNone, TxOutDatum CtxUTxO BabbageEra
bDatum) -> TxOutDatum CtxUTxO BabbageEra
-> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO BabbageEra
bDatum
                           (TxOutDatum CtxUTxO BabbageEra
anyDat, TxOutDatum CtxUTxO BabbageEra
TxOutDatumNone) -> TxOutDatum CtxUTxO BabbageEra
-> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO BabbageEra
anyDat
                           (TxOutDatum CtxUTxO BabbageEra
_,TxOutDatum CtxUTxO BabbageEra
_) -> String -> Parser (TxOutDatum CtxUTxO BabbageEra)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Parsed an Alonzo era datum and a Babbage era datum"
             ReferenceScript BabbageEra
finalRefScript <- case Maybe ScriptInAnyLang
mBabRefScript of
                                 Maybe ScriptInAnyLang
Nothing -> ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript BabbageEra
r
                                 Just ScriptInAnyLang
anyScript ->
                                   ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (ReferenceScript BabbageEra -> Parser (ReferenceScript BabbageEra))
-> ReferenceScript BabbageEra
-> Parser (ReferenceScript BabbageEra)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> ScriptInAnyLang -> ReferenceScript BabbageEra
forall era.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptInAnyLang -> ReferenceScript era
ReferenceScript ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra ScriptInAnyLang
anyScript

             TxOut CtxUTxO BabbageEra -> Parser (TxOut CtxUTxO BabbageEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxOut CtxUTxO BabbageEra -> Parser (TxOut CtxUTxO BabbageEra))
-> TxOut CtxUTxO BabbageEra -> Parser (TxOut CtxUTxO BabbageEra)
forall a b. (a -> b) -> a -> b
$ AddressInEra BabbageEra
-> TxOutValue BabbageEra
-> TxOutDatum CtxUTxO BabbageEra
-> ReferenceScript BabbageEra
-> TxOut CtxUTxO BabbageEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra BabbageEra
addr TxOutValue BabbageEra
v TxOutDatum CtxUTxO BabbageEra
finalDat ReferenceScript BabbageEra
finalRefScript

           alonzoTxOutParser :: ScriptDataSupportedInEra era -> Aeson.Object -> Aeson.Parser (TxOut CtxUTxO era)
           alonzoTxOutParser :: ScriptDataSupportedInEra era
-> Object -> Parser (TxOut CtxUTxO era)
alonzoTxOutParser ScriptDataSupportedInEra era
supp Object
o = do
            Maybe (Hash ScriptData)
mDatumHash <- Object
o Object -> Key -> Parser (Maybe (Hash ScriptData))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"datumhash"
            case Maybe (Hash ScriptData)
mDatumHash of
               Maybe (Hash ScriptData)
Nothing -> AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxUTxO era
-> ReferenceScript era
-> TxOut CtxUTxO era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum CtxUTxO era
 -> ReferenceScript era
 -> TxOut CtxUTxO era)
-> Parser (AddressInEra era)
-> Parser
     (TxOutValue era
      -> TxOutDatum CtxUTxO era
      -> ReferenceScript era
      -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                                          Parser
  (TxOutValue era
   -> TxOutDatum CtxUTxO era
   -> ReferenceScript era
   -> TxOut CtxUTxO era)
-> Parser (TxOutValue era)
-> Parser
     (TxOutDatum CtxUTxO era
      -> ReferenceScript era -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                                          Parser
  (TxOutDatum CtxUTxO era
   -> ReferenceScript era -> TxOut CtxUTxO era)
-> Parser (TxOutDatum CtxUTxO era)
-> Parser (ReferenceScript era -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxUTxO era -> Parser (TxOutDatum CtxUTxO era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxOutDatum CtxUTxO era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
                                          Parser (ReferenceScript era -> TxOut CtxUTxO era)
-> Parser (ReferenceScript era) -> Parser (TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era -> Parser (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
               Just Hash ScriptData
dHash ->
                 AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxUTxO era
-> ReferenceScript era
-> TxOut CtxUTxO era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (AddressInEra era
 -> TxOutValue era
 -> TxOutDatum CtxUTxO era
 -> ReferenceScript era
 -> TxOut CtxUTxO era)
-> Parser (AddressInEra era)
-> Parser
     (TxOutValue era
      -> TxOutDatum CtxUTxO era
      -> ReferenceScript era
      -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (AddressInEra era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"address"
                        Parser
  (TxOutValue era
   -> TxOutDatum CtxUTxO era
   -> ReferenceScript era
   -> TxOut CtxUTxO era)
-> Parser (TxOutValue era)
-> Parser
     (TxOutDatum CtxUTxO era
      -> ReferenceScript era -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (TxOutValue era)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
                        Parser
  (TxOutDatum CtxUTxO era
   -> ReferenceScript era -> TxOut CtxUTxO era)
-> Parser (TxOutDatum CtxUTxO era)
-> Parser (ReferenceScript era -> TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxOutDatum CtxUTxO era -> Parser (TxOutDatum CtxUTxO era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supp Hash ScriptData
dHash)
                        Parser (ReferenceScript era -> TxOut CtxUTxO era)
-> Parser (ReferenceScript era) -> Parser (TxOut CtxUTxO era)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReferenceScript era -> Parser (ReferenceScript era)
forall (m :: * -> *) a. Monad m => a -> m a
return ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone

fromByronTxOut :: Byron.TxOut -> TxOut ctx ByronEra
fromByronTxOut :: TxOut -> TxOut ctx ByronEra
fromByronTxOut (Byron.TxOut Address
addr Lovelace
value) =
  AddressInEra ByronEra
-> TxOutValue ByronEra
-> TxOutDatum ctx ByronEra
-> ReferenceScript ByronEra
-> TxOut ctx ByronEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
    (AddressTypeInEra ByronAddr ByronEra
-> Address ByronAddr -> AddressInEra ByronEra
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra AddressTypeInEra ByronAddr ByronEra
forall era. AddressTypeInEra ByronAddr era
ByronAddressInAnyEra (Address -> Address ByronAddr
ByronAddress Address
addr))
    (OnlyAdaSupportedInEra ByronEra -> Lovelace -> TxOutValue ByronEra
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra (Lovelace -> Lovelace
fromByronLovelace Lovelace
value))
     TxOutDatum ctx ByronEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript ByronEra
forall era. ReferenceScript era
ReferenceScriptNone


toByronTxOut :: TxOut ctx ByronEra -> Maybe Byron.TxOut
toByronTxOut :: TxOut ctx ByronEra -> Maybe TxOut
toByronTxOut (TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
addr))
                    (TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra Lovelace
value) TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_) =
    Address -> Lovelace -> TxOut
Byron.TxOut Address
addr (Lovelace -> TxOut) -> Maybe Lovelace -> Maybe TxOut
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lovelace -> Maybe Lovelace
toByronLovelace Lovelace
value

toByronTxOut (TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
_))
                    (TxOutValue MultiAssetSupportedInEra ByronEra
era Value
_) TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_) = case MultiAssetSupportedInEra ByronEra
era of {}

toByronTxOut (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEra ByronEra
era) ShelleyAddress{})
                    TxOutValue ByronEra
_ TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_) = case ShelleyBasedEra ByronEra
era of {}


toShelleyTxOut :: forall era ledgerera.
                  ShelleyLedgerEra era ~ ledgerera
               => ShelleyBasedEra era
               -> TxOut CtxUTxO era
               -> Ledger.TxOut ledgerera
toShelleyTxOut :: ShelleyBasedEra era -> TxOut CtxUTxO era -> TxOut ledgerera
toShelleyTxOut ShelleyBasedEra era
era (TxOut AddressInEra era
_ (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInByronEra Lovelace
_) TxOutDatum CtxUTxO era
_ ReferenceScript era
_) =
    case ShelleyBasedEra era
era of {}

toShelleyTxOut ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInShelleyEra Lovelace
value) TxOutDatum CtxUTxO era
_ ReferenceScript era
_) =
    Addr (Crypto (ShelleyEra StandardCrypto))
-> Value (ShelleyEra StandardCrypto)
-> TxOut (ShelleyEra StandardCrypto)
forall era.
(Era era, Show (Value era), Compactible (Value era)) =>
Addr (Crypto era) -> Value era -> TxOut era
Shelley.TxOut (AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr AddressInEra era
addr) (Lovelace -> Coin
toShelleyLovelace Lovelace
value)

toShelleyTxOut ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInAllegraEra Lovelace
value) TxOutDatum CtxUTxO era
_ ReferenceScript era
_) =
    Addr (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
-> Value (ShelleyMAEra 'Allegra StandardCrypto)
-> TxOut (ShelleyMAEra 'Allegra StandardCrypto)
forall era.
(Era era, Show (Value era), Compactible (Value era)) =>
Addr (Crypto era) -> Value era -> TxOut era
Shelley.TxOut (AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr AddressInEra era
addr) (Lovelace -> Coin
toShelleyLovelace Lovelace
value)

toShelleyTxOut ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInMaryEra Value
value) TxOutDatum CtxUTxO era
_ ReferenceScript era
_) =
    Addr (Crypto (ShelleyMAEra 'Mary StandardCrypto))
-> Value (ShelleyMAEra 'Mary StandardCrypto)
-> TxOut (ShelleyMAEra 'Mary StandardCrypto)
forall era.
(Era era, Show (Value era), Compactible (Value era)) =>
Addr (Crypto era) -> Value era -> TxOut era
Shelley.TxOut (AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr AddressInEra era
addr) (Value -> Value StandardCrypto
toMaryValue Value
value)

toShelleyTxOut ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInAlonzoEra Value
value) TxOutDatum CtxUTxO era
txoutdata ReferenceScript era
_) =
    Addr (Crypto (AlonzoEra StandardCrypto))
-> Value (AlonzoEra StandardCrypto)
-> StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
-> TxOut (AlonzoEra StandardCrypto)
forall era.
(Era era, Compactible (Value era), Val (Value era),
 HasCallStack) =>
Addr (Crypto era)
-> Value era -> StrictMaybe (DataHash (Crypto era)) -> TxOut era
Alonzo.TxOut (AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr AddressInEra era
addr) (Value -> Value StandardCrypto
toMaryValue Value
value)
                 (TxOutDatum CtxUTxO AlonzoEra
-> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash TxOutDatum CtxUTxO era
TxOutDatum CtxUTxO AlonzoEra
txoutdata)

toShelleyTxOut ShelleyBasedEra era
era (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInBabbageEra Value
value) TxOutDatum CtxUTxO era
txoutdata ReferenceScript era
refScript) =
    let cEra :: CardanoEra era
cEra = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era
    in Addr (Crypto (BabbageEra StandardCrypto))
-> Value (BabbageEra StandardCrypto)
-> Datum (BabbageEra StandardCrypto)
-> StrictMaybe (Script (BabbageEra StandardCrypto))
-> TxOut (BabbageEra StandardCrypto)
forall era.
(Era era, Compactible (Value era), Val (Value era),
 HasCallStack) =>
Addr (Crypto era)
-> Value era -> Datum era -> StrictMaybe (Script era) -> TxOut era
Babbage.TxOut (AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr AddressInEra era
addr) (Value -> Value StandardCrypto
toMaryValue Value
value)
                     (TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
forall era.
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto) =>
TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum TxOutDatum CtxUTxO era
txoutdata) (CardanoEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall era.
CardanoEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
refScriptToShelleyScript CardanoEra era
cEra ReferenceScript era
refScript)


fromShelleyTxOut :: ShelleyLedgerEra era ~ ledgerera
                 => ShelleyBasedEra era
                 -> Core.TxOut ledgerera
                 -> TxOut ctx era
fromShelleyTxOut :: ShelleyBasedEra era -> TxOut ledgerera -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
era TxOut ledgerera
ledgerTxOut =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
        AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
era Addr StandardCrypto
Addr (Crypto (ShelleyEra StandardCrypto))
addr)
              (OnlyAdaSupportedInEra ShelleyEra
-> Lovelace -> TxOutValue ShelleyEra
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra ShelleyEra
AdaOnlyInShelleyEra
                            (Coin -> Lovelace
fromShelleyLovelace Coin
Value (ShelleyEra StandardCrypto)
value))
               TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
      where
        Shelley.TxOut Addr (Crypto (ShelleyEra StandardCrypto))
addr Value (ShelleyEra StandardCrypto)
value = TxOut (ShelleyEra StandardCrypto)
TxOut ledgerera
ledgerTxOut

    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
        AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
era Addr StandardCrypto
Addr (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
addr)
              (OnlyAdaSupportedInEra AllegraEra
-> Lovelace -> TxOutValue AllegraEra
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra AllegraEra
AdaOnlyInAllegraEra
                            (Coin -> Lovelace
fromShelleyLovelace Coin
Value (ShelleyMAEra 'Allegra StandardCrypto)
value))
               TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
      where
        Shelley.TxOut Addr (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
addr Value (ShelleyMAEra 'Allegra StandardCrypto)
value = TxOut (ShelleyMAEra 'Allegra StandardCrypto)
TxOut ledgerera
ledgerTxOut

    ShelleyBasedEra era
ShelleyBasedEraMary ->
        AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
era Addr StandardCrypto
Addr (Crypto (ShelleyMAEra 'Mary StandardCrypto))
addr)
              (MultiAssetSupportedInEra MaryEra -> Value -> TxOutValue MaryEra
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra MaryEra
MultiAssetInMaryEra
                          (Value StandardCrypto -> Value
fromMaryValue Value StandardCrypto
Value (ShelleyMAEra 'Mary StandardCrypto)
value))
               TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
      where
        Shelley.TxOut Addr (Crypto (ShelleyMAEra 'Mary StandardCrypto))
addr Value (ShelleyMAEra 'Mary StandardCrypto)
value = TxOut (ShelleyMAEra 'Mary StandardCrypto)
TxOut ledgerera
ledgerTxOut

    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
       AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
era Addr StandardCrypto
Addr (Crypto (AlonzoEra StandardCrypto))
addr)
             (MultiAssetSupportedInEra AlonzoEra -> Value -> TxOutValue AlonzoEra
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra AlonzoEra
MultiAssetInAlonzoEra
                         (Value StandardCrypto -> Value
fromMaryValue Value StandardCrypto
Value (AlonzoEra StandardCrypto)
value))
             (ScriptDataSupportedInEra AlonzoEra
-> StrictMaybe (DataHash StandardCrypto)
-> TxOutDatum ctx AlonzoEra
forall era ctx.
ScriptDataSupportedInEra era
-> StrictMaybe (DataHash StandardCrypto) -> TxOutDatum ctx era
fromAlonzoTxOutDataHash ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra StrictMaybe (DataHash StandardCrypto)
StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
datahash)
             ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
      where
        Alonzo.TxOut Addr (Crypto (AlonzoEra StandardCrypto))
addr Value (AlonzoEra StandardCrypto)
value StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
datahash = TxOut ledgerera
TxOut (AlonzoEra StandardCrypto)
ledgerTxOut

    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
       AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
era Addr StandardCrypto
Addr (Crypto (BabbageEra StandardCrypto))
addr)
             (MultiAssetSupportedInEra BabbageEra
-> Value -> TxOutValue BabbageEra
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra BabbageEra
MultiAssetInBabbageEra
                         (Value StandardCrypto -> Value
fromMaryValue Value StandardCrypto
Value (BabbageEra StandardCrypto)
value))
             (ScriptDataSupportedInEra BabbageEra
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> Datum (BabbageEra StandardCrypto)
-> TxOutDatum ctx BabbageEra
forall ledgerera era ctx.
(Crypto ledgerera ~ StandardCrypto) =>
ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> Datum ledgerera
-> TxOutDatum ctx era
fromBabbageTxOutDatum
               ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra
               ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra
               Datum (BabbageEra StandardCrypto)
datum)
             (case StrictMaybe (Script (BabbageEra StandardCrypto))
mRefScript of
                StrictMaybe (Script (BabbageEra StandardCrypto))
SNothing -> ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
                SJust Script (BabbageEra StandardCrypto)
refScript ->
                  ShelleyBasedEra BabbageEra
-> Script (ShelleyLedgerEra BabbageEra)
-> ReferenceScript BabbageEra
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
fromShelleyScriptToReferenceScript ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage Script (BabbageEra StandardCrypto)
Script (ShelleyLedgerEra BabbageEra)
refScript)
      where
        Babbage.TxOut Addr (Crypto (BabbageEra StandardCrypto))
addr Value (BabbageEra StandardCrypto)
value Datum (BabbageEra StandardCrypto)
datum StrictMaybe (Script (BabbageEra StandardCrypto))
mRefScript = TxOut ledgerera
TxOut (BabbageEra StandardCrypto)
ledgerTxOut



-- TODO: If ledger creates an open type family for datums
-- we can consolidate this function with the Babbage version
toAlonzoTxOutDataHash
  :: TxOutDatum CtxUTxO AlonzoEra
  -> StrictMaybe (Alonzo.DataHash StandardCrypto)
toAlonzoTxOutDataHash :: TxOutDatum CtxUTxO AlonzoEra
-> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash  TxOutDatum CtxUTxO AlonzoEra
TxOutDatumNone                        = StrictMaybe (DataHash StandardCrypto)
forall a. StrictMaybe a
SNothing
toAlonzoTxOutDataHash (TxOutDatumHash ScriptDataSupportedInEra AlonzoEra
_ (ScriptDataHash dh)) = DataHash StandardCrypto -> StrictMaybe (DataHash StandardCrypto)
forall a. a -> StrictMaybe a
SJust DataHash StandardCrypto
dh
toAlonzoTxOutDataHash (TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra AlonzoEra
inlineDatumSupp ScriptData
_sd) =
  case ReferenceTxInsScriptsInlineDatumsSupportedInEra AlonzoEra
inlineDatumSupp :: ReferenceTxInsScriptsInlineDatumsSupportedInEra AlonzoEra of {}

fromAlonzoTxOutDataHash :: ScriptDataSupportedInEra era
                        -> StrictMaybe (Alonzo.DataHash StandardCrypto)
                        -> TxOutDatum ctx era
fromAlonzoTxOutDataHash :: ScriptDataSupportedInEra era
-> StrictMaybe (DataHash StandardCrypto) -> TxOutDatum ctx era
fromAlonzoTxOutDataHash ScriptDataSupportedInEra era
_    StrictMaybe (DataHash StandardCrypto)
SNothing  = TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
fromAlonzoTxOutDataHash ScriptDataSupportedInEra era
s (SJust DataHash StandardCrypto
dh)   = ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
s (DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
dh)

-- TODO: If ledger creates an open type family for datums
-- we can consolidate this function with the Alonzo version
toBabbageTxOutDatum
  :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
  => TxOutDatum CtxUTxO era -> Babbage.Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum :: TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum  TxOutDatum CtxUTxO era
TxOutDatumNone = Datum (ShelleyLedgerEra era)
forall era. Datum era
Babbage.NoDatum
toBabbageTxOutDatum (TxOutDatumHash ScriptDataSupportedInEra era
_ (ScriptDataHash dh)) = DataHash (Crypto (ShelleyLedgerEra era))
-> Datum (ShelleyLedgerEra era)
forall era. DataHash (Crypto era) -> Datum era
Babbage.DatumHash DataHash StandardCrypto
DataHash (Crypto (ShelleyLedgerEra era))
dh
toBabbageTxOutDatum (TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ ScriptData
sd) = ScriptData -> Datum (ShelleyLedgerEra era)
forall ledgerera. ScriptData -> Datum ledgerera
scriptDataToInlineDatum ScriptData
sd

fromBabbageTxOutDatum
  :: Ledger.Crypto ledgerera ~ StandardCrypto
  => ScriptDataSupportedInEra era
  -> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
  -> Babbage.Datum ledgerera
  -> TxOutDatum ctx era
fromBabbageTxOutDatum :: ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> Datum ledgerera
-> TxOutDatum ctx era
fromBabbageTxOutDatum ScriptDataSupportedInEra era
_ ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ Datum ledgerera
Babbage.NoDatum = TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
fromBabbageTxOutDatum ScriptDataSupportedInEra era
supp ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ (Babbage.DatumHash DataHash (Crypto ledgerera)
dh) =
  ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supp (Hash ScriptData -> TxOutDatum ctx era)
-> Hash ScriptData -> TxOutDatum ctx era
forall a b. (a -> b) -> a -> b
$ DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
DataHash (Crypto ledgerera)
dh
fromBabbageTxOutDatum ScriptDataSupportedInEra era
_ ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp (Babbage.Datum BinaryData ledgerera
binData) =
  ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp (ScriptData -> TxOutDatum ctx era)
-> ScriptData -> TxOutDatum ctx era
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> BinaryData ledgerera -> ScriptData
forall era ledgerera.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> BinaryData ledgerera -> ScriptData
binaryDataToScriptData ReferenceTxInsScriptsInlineDatumsSupportedInEra era
supp BinaryData ledgerera
binData



-- ----------------------------------------------------------------------------
-- Era-dependent transaction body features
--

-- | A representation of whether the era supports transactions with inputs used
-- only for collateral for script fees.
--
-- The Alonzo and subsequent eras support collateral inputs.
--
data CollateralSupportedInEra era where

     CollateralInAlonzoEra  :: CollateralSupportedInEra AlonzoEra
     CollateralInBabbageEra :: CollateralSupportedInEra BabbageEra

deriving instance Eq   (CollateralSupportedInEra era)
deriving instance Show (CollateralSupportedInEra era)

collateralSupportedInEra :: CardanoEra era
                         -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra :: CardanoEra era -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra CardanoEra era
ByronEra   = Maybe (CollateralSupportedInEra era)
forall a. Maybe a
Nothing
collateralSupportedInEra CardanoEra era
ShelleyEra = Maybe (CollateralSupportedInEra era)
forall a. Maybe a
Nothing
collateralSupportedInEra CardanoEra era
AllegraEra = Maybe (CollateralSupportedInEra era)
forall a. Maybe a
Nothing
collateralSupportedInEra CardanoEra era
MaryEra    = Maybe (CollateralSupportedInEra era)
forall a. Maybe a
Nothing
collateralSupportedInEra CardanoEra era
AlonzoEra  = CollateralSupportedInEra AlonzoEra
-> Maybe (CollateralSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just CollateralSupportedInEra AlonzoEra
CollateralInAlonzoEra
collateralSupportedInEra CardanoEra era
BabbageEra = CollateralSupportedInEra BabbageEra
-> Maybe (CollateralSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just CollateralSupportedInEra BabbageEra
CollateralInBabbageEra


-- | A representation of whether the era supports multi-asset transactions.
--
-- The Mary and subsequent eras support multi-asset transactions.
--
-- The negation of this is 'OnlyAdaSupportedInEra'.
--
data MultiAssetSupportedInEra era where

     -- | Multi-asset transactions are supported in the 'Mary' era.
     MultiAssetInMaryEra :: MultiAssetSupportedInEra MaryEra

     -- | Multi-asset transactions are supported in the 'Alonzo' era.
     MultiAssetInAlonzoEra :: MultiAssetSupportedInEra AlonzoEra

     -- | Multi-asset transactions are supported in the 'Babbage' era.
     MultiAssetInBabbageEra :: MultiAssetSupportedInEra BabbageEra

deriving instance Eq   (MultiAssetSupportedInEra era)
deriving instance Show (MultiAssetSupportedInEra era)

instance ToJSON (MultiAssetSupportedInEra era) where
  toJSON :: MultiAssetSupportedInEra era -> Value
toJSON = Text -> Value
Aeson.String (Text -> Value)
-> (MultiAssetSupportedInEra era -> Text)
-> MultiAssetSupportedInEra era
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack (String -> Text)
-> (MultiAssetSupportedInEra era -> String)
-> MultiAssetSupportedInEra era
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MultiAssetSupportedInEra era -> String
forall a. Show a => a -> String
show

-- | A representation of whether the era supports only ada transactions.
--
-- Prior to the Mary era only ada transactions are supported. Multi-assets are
-- supported from the Mary era onwards.
--
-- This is the negation of 'MultiAssetSupportedInEra'. It exists since we need
-- evidence to be positive.
--
data OnlyAdaSupportedInEra era where

     AdaOnlyInByronEra   :: OnlyAdaSupportedInEra ByronEra
     AdaOnlyInShelleyEra :: OnlyAdaSupportedInEra ShelleyEra
     AdaOnlyInAllegraEra :: OnlyAdaSupportedInEra AllegraEra

deriving instance Eq   (OnlyAdaSupportedInEra era)
deriving instance Show (OnlyAdaSupportedInEra era)

multiAssetSupportedInEra :: CardanoEra era
                         -> Either (OnlyAdaSupportedInEra era)
                                   (MultiAssetSupportedInEra era)
multiAssetSupportedInEra :: CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
ByronEra   = OnlyAdaSupportedInEra ByronEra
-> Either
     (OnlyAdaSupportedInEra ByronEra) (MultiAssetSupportedInEra era)
forall a b. a -> Either a b
Left OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra
multiAssetSupportedInEra CardanoEra era
ShelleyEra = OnlyAdaSupportedInEra ShelleyEra
-> Either
     (OnlyAdaSupportedInEra ShelleyEra) (MultiAssetSupportedInEra era)
forall a b. a -> Either a b
Left OnlyAdaSupportedInEra ShelleyEra
AdaOnlyInShelleyEra
multiAssetSupportedInEra CardanoEra era
AllegraEra = OnlyAdaSupportedInEra AllegraEra
-> Either
     (OnlyAdaSupportedInEra AllegraEra) (MultiAssetSupportedInEra era)
forall a b. a -> Either a b
Left OnlyAdaSupportedInEra AllegraEra
AdaOnlyInAllegraEra
multiAssetSupportedInEra CardanoEra era
MaryEra    = MultiAssetSupportedInEra MaryEra
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra MaryEra)
forall a b. b -> Either a b
Right MultiAssetSupportedInEra MaryEra
MultiAssetInMaryEra
multiAssetSupportedInEra CardanoEra era
AlonzoEra  = MultiAssetSupportedInEra AlonzoEra
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra AlonzoEra)
forall a b. b -> Either a b
Right MultiAssetSupportedInEra AlonzoEra
MultiAssetInAlonzoEra
multiAssetSupportedInEra CardanoEra era
BabbageEra = MultiAssetSupportedInEra BabbageEra
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra BabbageEra)
forall a b. b -> Either a b
Right MultiAssetSupportedInEra BabbageEra
MultiAssetInBabbageEra


-- | A representation of whether the era requires explicitly specified fees in
-- transactions.
--
-- The Byron era tx fees are implicit (as the difference bettween the sum of
-- outputs and sum of inputs), but all later eras the fees are specified in the
-- transaction explicitly.
--
data TxFeesExplicitInEra era where

     TxFeesExplicitInShelleyEra :: TxFeesExplicitInEra ShelleyEra
     TxFeesExplicitInAllegraEra :: TxFeesExplicitInEra AllegraEra
     TxFeesExplicitInMaryEra    :: TxFeesExplicitInEra MaryEra
     TxFeesExplicitInAlonzoEra  :: TxFeesExplicitInEra AlonzoEra
     TxFeesExplicitInBabbageEra :: TxFeesExplicitInEra BabbageEra

deriving instance Eq   (TxFeesExplicitInEra era)
deriving instance Show (TxFeesExplicitInEra era)

-- | A representation of whether the era requires implicitly specified fees in
-- transactions.
--
-- This is the negation of 'TxFeesExplicitInEra'.
--
data TxFeesImplicitInEra era where
     TxFeesImplicitInByronEra :: TxFeesImplicitInEra ByronEra

deriving instance Eq   (TxFeesImplicitInEra era)
deriving instance Show (TxFeesImplicitInEra era)

txFeesExplicitInEra :: CardanoEra era
                    -> Either (TxFeesImplicitInEra era)
                              (TxFeesExplicitInEra era)
txFeesExplicitInEra :: CardanoEra era
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra era)
txFeesExplicitInEra CardanoEra era
ByronEra   = TxFeesImplicitInEra ByronEra
-> Either (TxFeesImplicitInEra ByronEra) (TxFeesExplicitInEra era)
forall a b. a -> Either a b
Left  TxFeesImplicitInEra ByronEra
TxFeesImplicitInByronEra
txFeesExplicitInEra CardanoEra era
ShelleyEra = TxFeesExplicitInEra ShelleyEra
-> Either
     (TxFeesImplicitInEra era) (TxFeesExplicitInEra ShelleyEra)
forall a b. b -> Either a b
Right TxFeesExplicitInEra ShelleyEra
TxFeesExplicitInShelleyEra
txFeesExplicitInEra CardanoEra era
AllegraEra = TxFeesExplicitInEra AllegraEra
-> Either
     (TxFeesImplicitInEra era) (TxFeesExplicitInEra AllegraEra)
forall a b. b -> Either a b
Right TxFeesExplicitInEra AllegraEra
TxFeesExplicitInAllegraEra
txFeesExplicitInEra CardanoEra era
MaryEra    = TxFeesExplicitInEra MaryEra
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra MaryEra)
forall a b. b -> Either a b
Right TxFeesExplicitInEra MaryEra
TxFeesExplicitInMaryEra
txFeesExplicitInEra CardanoEra era
AlonzoEra  = TxFeesExplicitInEra AlonzoEra
-> Either (TxFeesImplicitInEra era) (TxFeesExplicitInEra AlonzoEra)
forall a b. b -> Either a b
Right TxFeesExplicitInEra AlonzoEra
TxFeesExplicitInAlonzoEra
txFeesExplicitInEra CardanoEra era
BabbageEra = TxFeesExplicitInEra BabbageEra
-> Either
     (TxFeesImplicitInEra era) (TxFeesExplicitInEra BabbageEra)
forall a b. b -> Either a b
Right TxFeesExplicitInEra BabbageEra
TxFeesExplicitInBabbageEra


-- | A representation of whether the era supports transactions with an upper
-- bound on the range of slots in which they are valid.
--
-- The Shelley and subsequent eras support an upper bound on the validity
-- range. In the Shelley era specifically it is actually required. It is
-- optional in later eras.
--
data ValidityUpperBoundSupportedInEra era where

     ValidityUpperBoundInShelleyEra :: ValidityUpperBoundSupportedInEra ShelleyEra
     ValidityUpperBoundInAllegraEra :: ValidityUpperBoundSupportedInEra AllegraEra
     ValidityUpperBoundInMaryEra    :: ValidityUpperBoundSupportedInEra MaryEra
     ValidityUpperBoundInAlonzoEra  :: ValidityUpperBoundSupportedInEra AlonzoEra
     ValidityUpperBoundInBabbageEra :: ValidityUpperBoundSupportedInEra BabbageEra

deriving instance Eq   (ValidityUpperBoundSupportedInEra era)
deriving instance Show (ValidityUpperBoundSupportedInEra era)

validityUpperBoundSupportedInEra :: CardanoEra era
                                 -> Maybe (ValidityUpperBoundSupportedInEra era)
validityUpperBoundSupportedInEra :: CardanoEra era -> Maybe (ValidityUpperBoundSupportedInEra era)
validityUpperBoundSupportedInEra CardanoEra era
ByronEra   = Maybe (ValidityUpperBoundSupportedInEra era)
forall a. Maybe a
Nothing
validityUpperBoundSupportedInEra CardanoEra era
ShelleyEra = ValidityUpperBoundSupportedInEra ShelleyEra
-> Maybe (ValidityUpperBoundSupportedInEra ShelleyEra)
forall a. a -> Maybe a
Just ValidityUpperBoundSupportedInEra ShelleyEra
ValidityUpperBoundInShelleyEra
validityUpperBoundSupportedInEra CardanoEra era
AllegraEra = ValidityUpperBoundSupportedInEra AllegraEra
-> Maybe (ValidityUpperBoundSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just ValidityUpperBoundSupportedInEra AllegraEra
ValidityUpperBoundInAllegraEra
validityUpperBoundSupportedInEra CardanoEra era
MaryEra    = ValidityUpperBoundSupportedInEra MaryEra
-> Maybe (ValidityUpperBoundSupportedInEra MaryEra)
forall a. a -> Maybe a
Just ValidityUpperBoundSupportedInEra MaryEra
ValidityUpperBoundInMaryEra
validityUpperBoundSupportedInEra CardanoEra era
AlonzoEra  = ValidityUpperBoundSupportedInEra AlonzoEra
-> Maybe (ValidityUpperBoundSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just ValidityUpperBoundSupportedInEra AlonzoEra
ValidityUpperBoundInAlonzoEra
validityUpperBoundSupportedInEra CardanoEra era
BabbageEra = ValidityUpperBoundSupportedInEra BabbageEra
-> Maybe (ValidityUpperBoundSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just ValidityUpperBoundSupportedInEra BabbageEra
ValidityUpperBoundInBabbageEra


-- | A representation of whether the era supports transactions having /no/
-- upper bound on the range of slots in which they are valid.
--
-- Note that the 'ShelleyEra' /does not support/ omitting a validity upper
-- bound. It was introduced as a /required/ field in Shelley and then made
-- optional in Allegra and subsequent eras.
--
-- The Byron era supports this by virtue of the fact that it does not support
-- validity ranges at all.
--
data ValidityNoUpperBoundSupportedInEra era where

     ValidityNoUpperBoundInByronEra   :: ValidityNoUpperBoundSupportedInEra ByronEra
     ValidityNoUpperBoundInAllegraEra :: ValidityNoUpperBoundSupportedInEra AllegraEra
     ValidityNoUpperBoundInMaryEra    :: ValidityNoUpperBoundSupportedInEra MaryEra
     ValidityNoUpperBoundInAlonzoEra  :: ValidityNoUpperBoundSupportedInEra AlonzoEra
     ValidityNoUpperBoundInBabbageEra :: ValidityNoUpperBoundSupportedInEra BabbageEra

deriving instance Eq   (ValidityNoUpperBoundSupportedInEra era)
deriving instance Show (ValidityNoUpperBoundSupportedInEra era)

validityNoUpperBoundSupportedInEra :: CardanoEra era
                                   -> Maybe (ValidityNoUpperBoundSupportedInEra era)
validityNoUpperBoundSupportedInEra :: CardanoEra era -> Maybe (ValidityNoUpperBoundSupportedInEra era)
validityNoUpperBoundSupportedInEra CardanoEra era
ByronEra   = ValidityNoUpperBoundSupportedInEra ByronEra
-> Maybe (ValidityNoUpperBoundSupportedInEra ByronEra)
forall a. a -> Maybe a
Just ValidityNoUpperBoundSupportedInEra ByronEra
ValidityNoUpperBoundInByronEra
validityNoUpperBoundSupportedInEra CardanoEra era
ShelleyEra = Maybe (ValidityNoUpperBoundSupportedInEra era)
forall a. Maybe a
Nothing
validityNoUpperBoundSupportedInEra CardanoEra era
AllegraEra = ValidityNoUpperBoundSupportedInEra AllegraEra
-> Maybe (ValidityNoUpperBoundSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just ValidityNoUpperBoundSupportedInEra AllegraEra
ValidityNoUpperBoundInAllegraEra
validityNoUpperBoundSupportedInEra CardanoEra era
MaryEra    = ValidityNoUpperBoundSupportedInEra MaryEra
-> Maybe (ValidityNoUpperBoundSupportedInEra MaryEra)
forall a. a -> Maybe a
Just ValidityNoUpperBoundSupportedInEra MaryEra
ValidityNoUpperBoundInMaryEra
validityNoUpperBoundSupportedInEra CardanoEra era
AlonzoEra  = ValidityNoUpperBoundSupportedInEra AlonzoEra
-> Maybe (ValidityNoUpperBoundSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just ValidityNoUpperBoundSupportedInEra AlonzoEra
ValidityNoUpperBoundInAlonzoEra
validityNoUpperBoundSupportedInEra CardanoEra era
BabbageEra = ValidityNoUpperBoundSupportedInEra BabbageEra
-> Maybe (ValidityNoUpperBoundSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just ValidityNoUpperBoundSupportedInEra BabbageEra
ValidityNoUpperBoundInBabbageEra


-- | A representation of whether the era supports transactions with a lower
-- bound on the range of slots in which they are valid.
--
-- The Allegra and subsequent eras support an optional lower bound on the
-- validity range. No equivalent of 'ValidityNoUpperBoundSupportedInEra' is
-- needed since all eras support having no lower bound.
--
data ValidityLowerBoundSupportedInEra era where

     ValidityLowerBoundInAllegraEra :: ValidityLowerBoundSupportedInEra AllegraEra
     ValidityLowerBoundInMaryEra    :: ValidityLowerBoundSupportedInEra MaryEra
     ValidityLowerBoundInAlonzoEra  :: ValidityLowerBoundSupportedInEra AlonzoEra
     ValidityLowerBoundInBabbageEra :: ValidityLowerBoundSupportedInEra BabbageEra

deriving instance Eq   (ValidityLowerBoundSupportedInEra era)
deriving instance Show (ValidityLowerBoundSupportedInEra era)

validityLowerBoundSupportedInEra :: CardanoEra era
                                 -> Maybe (ValidityLowerBoundSupportedInEra era)
validityLowerBoundSupportedInEra :: CardanoEra era -> Maybe (ValidityLowerBoundSupportedInEra era)
validityLowerBoundSupportedInEra CardanoEra era
ByronEra   = Maybe (ValidityLowerBoundSupportedInEra era)
forall a. Maybe a
Nothing
validityLowerBoundSupportedInEra CardanoEra era
ShelleyEra = Maybe (ValidityLowerBoundSupportedInEra era)
forall a. Maybe a
Nothing
validityLowerBoundSupportedInEra CardanoEra era
AllegraEra = ValidityLowerBoundSupportedInEra AllegraEra
-> Maybe (ValidityLowerBoundSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just ValidityLowerBoundSupportedInEra AllegraEra
ValidityLowerBoundInAllegraEra
validityLowerBoundSupportedInEra CardanoEra era
MaryEra    = ValidityLowerBoundSupportedInEra MaryEra
-> Maybe (ValidityLowerBoundSupportedInEra MaryEra)
forall a. a -> Maybe a
Just ValidityLowerBoundSupportedInEra MaryEra
ValidityLowerBoundInMaryEra
validityLowerBoundSupportedInEra CardanoEra era
AlonzoEra  = ValidityLowerBoundSupportedInEra AlonzoEra
-> Maybe (ValidityLowerBoundSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just ValidityLowerBoundSupportedInEra AlonzoEra
ValidityLowerBoundInAlonzoEra
validityLowerBoundSupportedInEra CardanoEra era
BabbageEra = ValidityLowerBoundSupportedInEra BabbageEra
-> Maybe (ValidityLowerBoundSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just ValidityLowerBoundSupportedInEra BabbageEra
ValidityLowerBoundInBabbageEra

-- | A representation of whether the era supports transaction metadata.
--
-- Transaction metadata is supported from the Shelley era onwards.
--
data TxMetadataSupportedInEra era where

     TxMetadataInShelleyEra :: TxMetadataSupportedInEra ShelleyEra
     TxMetadataInAllegraEra :: TxMetadataSupportedInEra AllegraEra
     TxMetadataInMaryEra    :: TxMetadataSupportedInEra MaryEra
     TxMetadataInAlonzoEra  :: TxMetadataSupportedInEra AlonzoEra
     TxMetadataInBabbageEra :: TxMetadataSupportedInEra BabbageEra

deriving instance Eq   (TxMetadataSupportedInEra era)
deriving instance Show (TxMetadataSupportedInEra era)

txMetadataSupportedInEra :: CardanoEra era
                         -> Maybe (TxMetadataSupportedInEra era)
txMetadataSupportedInEra :: CardanoEra era -> Maybe (TxMetadataSupportedInEra era)
txMetadataSupportedInEra CardanoEra era
ByronEra   = Maybe (TxMetadataSupportedInEra era)
forall a. Maybe a
Nothing
txMetadataSupportedInEra CardanoEra era
ShelleyEra = TxMetadataSupportedInEra ShelleyEra
-> Maybe (TxMetadataSupportedInEra ShelleyEra)
forall a. a -> Maybe a
Just TxMetadataSupportedInEra ShelleyEra
TxMetadataInShelleyEra
txMetadataSupportedInEra CardanoEra era
AllegraEra = TxMetadataSupportedInEra AllegraEra
-> Maybe (TxMetadataSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just TxMetadataSupportedInEra AllegraEra
TxMetadataInAllegraEra
txMetadataSupportedInEra CardanoEra era
MaryEra    = TxMetadataSupportedInEra MaryEra
-> Maybe (TxMetadataSupportedInEra MaryEra)
forall a. a -> Maybe a
Just TxMetadataSupportedInEra MaryEra
TxMetadataInMaryEra
txMetadataSupportedInEra CardanoEra era
AlonzoEra  = TxMetadataSupportedInEra AlonzoEra
-> Maybe (TxMetadataSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just TxMetadataSupportedInEra AlonzoEra
TxMetadataInAlonzoEra
txMetadataSupportedInEra CardanoEra era
BabbageEra = TxMetadataSupportedInEra BabbageEra
-> Maybe (TxMetadataSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just TxMetadataSupportedInEra BabbageEra
TxMetadataInBabbageEra


-- | A representation of whether the era supports auxiliary scripts in
-- transactions.
--
-- Auxiliary scripts are supported from the Allegra era onwards.
--
data AuxScriptsSupportedInEra era where

     AuxScriptsInAllegraEra :: AuxScriptsSupportedInEra AllegraEra
     AuxScriptsInMaryEra    :: AuxScriptsSupportedInEra MaryEra
     AuxScriptsInAlonzoEra  :: AuxScriptsSupportedInEra AlonzoEra
     AuxScriptsInBabbageEra :: AuxScriptsSupportedInEra BabbageEra

deriving instance Eq   (AuxScriptsSupportedInEra era)
deriving instance Show (AuxScriptsSupportedInEra era)

auxScriptsSupportedInEra :: CardanoEra era
                         -> Maybe (AuxScriptsSupportedInEra era)
auxScriptsSupportedInEra :: CardanoEra era -> Maybe (AuxScriptsSupportedInEra era)
auxScriptsSupportedInEra CardanoEra era
ByronEra   = Maybe (AuxScriptsSupportedInEra era)
forall a. Maybe a
Nothing
auxScriptsSupportedInEra CardanoEra era
ShelleyEra = Maybe (AuxScriptsSupportedInEra era)
forall a. Maybe a
Nothing
auxScriptsSupportedInEra CardanoEra era
AllegraEra = AuxScriptsSupportedInEra AllegraEra
-> Maybe (AuxScriptsSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just AuxScriptsSupportedInEra AllegraEra
AuxScriptsInAllegraEra
auxScriptsSupportedInEra CardanoEra era
MaryEra    = AuxScriptsSupportedInEra MaryEra
-> Maybe (AuxScriptsSupportedInEra MaryEra)
forall a. a -> Maybe a
Just AuxScriptsSupportedInEra MaryEra
AuxScriptsInMaryEra
auxScriptsSupportedInEra CardanoEra era
AlonzoEra  = AuxScriptsSupportedInEra AlonzoEra
-> Maybe (AuxScriptsSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just AuxScriptsSupportedInEra AlonzoEra
AuxScriptsInAlonzoEra
auxScriptsSupportedInEra CardanoEra era
BabbageEra = AuxScriptsSupportedInEra BabbageEra
-> Maybe (AuxScriptsSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just AuxScriptsSupportedInEra BabbageEra
AuxScriptsInBabbageEra


-- | A representation of whether the era supports transactions that specify
-- in the body that they need extra key witnesses, and where this fact is
-- visible to scripts.
--
-- Extra key witnesses visible to scripts are supported from the Alonzo era
-- onwards.
--
data TxExtraKeyWitnessesSupportedInEra era where

     ExtraKeyWitnessesInAlonzoEra  :: TxExtraKeyWitnessesSupportedInEra AlonzoEra
     ExtraKeyWitnessesInBabbageEra :: TxExtraKeyWitnessesSupportedInEra BabbageEra

deriving instance Eq   (TxExtraKeyWitnessesSupportedInEra era)
deriving instance Show (TxExtraKeyWitnessesSupportedInEra era)

extraKeyWitnessesSupportedInEra :: CardanoEra era
                                -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
extraKeyWitnessesSupportedInEra :: CardanoEra era -> Maybe (TxExtraKeyWitnessesSupportedInEra era)
extraKeyWitnessesSupportedInEra CardanoEra era
ByronEra   = Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall a. Maybe a
Nothing
extraKeyWitnessesSupportedInEra CardanoEra era
ShelleyEra = Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall a. Maybe a
Nothing
extraKeyWitnessesSupportedInEra CardanoEra era
AllegraEra = Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall a. Maybe a
Nothing
extraKeyWitnessesSupportedInEra CardanoEra era
MaryEra    = Maybe (TxExtraKeyWitnessesSupportedInEra era)
forall a. Maybe a
Nothing
extraKeyWitnessesSupportedInEra CardanoEra era
AlonzoEra  = TxExtraKeyWitnessesSupportedInEra AlonzoEra
-> Maybe (TxExtraKeyWitnessesSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just TxExtraKeyWitnessesSupportedInEra AlonzoEra
ExtraKeyWitnessesInAlonzoEra
extraKeyWitnessesSupportedInEra CardanoEra era
BabbageEra = TxExtraKeyWitnessesSupportedInEra BabbageEra
-> Maybe (TxExtraKeyWitnessesSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just TxExtraKeyWitnessesSupportedInEra BabbageEra
ExtraKeyWitnessesInBabbageEra


-- | A representation of whether the era supports multi-asset transactions.
--
-- The Mary and subsequent eras support multi-asset transactions.
--
-- The negation of this is 'OnlyAdaSupportedInEra'.
--
data ScriptDataSupportedInEra era where

     -- | Script data is supported in transactions in the 'Alonzo' era.
     ScriptDataInAlonzoEra  :: ScriptDataSupportedInEra AlonzoEra
     ScriptDataInBabbageEra :: ScriptDataSupportedInEra BabbageEra

deriving instance Eq   (ScriptDataSupportedInEra era)
deriving instance Show (ScriptDataSupportedInEra era)

scriptDataSupportedInEra :: CardanoEra era
                         -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra :: CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra era
ByronEra   = Maybe (ScriptDataSupportedInEra era)
forall a. Maybe a
Nothing
scriptDataSupportedInEra CardanoEra era
ShelleyEra = Maybe (ScriptDataSupportedInEra era)
forall a. Maybe a
Nothing
scriptDataSupportedInEra CardanoEra era
AllegraEra = Maybe (ScriptDataSupportedInEra era)
forall a. Maybe a
Nothing
scriptDataSupportedInEra CardanoEra era
MaryEra    = Maybe (ScriptDataSupportedInEra era)
forall a. Maybe a
Nothing
scriptDataSupportedInEra CardanoEra era
AlonzoEra  = ScriptDataSupportedInEra AlonzoEra
-> Maybe (ScriptDataSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra
scriptDataSupportedInEra CardanoEra era
BabbageEra = ScriptDataSupportedInEra BabbageEra
-> Maybe (ScriptDataSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra


-- | A representation of whether the era supports withdrawals from reward
-- accounts.
--
-- The Shelley and subsequent eras support stake addresses, their associated
-- reward accounts and support for withdrawals from them.
--
data WithdrawalsSupportedInEra era where

     WithdrawalsInShelleyEra :: WithdrawalsSupportedInEra ShelleyEra
     WithdrawalsInAllegraEra :: WithdrawalsSupportedInEra AllegraEra
     WithdrawalsInMaryEra    :: WithdrawalsSupportedInEra MaryEra
     WithdrawalsInAlonzoEra  :: WithdrawalsSupportedInEra AlonzoEra
     WithdrawalsInBabbageEra :: WithdrawalsSupportedInEra BabbageEra

deriving instance Eq   (WithdrawalsSupportedInEra era)
deriving instance Show (WithdrawalsSupportedInEra era)

withdrawalsSupportedInEra :: CardanoEra era
                          -> Maybe (WithdrawalsSupportedInEra era)
withdrawalsSupportedInEra :: CardanoEra era -> Maybe (WithdrawalsSupportedInEra era)
withdrawalsSupportedInEra CardanoEra era
ByronEra   = Maybe (WithdrawalsSupportedInEra era)
forall a. Maybe a
Nothing
withdrawalsSupportedInEra CardanoEra era
ShelleyEra = WithdrawalsSupportedInEra ShelleyEra
-> Maybe (WithdrawalsSupportedInEra ShelleyEra)
forall a. a -> Maybe a
Just WithdrawalsSupportedInEra ShelleyEra
WithdrawalsInShelleyEra
withdrawalsSupportedInEra CardanoEra era
AllegraEra = WithdrawalsSupportedInEra AllegraEra
-> Maybe (WithdrawalsSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just WithdrawalsSupportedInEra AllegraEra
WithdrawalsInAllegraEra
withdrawalsSupportedInEra CardanoEra era
MaryEra    = WithdrawalsSupportedInEra MaryEra
-> Maybe (WithdrawalsSupportedInEra MaryEra)
forall a. a -> Maybe a
Just WithdrawalsSupportedInEra MaryEra
WithdrawalsInMaryEra
withdrawalsSupportedInEra CardanoEra era
AlonzoEra  = WithdrawalsSupportedInEra AlonzoEra
-> Maybe (WithdrawalsSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just WithdrawalsSupportedInEra AlonzoEra
WithdrawalsInAlonzoEra
withdrawalsSupportedInEra CardanoEra era
BabbageEra = WithdrawalsSupportedInEra BabbageEra
-> Maybe (WithdrawalsSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just WithdrawalsSupportedInEra BabbageEra
WithdrawalsInBabbageEra


-- | A representation of whether the era supports 'Certificate's embedded in
-- transactions.
--
-- The Shelley and subsequent eras support such certificates.
--
data CertificatesSupportedInEra era where

     CertificatesInShelleyEra :: CertificatesSupportedInEra ShelleyEra
     CertificatesInAllegraEra :: CertificatesSupportedInEra AllegraEra
     CertificatesInMaryEra    :: CertificatesSupportedInEra MaryEra
     CertificatesInAlonzoEra  :: CertificatesSupportedInEra AlonzoEra
     CertificatesInBabbageEra :: CertificatesSupportedInEra BabbageEra

deriving instance Eq   (CertificatesSupportedInEra era)
deriving instance Show (CertificatesSupportedInEra era)

certificatesSupportedInEra :: CardanoEra era
                           -> Maybe (CertificatesSupportedInEra era)
certificatesSupportedInEra :: CardanoEra era -> Maybe (CertificatesSupportedInEra era)
certificatesSupportedInEra CardanoEra era
ByronEra   = Maybe (CertificatesSupportedInEra era)
forall a. Maybe a
Nothing
certificatesSupportedInEra CardanoEra era
ShelleyEra = CertificatesSupportedInEra ShelleyEra
-> Maybe (CertificatesSupportedInEra ShelleyEra)
forall a. a -> Maybe a
Just CertificatesSupportedInEra ShelleyEra
CertificatesInShelleyEra
certificatesSupportedInEra CardanoEra era
AllegraEra = CertificatesSupportedInEra AllegraEra
-> Maybe (CertificatesSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just CertificatesSupportedInEra AllegraEra
CertificatesInAllegraEra
certificatesSupportedInEra CardanoEra era
MaryEra    = CertificatesSupportedInEra MaryEra
-> Maybe (CertificatesSupportedInEra MaryEra)
forall a. a -> Maybe a
Just CertificatesSupportedInEra MaryEra
CertificatesInMaryEra
certificatesSupportedInEra CardanoEra era
AlonzoEra  = CertificatesSupportedInEra AlonzoEra
-> Maybe (CertificatesSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just CertificatesSupportedInEra AlonzoEra
CertificatesInAlonzoEra
certificatesSupportedInEra CardanoEra era
BabbageEra = CertificatesSupportedInEra BabbageEra
-> Maybe (CertificatesSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just CertificatesSupportedInEra BabbageEra
CertificatesInBabbageEra


-- | A representation of whether the era supports 'UpdateProposal's embedded in
-- transactions.
--
-- The Shelley and subsequent eras support such update proposals. They Byron
-- era has a notion of an update proposal, but it is a standalone chain object
-- and not embedded in a transaction.
--
data UpdateProposalSupportedInEra era where

     UpdateProposalInShelleyEra :: UpdateProposalSupportedInEra ShelleyEra
     UpdateProposalInAllegraEra :: UpdateProposalSupportedInEra AllegraEra
     UpdateProposalInMaryEra    :: UpdateProposalSupportedInEra MaryEra
     UpdateProposalInAlonzoEra  :: UpdateProposalSupportedInEra AlonzoEra
     UpdateProposalInBabbageEra :: UpdateProposalSupportedInEra BabbageEra

deriving instance Eq   (UpdateProposalSupportedInEra era)
deriving instance Show (UpdateProposalSupportedInEra era)

updateProposalSupportedInEra :: CardanoEra era
                             -> Maybe (UpdateProposalSupportedInEra era)
updateProposalSupportedInEra :: CardanoEra era -> Maybe (UpdateProposalSupportedInEra era)
updateProposalSupportedInEra CardanoEra era
ByronEra   = Maybe (UpdateProposalSupportedInEra era)
forall a. Maybe a
Nothing
updateProposalSupportedInEra CardanoEra era
ShelleyEra = UpdateProposalSupportedInEra ShelleyEra
-> Maybe (UpdateProposalSupportedInEra ShelleyEra)
forall a. a -> Maybe a
Just UpdateProposalSupportedInEra ShelleyEra
UpdateProposalInShelleyEra
updateProposalSupportedInEra CardanoEra era
AllegraEra = UpdateProposalSupportedInEra AllegraEra
-> Maybe (UpdateProposalSupportedInEra AllegraEra)
forall a. a -> Maybe a
Just UpdateProposalSupportedInEra AllegraEra
UpdateProposalInAllegraEra
updateProposalSupportedInEra CardanoEra era
MaryEra    = UpdateProposalSupportedInEra MaryEra
-> Maybe (UpdateProposalSupportedInEra MaryEra)
forall a. a -> Maybe a
Just UpdateProposalSupportedInEra MaryEra
UpdateProposalInMaryEra
updateProposalSupportedInEra CardanoEra era
AlonzoEra  = UpdateProposalSupportedInEra AlonzoEra
-> Maybe (UpdateProposalSupportedInEra AlonzoEra)
forall a. a -> Maybe a
Just UpdateProposalSupportedInEra AlonzoEra
UpdateProposalInAlonzoEra
updateProposalSupportedInEra CardanoEra era
BabbageEra = UpdateProposalSupportedInEra BabbageEra
-> Maybe (UpdateProposalSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just UpdateProposalSupportedInEra BabbageEra
UpdateProposalInBabbageEra


-- ----------------------------------------------------------------------------
-- Building vs viewing transactions
--

data BuildTx
data ViewTx

data BuildTxWith build a where

     ViewTx      ::      BuildTxWith ViewTx  a
     BuildTxWith :: a -> BuildTxWith BuildTx a

deriving instance Eq   a => Eq   (BuildTxWith build a)
deriving instance Show a => Show (BuildTxWith build a)

-- ----------------------------------------------------------------------------
-- Transaction input values (era-dependent)
--

type TxIns build era = [(TxIn, BuildTxWith build (Witness WitCtxTxIn era))]

data TxInsCollateral era where

     TxInsCollateralNone :: TxInsCollateral era

     TxInsCollateral     :: CollateralSupportedInEra era
                         -> [TxIn] -- Only key witnesses, no scripts.
                         -> TxInsCollateral era

deriving instance Eq   (TxInsCollateral era)
deriving instance Show (TxInsCollateral era)

data TxInsReference build era where

     TxInsReferenceNone :: TxInsReference build era

     TxInsReference     :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
                        -> [TxIn]
                        -> TxInsReference build era

deriving instance Eq   (TxInsReference build era)
deriving instance Show (TxInsReference build era)

-- ----------------------------------------------------------------------------
-- Transaction output values (era-dependent)
--

data TxOutValue era where

     TxOutAdaOnly :: OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era

     TxOutValue   :: MultiAssetSupportedInEra era -> Value -> TxOutValue era

deriving instance Eq   (TxOutValue era)
deriving instance Show (TxOutValue era)
deriving instance Generic (TxOutValue era)

instance ToJSON (TxOutValue era) where
  toJSON :: TxOutValue era -> Value
toJSON (TxOutAdaOnly OnlyAdaSupportedInEra era
_ Lovelace
ll) = Lovelace -> Value
forall a. ToJSON a => a -> Value
toJSON Lovelace
ll
  toJSON (TxOutValue MultiAssetSupportedInEra era
_ Value
val) = Value -> Value
forall a. ToJSON a => a -> Value
toJSON Value
val

instance IsCardanoEra era => FromJSON (TxOutValue era) where
  parseJSON :: Value -> Parser (TxOutValue era)
parseJSON = String
-> (Object -> Parser (TxOutValue era))
-> Value
-> Parser (TxOutValue era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TxOutValue" ((Object -> Parser (TxOutValue era))
 -> Value -> Parser (TxOutValue era))
-> (Object -> Parser (TxOutValue era))
-> Value
-> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra of
      Left OnlyAdaSupportedInEra era
onlyAda -> do
        Value
ll <- Object
o Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lovelace"
        TxOutValue era -> Parser (TxOutValue era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutValue era -> Parser (TxOutValue era))
-> TxOutValue era -> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra era
onlyAda (Lovelace -> TxOutValue era) -> Lovelace -> TxOutValue era
forall a b. (a -> b) -> a -> b
$ Value -> Lovelace
selectLovelace Value
ll
      Right MultiAssetSupportedInEra era
maSupported -> do
        let l :: [Pair]
l = Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList Object
o
        [Value]
vals <- (Pair -> Parser Value) -> [Pair] -> Parser [Value]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Pair -> Parser Value
decodeAssetId [Pair]
l
        TxOutValue era -> Parser (TxOutValue era)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutValue era -> Parser (TxOutValue era))
-> TxOutValue era -> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
maSupported (Value -> TxOutValue era) -> Value -> TxOutValue era
forall a b. (a -> b) -> a -> b
$ [Value] -> Value
forall a. Monoid a => [a] -> a
mconcat [Value]
vals
    where
     decodeAssetId :: (Aeson.Key, Aeson.Value) -> Aeson.Parser Value
     decodeAssetId :: Pair -> Parser Value
decodeAssetId (Key
polid, Aeson.Object Object
assetNameHm) = do
       let polId :: PolicyId
polId = String -> PolicyId
forall a. IsString a => String -> a
fromString (String -> PolicyId) -> (Text -> String) -> Text -> PolicyId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack (Text -> PolicyId) -> Text -> PolicyId
forall a b. (a -> b) -> a -> b
$ Key -> Text
Aeson.toText Key
polid
       [(AssetName, Quantity)]
aNameQuantity <- Object -> Parser [(AssetName, Quantity)]
decodeAssets Object
assetNameHm
       Value -> Parser Value
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Parser Value)
-> ([(AssetId, Quantity)] -> Value)
-> [(AssetId, Quantity)]
-> Parser Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(AssetId, Quantity)] -> Value
valueFromList
         ([(AssetId, Quantity)] -> Parser Value)
-> [(AssetId, Quantity)] -> Parser Value
forall a b. (a -> b) -> a -> b
$ ((AssetName, Quantity) -> (AssetId, Quantity))
-> [(AssetName, Quantity)] -> [(AssetId, Quantity)]
forall a b. (a -> b) -> [a] -> [b]
map ((AssetName -> AssetId)
-> (AssetName, Quantity) -> (AssetId, Quantity)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((AssetName -> AssetId)
 -> (AssetName, Quantity) -> (AssetId, Quantity))
-> (AssetName -> AssetId)
-> (AssetName, Quantity)
-> (AssetId, Quantity)
forall a b. (a -> b) -> a -> b
$ PolicyId -> AssetName -> AssetId
AssetId PolicyId
polId) [(AssetName, Quantity)]
aNameQuantity

     decodeAssetId (Key
"lovelace", Aeson.Number Scientific
sci) =
       case Scientific -> Maybe Word64
forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger Scientific
sci of
         Just (Word64
ll :: Word64) ->
           Value -> Parser Value
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Parser Value) -> Value -> Parser Value
forall a b. (a -> b) -> a -> b
$ [(AssetId, Quantity)] -> Value
valueFromList [(AssetId
AdaAssetId, Integer -> Quantity
Quantity (Integer -> Quantity) -> Integer -> Quantity
forall a b. (a -> b) -> a -> b
$ Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
ll)]
         Maybe Word64
Nothing ->
           String -> Parser Value
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Value) -> String -> Parser Value
forall a b. (a -> b) -> a -> b
$ String
"Expected a Bounded number but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
sci
     decodeAssetId Pair
wrong = String -> Parser Value
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Value) -> String -> Parser Value
forall a b. (a -> b) -> a -> b
$ String
"Expected a policy id and a JSON object but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Pair -> String
forall a. Show a => a -> String
show Pair
wrong

     decodeAssets :: Aeson.Object -> Aeson.Parser [(AssetName, Quantity)]
     decodeAssets :: Object -> Parser [(AssetName, Quantity)]
decodeAssets Object
assetNameHm =
       let l :: [Pair]
l = Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
KeyMap.toList Object
assetNameHm
       in (Pair -> Parser (AssetName, Quantity))
-> [Pair] -> Parser [(AssetName, Quantity)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Key
aName, Value
q) -> (,) (AssetName -> Quantity -> (AssetName, Quantity))
-> Parser AssetName -> Parser (Quantity -> (AssetName, Quantity))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key -> Parser AssetName
parseAssetName Key
aName Parser (Quantity -> (AssetName, Quantity))
-> Parser Quantity -> Parser (AssetName, Quantity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value -> Parser Quantity
decodeQuantity Value
q) [Pair]
l

     parseAssetName :: Aeson.Key -> Aeson.Parser AssetName
     parseAssetName :: Key -> Parser AssetName
parseAssetName Key
aName = Parser AssetName -> Text -> Parser AssetName
forall a. Parser a -> Text -> Parser a
runParsecParser Parser AssetName
assetName (Key -> Text
Aeson.toText Key
aName)

     decodeQuantity :: Aeson.Value -> Aeson.Parser Quantity
     decodeQuantity :: Value -> Parser Quantity
decodeQuantity (Aeson.Number Scientific
sci) =
       case Scientific -> Maybe Word64
forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger Scientific
sci of
         Just (Word64
ll :: Word64) -> Quantity -> Parser Quantity
forall (m :: * -> *) a. Monad m => a -> m a
return (Quantity -> Parser Quantity)
-> (Integer -> Quantity) -> Integer -> Parser Quantity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Quantity
Quantity (Integer -> Parser Quantity) -> Integer -> Parser Quantity
forall a b. (a -> b) -> a -> b
$ Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
ll
         Maybe Word64
Nothing -> String -> Parser Quantity
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Quantity) -> String -> Parser Quantity
forall a b. (a -> b) -> a -> b
$ String
"Expected a Bounded number but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
sci
     decodeQuantity Value
wrong = String -> Parser Quantity
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Quantity) -> String -> Parser Quantity
forall a b. (a -> b) -> a -> b
$ String
"Expected aeson Number but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
forall a. Show a => a -> String
show Value
wrong

lovelaceToTxOutValue :: IsCardanoEra era => Lovelace -> TxOutValue era
lovelaceToTxOutValue :: Lovelace -> TxOutValue era
lovelaceToTxOutValue Lovelace
l =
    case CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra of
      Left OnlyAdaSupportedInEra era
adaOnly     -> OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra era
adaOnly  Lovelace
l
      Right MultiAssetSupportedInEra era
multiAsset -> MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
multiAsset (Lovelace -> Value
lovelaceToValue Lovelace
l)

txOutValueToLovelace :: TxOutValue era -> Lovelace
txOutValueToLovelace :: TxOutValue era -> Lovelace
txOutValueToLovelace TxOutValue era
tv =
  case TxOutValue era
tv of
    TxOutAdaOnly OnlyAdaSupportedInEra era
_ Lovelace
l -> Lovelace
l
    TxOutValue MultiAssetSupportedInEra era
_ Value
v -> Value -> Lovelace
selectLovelace Value
v

txOutValueToValue :: TxOutValue era -> Value
txOutValueToValue :: TxOutValue era -> Value
txOutValueToValue TxOutValue era
tv =
  case TxOutValue era
tv of
    TxOutAdaOnly OnlyAdaSupportedInEra era
_ Lovelace
l -> Lovelace -> Value
lovelaceToValue Lovelace
l
    TxOutValue MultiAssetSupportedInEra era
_ Value
v -> Value
v

prettyRenderTxOut :: TxOutInAnyEra -> Text
prettyRenderTxOut :: TxOutInAnyEra -> Text
prettyRenderTxOut (TxOutInAnyEra CardanoEra era
_ (TxOut (AddressInEra AddressTypeInEra addrtype era
_ Address addrtype
addr) TxOutValue era
txOutVal TxOutDatum CtxTx era
_ ReferenceScript era
_)) =
     AddressAny -> Text
forall addr. SerialiseAddress addr => addr -> Text
serialiseAddress (Address addrtype -> AddressAny
forall addr. Address addr -> AddressAny
toAddressAny Address addrtype
addr) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" + "
  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Value -> Text
renderValue (TxOutValue era -> Value
forall era. TxOutValue era -> Value
txOutValueToValue TxOutValue era
txOutVal)

data TxReturnCollateral ctx era where

     TxReturnCollateralNone :: TxReturnCollateral ctx era

     TxReturnCollateral     :: TxTotalAndReturnCollateralSupportedInEra era
                            -> TxOut ctx era
                            -> TxReturnCollateral ctx era

deriving instance Eq   (TxReturnCollateral ctx era)
deriving instance Show (TxReturnCollateral ctx era)

data TxTotalCollateral era where

     TxTotalCollateralNone :: TxTotalCollateral era

     TxTotalCollateral     :: TxTotalAndReturnCollateralSupportedInEra era
                           -> Lovelace
                           -> TxTotalCollateral era

deriving instance Eq   (TxTotalCollateral era)
deriving instance Show (TxTotalCollateral era)

data TxTotalAndReturnCollateralSupportedInEra era where

     TxTotalAndReturnCollateralInBabbageEra :: TxTotalAndReturnCollateralSupportedInEra BabbageEra

deriving instance Eq   (TxTotalAndReturnCollateralSupportedInEra era)
deriving instance Show (TxTotalAndReturnCollateralSupportedInEra era)

totalAndReturnCollateralSupportedInEra
  :: CardanoEra era -> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra :: CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra CardanoEra era
ByronEra = Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a. Maybe a
Nothing
totalAndReturnCollateralSupportedInEra CardanoEra era
ShelleyEra = Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a. Maybe a
Nothing
totalAndReturnCollateralSupportedInEra CardanoEra era
AllegraEra = Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a. Maybe a
Nothing
totalAndReturnCollateralSupportedInEra CardanoEra era
MaryEra = Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a. Maybe a
Nothing
totalAndReturnCollateralSupportedInEra CardanoEra era
AlonzoEra = Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a. Maybe a
Nothing
totalAndReturnCollateralSupportedInEra CardanoEra era
BabbageEra = TxTotalAndReturnCollateralSupportedInEra BabbageEra
-> Maybe (TxTotalAndReturnCollateralSupportedInEra BabbageEra)
forall a. a -> Maybe a
Just TxTotalAndReturnCollateralSupportedInEra BabbageEra
TxTotalAndReturnCollateralInBabbageEra

-- ----------------------------------------------------------------------------
-- Transaction output datum (era-dependent)
--

data TxOutDatum ctx era where

     TxOutDatumNone   :: TxOutDatum ctx era

     -- | A transaction output that only specifies the hash of the datum, but
     -- not the full datum value.
     --
     TxOutDatumHash   :: ScriptDataSupportedInEra era
                      -> Hash ScriptData
                      -> TxOutDatum ctx era

     -- | A transaction output that specifies the whole datum value. This can
     -- only be used in the context of the transaction body, and does not occur
     -- in the UTxO. The UTxO only contains the datum hash.
     --
     TxOutDatumInTx'  :: ScriptDataSupportedInEra era
                      -> Hash ScriptData
                      -> ScriptData
                      -> TxOutDatum CtxTx era

     -- | A transaction output that specifies the whole datum instead of the
     -- datum hash. Note that the datum map will not be updated with this datum,
     -- it only exists at the transaction output.
     --
     TxOutDatumInline :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
                      -> ScriptData
                      -> TxOutDatum ctx era

deriving instance Eq   (TxOutDatum ctx era)
deriving instance Show (TxOutDatum ctx era)


pattern TxOutDatumInTx
  :: ScriptDataSupportedInEra era
  -> ScriptData
  -> TxOutDatum CtxTx era
pattern $bTxOutDatumInTx :: ScriptDataSupportedInEra era -> ScriptData -> TxOutDatum CtxTx era
$mTxOutDatumInTx :: forall r era.
TxOutDatum CtxTx era
-> (ScriptDataSupportedInEra era -> ScriptData -> r)
-> (Void# -> r)
-> r
TxOutDatumInTx s d <- TxOutDatumInTx' s _ d
  where
    TxOutDatumInTx ScriptDataSupportedInEra era
s ScriptData
d = ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx' ScriptDataSupportedInEra era
s (ScriptData -> Hash ScriptData
hashScriptData ScriptData
d) ScriptData
d

{-# COMPLETE TxOutDatumNone, TxOutDatumHash, TxOutDatumInTx', TxOutDatumInline #-}
{-# COMPLETE TxOutDatumNone, TxOutDatumHash, TxOutDatumInTx , TxOutDatumInline #-}

parseHash :: SerialiseAsRawBytes (Hash a) => AsType (Hash a) -> Parsec.Parser (Hash a)
parseHash :: AsType (Hash a) -> Parser (Hash a)
parseHash AsType (Hash a)
asType = do
  String
str <- ParsecT String () Identity Char
-> ParsecT String () Identity String
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
Parsec.hexDigit ParsecT String () Identity String
-> String -> ParsecT String () Identity String
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"hash"
  (RawBytesHexError -> String)
-> Either RawBytesHexError (Hash a) -> Parser (Hash a)
forall (m :: * -> *) e a.
MonadFail m =>
(e -> String) -> Either e a -> m a
failEitherWith (\RawBytesHexError
e -> String
"Failed to parse hash: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ RawBytesHexError -> String
forall e. Error e => e -> String
displayError RawBytesHexError
e) (Either RawBytesHexError (Hash a) -> Parser (Hash a))
-> Either RawBytesHexError (Hash a) -> Parser (Hash a)
forall a b. (a -> b) -> a -> b
$
    AsType (Hash a) -> ByteString -> Either RawBytesHexError (Hash a)
forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Either RawBytesHexError a
deserialiseFromRawBytesHex AsType (Hash a)
asType (String -> ByteString
BSC.pack String
str)

-- ----------------------------------------------------------------------------
-- Transaction fees
--

data TxFee era where

     TxFeeImplicit :: TxFeesImplicitInEra era -> TxFee era

     TxFeeExplicit :: TxFeesExplicitInEra era -> Lovelace -> TxFee era

deriving instance Eq   (TxFee era)
deriving instance Show (TxFee era)


-- ----------------------------------------------------------------------------
-- Transaction validity range
--

-- | This was formerly known as the TTL.
--
data TxValidityUpperBound era where

     TxValidityNoUpperBound :: ValidityNoUpperBoundSupportedInEra era
                            -> TxValidityUpperBound era

     TxValidityUpperBound   :: ValidityUpperBoundSupportedInEra era
                            -> SlotNo
                            -> TxValidityUpperBound era

deriving instance Eq   (TxValidityUpperBound era)
deriving instance Show (TxValidityUpperBound era)


data TxValidityLowerBound era where

     TxValidityNoLowerBound :: TxValidityLowerBound era

     TxValidityLowerBound   :: ValidityLowerBoundSupportedInEra era
                            -> SlotNo
                            -> TxValidityLowerBound era

deriving instance Eq   (TxValidityLowerBound era)
deriving instance Show (TxValidityLowerBound era)


-- ----------------------------------------------------------------------------
-- Transaction metadata (era-dependent)
--

data TxMetadataInEra era where

     TxMetadataNone  :: TxMetadataInEra era

     TxMetadataInEra :: TxMetadataSupportedInEra era
                     -> TxMetadata
                     -> TxMetadataInEra era

deriving instance Eq   (TxMetadataInEra era)
deriving instance Show (TxMetadataInEra era)


-- ----------------------------------------------------------------------------
-- Auxiliary scripts (era-dependent)
--

data TxAuxScripts era where

     TxAuxScriptsNone :: TxAuxScripts era

     TxAuxScripts     :: AuxScriptsSupportedInEra era
                      -> [ScriptInEra era]
                      -> TxAuxScripts era

deriving instance Eq   (TxAuxScripts era)
deriving instance Show (TxAuxScripts era)

-- ----------------------------------------------------------------------------
-- Optionally required signatures (era-dependent)
--

data TxExtraKeyWitnesses era where

  TxExtraKeyWitnessesNone :: TxExtraKeyWitnesses era

  TxExtraKeyWitnesses     :: TxExtraKeyWitnessesSupportedInEra era
                          -> [Hash PaymentKey]
                          -> TxExtraKeyWitnesses era

deriving instance Eq   (TxExtraKeyWitnesses era)
deriving instance Show (TxExtraKeyWitnesses era)

-- ----------------------------------------------------------------------------
-- Withdrawals within transactions (era-dependent)
--

data TxWithdrawals build era where

     TxWithdrawalsNone :: TxWithdrawals build era

     TxWithdrawals     :: WithdrawalsSupportedInEra era
                       -> [(StakeAddress, Lovelace,
                            BuildTxWith build (Witness WitCtxStake era))]
                       -> TxWithdrawals build era

deriving instance Eq   (TxWithdrawals build era)
deriving instance Show (TxWithdrawals build era)


-- ----------------------------------------------------------------------------
-- Certificates within transactions (era-dependent)
--

data TxCertificates build era where

     TxCertificatesNone :: TxCertificates build era

     TxCertificates     :: CertificatesSupportedInEra era
                        -> [Certificate]
                        -> BuildTxWith build
                             (Map StakeCredential (Witness WitCtxStake era))
                        -> TxCertificates build era

deriving instance Eq   (TxCertificates build era)
deriving instance Show (TxCertificates build era)


-- ----------------------------------------------------------------------------
-- Transaction update proposal (era-dependent)
--

data TxUpdateProposal era where

     TxUpdateProposalNone :: TxUpdateProposal era

     TxUpdateProposal     :: UpdateProposalSupportedInEra era
                          -> UpdateProposal
                          -> TxUpdateProposal era

deriving instance Eq   (TxUpdateProposal era)
deriving instance Show (TxUpdateProposal era)


-- ----------------------------------------------------------------------------
-- Value minting within transactions (era-dependent)
--

data TxMintValue build era where

     TxMintNone  :: TxMintValue build era

     TxMintValue :: MultiAssetSupportedInEra era
                 -> Value
                 -> BuildTxWith build
                      (Map PolicyId (ScriptWitness WitCtxMint era))
                 -> TxMintValue build era

deriving instance Eq   (TxMintValue build era)
deriving instance Show (TxMintValue build era)


-- ----------------------------------------------------------------------------
-- Transaction body content
--

data TxBodyContent build era =
     TxBodyContent {
       TxBodyContent build era -> TxIns build era
txIns              :: TxIns build era,
       TxBodyContent build era -> TxInsCollateral era
txInsCollateral    :: TxInsCollateral era,
       TxBodyContent build era -> TxInsReference build era
txInsReference     :: TxInsReference build era,
       TxBodyContent build era -> [TxOut CtxTx era]
txOuts             :: [TxOut CtxTx era],
       TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral  :: TxTotalCollateral era,
       TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era,
       TxBodyContent build era -> TxFee era
txFee              :: TxFee era,
       TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange    :: (TxValidityLowerBound era,
                              TxValidityUpperBound era),
       TxBodyContent build era -> TxMetadataInEra era
txMetadata         :: TxMetadataInEra era,
       TxBodyContent build era -> TxAuxScripts era
txAuxScripts       :: TxAuxScripts era,
       TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits     :: TxExtraKeyWitnesses era,
       TxBodyContent build era
-> BuildTxWith build (Maybe ProtocolParameters)
txProtocolParams   :: BuildTxWith build (Maybe ProtocolParameters),
       TxBodyContent build era -> TxWithdrawals build era
txWithdrawals      :: TxWithdrawals  build era,
       TxBodyContent build era -> TxCertificates build era
txCertificates     :: TxCertificates build era,
       TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal   :: TxUpdateProposal era,
       TxBodyContent build era -> TxMintValue build era
txMintValue        :: TxMintValue    build era,
       TxBodyContent build era -> TxScriptValidity era
txScriptValidity   :: TxScriptValidity era
     }
     deriving (TxBodyContent build era -> TxBodyContent build era -> Bool
(TxBodyContent build era -> TxBodyContent build era -> Bool)
-> (TxBodyContent build era -> TxBodyContent build era -> Bool)
-> Eq (TxBodyContent build era)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall build era.
TxBodyContent build era -> TxBodyContent build era -> Bool
/= :: TxBodyContent build era -> TxBodyContent build era -> Bool
$c/= :: forall build era.
TxBodyContent build era -> TxBodyContent build era -> Bool
== :: TxBodyContent build era -> TxBodyContent build era -> Bool
$c== :: forall build era.
TxBodyContent build era -> TxBodyContent build era -> Bool
Eq, Int -> TxBodyContent build era -> ShowS
[TxBodyContent build era] -> ShowS
TxBodyContent build era -> String
(Int -> TxBodyContent build era -> ShowS)
-> (TxBodyContent build era -> String)
-> ([TxBodyContent build era] -> ShowS)
-> Show (TxBodyContent build era)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall build era. Int -> TxBodyContent build era -> ShowS
forall build era. [TxBodyContent build era] -> ShowS
forall build era. TxBodyContent build era -> String
showList :: [TxBodyContent build era] -> ShowS
$cshowList :: forall build era. [TxBodyContent build era] -> ShowS
show :: TxBodyContent build era -> String
$cshow :: forall build era. TxBodyContent build era -> String
showsPrec :: Int -> TxBodyContent build era -> ShowS
$cshowsPrec :: forall build era. Int -> TxBodyContent build era -> ShowS
Show)


-- ----------------------------------------------------------------------------
-- Transaction bodies
--

data TxBody era where

     ByronTxBody
       :: Annotated Byron.Tx ByteString
       -> TxBody ByronEra

     ShelleyTxBody
       :: ShelleyBasedEra era
       -> Ledger.TxBody (ShelleyLedgerEra era)

          -- We include the scripts along with the tx body, rather than the
          -- witnesses set, since they need to be known when building the body.
       -> [Ledger.Script (ShelleyLedgerEra era)]

          -- The info for each use of each script: the script input data, both
          -- the UTxO input data (called the "datum") and the supplied input
          -- data (called the "redeemer") and the execution units.
       -> TxBodyScriptData era

          -- The 'Ledger.AuxiliaryData' consists of one or several things,
          -- depending on era:
          -- + transaction metadata  (in Shelley and later)
          -- + auxiliary scripts     (in Allegra and later)
          -- Note that there is no auxiliary script data as such, because the
          -- extra script data has to be passed to scripts and hence is needed
          -- for validation. It is thus part of the witness data, not the
          -- auxiliary data.
       -> Maybe (Ledger.AuxiliaryData (ShelleyLedgerEra era))

       -> TxScriptValidity era -- ^ Mark script as expected to pass or fail validation

       -> TxBody era
     -- The 'ShelleyBasedEra' GADT tells us what era we are in.
     -- The 'ShelleyLedgerEra' type family maps that to the era type from the
     -- ledger lib. The 'Ledger.TxBody' type family maps that to a specific
     -- tx body type, which is different for each Shelley-based era.


data TxBodyScriptData era where
     TxBodyNoScriptData :: TxBodyScriptData era
     TxBodyScriptData   :: ScriptDataSupportedInEra era
                        -> Alonzo.TxDats (ShelleyLedgerEra era)
                        -> Alonzo.Redeemers (ShelleyLedgerEra era)
                        -> TxBodyScriptData era

deriving instance Eq   (TxBodyScriptData era)
deriving instance Show (TxBodyScriptData era)


-- The GADT in the ShelleyTxBody case requires a custom instance
instance Eq (TxBody era) where
    == :: TxBody era -> TxBody era -> Bool
(==) (ByronTxBody Annotated Tx ByteString
txbodyA)
         (ByronTxBody Annotated Tx ByteString
txbodyB) = Annotated Tx ByteString
txbodyA Annotated Tx ByteString -> Annotated Tx ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== Annotated Tx ByteString
txbodyB

    (==) (ShelleyTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
txbodyA [Script (ShelleyLedgerEra era)]
txscriptsA TxBodyScriptData era
redeemersA Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA TxScriptValidity era
scriptValidityA)
         (ShelleyTxBody ShelleyBasedEra era
_   TxBody (ShelleyLedgerEra era)
txbodyB [Script (ShelleyLedgerEra era)]
txscriptsB TxBodyScriptData era
redeemersB Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB TxScriptValidity era
scriptValidityB) =
         case ShelleyBasedEra era
era of
           ShelleyBasedEra era
ShelleyBasedEraShelley -> TxBody (ShelleyEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA     TxBody (ShelleyEra StandardCrypto)
-> TxBody (ShelleyEra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)]
[MultiSig StandardCrypto]
txscriptsA  [MultiSig StandardCrypto] -> [MultiSig StandardCrypto] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (ShelleyLedgerEra era)]
[MultiSig StandardCrypto]
txscriptsB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (ShelleyLedgerEra era))
Maybe (Metadata (ShelleyEra StandardCrypto))
txmetadataA Maybe (Metadata (ShelleyEra StandardCrypto))
-> Maybe (Metadata (ShelleyEra StandardCrypto)) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyLedgerEra era))
Maybe (Metadata (ShelleyEra StandardCrypto))
txmetadataB

           ShelleyBasedEra era
ShelleyBasedEraAllegra -> TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA     TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscriptsA  [Timelock StandardCrypto] -> [Timelock StandardCrypto] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscriptsB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB

           ShelleyBasedEra era
ShelleyBasedEraMary    -> TxBody (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA     TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> TxBody (ShelleyMAEra 'Mary StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscriptsA  [Timelock StandardCrypto] -> [Timelock StandardCrypto] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscriptsB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB

           ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA         TxBody (AlonzoEra StandardCrypto)
-> TxBody (AlonzoEra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (AlonzoEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscriptsA      [Script (AlonzoEra StandardCrypto)]
-> [Script (AlonzoEra StandardCrypto)] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (AlonzoEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscriptsB
                                  Bool -> Bool -> Bool
&& TxBodyScriptData era
redeemersA      TxBodyScriptData era -> TxBodyScriptData era -> Bool
forall a. Eq a => a -> a -> Bool
== TxBodyScriptData era
redeemersB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA     Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
-> Maybe (AuxiliaryData (AlonzoEra StandardCrypto)) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB
                                  Bool -> Bool -> Bool
&& TxScriptValidity era
scriptValidityA TxScriptValidity era -> TxScriptValidity era -> Bool
forall a. Eq a => a -> a -> Bool
== TxScriptValidity era
scriptValidityB

           ShelleyBasedEra era
ShelleyBasedEraBabbage -> TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA         TxBody (BabbageEra StandardCrypto)
-> TxBody (BabbageEra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (BabbageEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscriptsA      [Script (BabbageEra StandardCrypto)]
-> [Script (BabbageEra StandardCrypto)] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (BabbageEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscriptsB
                                  Bool -> Bool -> Bool
&& TxBodyScriptData era
redeemersA      TxBodyScriptData era -> TxBodyScriptData era -> Bool
forall a. Eq a => a -> a -> Bool
== TxBodyScriptData era
redeemersB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA     Maybe (AuxiliaryData (BabbageEra StandardCrypto))
-> Maybe (AuxiliaryData (BabbageEra StandardCrypto)) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB
                                  Bool -> Bool -> Bool
&& TxScriptValidity era
scriptValidityA TxScriptValidity era -> TxScriptValidity era -> Bool
forall a. Eq a => a -> a -> Bool
== TxScriptValidity era
scriptValidityB

    (==) ByronTxBody{} (ShelleyTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
_ [Script (ShelleyLedgerEra era)]
_ TxBodyScriptData era
_ Maybe (AuxiliaryData (ShelleyLedgerEra era))
_ TxScriptValidity era
_) = case ShelleyBasedEra era
era of {}


-- The GADT in the ShelleyTxBody case requires a custom instance
instance Show (TxBody era) where
    showsPrec :: Int -> TxBody era -> ShowS
showsPrec Int
p (ByronTxBody Annotated Tx ByteString
txbody) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ByronTxBody "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Annotated Tx ByteString -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Annotated Tx ByteString
txbody
        )

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraShelley
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraShelley "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBody (ShelleyEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBody (ShelleyEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [MultiSig StandardCrypto] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (ShelleyLedgerEra era)]
[MultiSig StandardCrypto]
txscripts
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBodyScriptData era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBodyScriptData era
redeemers
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe (Metadata (ShelleyEra StandardCrypto)) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (ShelleyLedgerEra era))
Maybe (Metadata (ShelleyEra StandardCrypto))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraAllegra
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraAllegra "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Timelock StandardCrypto] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscripts
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBodyScriptData era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBodyScriptData era
redeemers
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraMary
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraMary "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBody (ShelleyMAEra 'Mary StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBody (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Timelock StandardCrypto] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (ShelleyLedgerEra era)]
[Timelock StandardCrypto]
txscripts
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBodyScriptData era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBodyScriptData era
redeemers
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraAlonzo
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraAlonzo "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBody (AlonzoEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Script (AlonzoEra StandardCrypto)] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (AlonzoEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBodyScriptData era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBodyScriptData era
redeemers
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe (AuxiliaryData (AlonzoEra StandardCrypto)) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraBabbage
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraBabbage "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBody (BabbageEra StandardCrypto) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Script (BabbageEra StandardCrypto)] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (BabbageEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxBodyScriptData era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxBodyScriptData era
redeemers
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe (AuxiliaryData (BabbageEra StandardCrypto)) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )



instance HasTypeProxy era => HasTypeProxy (TxBody era) where
    data AsType (TxBody era) = AsTxBody (AsType era)
    proxyToAsType :: Proxy (TxBody era) -> AsType (TxBody era)
proxyToAsType Proxy (TxBody era)
_ = AsType era -> AsType (TxBody era)
forall era. AsType era -> AsType (TxBody era)
AsTxBody (Proxy era -> AsType era
forall t. HasTypeProxy t => Proxy t -> AsType t
proxyToAsType (Proxy era
forall k (t :: k). Proxy t
Proxy :: Proxy era))

pattern AsByronTxBody :: AsType (TxBody ByronEra)
pattern $bAsByronTxBody :: AsType (TxBody ByronEra)
$mAsByronTxBody :: forall r.
AsType (TxBody ByronEra) -> (Void# -> r) -> (Void# -> r) -> r
AsByronTxBody   = AsTxBody AsByronEra
{-# COMPLETE AsByronTxBody #-}

pattern AsShelleyTxBody :: AsType (TxBody ShelleyEra)
pattern $bAsShelleyTxBody :: AsType (TxBody ShelleyEra)
$mAsShelleyTxBody :: forall r.
AsType (TxBody ShelleyEra) -> (Void# -> r) -> (Void# -> r) -> r
AsShelleyTxBody = AsTxBody AsShelleyEra
{-# COMPLETE AsShelleyTxBody #-}

pattern AsMaryTxBody :: AsType (TxBody MaryEra)
pattern $bAsMaryTxBody :: AsType (TxBody MaryEra)
$mAsMaryTxBody :: forall r.
AsType (TxBody MaryEra) -> (Void# -> r) -> (Void# -> r) -> r
AsMaryTxBody = AsTxBody AsMaryEra
{-# COMPLETE AsMaryTxBody #-}

instance IsCardanoEra era => SerialiseAsCBOR (TxBody era) where

    serialiseToCBOR :: TxBody era -> ByteString
serialiseToCBOR (ByronTxBody Annotated Tx ByteString
txbody) =
      Annotated Tx ByteString -> ByteString
forall t. Decoded t => t -> ByteString
recoverBytes Annotated Tx ByteString
txbody

    serialiseToCBOR (ShelleyTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      case ShelleyBasedEra era
era of
        -- Use the same serialisation impl, but at different types:
        ShelleyBasedEra era
ShelleyBasedEraShelley -> ShelleyBasedEra era
-> TxBody (ShelleyEra StandardCrypto)
-> [Script (ShelleyEra StandardCrypto)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
-> TxScriptValidity era
-> ByteString
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera, ToCBOR (TxBody ledgerera),
 ToCBOR (Script ledgerera), ToCBOR (TxDats ledgerera),
 ToCBOR (Redeemers ledgerera), ToCBOR (AuxiliaryData ledgerera)) =>
ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody
                                    ShelleyBasedEra era
era TxBody (ShelleyEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity
        ShelleyBasedEra era
ShelleyBasedEraAllegra -> ShelleyBasedEra era
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> [Script (ShelleyMAEra 'Allegra StandardCrypto)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> TxScriptValidity era
-> ByteString
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera, ToCBOR (TxBody ledgerera),
 ToCBOR (Script ledgerera), ToCBOR (TxDats ledgerera),
 ToCBOR (Redeemers ledgerera), ToCBOR (AuxiliaryData ledgerera)) =>
ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody
                                    ShelleyBasedEra era
era TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyMAEra 'Allegra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity
        ShelleyBasedEra era
ShelleyBasedEraMary    -> ShelleyBasedEra era
-> TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> [Script (ShelleyMAEra 'Mary StandardCrypto)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> TxScriptValidity era
-> ByteString
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera, ToCBOR (TxBody ledgerera),
 ToCBOR (Script ledgerera), ToCBOR (TxDats ledgerera),
 ToCBOR (Redeemers ledgerera), ToCBOR (AuxiliaryData ledgerera)) =>
ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody
                                    ShelleyBasedEra era
era TxBody (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyMAEra 'Mary StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity
        ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> ShelleyBasedEra era
-> TxBody (AlonzoEra StandardCrypto)
-> [Script (AlonzoEra StandardCrypto)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
-> TxScriptValidity era
-> ByteString
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera, ToCBOR (TxBody ledgerera),
 ToCBOR (Script ledgerera), ToCBOR (TxDats ledgerera),
 ToCBOR (Redeemers ledgerera), ToCBOR (AuxiliaryData ledgerera)) =>
ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody
                                    ShelleyBasedEra era
era TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody [Script (AlonzoEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity

        ShelleyBasedEra era
ShelleyBasedEraBabbage -> ShelleyBasedEra era
-> TxBody (BabbageEra StandardCrypto)
-> [Script (BabbageEra StandardCrypto)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (BabbageEra StandardCrypto))
-> TxScriptValidity era
-> ByteString
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera, ToCBOR (TxBody ledgerera),
 ToCBOR (Script ledgerera), ToCBOR (TxDats ledgerera),
 ToCBOR (Redeemers ledgerera), ToCBOR (AuxiliaryData ledgerera)) =>
ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody
                                    ShelleyBasedEra era
era TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody [Script (BabbageEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity
    deserialiseFromCBOR :: AsType (TxBody era)
-> ByteString -> Either DecoderError (TxBody era)
deserialiseFromCBOR AsType (TxBody era)
_ ByteString
bs =
      case CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra :: CardanoEra era of
        CardanoEra era
ByronEra ->
          Annotated Tx ByteString -> TxBody ByronEra
ByronTxBody (Annotated Tx ByteString -> TxBody ByronEra)
-> Either DecoderError (Annotated Tx ByteString)
-> Either DecoderError (TxBody ByronEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            Text
-> (forall s. Decoder s (Annotated Tx ByteSpan))
-> LByteString
-> Either DecoderError (Annotated Tx ByteString)
forall (f :: * -> *).
Functor f =>
Text
-> (forall s. Decoder s (f ByteSpan))
-> LByteString
-> Either DecoderError (f ByteString)
CBOR.decodeFullAnnotatedBytes
              Text
"Byron TxBody"
              forall s. Decoder s (Annotated Tx ByteSpan)
forall a s. FromCBOR a => Decoder s (Annotated a ByteSpan)
CBOR.fromCBORAnnotated
              (ByteString -> LByteString
LBS.fromStrict ByteString
bs)

        -- Use the same derialisation impl, but at different types:
        CardanoEra era
ShelleyEra -> ShelleyBasedEra ShelleyEra
-> ByteString -> Either DecoderError (TxBody ShelleyEra)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 FromCBOR (Annotator (TxBody ledgerera)),
 FromCBOR (Annotator (Script ledgerera)),
 FromCBOR (Annotator (TxDats ledgerera)),
 FromCBOR (Annotator (Redeemers ledgerera)),
 FromCBOR (Annotator (AuxiliaryData ledgerera))) =>
ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley ByteString
bs
        CardanoEra era
AllegraEra -> ShelleyBasedEra AllegraEra
-> ByteString -> Either DecoderError (TxBody AllegraEra)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 FromCBOR (Annotator (TxBody ledgerera)),
 FromCBOR (Annotator (Script ledgerera)),
 FromCBOR (Annotator (TxDats ledgerera)),
 FromCBOR (Annotator (Redeemers ledgerera)),
 FromCBOR (Annotator (AuxiliaryData ledgerera))) =>
ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra ByteString
bs
        CardanoEra era
MaryEra    -> ShelleyBasedEra MaryEra
-> ByteString -> Either DecoderError (TxBody MaryEra)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 FromCBOR (Annotator (TxBody ledgerera)),
 FromCBOR (Annotator (Script ledgerera)),
 FromCBOR (Annotator (TxDats ledgerera)),
 FromCBOR (Annotator (Redeemers ledgerera)),
 FromCBOR (Annotator (AuxiliaryData ledgerera))) =>
ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra MaryEra
ShelleyBasedEraMary    ByteString
bs
        CardanoEra era
AlonzoEra  -> ShelleyBasedEra AlonzoEra
-> ByteString -> Either DecoderError (TxBody AlonzoEra)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 FromCBOR (Annotator (TxBody ledgerera)),
 FromCBOR (Annotator (Script ledgerera)),
 FromCBOR (Annotator (TxDats ledgerera)),
 FromCBOR (Annotator (Redeemers ledgerera)),
 FromCBOR (Annotator (AuxiliaryData ledgerera))) =>
ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo  ByteString
bs
        CardanoEra era
BabbageEra -> ShelleyBasedEra BabbageEra
-> ByteString -> Either DecoderError (TxBody BabbageEra)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 FromCBOR (Annotator (TxBody ledgerera)),
 FromCBOR (Annotator (Script ledgerera)),
 FromCBOR (Annotator (TxDats ledgerera)),
 FromCBOR (Annotator (Redeemers ledgerera)),
 FromCBOR (Annotator (AuxiliaryData ledgerera))) =>
ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage ByteString
bs

-- | The serialisation format for the different Shelley-based eras are not the
-- same, but they can be handled generally with one overloaded implementation.
serialiseShelleyBasedTxBody
  :: forall era ledgerera.
     ShelleyLedgerEra era ~ ledgerera
  => ToCBOR (Ledger.TxBody ledgerera)
  => ToCBOR (Ledger.Script ledgerera)
  => ToCBOR (Alonzo.TxDats ledgerera)
  => ToCBOR (Alonzo.Redeemers ledgerera)
  => ToCBOR (Ledger.AuxiliaryData ledgerera)
  => ShelleyBasedEra era
  -> Ledger.TxBody ledgerera
  -> [Ledger.Script ledgerera]
  -> TxBodyScriptData era
  -> Maybe (Ledger.AuxiliaryData ledgerera)
  -> TxScriptValidity era -- ^ Mark script as expected to pass or fail validation
  -> ByteString
serialiseShelleyBasedTxBody :: ShelleyBasedEra era
-> TxBody ledgerera
-> [Script ledgerera]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData ledgerera)
-> TxScriptValidity era
-> ByteString
serialiseShelleyBasedTxBody ShelleyBasedEra era
era TxBody ledgerera
txbody [Script ledgerera]
txscripts
                            TxBodyScriptData era
TxBodyNoScriptData Maybe (AuxiliaryData ledgerera)
txmetadata TxScriptValidity era
scriptValidity =
    -- Backwards compat for pre-Alonzo era tx body files
    case ShelleyBasedEra era
era of
      ShelleyBasedEra era
ShelleyBasedEraShelley -> ByteString
preAlonzo
      ShelleyBasedEra era
ShelleyBasedEraAllegra -> ByteString
preAlonzo
      ShelleyBasedEra era
ShelleyBasedEraMary -> ByteString
preAlonzo
      ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
        Encoding -> ByteString
CBOR.serializeEncoding'
          (Encoding -> ByteString) -> Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$ Word -> Encoding
CBOR.encodeListLen Word
4
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> TxBody (AlonzoEra StandardCrypto) -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR TxBody (AlonzoEra StandardCrypto)
TxBody ledgerera
txbody
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Script (AlonzoEra StandardCrypto)] -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR [Script (AlonzoEra StandardCrypto)]
[Script ledgerera]
txscripts
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ScriptValidity -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR (TxScriptValidity era -> ScriptValidity
forall era. TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity TxScriptValidity era
scriptValidity)
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (AuxiliaryData (AlonzoEra StandardCrypto) -> Encoding)
-> Maybe (AuxiliaryData (AlonzoEra StandardCrypto)) -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
CBOR.encodeNullMaybe AuxiliaryData (AlonzoEra StandardCrypto) -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData ledgerera)
txmetadata
      ShelleyBasedEra era
ShelleyBasedEraBabbage ->
        Encoding -> ByteString
CBOR.serializeEncoding'
          (Encoding -> ByteString) -> Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$ Word -> Encoding
CBOR.encodeListLen Word
4
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> TxBody (BabbageEra StandardCrypto) -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR TxBody (BabbageEra StandardCrypto)
TxBody ledgerera
txbody
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Script (BabbageEra StandardCrypto)] -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR [Script (BabbageEra StandardCrypto)]
[Script ledgerera]
txscripts
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ScriptValidity -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR (TxScriptValidity era -> ScriptValidity
forall era. TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity TxScriptValidity era
scriptValidity)
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (AuxiliaryData (BabbageEra StandardCrypto) -> Encoding)
-> Maybe (AuxiliaryData (BabbageEra StandardCrypto)) -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
CBOR.encodeNullMaybe AuxiliaryData (BabbageEra StandardCrypto) -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData ledgerera)
txmetadata
 where
   preAlonzo :: ByteString
preAlonzo = Encoding -> ByteString
CBOR.serializeEncoding'
                 (Encoding -> ByteString) -> Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$ Word -> Encoding
CBOR.encodeListLen Word
3
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> TxBody ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR TxBody ledgerera
txbody
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Script ledgerera] -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR [Script ledgerera]
txscripts
                Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (AuxiliaryData ledgerera -> Encoding)
-> Maybe (AuxiliaryData ledgerera) -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
CBOR.encodeNullMaybe AuxiliaryData ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR Maybe (AuxiliaryData ledgerera)
txmetadata

serialiseShelleyBasedTxBody ShelleyBasedEra era
_era TxBody ledgerera
txbody [Script ledgerera]
txscripts
                            (TxBodyScriptData ScriptDataSupportedInEra era
_ TxDats (ShelleyLedgerEra era)
datums Redeemers (ShelleyLedgerEra era)
redeemers)
                            Maybe (AuxiliaryData ledgerera)
txmetadata TxScriptValidity era
txBodycriptValidity =
    Encoding -> ByteString
CBOR.serializeEncoding' (Encoding -> ByteString) -> Encoding -> ByteString
forall a b. (a -> b) -> a -> b
$
        Word -> Encoding
CBOR.encodeListLen Word
6
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> TxBody ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR TxBody ledgerera
txbody
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Script ledgerera] -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR [Script ledgerera]
txscripts
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> TxDats ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR TxDats ledgerera
TxDats (ShelleyLedgerEra era)
datums
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Redeemers ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR Redeemers ledgerera
Redeemers (ShelleyLedgerEra era)
redeemers
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ScriptValidity -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR (TxScriptValidity era -> ScriptValidity
forall era. TxScriptValidity era -> ScriptValidity
txScriptValidityToScriptValidity TxScriptValidity era
txBodycriptValidity)
     Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (AuxiliaryData ledgerera -> Encoding)
-> Maybe (AuxiliaryData ledgerera) -> Encoding
forall a. (a -> Encoding) -> Maybe a -> Encoding
CBOR.encodeNullMaybe AuxiliaryData ledgerera -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR Maybe (AuxiliaryData ledgerera)
txmetadata

deserialiseShelleyBasedTxBody
  :: forall era ledgerera.
     ShelleyLedgerEra era ~ ledgerera
  => FromCBOR (CBOR.Annotator (Ledger.TxBody ledgerera))
  => FromCBOR (CBOR.Annotator (Ledger.Script ledgerera))
  => FromCBOR (CBOR.Annotator (Alonzo.TxDats ledgerera))
  => FromCBOR (CBOR.Annotator (Alonzo.Redeemers ledgerera))
  => FromCBOR (CBOR.Annotator (Ledger.AuxiliaryData ledgerera))
  => ShelleyBasedEra era
  -> ByteString
  -> Either CBOR.DecoderError (TxBody era)
deserialiseShelleyBasedTxBody :: ShelleyBasedEra era
-> ByteString -> Either DecoderError (TxBody era)
deserialiseShelleyBasedTxBody ShelleyBasedEra era
era ByteString
bs =
    Text
-> (forall s. Decoder s (Annotator (TxBody era)))
-> LByteString
-> Either DecoderError (TxBody era)
forall a.
Text
-> (forall s. Decoder s (Annotator a))
-> LByteString
-> Either DecoderError a
CBOR.decodeAnnotator
      Text
"Shelley TxBody"
      forall s. Decoder s (Annotator (TxBody era))
decodeAnnotatedTuple
      (ByteString -> LByteString
LBS.fromStrict ByteString
bs)
  where
    decodeAnnotatedTuple :: CBOR.Decoder s (CBOR.Annotator (TxBody era))
    decodeAnnotatedTuple :: Decoder s (Annotator (TxBody era))
decodeAnnotatedTuple = do
      Int
len <- Decoder s Int
forall s. Decoder s Int
CBOR.decodeListLen

      case Int
len of
        -- Backwards compat for pre-Alonzo era tx body files
        Int
2 -> do
          Annotator (TxBody ledgerera)
txbody     <- Decoder s (Annotator (TxBody ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata <- Decoder s (Annotator (AuxiliaryData ledgerera))
-> Decoder s (Maybe (Annotator (AuxiliaryData ledgerera)))
forall s a. Decoder s a -> Decoder s (Maybe a)
CBOR.decodeNullMaybe Decoder s (Annotator (AuxiliaryData ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall (m :: * -> *) a. Monad m => a -> m a
return (Annotator (TxBody era) -> Decoder s (Annotator (TxBody era)))
-> Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall a b. (a -> b) -> a -> b
$ (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a. (FullByteString -> a) -> Annotator a
CBOR.Annotator ((FullByteString -> TxBody era) -> Annotator (TxBody era))
-> (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a b. (a -> b) -> a -> b
$ \FullByteString
fbs ->
            ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody ShelleyBasedEra era
era
              ((Annotator (TxBody ledgerera)
 -> FullByteString -> TxBody ledgerera)
-> FullByteString
-> Annotator (TxBody ledgerera)
-> TxBody ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBody ledgerera) -> FullByteString -> TxBody ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs Annotator (TxBody ledgerera)
txbody)
              [] -- scripts
              ((Annotator (TxBodyScriptData era)
 -> FullByteString -> TxBodyScriptData era)
-> FullByteString
-> Annotator (TxBodyScriptData era)
-> TxBodyScriptData era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBodyScriptData era)
-> FullByteString -> TxBodyScriptData era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxBodyScriptData era -> Annotator (TxBodyScriptData era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData))
              ((Annotator (AuxiliaryData ledgerera) -> AuxiliaryData ledgerera)
-> Maybe (Annotator (AuxiliaryData ledgerera))
-> Maybe (AuxiliaryData ledgerera)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Annotator (AuxiliaryData ledgerera)
 -> FullByteString -> AuxiliaryData ledgerera)
-> FullByteString
-> Annotator (AuxiliaryData ledgerera)
-> AuxiliaryData ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (AuxiliaryData ledgerera)
-> FullByteString -> AuxiliaryData ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs) Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata)
              ((Annotator (TxScriptValidity era)
 -> FullByteString -> TxScriptValidity era)
-> FullByteString
-> Annotator (TxScriptValidity era)
-> TxScriptValidity era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxScriptValidity era)
-> FullByteString -> TxScriptValidity era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxScriptValidity era -> Annotator (TxScriptValidity era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone))
        Int
3 -> do
          Annotator (TxBody ledgerera)
txbody     <- Decoder s (Annotator (TxBody ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          [Annotator (Script ledgerera)]
txscripts  <- Decoder s [Annotator (Script ledgerera)]
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata <- Decoder s (Annotator (AuxiliaryData ledgerera))
-> Decoder s (Maybe (Annotator (AuxiliaryData ledgerera)))
forall s a. Decoder s a -> Decoder s (Maybe a)
CBOR.decodeNullMaybe Decoder s (Annotator (AuxiliaryData ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall (m :: * -> *) a. Monad m => a -> m a
return (Annotator (TxBody era) -> Decoder s (Annotator (TxBody era)))
-> Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall a b. (a -> b) -> a -> b
$ (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a. (FullByteString -> a) -> Annotator a
CBOR.Annotator ((FullByteString -> TxBody era) -> Annotator (TxBody era))
-> (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a b. (a -> b) -> a -> b
$ \FullByteString
fbs ->
            ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody ShelleyBasedEra era
era
              ((Annotator (TxBody ledgerera)
 -> FullByteString -> TxBody ledgerera)
-> FullByteString
-> Annotator (TxBody ledgerera)
-> TxBody ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBody ledgerera) -> FullByteString -> TxBody ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs Annotator (TxBody ledgerera)
txbody)
              ((Annotator (Script ledgerera) -> Script ledgerera)
-> [Annotator (Script ledgerera)] -> [Script ledgerera]
forall a b. (a -> b) -> [a] -> [b]
map ((Annotator (Script ledgerera)
 -> FullByteString -> Script ledgerera)
-> FullByteString
-> Annotator (Script ledgerera)
-> Script ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (Script ledgerera) -> FullByteString -> Script ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs) [Annotator (Script ledgerera)]
txscripts)
              ((Annotator (TxBodyScriptData era)
 -> FullByteString -> TxBodyScriptData era)
-> FullByteString
-> Annotator (TxBodyScriptData era)
-> TxBodyScriptData era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBodyScriptData era)
-> FullByteString -> TxBodyScriptData era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxBodyScriptData era -> Annotator (TxBodyScriptData era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData))
              ((Annotator (AuxiliaryData ledgerera) -> AuxiliaryData ledgerera)
-> Maybe (Annotator (AuxiliaryData ledgerera))
-> Maybe (AuxiliaryData ledgerera)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Annotator (AuxiliaryData ledgerera)
 -> FullByteString -> AuxiliaryData ledgerera)
-> FullByteString
-> Annotator (AuxiliaryData ledgerera)
-> AuxiliaryData ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (AuxiliaryData ledgerera)
-> FullByteString -> AuxiliaryData ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs) Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata)
              ((Annotator (TxScriptValidity era)
 -> FullByteString -> TxScriptValidity era)
-> FullByteString
-> Annotator (TxScriptValidity era)
-> TxScriptValidity era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxScriptValidity era)
-> FullByteString -> TxScriptValidity era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxScriptValidity era -> Annotator (TxScriptValidity era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone))
        Int
4 -> do
          TxScriptValiditySupportedInEra era
sValiditySupported <-
            case ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
forall era.
ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
era of
              Maybe (TxScriptValiditySupportedInEra era)
Nothing -> String -> Decoder s (TxScriptValiditySupportedInEra era)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (TxScriptValiditySupportedInEra era))
-> String -> Decoder s (TxScriptValiditySupportedInEra era)
forall a b. (a -> b) -> a -> b
$ String
"deserialiseShelleyBasedTxBody: Expected an era that supports the \
                                \script validity flag but got: "
                              String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShelleyBasedEra era -> String
forall a. Show a => a -> String
show ShelleyBasedEra era
era
              Just TxScriptValiditySupportedInEra era
supported -> TxScriptValiditySupportedInEra era
-> Decoder s (TxScriptValiditySupportedInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxScriptValiditySupportedInEra era
supported

          Annotator (TxBody ledgerera)
txbody     <- Decoder s (Annotator (TxBody ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          [Annotator (Script ledgerera)]
txscripts  <- Decoder s [Annotator (Script ledgerera)]
forall a s. FromCBOR a => Decoder s a
fromCBOR
          ScriptValidity
scriptValidity <- Decoder s ScriptValidity
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata <- Decoder s (Annotator (AuxiliaryData ledgerera))
-> Decoder s (Maybe (Annotator (AuxiliaryData ledgerera)))
forall s a. Decoder s a -> Decoder s (Maybe a)
CBOR.decodeNullMaybe Decoder s (Annotator (AuxiliaryData ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall (m :: * -> *) a. Monad m => a -> m a
return (Annotator (TxBody era) -> Decoder s (Annotator (TxBody era)))
-> Annotator (TxBody era) -> Decoder s (Annotator (TxBody era))
forall a b. (a -> b) -> a -> b
$ (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a. (FullByteString -> a) -> Annotator a
CBOR.Annotator ((FullByteString -> TxBody era) -> Annotator (TxBody era))
-> (FullByteString -> TxBody era) -> Annotator (TxBody era)
forall a b. (a -> b) -> a -> b
$ \FullByteString
fbs ->
            ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody ShelleyBasedEra era
era
              ((Annotator (TxBody ledgerera)
 -> FullByteString -> TxBody ledgerera)
-> FullByteString
-> Annotator (TxBody ledgerera)
-> TxBody ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBody ledgerera) -> FullByteString -> TxBody ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs Annotator (TxBody ledgerera)
txbody)
              ((Annotator (Script ledgerera) -> Script ledgerera)
-> [Annotator (Script ledgerera)] -> [Script ledgerera]
forall a b. (a -> b) -> [a] -> [b]
map ((Annotator (Script ledgerera)
 -> FullByteString -> Script ledgerera)
-> FullByteString
-> Annotator (Script ledgerera)
-> Script ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (Script ledgerera) -> FullByteString -> Script ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs) [Annotator (Script ledgerera)]
txscripts)
              ((Annotator (TxBodyScriptData era)
 -> FullByteString -> TxBodyScriptData era)
-> FullByteString
-> Annotator (TxBodyScriptData era)
-> TxBodyScriptData era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxBodyScriptData era)
-> FullByteString -> TxBodyScriptData era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxBodyScriptData era -> Annotator (TxBodyScriptData era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData))
              ((Annotator (AuxiliaryData ledgerera) -> AuxiliaryData ledgerera)
-> Maybe (Annotator (AuxiliaryData ledgerera))
-> Maybe (AuxiliaryData ledgerera)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Annotator (AuxiliaryData ledgerera)
 -> FullByteString -> AuxiliaryData ledgerera)
-> FullByteString
-> Annotator (AuxiliaryData ledgerera)
-> AuxiliaryData ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (AuxiliaryData ledgerera)
-> FullByteString -> AuxiliaryData ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs) Maybe (Annotator (AuxiliaryData ledgerera))
txmetadata)
              ((Annotator (TxScriptValidity era)
 -> FullByteString -> TxScriptValidity era)
-> FullByteString
-> Annotator (TxScriptValidity era)
-> TxScriptValidity era
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxScriptValidity era)
-> FullByteString -> TxScriptValidity era
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs (TxScriptValidity era -> Annotator (TxScriptValidity era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxScriptValidity era -> Annotator (TxScriptValidity era))
-> TxScriptValidity era -> Annotator (TxScriptValidity era)
forall a b. (a -> b) -> a -> b
$ TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
forall era.
TxScriptValiditySupportedInEra era
-> ScriptValidity -> TxScriptValidity era
TxScriptValidity TxScriptValiditySupportedInEra era
sValiditySupported ScriptValidity
scriptValidity))
        Int
6 -> do
          ScriptDataSupportedInEra era
sDataSupported <-
            case CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era) of
              Maybe (ScriptDataSupportedInEra era)
Nothing -> String -> Decoder s (ScriptDataSupportedInEra era)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (ScriptDataSupportedInEra era))
-> String -> Decoder s (ScriptDataSupportedInEra era)
forall a b. (a -> b) -> a -> b
$ String
"deserialiseShelleyBasedTxBody: Expected an era that supports script\
                                \ data but got: "
                             String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShelleyBasedEra era -> String
forall a. Show a => a -> String
show ShelleyBasedEra era
era
              Just ScriptDataSupportedInEra era
supported -> ScriptDataSupportedInEra era
-> Decoder s (ScriptDataSupportedInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return ScriptDataSupportedInEra era
supported

          TxScriptValiditySupportedInEra era
sValiditySupported <-
            case ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
forall era.
ShelleyBasedEra era -> Maybe (TxScriptValiditySupportedInEra era)
txScriptValiditySupportedInShelleyBasedEra ShelleyBasedEra era
era of
              Maybe (TxScriptValiditySupportedInEra era)
Nothing -> String -> Decoder s (TxScriptValiditySupportedInEra era)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (TxScriptValiditySupportedInEra era))
-> String -> Decoder s (TxScriptValiditySupportedInEra era)
forall a b. (a -> b) -> a -> b
$ String
"deserialiseShelleyBasedTxBody: Expected an era that supports the \
                                \script validity flag but got: "
                              String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShelleyBasedEra era -> String
forall a. Show a => a -> String
show ShelleyBasedEra era
era
              Just TxScriptValiditySupportedInEra era
supported -> TxScriptValiditySupportedInEra era
-> Decoder s (TxScriptValiditySupportedInEra era)
forall (m :: * -> *) a. Monad m => a -> m a
return TxScriptValiditySupportedInEra era
supported

          Annotator (TxBody ledgerera)
txbody    <- Decoder s (Annotator (TxBody ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          [Annotator (Script ledgerera)]
txscripts <- Decoder s [Annotator (Script ledgerera)]
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Annotator (TxDats ledgerera)
datums    <- Decoder s (Annotator (TxDats ledgerera))
forall a s. FromCBOR a => Decoder s a
fromCBOR
          Annotator (Redeemers ledgerera)
redeemers</