{-# 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 #-}

{- HLINT ignore "Avoid lambda using `infix`" -}
{- HLINT ignore "Redundant flip" -}
{- HLINT ignore "Use section" -}

-- | 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 qualified Text.Parsec as Parsec
import           Text.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.EraCast
import           Cardano.Api.Eras
import           Cardano.Api.Error
import           Cardano.Api.Hash
import           Cardano.Api.HasTypeProxy
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

-- | 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)

instance EraCast (TxOut ctx) where
  eraCast :: CardanoEra toEra
-> TxOut ctx fromEra -> Either EraCastError (TxOut ctx toEra)
eraCast CardanoEra toEra
toEra (TxOut AddressInEra fromEra
addressInEra TxOutValue fromEra
txOutValue TxOutDatum ctx fromEra
txOutDatum ReferenceScript fromEra
referenceScript) =
    AddressInEra toEra
-> TxOutValue toEra
-> TxOutDatum ctx toEra
-> ReferenceScript toEra
-> TxOut ctx toEra
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
      (AddressInEra toEra
 -> TxOutValue toEra
 -> TxOutDatum ctx toEra
 -> ReferenceScript toEra
 -> TxOut ctx toEra)
-> Either EraCastError (AddressInEra toEra)
-> Either
     EraCastError
     (TxOutValue toEra
      -> TxOutDatum ctx toEra
      -> ReferenceScript toEra
      -> TxOut ctx toEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CardanoEra toEra
-> AddressInEra fromEra -> Either EraCastError (AddressInEra toEra)
forall (f :: * -> *) fromEra toEra.
(EraCast f, IsCardanoEra fromEra, IsCardanoEra toEra) =>
CardanoEra toEra -> f fromEra -> Either EraCastError (f toEra)
eraCast CardanoEra toEra
toEra AddressInEra fromEra
addressInEra
      Either
  EraCastError
  (TxOutValue toEra
   -> TxOutDatum ctx toEra
   -> ReferenceScript toEra
   -> TxOut ctx toEra)
-> Either EraCastError (TxOutValue toEra)
-> Either
     EraCastError
     (TxOutDatum ctx toEra -> ReferenceScript toEra -> TxOut ctx toEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra toEra
-> TxOutValue fromEra -> Either EraCastError (TxOutValue toEra)
forall (f :: * -> *) fromEra toEra.
(EraCast f, IsCardanoEra fromEra, IsCardanoEra toEra) =>
CardanoEra toEra -> f fromEra -> Either EraCastError (f toEra)
eraCast CardanoEra toEra
toEra TxOutValue fromEra
txOutValue
      Either
  EraCastError
  (TxOutDatum ctx toEra -> ReferenceScript toEra -> TxOut ctx toEra)
-> Either EraCastError (TxOutDatum ctx toEra)
-> Either EraCastError (ReferenceScript toEra -> TxOut ctx toEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra toEra
-> TxOutDatum ctx fromEra
-> Either EraCastError (TxOutDatum ctx toEra)
forall (f :: * -> *) fromEra toEra.
(EraCast f, IsCardanoEra fromEra, IsCardanoEra toEra) =>
CardanoEra toEra -> f fromEra -> Either EraCastError (f toEra)
eraCast CardanoEra toEra
toEra TxOutDatum ctx fromEra
txOutDatum
      Either EraCastError (ReferenceScript toEra -> TxOut ctx toEra)
-> Either EraCastError (ReferenceScript toEra)
-> Either EraCastError (TxOut ctx toEra)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CardanoEra toEra
-> ReferenceScript fromEra
-> Either EraCastError (ReferenceScript toEra)
forall (f :: * -> *) fromEra toEra.
(EraCast f, IsCardanoEra fromEra, IsCardanoEra toEra) =>
CardanoEra toEra -> f fromEra -> Either EraCastError (f toEra)
eraCast CardanoEra toEra
toEra ReferenceScript fromEra
referenceScript

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 Value (ShelleyEra StandardCrypto)
Coin
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 ledgerera
TxOut (ShelleyEra StandardCrypto)
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 Value (ShelleyMAEra 'Allegra StandardCrypto)
Coin
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 ledgerera
TxOut (ShelleyMAEra 'Allegra StandardCrypto)
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 (ShelleyMAEra 'Mary StandardCrypto)
Value 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 ledgerera
TxOut (ShelleyMAEra 'Mary StandardCrypto)
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 (AlonzoEra StandardCrypto)
Value 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 (BabbageEra StandardCrypto)
Value 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

instance EraCast TxOutValue where
  eraCast :: CardanoEra toEra
-> TxOutValue fromEra -> Either EraCastError (TxOutValue toEra)
eraCast CardanoEra toEra
toEra TxOutValue fromEra
v = case TxOutValue fromEra
v of
    TxOutAdaOnly OnlyAdaSupportedInEra fromEra
_previousEra Lovelace
lovelace ->
      case CardanoEra toEra
-> Either
     (OnlyAdaSupportedInEra toEra) (MultiAssetSupportedInEra toEra)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra toEra
toEra of
        Left OnlyAdaSupportedInEra toEra
adaOnly -> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. b -> Either a b
Right (TxOutValue toEra -> Either EraCastError (TxOutValue toEra))
-> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. (a -> b) -> a -> b
$ OnlyAdaSupportedInEra toEra -> Lovelace -> TxOutValue toEra
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra toEra
adaOnly Lovelace
lovelace
        Right MultiAssetSupportedInEra toEra
multiAssetSupp -> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. b -> Either a b
Right (TxOutValue toEra -> Either EraCastError (TxOutValue toEra))
-> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. (a -> b) -> a -> b
$ MultiAssetSupportedInEra toEra -> Value -> TxOutValue toEra
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra toEra
multiAssetSupp (Value -> TxOutValue toEra) -> Value -> TxOutValue toEra
forall a b. (a -> b) -> a -> b
$ Lovelace -> Value
lovelaceToValue Lovelace
lovelace
    TxOutValue  (MultiAssetSupportedInEra fromEra
_ :: MultiAssetSupportedInEra fromEra) Value
value  ->
      case CardanoEra toEra
-> Either
     (OnlyAdaSupportedInEra toEra) (MultiAssetSupportedInEra toEra)
forall era.
CardanoEra era
-> Either
     (OnlyAdaSupportedInEra era) (MultiAssetSupportedInEra era)
multiAssetSupportedInEra CardanoEra toEra
toEra of
        Left OnlyAdaSupportedInEra toEra
_adaOnly -> EraCastError -> Either EraCastError (TxOutValue toEra)
forall a b. a -> Either a b
Left (EraCastError -> Either EraCastError (TxOutValue toEra))
-> EraCastError -> Either EraCastError (TxOutValue toEra)
forall a b. (a -> b) -> a -> b
$ TxOutValue fromEra
-> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
forall fromEra toEra value.
(IsCardanoEra fromEra, IsCardanoEra toEra, Show value) =>
value -> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
EraCastError TxOutValue fromEra
v (IsCardanoEra fromEra => CardanoEra fromEra
forall era. IsCardanoEra era => CardanoEra era
cardanoEra @fromEra) CardanoEra toEra
toEra
        Right MultiAssetSupportedInEra toEra
multiAssetSupp -> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. b -> Either a b
Right (TxOutValue toEra -> Either EraCastError (TxOutValue toEra))
-> TxOutValue toEra -> Either EraCastError (TxOutValue toEra)
forall a b. (a -> b) -> a -> b
$ MultiAssetSupportedInEra toEra -> Value -> TxOutValue toEra
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra toEra
multiAssetSupp Value
value


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)

instance EraCast (TxOutDatum ctx)  where
  eraCast :: CardanoEra toEra
-> TxOutDatum ctx fromEra
-> Either EraCastError (TxOutDatum ctx toEra)
eraCast CardanoEra toEra
toEra TxOutDatum ctx fromEra
v = case TxOutDatum ctx fromEra
v of
    TxOutDatum ctx fromEra
TxOutDatumNone -> TxOutDatum ctx toEra -> Either EraCastError (TxOutDatum ctx toEra)
forall (f :: * -> *) a. Applicative f => a -> f a
pure TxOutDatum ctx toEra
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
    TxOutDatumHash (ScriptDataSupportedInEra fromEra
_ :: ScriptDataSupportedInEra fromEra) Hash ScriptData
hash ->
      case CardanoEra toEra -> Maybe (ScriptDataSupportedInEra toEra)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra toEra
toEra of
        Maybe (ScriptDataSupportedInEra toEra)
Nothing -> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. a -> Either a b
Left (EraCastError -> Either EraCastError (TxOutDatum ctx toEra))
-> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. (a -> b) -> a -> b
$ TxOutDatum ctx fromEra
-> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
forall fromEra toEra value.
(IsCardanoEra fromEra, IsCardanoEra toEra, Show value) =>
value -> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
EraCastError TxOutDatum ctx fromEra
v (IsCardanoEra fromEra => CardanoEra fromEra
forall era. IsCardanoEra era => CardanoEra era
cardanoEra @fromEra) CardanoEra toEra
toEra
        Just ScriptDataSupportedInEra toEra
sDatumsSupported ->
          TxOutDatum ctx toEra -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. b -> Either a b
Right (TxOutDatum ctx toEra
 -> Either EraCastError (TxOutDatum ctx toEra))
-> TxOutDatum ctx toEra
-> Either EraCastError (TxOutDatum ctx toEra)
forall a b. (a -> b) -> a -> b
$ ScriptDataSupportedInEra toEra
-> Hash ScriptData -> TxOutDatum ctx toEra
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra toEra
sDatumsSupported Hash ScriptData
hash
    TxOutDatumInTx' (ScriptDataSupportedInEra fromEra
_ :: ScriptDataSupportedInEra fromEra) Hash ScriptData
scriptData ScriptData
hash ->
      case CardanoEra toEra -> Maybe (ScriptDataSupportedInEra toEra)
forall era. CardanoEra era -> Maybe (ScriptDataSupportedInEra era)
scriptDataSupportedInEra CardanoEra toEra
toEra of
        Maybe (ScriptDataSupportedInEra toEra)
Nothing -> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. a -> Either a b
Left (EraCastError -> Either EraCastError (TxOutDatum ctx toEra))
-> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. (a -> b) -> a -> b
$ TxOutDatum ctx fromEra
-> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
forall fromEra toEra value.
(IsCardanoEra fromEra, IsCardanoEra toEra, Show value) =>
value -> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
EraCastError TxOutDatum ctx fromEra
v (IsCardanoEra fromEra => CardanoEra fromEra
forall era. IsCardanoEra era => CardanoEra era
cardanoEra @fromEra) CardanoEra toEra
toEra
        Just ScriptDataSupportedInEra toEra
sDatumsSupported ->
          TxOutDatum CtxTx toEra
-> Either EraCastError (TxOutDatum CtxTx toEra)
forall a b. b -> Either a b
Right (TxOutDatum CtxTx toEra
 -> Either EraCastError (TxOutDatum CtxTx toEra))
-> TxOutDatum CtxTx toEra
-> Either EraCastError (TxOutDatum CtxTx toEra)
forall a b. (a -> b) -> a -> b
$ ScriptDataSupportedInEra toEra
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx toEra
forall era.
ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx' ScriptDataSupportedInEra toEra
sDatumsSupported Hash ScriptData
scriptData ScriptData
hash
    TxOutDatumInline (ReferenceTxInsScriptsInlineDatumsSupportedInEra fromEra
_ :: ReferenceTxInsScriptsInlineDatumsSupportedInEra fromEra) ScriptData
scriptData ->
      case CardanoEra toEra
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra toEra)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra CardanoEra toEra
toEra of
        Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra toEra)
Nothing -> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. a -> Either a b
Left (EraCastError -> Either EraCastError (TxOutDatum ctx toEra))
-> EraCastError -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. (a -> b) -> a -> b
$ TxOutDatum ctx fromEra
-> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
forall fromEra toEra value.
(IsCardanoEra fromEra, IsCardanoEra toEra, Show value) =>
value -> CardanoEra fromEra -> CardanoEra toEra -> EraCastError
EraCastError TxOutDatum ctx fromEra
v (IsCardanoEra fromEra => CardanoEra fromEra
forall era. IsCardanoEra era => CardanoEra era
cardanoEra @fromEra) CardanoEra toEra
toEra
        Just ReferenceTxInsScriptsInlineDatumsSupportedInEra toEra
refInsAndInlineSupported ->
          TxOutDatum ctx toEra -> Either EraCastError (TxOutDatum ctx toEra)
forall a b. b -> Either a b
Right (TxOutDatum ctx toEra
 -> Either EraCastError (TxOutDatum ctx toEra))
-> TxOutDatum ctx toEra
-> Either EraCastError (TxOutDatum ctx toEra)
forall a b. (a -> b) -> a -> b
$ ReferenceTxInsScriptsInlineDatumsSupportedInEra toEra
-> ScriptData -> TxOutDatum ctx toEra
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra toEra
refInsAndInlineSupported ScriptData
scriptData

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 (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
txbodyA     TxBody (ShelleyEra StandardCrypto)
-> TxBody (ShelleyEra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
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 (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
txbodyA     TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
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 (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
txmetadataA Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
txmetadataB

           ShelleyBasedEra era
ShelleyBasedEraMary    -> TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
txbodyA     TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> TxBody (ShelleyMAEra 'Mary StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
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 (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
txmetadataA Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
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 (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
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 (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
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 (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Allegra 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
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 (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
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 (ShelleyLedgerEra era))
Maybe (AuxiliaryData (ShelleyMAEra 'Mary 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
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 <- Decoder s (Annotator (Redeemers 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

          let txscriptdata :: Annotator (TxBodyScriptData era)
txscriptdata = (FullByteString -> TxBodyScriptData era)
-> Annotator (TxBodyScriptData era)
forall a. (FullByteString -> a) -> Annotator a
CBOR.Annotator ((FullByteString -> TxBodyScriptData era)
 -> Annotator (TxBodyScriptData era))
-> (FullByteString -> TxBodyScriptData era)
-> Annotator (TxBodyScriptData era)
forall a b. (a -> b) -> a -> b
$ \FullByteString
fbs ->
                               ScriptDataSupportedInEra era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
ScriptDataSupportedInEra era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData ScriptDataSupportedInEra era
sDataSupported
                                 ((Annotator (TxDats ledgerera)
 -> FullByteString -> TxDats ledgerera)
-> FullByteString
-> Annotator (TxDats ledgerera)
-> TxDats ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (TxDats ledgerera) -> FullByteString -> TxDats ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs Annotator (TxDats ledgerera)
datums)
                                 ((Annotator (Redeemers ledgerera)
 -> FullByteString -> Redeemers ledgerera)
-> FullByteString
-> Annotator (Redeemers ledgerera)
-> Redeemers ledgerera
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotator (Redeemers ledgerera)
-> FullByteString -> Redeemers ledgerera
forall a. Annotator a -> FullByteString -> a
CBOR.runAnnotator FullByteString
fbs Annotator (Redeemers ledgerera)
redeemers)

          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 Annotator (TxBodyScriptData era)
txscriptdata)
              ((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
_ -> String -> Decoder s (Annotator (TxBody era))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (Annotator (TxBody era)))
-> String -> Decoder s (Annotator (TxBody era))
forall a b. (a -> b) -> a -> b
$ String
"expected tx body tuple of size 2, 3, 4 or 6, got " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
len

instance IsCardanoEra era => HasTextEnvelope (TxBody era) where
    textEnvelopeType :: AsType (TxBody era) -> TextEnvelopeType
textEnvelopeType AsType (TxBody era)
_ =
      case CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra :: CardanoEra era of
        CardanoEra era
ByronEra   -> TextEnvelopeType
"TxUnsignedByron"
        CardanoEra era
ShelleyEra -> TextEnvelopeType
"TxUnsignedShelley"
        CardanoEra era
AllegraEra -> TextEnvelopeType
"TxBodyAllegra"
        CardanoEra era
MaryEra    -> TextEnvelopeType
"TxBodyMary"
        CardanoEra era
AlonzoEra  -> TextEnvelopeType
"TxBodyAlonzo"
        CardanoEra era
BabbageEra -> TextEnvelopeType
"TxBodyBabbage"

-- | Calculate the transaction identifier for a 'TxBody'.
--
getTxId :: forall era. TxBody era -> TxId
getTxId :: TxBody era -> TxId
getTxId (ByronTxBody Annotated Tx ByteString
tx) =
    Hash Blake2b_256 EraIndependentTxBody -> TxId
Hash StandardCrypto EraIndependentTxBody -> TxId
TxId
  (Hash Blake2b_256 EraIndependentTxBody -> TxId)
-> (Annotated Tx ByteString
    -> Hash Blake2b_256 EraIndependentTxBody)
-> Annotated Tx ByteString
-> TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash Blake2b_256 EraIndependentTxBody
-> Maybe (Hash Blake2b_256 EraIndependentTxBody)
-> Hash Blake2b_256 EraIndependentTxBody
forall a. a -> Maybe a -> a
fromMaybe Hash Blake2b_256 EraIndependentTxBody
forall a. a
impossible
  (Maybe (Hash Blake2b_256 EraIndependentTxBody)
 -> Hash Blake2b_256 EraIndependentTxBody)
-> (Annotated Tx ByteString
    -> Maybe (Hash Blake2b_256 EraIndependentTxBody))
-> Annotated Tx ByteString
-> Hash Blake2b_256 EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Maybe (Hash Blake2b_256 EraIndependentTxBody)
forall h a. HashAlgorithm h => ShortByteString -> Maybe (Hash h a)
Crypto.hashFromBytesShort
  (ShortByteString -> Maybe (Hash Blake2b_256 EraIndependentTxBody))
-> (Annotated Tx ByteString -> ShortByteString)
-> Annotated Tx ByteString
-> Maybe (Hash Blake2b_256 EraIndependentTxBody)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AbstractHash Blake2b_256 Tx -> ShortByteString
forall algo a. AbstractHash algo a -> ShortByteString
Byron.abstractHashToShort
  (AbstractHash Blake2b_256 Tx -> ShortByteString)
-> (Annotated Tx ByteString -> AbstractHash Blake2b_256 Tx)
-> Annotated Tx ByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotated Tx ByteString -> AbstractHash Blake2b_256 Tx
forall t. Decoded t => t -> Hash (BaseType t)
Byron.hashDecoded
  (Annotated Tx ByteString -> TxId)
-> Annotated Tx ByteString -> TxId
forall a b. (a -> b) -> a -> b
$ Annotated Tx ByteString
tx
  where
    impossible :: a
impossible =
      String -> a
forall a. HasCallStack => String -> a
error String
"getTxId: byron and shelley hash sizes do not match"

getTxId (ShelleyTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
tx [Script (ShelleyLedgerEra era)]
_ TxBodyScriptData era
_ Maybe (AuxiliaryData (ShelleyLedgerEra era))
_ TxScriptValidity era
_) =
  ShelleyBasedEra era
-> ((Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
     UsesTxBody (ShelleyLedgerEra era)) =>
    TxId)
-> TxId
forall a.
ShelleyBasedEra era
-> ((Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
     UsesTxBody (ShelleyLedgerEra era)) =>
    a)
-> a
obtainConstraints ShelleyBasedEra era
era (((Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
   UsesTxBody (ShelleyLedgerEra era)) =>
  TxId)
 -> TxId)
-> ((Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
     UsesTxBody (ShelleyLedgerEra era)) =>
    TxId)
-> TxId
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
forall era.
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
tx
 where
  obtainConstraints
    :: ShelleyBasedEra era
    -> (( Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
        , Ledger.UsesTxBody (ShelleyLedgerEra era)
        ) => a)
    -> a
  obtainConstraints :: ShelleyBasedEra era
-> ((Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
     UsesTxBody (ShelleyLedgerEra era)) =>
    a)
-> a
obtainConstraints ShelleyBasedEra era
ShelleyBasedEraShelley (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f = a
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f
  obtainConstraints ShelleyBasedEra era
ShelleyBasedEraAllegra (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f = a
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f
  obtainConstraints ShelleyBasedEra era
ShelleyBasedEraMary    (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f = a
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f
  obtainConstraints ShelleyBasedEra era
ShelleyBasedEraAlonzo  (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f = a
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f
  obtainConstraints ShelleyBasedEra era
ShelleyBasedEraBabbage (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f = a
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
a
f

getTxIdShelley
  :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
  => Ledger.UsesTxBody (ShelleyLedgerEra era)
  => ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley :: ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley ShelleyBasedEra era
_ TxBody (ShelleyLedgerEra era)
tx =
    Hash Blake2b_256 EraIndependentTxBody -> TxId
Hash StandardCrypto EraIndependentTxBody -> TxId
TxId
  (Hash Blake2b_256 EraIndependentTxBody -> TxId)
-> (TxId StandardCrypto -> Hash Blake2b_256 EraIndependentTxBody)
-> TxId StandardCrypto
-> TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash Blake2b_256 EraIndependentTxBody
-> Hash Blake2b_256 EraIndependentTxBody
forall h a b. Hash h a -> Hash h b
Crypto.castHash
  (Hash Blake2b_256 EraIndependentTxBody
 -> Hash Blake2b_256 EraIndependentTxBody)
-> (TxId StandardCrypto -> Hash Blake2b_256 EraIndependentTxBody)
-> TxId StandardCrypto
-> Hash Blake2b_256 EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(Ledger.TxId SafeHash StandardCrypto EraIndependentTxBody
txhash) -> SafeHash StandardCrypto EraIndependentTxBody
-> Hash StandardCrypto EraIndependentTxBody
forall crypto i. SafeHash crypto i -> Hash (HASH crypto) i
SafeHash.extractHash SafeHash StandardCrypto EraIndependentTxBody
txhash)
  (TxId StandardCrypto -> TxId) -> TxId StandardCrypto -> TxId
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era) -> TxId StandardCrypto
forall era c.
(HashAlgorithm (HASH c),
 HashAnnotated (TxBody era) EraIndependentTxBody c) =>
TxBody era -> TxId c
Ledger.txid TxBody (ShelleyLedgerEra era)
tx

-- ----------------------------------------------------------------------------
-- Constructing transaction bodies
--

data TxBodyError =
       TxBodyEmptyTxIns
     | TxBodyEmptyTxInsCollateral
     | TxBodyEmptyTxOuts
     | TxBodyOutputNegative Quantity TxOutInAnyEra
     | TxBodyOutputOverflow Quantity TxOutInAnyEra
     | TxBodyMetadataError [(Word64, TxMetadataRangeError)]
     | TxBodyMintAdaError
     | TxBodyMissingProtocolParams
     | TxBodyInIxOverflow TxIn
     deriving (TxBodyError -> TxBodyError -> Bool
(TxBodyError -> TxBodyError -> Bool)
-> (TxBodyError -> TxBodyError -> Bool) -> Eq TxBodyError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxBodyError -> TxBodyError -> Bool
$c/= :: TxBodyError -> TxBodyError -> Bool
== :: TxBodyError -> TxBodyError -> Bool
$c== :: TxBodyError -> TxBodyError -> Bool
Eq, Int -> TxBodyError -> ShowS
[TxBodyError] -> ShowS
TxBodyError -> String
(Int -> TxBodyError -> ShowS)
-> (TxBodyError -> String)
-> ([TxBodyError] -> ShowS)
-> Show TxBodyError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxBodyError] -> ShowS
$cshowList :: [TxBodyError] -> ShowS
show :: TxBodyError -> String
$cshow :: TxBodyError -> String
showsPrec :: Int -> TxBodyError -> ShowS
$cshowsPrec :: Int -> TxBodyError -> ShowS
Show)

instance Error TxBodyError where
    displayError :: TxBodyError -> String
displayError TxBodyError
TxBodyEmptyTxIns  = String
"Transaction body has no inputs"
    displayError TxBodyError
TxBodyEmptyTxInsCollateral =
      String
"Transaction body has no collateral inputs, but uses Plutus scripts"
    displayError TxBodyError
TxBodyEmptyTxOuts = String
"Transaction body has no outputs"
    displayError (TxBodyOutputNegative (Quantity Integer
q) TxOutInAnyEra
txout) =
      String
"Negative quantity (" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
q String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
") in transaction output: " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      TxOutInAnyEra -> String
forall a. Show a => a -> String
show TxOutInAnyEra
txout
    displayError (TxBodyOutputOverflow (Quantity Integer
q) TxOutInAnyEra
txout) =
      String
"Quantity too large (" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
q String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" >= 2^64) in transaction output: " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      TxOutInAnyEra -> String
forall a. Show a => a -> String
show TxOutInAnyEra
txout
    displayError (TxBodyMetadataError [(Word64
k, TxMetadataRangeError
err)]) =
      String
"Error in metadata entry " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word64 -> String
forall a. Show a => a -> String
show Word64
k String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
": " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TxMetadataRangeError -> String
forall e. Error e => e -> String
displayError TxMetadataRangeError
err
    displayError (TxBodyMetadataError [(Word64, TxMetadataRangeError)]
errs) =
      String
"Error in metadata entries: " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"; "
        [ Word64 -> String
forall a. Show a => a -> String
show Word64
k String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
": " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TxMetadataRangeError -> String
forall e. Error e => e -> String
displayError TxMetadataRangeError
err
        | (Word64
k, TxMetadataRangeError
err) <- [(Word64, TxMetadataRangeError)]
errs ]
    displayError TxBodyError
TxBodyMintAdaError =
      String
"Transaction cannot mint ada, only non-ada assets"
    displayError TxBodyError
TxBodyMissingProtocolParams =
      String
"Transaction uses Plutus scripts but does not provide the protocol " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      String
"parameters to hash"
    displayError (TxBodyInIxOverflow TxIn
txin) =
      String
"Transaction input index is too big, " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      String
"acceptable value is up to 2^32-1, " String -> ShowS
forall a. [a] -> [a] -> [a]
++
      String
"in input " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TxIn -> String
forall a. Show a => a -> String
show TxIn
txin


makeTransactionBody :: forall era.
     IsCardanoEra era
  => TxBodyContent BuildTx era
  -> Either TxBodyError (TxBody era)
makeTransactionBody :: TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeTransactionBody =
    case CardanoEra era -> CardanoEraStyle era
forall era. CardanoEra era -> CardanoEraStyle era
cardanoEraStyle (CardanoEra era
forall era. IsCardanoEra era => CardanoEra era
cardanoEra :: CardanoEra era) of
      CardanoEraStyle era
LegacyByronEra      -> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
TxBodyContent BuildTx ByronEra
-> Either TxBodyError (TxBody ByronEra)
makeByronTransactionBody
      ShelleyBasedEra ShelleyBasedEra era
era -> ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody ShelleyBasedEra era
era


pattern TxBody :: TxBodyContent ViewTx era -> TxBody era
pattern $mTxBody :: forall r era.
TxBody era -> (TxBodyContent ViewTx era -> r) -> (Void# -> r) -> r
TxBody txbodycontent <- (getTxBodyContent -> txbodycontent)
{-# COMPLETE TxBody #-}

getTxBodyContent :: TxBody era -> TxBodyContent ViewTx era
getTxBodyContent :: TxBody era -> TxBodyContent ViewTx era
getTxBodyContent (ByronTxBody Annotated Tx ByteString
body) = Annotated Tx ByteString -> TxBodyContent ViewTx ByronEra
getByronTxBodyContent Annotated Tx ByteString
body
getTxBodyContent (ShelleyTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body [Script (ShelleyLedgerEra era)]
_scripts TxBodyScriptData era
scriptdata Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux TxScriptValidity era
scriptValidity) =
    ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
forall era.
ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
era TxScriptValidity era
scriptValidity TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux

fromLedgerTxBody
  :: ShelleyBasedEra era
  -> TxScriptValidity era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxBodyScriptData era
  -> Maybe (Ledger.AuxiliaryData (ShelleyLedgerEra era))
  -> TxBodyContent ViewTx era
fromLedgerTxBody :: ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
era TxScriptValidity era
scriptValidity TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux =
    TxBodyContent :: forall build era.
TxIns build era
-> TxInsCollateral era
-> TxInsReference build era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> TxScriptValidity era
-> TxBodyContent build era
TxBodyContent
      { txIns :: TxIns ViewTx era
txIns              = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxIns ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [(TxIn, BuildTxWith ViewTx (Witness WitCtxTxIn era))]
fromLedgerTxIns               ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txInsCollateral :: TxInsCollateral era
txInsCollateral    = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsCollateral era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsCollateral era
fromLedgerTxInsCollateral     ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txInsReference :: TxInsReference ViewTx era
txInsReference     = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference ViewTx era
fromLedgerTxInsReference      ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txOuts :: [TxOut CtxTx era]
txOuts             = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
fromLedgerTxOuts              ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata
      , txTotalCollateral :: TxTotalCollateral era
txTotalCollateral  = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
fromLedgerTxTotalCollateral   ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral  ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txFee :: TxFee era
txFee              = ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxFee era
forall era.
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee               ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txValidityRange :: (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange    = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> (TxValidityLowerBound era, TxValidityUpperBound era)
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> (TxValidityLowerBound era, TxValidityUpperBound era)
fromLedgerTxValidityRange     ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txWithdrawals :: TxWithdrawals ViewTx era
txWithdrawals      = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxWithdrawals ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxWithdrawals ViewTx era
fromLedgerTxWithdrawals       ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txCertificates :: TxCertificates ViewTx era
txCertificates     = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxCertificates ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxCertificates ViewTx era
fromLedgerTxCertificates      ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txUpdateProposal :: TxUpdateProposal era
txUpdateProposal   = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
fromLedgerTxUpdateProposal    ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txMintValue :: TxMintValue ViewTx era
txMintValue        = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxMintValue ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxMintValue ViewTx era
fromLedgerTxMintValue         ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits     = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxExtraKeyWitnesses era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body
      , txProtocolParams :: BuildTxWith ViewTx (Maybe ProtocolParameters)
txProtocolParams   = BuildTxWith ViewTx (Maybe ProtocolParameters)
forall a. BuildTxWith ViewTx a
ViewTx
      , TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
      , TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
      , txScriptValidity :: TxScriptValidity era
txScriptValidity   = TxScriptValidity era
scriptValidity
      }
  where
    (TxMetadataInEra era
txMetadata, TxAuxScripts era
txAuxScripts) = ShelleyBasedEra era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
forall era.
ShelleyBasedEra era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
era Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux


fromLedgerTxIns
  :: forall era.
     ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> [(TxIn,BuildTxWith ViewTx (Witness WitCtxTxIn era))]
fromLedgerTxIns :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [(TxIn, BuildTxWith ViewTx (Witness WitCtxTxIn era))]
fromLedgerTxIns ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
    [ (TxIn StandardCrypto -> TxIn
fromShelleyTxIn TxIn StandardCrypto
input, BuildTxWith ViewTx (Witness WitCtxTxIn era)
forall a. BuildTxWith ViewTx a
ViewTx)
    | TxIn StandardCrypto
input <- Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall a. Set a -> [a]
Set.toList (ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
inputs ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body) ]
  where
    inputs :: ShelleyBasedEra era
           -> Ledger.TxBody (ShelleyLedgerEra era)
           -> Set (Ledger.TxIn StandardCrypto)
    inputs :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
inputs ShelleyBasedEra era
ShelleyBasedEraShelley = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   Set (TxIn (Crypto era))
Shelley._inputs
    inputs ShelleyBasedEra era
ShelleyBasedEraAllegra = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era. TxBody era -> Set (TxIn (Crypto era))
Allegra.inputs'
    inputs ShelleyBasedEra era
ShelleyBasedEraMary    = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era. TxBody era -> Set (TxIn (Crypto era))
Mary.inputs'
    inputs ShelleyBasedEra era
ShelleyBasedEraAlonzo  = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era. TxBody era -> Set (TxIn (Crypto era))
Alonzo.inputs'
    inputs ShelleyBasedEra era
ShelleyBasedEraBabbage = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era.
TxBody era -> BabbageBody era => Set (TxIn (Crypto era))
Babbage.inputs


fromLedgerTxInsCollateral
  :: forall era.
     ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxInsCollateral era
fromLedgerTxInsCollateral :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsCollateral era
fromLedgerTxInsCollateral ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
    case CardanoEra era -> Maybe (CollateralSupportedInEra era)
forall era. CardanoEra era -> Maybe (CollateralSupportedInEra era)
collateralSupportedInEra (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era) of
      Maybe (CollateralSupportedInEra era)
Nothing        -> TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
      Just CollateralSupportedInEra era
supported ->
        CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
forall era.
CollateralSupportedInEra era -> [TxIn] -> TxInsCollateral era
TxInsCollateral CollateralSupportedInEra era
supported ([TxIn] -> TxInsCollateral era) -> [TxIn] -> TxInsCollateral era
forall a b. (a -> b) -> a -> b
$ (TxIn StandardCrypto -> TxIn) -> [TxIn StandardCrypto] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn StandardCrypto -> TxIn
fromShelleyTxIn [TxIn StandardCrypto]
collateral
  where
    collateral :: [Ledger.TxIn StandardCrypto]
    collateral :: [TxIn StandardCrypto]
collateral = case ShelleyBasedEra era
era of
      ShelleyBasedEra era
ShelleyBasedEraShelley -> []
      ShelleyBasedEra era
ShelleyBasedEraAllegra -> []
      ShelleyBasedEra era
ShelleyBasedEraMary    -> []
      ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Set (TxIn StandardCrypto) -> [TxIn StandardCrypto])
-> Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall a b. (a -> b) -> a -> b
$ TxBody (AlonzoEra StandardCrypto)
-> Set (TxIn (Crypto (AlonzoEra StandardCrypto)))
forall era. TxBody era -> Set (TxIn (Crypto era))
Alonzo.collateral' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body
      ShelleyBasedEra era
ShelleyBasedEraBabbage -> Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Set (TxIn StandardCrypto) -> [TxIn StandardCrypto])
-> Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall a b. (a -> b) -> a -> b
$ TxBody (BabbageEra StandardCrypto)
-> BabbageBody (BabbageEra StandardCrypto) =>
   Set (TxIn (Crypto (BabbageEra StandardCrypto)))
forall era.
TxBody era -> BabbageBody era => Set (TxIn (Crypto era))
Babbage.collateral TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerTxInsReference
  :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxInsReference ViewTx era
fromLedgerTxInsReference :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference ViewTx era
fromLedgerTxInsReference ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
txBody =
  case CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
refInsScriptsAndInlineDatsSupportedInEra (CardanoEra era
 -> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era))
-> CardanoEra era
-> Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era of
    Maybe (ReferenceTxInsScriptsInlineDatumsSupportedInEra era)
Nothing -> TxInsReference ViewTx era
forall build era. TxInsReference build era
TxInsReferenceNone
    Just ReferenceTxInsScriptsInlineDatumsSupportedInEra era
suppInEra ->
      let ledgerRefInputs :: Set (TxIn StandardCrypto)
ledgerRefInputs = ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> (HasField
      "referenceInputs"
      (TxBody (ShelleyLedgerEra era))
      (Set (TxIn StandardCrypto)) =>
    Set (TxIn StandardCrypto))
-> Set (TxIn StandardCrypto)
forall era a.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> (HasField
      "referenceInputs"
      (TxBody (ShelleyLedgerEra era))
      (Set (TxIn StandardCrypto)) =>
    a)
-> a
obtainReferenceInputsHasFieldConstraint ReferenceTxInsScriptsInlineDatumsSupportedInEra era
suppInEra ((HasField
    "referenceInputs"
    (TxBody (ShelleyLedgerEra era))
    (Set (TxIn StandardCrypto)) =>
  Set (TxIn StandardCrypto))
 -> Set (TxIn StandardCrypto))
-> (HasField
      "referenceInputs"
      (TxBody (ShelleyLedgerEra era))
      (Set (TxIn StandardCrypto)) =>
    Set (TxIn StandardCrypto))
-> Set (TxIn StandardCrypto)
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall k (x :: k) r a. HasField x r a => r -> a
getField @"referenceInputs" TxBody (ShelleyLedgerEra era)
txBody
      in ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> [TxIn] -> TxInsReference ViewTx era
forall era build.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> [TxIn] -> TxInsReference build era
TxInsReference ReferenceTxInsScriptsInlineDatumsSupportedInEra era
suppInEra
           ([TxIn] -> TxInsReference ViewTx era)
-> [TxIn] -> TxInsReference ViewTx era
forall a b. (a -> b) -> a -> b
$ (TxIn StandardCrypto -> TxIn) -> [TxIn StandardCrypto] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn StandardCrypto -> TxIn
fromShelleyTxIn ([TxIn StandardCrypto] -> [TxIn])
-> (Set (TxIn StandardCrypto) -> [TxIn StandardCrypto])
-> Set (TxIn StandardCrypto)
-> [TxIn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall a. Set a -> [a]
Set.toList (Set (TxIn StandardCrypto) -> [TxIn])
-> Set (TxIn StandardCrypto) -> [TxIn]
forall a b. (a -> b) -> a -> b
$ Set (TxIn StandardCrypto)
ledgerRefInputs
 where
  obtainReferenceInputsHasFieldConstraint
    :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
    -> (HasField "referenceInputs" (Ledger.TxBody (ShelleyLedgerEra era)) (Set (Ledger.TxIn StandardCrypto)) => a)
    -> a
  obtainReferenceInputsHasFieldConstraint :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> (HasField
      "referenceInputs"
      (TxBody (ShelleyLedgerEra era))
      (Set (TxIn StandardCrypto)) =>
    a)
-> a
obtainReferenceInputsHasFieldConstraint ReferenceTxInsScriptsInlineDatumsSupportedInEra era
ReferenceTxInsScriptsInlineDatumsInBabbageEra HasField
  "referenceInputs"
  (TxBody (ShelleyLedgerEra era))
  (Set (TxIn StandardCrypto)) =>
a
f = a
HasField
  "referenceInputs"
  (TxBody (ShelleyLedgerEra era))
  (Set (TxIn StandardCrypto)) =>
a
f

fromLedgerTxOuts
  :: forall era.
     ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxBodyScriptData era
  -> [TxOut CtxTx era]
fromLedgerTxOuts :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
fromLedgerTxOuts ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      [ ShelleyBasedEra era
-> TxOut (ShelleyEra StandardCrypto) -> TxOut CtxTx era
forall era ledgerera ctx.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
era TxOut (ShelleyEra StandardCrypto)
TxOut (ShelleyEra StandardCrypto)
txout | TxOut (ShelleyEra StandardCrypto)
txout <- StrictSeq (TxOut (ShelleyEra StandardCrypto))
-> [TxOut (ShelleyEra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   StrictSeq (TxOut (ShelleyEra StandardCrypto))
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   StrictSeq (TxOut era)
Shelley._outputs TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body) ]

    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      [ ShelleyBasedEra era
-> TxOut (ShelleyMAEra 'Allegra StandardCrypto) -> TxOut CtxTx era
forall era ledgerera ctx.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
era TxOut (ShelleyMAEra 'Allegra StandardCrypto)
TxOut (ShelleyMAEra 'Allegra StandardCrypto)
txout | TxOut (ShelleyMAEra 'Allegra StandardCrypto)
txout <- StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
-> [TxOut (ShelleyMAEra 'Allegra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Allegra.outputs' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body) ]

    ShelleyBasedEra era
ShelleyBasedEraMary ->
      [ ShelleyBasedEra era
-> TxOut (ShelleyMAEra 'Mary StandardCrypto) -> TxOut CtxTx era
forall era ledgerera ctx.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
era TxOut (ShelleyMAEra 'Mary StandardCrypto)
TxOut (ShelleyMAEra 'Mary StandardCrypto)
txout | TxOut (ShelleyMAEra 'Mary StandardCrypto)
txout <- StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
-> [TxOut (ShelleyMAEra 'Mary StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Mary.outputs' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body) ]

    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      [ MultiAssetSupportedInEra AlonzoEra
-> ScriptDataSupportedInEra AlonzoEra
-> Map (DataHash StandardCrypto) (Data (AlonzoEra StandardCrypto))
-> TxOut (AlonzoEra StandardCrypto)
-> TxOut CtxTx AlonzoEra
forall era ledgerera.
(IsShelleyBasedEra era, Era ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 Value ledgerera ~ Value StandardCrypto) =>
MultiAssetSupportedInEra era
-> ScriptDataSupportedInEra era
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> TxOut ledgerera
-> TxOut CtxTx era
fromAlonzoTxOut
          MultiAssetSupportedInEra AlonzoEra
MultiAssetInAlonzoEra
          ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra
          Map (DataHash StandardCrypto) (Data (AlonzoEra StandardCrypto))
Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
txdatums
          TxOut (AlonzoEra StandardCrypto)
txout
      | let txdatums :: Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
txdatums = TxBodyScriptData era
-> Map
     (DataHash (Crypto (ShelleyLedgerEra era)))
     (Data (ShelleyLedgerEra era))
forall era.
TxBodyScriptData era
-> Map
     (DataHash (Crypto (ShelleyLedgerEra era)))
     (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
scriptdata
      , TxOut (AlonzoEra StandardCrypto)
txout <- StrictSeq (TxOut (AlonzoEra StandardCrypto))
-> [TxOut (AlonzoEra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TxBody (AlonzoEra StandardCrypto)
-> StrictSeq (TxOut (AlonzoEra StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Alonzo.outputs' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body) ]

    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      [ MultiAssetSupportedInEra BabbageEra
-> ScriptDataSupportedInEra BabbageEra
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
-> Map (DataHash StandardCrypto) (Data (BabbageEra StandardCrypto))
-> TxOut (BabbageEra StandardCrypto)
-> TxOut CtxTx BabbageEra
forall ledgerera era.
(Era ledgerera, IsShelleyBasedEra era,
 ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 Value ledgerera ~ Value StandardCrypto) =>
MultiAssetSupportedInEra era
-> ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> TxOut ledgerera
-> TxOut CtxTx era
fromBabbageTxOut
          MultiAssetSupportedInEra BabbageEra
MultiAssetInBabbageEra
          ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra
          ReferenceTxInsScriptsInlineDatumsSupportedInEra BabbageEra
ReferenceTxInsScriptsInlineDatumsInBabbageEra
          Map (DataHash StandardCrypto) (Data (BabbageEra StandardCrypto))
Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
txdatums
          (Sized (TxOut (BabbageEra StandardCrypto))
-> TxOut (BabbageEra StandardCrypto)
forall a. Sized a -> a
CBOR.sizedValue Sized (TxOut (BabbageEra StandardCrypto))
txouts)
      | let txdatums :: Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
txdatums = TxBodyScriptData era
-> Map
     (DataHash (Crypto (ShelleyLedgerEra era)))
     (Data (ShelleyLedgerEra era))
forall era.
TxBodyScriptData era
-> Map
     (DataHash (Crypto (ShelleyLedgerEra era)))
     (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
scriptdata
      , Sized (TxOut (BabbageEra StandardCrypto))
txouts <- StrictSeq (Sized (TxOut (BabbageEra StandardCrypto)))
-> [Sized (TxOut (BabbageEra StandardCrypto))]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TxBody (BabbageEra StandardCrypto)
-> BabbageBody (BabbageEra StandardCrypto) =>
   StrictSeq (Sized (TxOut (BabbageEra StandardCrypto)))
forall era.
TxBody era -> BabbageBody era => StrictSeq (Sized (TxOut era))
Babbage.outputs TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body)
      ]
  where
    selectTxDatums :: TxBodyScriptData era
-> Map
     (DataHash (Crypto (ShelleyLedgerEra era)))
     (Data (ShelleyLedgerEra era))
selectTxDatums  TxBodyScriptData era
TxBodyNoScriptData                            = Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
forall k a. Map k a
Map.empty
    selectTxDatums (TxBodyScriptData ScriptDataSupportedInEra era
_ (Alonzo.TxDats' datums) Redeemers (ShelleyLedgerEra era)
_) = Map
  (DataHash (Crypto (ShelleyLedgerEra era)))
  (Data (ShelleyLedgerEra era))
datums

fromAlonzoTxOut :: forall era ledgerera.
                   IsShelleyBasedEra era
                => Ledger.Era ledgerera
                => Ledger.Crypto ledgerera ~ StandardCrypto
                => Ledger.Value ledgerera ~ Mary.Value StandardCrypto
                => MultiAssetSupportedInEra era
                -> ScriptDataSupportedInEra era
                -> Map (Alonzo.DataHash StandardCrypto)
                       (Alonzo.Data ledgerera)
                -> Alonzo.TxOut ledgerera
                -> TxOut CtxTx era
fromAlonzoTxOut :: MultiAssetSupportedInEra era
-> ScriptDataSupportedInEra era
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> TxOut ledgerera
-> TxOut CtxTx era
fromAlonzoTxOut MultiAssetSupportedInEra era
multiAssetInEra ScriptDataSupportedInEra era
scriptDataInEra Map (DataHash StandardCrypto) (Data ledgerera)
txdatums
                (Alonzo.TxOut Addr (Crypto ledgerera)
addr Value ledgerera
value StrictMaybe (DataHash (Crypto ledgerera))
datahash) =
   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 (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra Addr StandardCrypto
Addr (Crypto ledgerera)
addr)
         (MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
multiAssetInEra (Value StandardCrypto -> Value
fromMaryValue Value ledgerera
Value StandardCrypto
value))
         (ScriptDataSupportedInEra era
-> StrictMaybe (DataHash StandardCrypto) -> TxOutDatum CtxTx era
fromAlonzoTxOutDatum ScriptDataSupportedInEra era
scriptDataInEra StrictMaybe (DataHash StandardCrypto)
StrictMaybe (DataHash (Crypto ledgerera))
datahash)
         ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
  where
    fromAlonzoTxOutDatum :: ScriptDataSupportedInEra era
                         -> StrictMaybe (Alonzo.DataHash StandardCrypto)
                         -> TxOutDatum CtxTx era
    fromAlonzoTxOutDatum :: ScriptDataSupportedInEra era
-> StrictMaybe (DataHash StandardCrypto) -> TxOutDatum CtxTx era
fromAlonzoTxOutDatum ScriptDataSupportedInEra era
_          StrictMaybe (DataHash StandardCrypto)
SNothing = TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
    fromAlonzoTxOutDatum ScriptDataSupportedInEra era
supported (SJust DataHash StandardCrypto
dh)
      | Just Data ledgerera
d <- DataHash StandardCrypto
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> Maybe (Data ledgerera)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup DataHash StandardCrypto
dh Map (DataHash StandardCrypto) (Data ledgerera)
txdatums
                  = ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx' ScriptDataSupportedInEra era
supported (DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
dh)
                                              (Data ledgerera -> ScriptData
forall ledgerera. Data ledgerera -> ScriptData
fromAlonzoData Data ledgerera
d)
      | Bool
otherwise = ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
supported (DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
dh)

fromBabbageTxOut
  :: forall ledgerera era. Ledger.Era ledgerera
  => IsShelleyBasedEra era
  => ShelleyLedgerEra era ~ ledgerera
  => Ledger.Crypto ledgerera ~ StandardCrypto
  => Ledger.Value ledgerera ~ Mary.Value StandardCrypto
  => MultiAssetSupportedInEra era
  -> ScriptDataSupportedInEra era
  -> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
  -> Map (Alonzo.DataHash StandardCrypto)
         (Alonzo.Data ledgerera)
  -> Babbage.TxOut ledgerera
  -> TxOut CtxTx era
fromBabbageTxOut :: MultiAssetSupportedInEra era
-> ScriptDataSupportedInEra era
-> ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> TxOut ledgerera
-> TxOut CtxTx era
fromBabbageTxOut MultiAssetSupportedInEra era
multiAssetInEra ScriptDataSupportedInEra era
scriptDataInEra ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineDatumsInEra Map (DataHash StandardCrypto) (Data ledgerera)
txdatums TxOut ledgerera
txout =
   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
     (ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
forall era.
ShelleyBasedEra era -> Addr StandardCrypto -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra Addr StandardCrypto
Addr (Crypto ledgerera)
addr)
     (MultiAssetSupportedInEra era -> Value -> TxOutValue era
forall era. MultiAssetSupportedInEra era -> Value -> TxOutValue era
TxOutValue MultiAssetSupportedInEra era
multiAssetInEra (Value StandardCrypto -> Value
fromMaryValue Value ledgerera
Value StandardCrypto
val))
     TxOutDatum CtxTx era
babbageTxOutDatum
     (case StrictMaybe (Script ledgerera)
mRefScript of
       StrictMaybe (Script ledgerera)
SNothing -> ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
       SJust Script ledgerera
rScript -> ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
fromShelleyScriptToReferenceScript ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra Script ledgerera
Script (ShelleyLedgerEra era)
rScript
     )
 where
   -- NOTE: This is different to 'fromBabbageTxOutDatum' as it may resolve
   -- 'DatumHash' values using the datums included in the transaction.
   babbageTxOutDatum :: TxOutDatum CtxTx era
   babbageTxOutDatum :: TxOutDatum CtxTx era
babbageTxOutDatum =
     case Datum ledgerera
datum of
       Datum ledgerera
Babbage.NoDatum -> TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
       Babbage.DatumHash DataHash (Crypto ledgerera)
dh -> DataHash StandardCrypto -> TxOutDatum CtxTx era
resolveDatumInTx DataHash StandardCrypto
DataHash (Crypto ledgerera)
dh
       Babbage.Datum BinaryData ledgerera
d ->
         ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum CtxTx era
forall era ctx.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> ScriptData -> TxOutDatum ctx era
TxOutDatumInline ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineDatumsInEra (ScriptData -> TxOutDatum CtxTx era)
-> ScriptData -> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$
           ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> BinaryData ledgerera -> ScriptData
forall era ledgerera.
ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> BinaryData ledgerera -> ScriptData
binaryDataToScriptData ReferenceTxInsScriptsInlineDatumsSupportedInEra era
inlineDatumsInEra BinaryData ledgerera
d

   resolveDatumInTx :: Alonzo.DataHash StandardCrypto -> TxOutDatum CtxTx era
   resolveDatumInTx :: DataHash StandardCrypto -> TxOutDatum CtxTx era
resolveDatumInTx DataHash StandardCrypto
dh
      | Just Data ledgerera
d <- DataHash StandardCrypto
-> Map (DataHash StandardCrypto) (Data ledgerera)
-> Maybe (Data ledgerera)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup DataHash StandardCrypto
dh Map (DataHash StandardCrypto) (Data ledgerera)
txdatums
                  = ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
forall era.
ScriptDataSupportedInEra era
-> Hash ScriptData -> ScriptData -> TxOutDatum CtxTx era
TxOutDatumInTx' ScriptDataSupportedInEra era
scriptDataInEra (DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
dh) (Data ledgerera -> ScriptData
forall ledgerera. Data ledgerera -> ScriptData
fromAlonzoData Data ledgerera
d)
      | Bool
otherwise = ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
ScriptDataSupportedInEra era
-> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash ScriptDataSupportedInEra era
scriptDataInEra (DataHash StandardCrypto -> Hash ScriptData
ScriptDataHash DataHash StandardCrypto
dh)

   (Babbage.TxOut Addr (Crypto ledgerera)
addr Value ledgerera
val Datum ledgerera
datum StrictMaybe (Script ledgerera)
mRefScript) = TxOut ledgerera
txout

fromLedgerTxTotalCollateral
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxTotalCollateral era
fromLedgerTxTotalCollateral :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
fromLedgerTxTotalCollateral ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
txbody =
  case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra (CardanoEra era
 -> Maybe (TxTotalAndReturnCollateralSupportedInEra era))
-> CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era of
    Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
    Just TxTotalAndReturnCollateralSupportedInEra era
supp ->
      case TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "totalCollateral"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe Coin) =>
    StrictMaybe Coin)
-> StrictMaybe Coin
forall era a.
TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "totalCollateral"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe Coin) =>
    a)
-> a
obtainTotalCollateralHasFieldConstraint TxTotalAndReturnCollateralSupportedInEra era
supp ((HasField
    "totalCollateral"
    (TxBody (ShelleyLedgerEra era))
    (StrictMaybe Coin) =>
  StrictMaybe Coin)
 -> StrictMaybe Coin)
-> (HasField
      "totalCollateral"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe Coin) =>
    StrictMaybe Coin)
-> StrictMaybe Coin
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era) -> StrictMaybe Coin
forall k (x :: k) r a. HasField x r a => r -> a
getField @"totalCollateral" TxBody (ShelleyLedgerEra era)
txbody of
        StrictMaybe Coin
SNothing -> TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
        SJust Coin
totColl -> TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
forall era.
TxTotalAndReturnCollateralSupportedInEra era
-> Lovelace -> TxTotalCollateral era
TxTotalCollateral TxTotalAndReturnCollateralSupportedInEra era
supp (Lovelace -> TxTotalCollateral era)
-> Lovelace -> TxTotalCollateral era
forall a b. (a -> b) -> a -> b
$ Coin -> Lovelace
fromShelleyLovelace Coin
totColl
 where
  obtainTotalCollateralHasFieldConstraint
    :: TxTotalAndReturnCollateralSupportedInEra era
    -> (HasField "totalCollateral" (Ledger.TxBody (ShelleyLedgerEra era)) (StrictMaybe Ledger.Coin) => a)
    -> a
  obtainTotalCollateralHasFieldConstraint :: TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "totalCollateral"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe Coin) =>
    a)
-> a
obtainTotalCollateralHasFieldConstraint TxTotalAndReturnCollateralSupportedInEra era
TxTotalAndReturnCollateralInBabbageEra HasField
  "totalCollateral"
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe Coin) =>
a
f = a
HasField
  "totalCollateral"
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe Coin) =>
a
f

fromLedgerTxReturnCollateral
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
txbody =
  case CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall era.
CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
totalAndReturnCollateralSupportedInEra (CardanoEra era
 -> Maybe (TxTotalAndReturnCollateralSupportedInEra era))
-> CardanoEra era
-> Maybe (TxTotalAndReturnCollateralSupportedInEra era)
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
shelleyBasedToCardanoEra ShelleyBasedEra era
era of
    Maybe (TxTotalAndReturnCollateralSupportedInEra era)
Nothing -> TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
    Just TxTotalAndReturnCollateralSupportedInEra era
supp ->
      case TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "collateralReturn"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
    StrictMaybe (TxOut (ShelleyLedgerEra era)))
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall era a.
TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "collateralReturn"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
    a)
-> a
obtainCollateralReturnHasFieldConstraint TxTotalAndReturnCollateralSupportedInEra era
supp ((HasField
    "collateralReturn"
    (TxBody (ShelleyLedgerEra era))
    (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
  StrictMaybe (TxOut (ShelleyLedgerEra era)))
 -> StrictMaybe (TxOut (ShelleyLedgerEra era)))
-> (HasField
      "collateralReturn"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
    StrictMaybe (TxOut (ShelleyLedgerEra era)))
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era)
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall k (x :: k) r a. HasField x r a => r -> a
getField @"collateralReturn" TxBody (ShelleyLedgerEra era)
txbody of
        StrictMaybe (TxOut (ShelleyLedgerEra era))
SNothing -> TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
        SJust TxOut (ShelleyLedgerEra era)
collReturnOut ->
          TxTotalAndReturnCollateralSupportedInEra era
-> TxOut CtxTx era -> TxReturnCollateral CtxTx era
forall era ctx.
TxTotalAndReturnCollateralSupportedInEra era
-> TxOut ctx era -> TxReturnCollateral ctx era
TxReturnCollateral TxTotalAndReturnCollateralSupportedInEra era
supp (TxOut CtxTx era -> TxReturnCollateral CtxTx era)
-> TxOut CtxTx era -> TxReturnCollateral CtxTx era
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era
forall era ledgerera ctx.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
era TxOut (ShelleyLedgerEra era)
collReturnOut
 where
  obtainCollateralReturnHasFieldConstraint
    :: TxTotalAndReturnCollateralSupportedInEra era
    -> (HasField "collateralReturn"
          (Ledger.TxBody (ShelleyLedgerEra era))
          (StrictMaybe (Ledger.TxOut (ShelleyLedgerEra era))) => a)
    -> a
  obtainCollateralReturnHasFieldConstraint :: TxTotalAndReturnCollateralSupportedInEra era
-> (HasField
      "collateralReturn"
      (TxBody (ShelleyLedgerEra era))
      (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
    a)
-> a
obtainCollateralReturnHasFieldConstraint TxTotalAndReturnCollateralSupportedInEra era
TxTotalAndReturnCollateralInBabbageEra HasField
  "collateralReturn"
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
a
f = a
HasField
  "collateralReturn"
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (TxOut (ShelleyLedgerEra era))) =>
a
f


fromLedgerTxFee
  :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee :: ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      TxFeesExplicitInEra ShelleyEra -> Lovelace -> TxFee ShelleyEra
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra ShelleyEra
TxFeesExplicitInShelleyEra (Lovelace -> TxFee ShelleyEra) -> Lovelace -> TxFee ShelleyEra
forall a b. (a -> b) -> a -> b
$
      Coin -> Lovelace
fromShelleyLovelace (Coin -> Lovelace) -> Coin -> Lovelace
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   Coin
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   Coin
Shelley._txfee TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body
    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      TxFeesExplicitInEra AllegraEra -> Lovelace -> TxFee AllegraEra
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra AllegraEra
TxFeesExplicitInAllegraEra (Lovelace -> TxFee AllegraEra) -> Lovelace -> TxFee AllegraEra
forall a b. (a -> b) -> a -> b
$
      Coin -> Lovelace
fromShelleyLovelace (Coin -> Lovelace) -> Coin -> Lovelace
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> Coin
forall era. TxBody era -> Coin
Allegra.txfee' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body
    ShelleyBasedEra era
ShelleyBasedEraMary ->
      TxFeesExplicitInEra MaryEra -> Lovelace -> TxFee MaryEra
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra MaryEra
TxFeesExplicitInMaryEra (Lovelace -> TxFee MaryEra) -> Lovelace -> TxFee MaryEra
forall a b. (a -> b) -> a -> b
$
      Coin -> Lovelace
fromShelleyLovelace (Coin -> Lovelace) -> Coin -> Lovelace
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyMAEra 'Mary StandardCrypto) -> Coin
forall era. TxBody era -> Coin
Mary.txfee' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body
    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      TxFeesExplicitInEra AlonzoEra -> Lovelace -> TxFee AlonzoEra
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra AlonzoEra
TxFeesExplicitInAlonzoEra (Lovelace -> TxFee AlonzoEra) -> Lovelace -> TxFee AlonzoEra
forall a b. (a -> b) -> a -> b
$
      Coin -> Lovelace
fromShelleyLovelace (Coin -> Lovelace) -> Coin -> Lovelace
forall a b. (a -> b) -> a -> b
$ TxBody (AlonzoEra StandardCrypto) -> Coin
forall era. TxBody era -> Coin
Alonzo.txfee' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body
    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      TxFeesExplicitInEra BabbageEra -> Lovelace -> TxFee BabbageEra
forall era. TxFeesExplicitInEra era -> Lovelace -> TxFee era
TxFeeExplicit TxFeesExplicitInEra BabbageEra
TxFeesExplicitInBabbageEra (Lovelace -> TxFee BabbageEra) -> Lovelace -> TxFee BabbageEra
forall a b. (a -> b) -> a -> b
$
      Coin -> Lovelace
fromShelleyLovelace (Coin -> Lovelace) -> Coin -> Lovelace
forall a b. (a -> b) -> a -> b
$ TxBody (BabbageEra StandardCrypto)
-> BabbageBody (BabbageEra StandardCrypto) => Coin
forall era. TxBody era -> BabbageBody era => Coin
Babbage.txfee TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerTxValidityRange
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> (TxValidityLowerBound era, TxValidityUpperBound era)
fromLedgerTxValidityRange :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> (TxValidityLowerBound era, TxValidityUpperBound era)
fromLedgerTxValidityRange ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      ( TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
      , ValidityUpperBoundSupportedInEra ShelleyEra
-> SlotNo -> TxValidityUpperBound ShelleyEra
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound ValidityUpperBoundSupportedInEra ShelleyEra
ValidityUpperBoundInShelleyEra (SlotNo -> TxValidityUpperBound ShelleyEra)
-> SlotNo -> TxValidityUpperBound ShelleyEra
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   SlotNo
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   SlotNo
Shelley._ttl TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body
      )

    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      ( case StrictMaybe SlotNo
invalidBefore of
          StrictMaybe SlotNo
SNothing -> TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
          SJust SlotNo
s  -> ValidityLowerBoundSupportedInEra AllegraEra
-> SlotNo -> TxValidityLowerBound AllegraEra
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra AllegraEra
ValidityLowerBoundInAllegraEra SlotNo
s
      , case StrictMaybe SlotNo
invalidHereafter of
          StrictMaybe SlotNo
SNothing -> ValidityNoUpperBoundSupportedInEra AllegraEra
-> TxValidityUpperBound AllegraEra
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra AllegraEra
ValidityNoUpperBoundInAllegraEra
          SJust SlotNo
s  -> ValidityUpperBoundSupportedInEra AllegraEra
-> SlotNo -> TxValidityUpperBound AllegraEra
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound   ValidityUpperBoundSupportedInEra AllegraEra
ValidityUpperBoundInAllegraEra SlotNo
s
      )
      where
        Allegra.ValidityInterval{StrictMaybe SlotNo
invalidBefore :: ValidityInterval -> StrictMaybe SlotNo
invalidBefore :: StrictMaybe SlotNo
invalidBefore, StrictMaybe SlotNo
invalidHereafter :: ValidityInterval -> StrictMaybe SlotNo
invalidHereafter :: StrictMaybe SlotNo
invalidHereafter} =
          TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> ValidityInterval
forall era. TxBody era -> ValidityInterval
Allegra.vldt' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraMary ->
      ( case StrictMaybe SlotNo
invalidBefore of
          StrictMaybe SlotNo
SNothing -> TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
          SJust SlotNo
s  -> ValidityLowerBoundSupportedInEra MaryEra
-> SlotNo -> TxValidityLowerBound MaryEra
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra MaryEra
ValidityLowerBoundInMaryEra SlotNo
s
      , case StrictMaybe SlotNo
invalidHereafter of
          StrictMaybe SlotNo
SNothing -> ValidityNoUpperBoundSupportedInEra MaryEra
-> TxValidityUpperBound MaryEra
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra MaryEra
ValidityNoUpperBoundInMaryEra
          SJust SlotNo
s  -> ValidityUpperBoundSupportedInEra MaryEra
-> SlotNo -> TxValidityUpperBound MaryEra
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound   ValidityUpperBoundSupportedInEra MaryEra
ValidityUpperBoundInMaryEra SlotNo
s
      )
      where
        Mary.ValidityInterval{StrictMaybe SlotNo
invalidBefore :: StrictMaybe SlotNo
invalidBefore :: ValidityInterval -> StrictMaybe SlotNo
invalidBefore, StrictMaybe SlotNo
invalidHereafter :: StrictMaybe SlotNo
invalidHereafter :: ValidityInterval -> StrictMaybe SlotNo
invalidHereafter} = TxBody (ShelleyMAEra 'Mary StandardCrypto) -> ValidityInterval
forall era. TxBody era -> ValidityInterval
Mary.vldt' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      ( case StrictMaybe SlotNo
invalidBefore of
          StrictMaybe SlotNo
SNothing -> TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
          SJust SlotNo
s  -> ValidityLowerBoundSupportedInEra AlonzoEra
-> SlotNo -> TxValidityLowerBound AlonzoEra
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra AlonzoEra
ValidityLowerBoundInAlonzoEra SlotNo
s
      , case StrictMaybe SlotNo
invalidHereafter of
          StrictMaybe SlotNo
SNothing -> ValidityNoUpperBoundSupportedInEra AlonzoEra
-> TxValidityUpperBound AlonzoEra
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra AlonzoEra
ValidityNoUpperBoundInAlonzoEra
          SJust SlotNo
s  -> ValidityUpperBoundSupportedInEra AlonzoEra
-> SlotNo -> TxValidityUpperBound AlonzoEra
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound   ValidityUpperBoundSupportedInEra AlonzoEra
ValidityUpperBoundInAlonzoEra SlotNo
s
      )
      where
        Mary.ValidityInterval{StrictMaybe SlotNo
invalidBefore :: StrictMaybe SlotNo
invalidBefore :: ValidityInterval -> StrictMaybe SlotNo
invalidBefore, StrictMaybe SlotNo
invalidHereafter :: StrictMaybe SlotNo
invalidHereafter :: ValidityInterval -> StrictMaybe SlotNo
invalidHereafter} = TxBody (AlonzoEra StandardCrypto) -> ValidityInterval
forall era. TxBody era -> ValidityInterval
Alonzo.vldt' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      ( case StrictMaybe SlotNo
invalidBefore of
          StrictMaybe SlotNo
SNothing -> TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
          SJust SlotNo
s  -> ValidityLowerBoundSupportedInEra BabbageEra
-> SlotNo -> TxValidityLowerBound BabbageEra
forall era.
ValidityLowerBoundSupportedInEra era
-> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound ValidityLowerBoundSupportedInEra BabbageEra
ValidityLowerBoundInBabbageEra SlotNo
s
      , case StrictMaybe SlotNo
invalidHereafter of
          StrictMaybe SlotNo
SNothing -> ValidityNoUpperBoundSupportedInEra BabbageEra
-> TxValidityUpperBound BabbageEra
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra BabbageEra
ValidityNoUpperBoundInBabbageEra
          SJust SlotNo
s  -> ValidityUpperBoundSupportedInEra BabbageEra
-> SlotNo -> TxValidityUpperBound BabbageEra
forall era.
ValidityUpperBoundSupportedInEra era
-> SlotNo -> TxValidityUpperBound era
TxValidityUpperBound   ValidityUpperBoundSupportedInEra BabbageEra
ValidityUpperBoundInBabbageEra SlotNo
s
      )
      where
        Mary.ValidityInterval{StrictMaybe SlotNo
invalidBefore :: StrictMaybe SlotNo
invalidBefore :: ValidityInterval -> StrictMaybe SlotNo
invalidBefore, StrictMaybe SlotNo
invalidHereafter :: StrictMaybe SlotNo
invalidHereafter :: ValidityInterval -> StrictMaybe SlotNo
invalidHereafter} = TxBody (BabbageEra StandardCrypto)
-> BabbageBody (BabbageEra StandardCrypto) => ValidityInterval
forall era. TxBody era -> BabbageBody era => ValidityInterval
Babbage.txvldt TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerAuxiliaryData
  :: ShelleyBasedEra era
  -> Ledger.AuxiliaryData (ShelleyLedgerEra era)
  -> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData :: ShelleyBasedEra era
-> AuxiliaryData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraShelley (Shelley.Metadata metadata) =
  (Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
metadata, [])
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraAllegra (Allegra.AuxiliaryData ms ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra AllegraEra
-> Script (ShelleyLedgerEra AllegraEra) -> ScriptInEra AllegraEra
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra (Timelock StandardCrypto -> ScriptInEra AllegraEra)
-> [Timelock StandardCrypto] -> [ScriptInEra AllegraEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock StandardCrypto) -> [Timelock StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (Script (ShelleyMAEra 'Allegra StandardCrypto))
StrictSeq (Timelock StandardCrypto)
ss
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraMary (Mary.AuxiliaryData ms ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra MaryEra
-> Script (ShelleyLedgerEra MaryEra) -> ScriptInEra MaryEra
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra MaryEra
ShelleyBasedEraMary (Timelock StandardCrypto -> ScriptInEra MaryEra)
-> [Timelock StandardCrypto] -> [ScriptInEra MaryEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock StandardCrypto) -> [Timelock StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (Script (ShelleyMAEra 'Mary StandardCrypto))
StrictSeq (Timelock StandardCrypto)
ss
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraAlonzo (Alonzo.AuxiliaryData ms ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra AlonzoEra
-> Script (ShelleyLedgerEra AlonzoEra) -> ScriptInEra AlonzoEra
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo (Script (AlonzoEra StandardCrypto) -> ScriptInEra AlonzoEra)
-> [Script (AlonzoEra StandardCrypto)] -> [ScriptInEra AlonzoEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Script (AlonzoEra StandardCrypto))
-> [Script (AlonzoEra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (Script (AlonzoEra StandardCrypto))
StrictSeq (Script (AlonzoEra StandardCrypto))
ss
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraBabbage (Alonzo.AuxiliaryData ms ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra BabbageEra
-> Script (ShelleyLedgerEra BabbageEra) -> ScriptInEra BabbageEra
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage (Script (BabbageEra StandardCrypto) -> ScriptInEra BabbageEra)
-> [Script (BabbageEra StandardCrypto)] -> [ScriptInEra BabbageEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Script (BabbageEra StandardCrypto))
-> [Script (BabbageEra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (Script (BabbageEra StandardCrypto))
StrictSeq (Script (BabbageEra StandardCrypto))
ss
  )

fromLedgerTxAuxiliaryData
  :: ShelleyBasedEra era
  -> Maybe (Ledger.AuxiliaryData (ShelleyLedgerEra era))
  -> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData :: ShelleyBasedEra era
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
_ Maybe (AuxiliaryData (ShelleyLedgerEra era))
Nothing = (TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone, TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
era (Just AuxiliaryData (ShelleyLedgerEra era)
auxData) =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      ( if Map Word64 TxMetadataValue -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then
          TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
        else
          TxMetadataSupportedInEra ShelleyEra
-> TxMetadata -> TxMetadataInEra ShelleyEra
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra ShelleyEra
TxMetadataInShelleyEra (TxMetadata -> TxMetadataInEra ShelleyEra)
-> TxMetadata -> TxMetadataInEra ShelleyEra
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms
      , TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
      )
    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      ( if Map Word64 TxMetadataValue -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then
          TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
        else
          TxMetadataSupportedInEra AllegraEra
-> TxMetadata -> TxMetadataInEra AllegraEra
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra AllegraEra
TxMetadataInAllegraEra (TxMetadata -> TxMetadataInEra AllegraEra)
-> TxMetadata -> TxMetadataInEra AllegraEra
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms
      , case [ScriptInEra era]
ss of
          [] -> TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
          [ScriptInEra era]
_  -> AuxScriptsSupportedInEra AllegraEra
-> [ScriptInEra AllegraEra] -> TxAuxScripts AllegraEra
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra AllegraEra
AuxScriptsInAllegraEra [ScriptInEra era]
[ScriptInEra AllegraEra]
ss
      )
    ShelleyBasedEra era
ShelleyBasedEraMary ->
      ( if Map Word64 TxMetadataValue -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then
          TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
        else
          TxMetadataSupportedInEra MaryEra
-> TxMetadata -> TxMetadataInEra MaryEra
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra MaryEra
TxMetadataInMaryEra (TxMetadata -> TxMetadataInEra MaryEra)
-> TxMetadata -> TxMetadataInEra MaryEra
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms
      , case [ScriptInEra era]
ss of
          [] -> TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
          [ScriptInEra era]
_  -> AuxScriptsSupportedInEra MaryEra
-> [ScriptInEra MaryEra] -> TxAuxScripts MaryEra
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra MaryEra
AuxScriptsInMaryEra [ScriptInEra era]
[ScriptInEra MaryEra]
ss
      )
    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      ( if Map Word64 TxMetadataValue -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then
          TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
        else
          TxMetadataSupportedInEra AlonzoEra
-> TxMetadata -> TxMetadataInEra AlonzoEra
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra AlonzoEra
TxMetadataInAlonzoEra (TxMetadata -> TxMetadataInEra AlonzoEra)
-> TxMetadata -> TxMetadataInEra AlonzoEra
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms
      , case [ScriptInEra era]
ss of
          [] -> TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
          [ScriptInEra era]
_  -> AuxScriptsSupportedInEra AlonzoEra
-> [ScriptInEra AlonzoEra] -> TxAuxScripts AlonzoEra
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra AlonzoEra
AuxScriptsInAlonzoEra [ScriptInEra era]
[ScriptInEra AlonzoEra]
ss
      )
    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      ( if Map Word64 TxMetadataValue -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then
          TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
        else
          TxMetadataSupportedInEra BabbageEra
-> TxMetadata -> TxMetadataInEra BabbageEra
forall era.
TxMetadataSupportedInEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra TxMetadataSupportedInEra BabbageEra
TxMetadataInBabbageEra (TxMetadata -> TxMetadataInEra BabbageEra)
-> TxMetadata -> TxMetadataInEra BabbageEra
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms
      , case [ScriptInEra era]
ss of
          [] -> TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
          [ScriptInEra era]
_  -> AuxScriptsSupportedInEra BabbageEra
-> [ScriptInEra BabbageEra] -> TxAuxScripts BabbageEra
forall era.
AuxScriptsSupportedInEra era
-> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AuxScriptsSupportedInEra BabbageEra
AuxScriptsInBabbageEra [ScriptInEra era]
[ScriptInEra BabbageEra]
ss
      )
  where
    (Map Word64 TxMetadataValue
ms, [ScriptInEra era]
ss) = ShelleyBasedEra era
-> AuxiliaryData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
forall era.
ShelleyBasedEra era
-> AuxiliaryData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData ShelleyBasedEra era
era AuxiliaryData (ShelleyLedgerEra era)
auxData


fromLedgerTxExtraKeyWitnesses :: ShelleyBasedEra era
                              -> Ledger.TxBody (ShelleyLedgerEra era)
                              -> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
sbe of
    ShelleyBasedEra era
ShelleyBasedEraShelley -> TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
    ShelleyBasedEra era
ShelleyBasedEraAllegra -> TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
    ShelleyBasedEra era
ShelleyBasedEraMary    -> TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
    ShelleyBasedEra era
ShelleyBasedEraAlonzo
      | Set (KeyHash 'Witness StandardCrypto) -> Bool
forall a. Set a -> Bool
Set.null Set (KeyHash 'Witness StandardCrypto)
Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
keyhashes -> TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
      | Bool
otherwise          -> TxExtraKeyWitnessesSupportedInEra AlonzoEra
-> [Hash PaymentKey] -> TxExtraKeyWitnesses AlonzoEra
forall era.
TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses
                                TxExtraKeyWitnessesSupportedInEra AlonzoEra
ExtraKeyWitnessesInAlonzoEra
                                [ KeyHash 'Payment StandardCrypto -> Hash PaymentKey
PaymentKeyHash (KeyHash 'Witness StandardCrypto -> KeyHash 'Payment StandardCrypto
forall (a :: KeyRole -> * -> *) (r :: KeyRole) crypto
       (r' :: KeyRole).
HasKeyRole a =>
a r crypto -> a r' crypto
Shelley.coerceKeyRole KeyHash 'Witness StandardCrypto
keyhash)
                                | KeyHash 'Witness StandardCrypto
keyhash <- Set (KeyHash 'Witness StandardCrypto)
-> [KeyHash 'Witness StandardCrypto]
forall a. Set a -> [a]
Set.toList Set (KeyHash 'Witness StandardCrypto)
Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
keyhashes ]
      where
        keyhashes :: Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
keyhashes = TxBody (AlonzoEra StandardCrypto)
-> AlonzoBody (AlonzoEra StandardCrypto) =>
   Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
forall era.
TxBody era -> AlonzoBody era => Set (KeyHash 'Witness (Crypto era))
Alonzo.reqSignerHashes TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body
    ShelleyBasedEra era
ShelleyBasedEraBabbage
      | Set (KeyHash 'Witness StandardCrypto) -> Bool
forall a. Set a -> Bool
Set.null Set (KeyHash 'Witness StandardCrypto)
Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
keyhashes -> TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
      | Bool
otherwise          -> TxExtraKeyWitnessesSupportedInEra BabbageEra
-> [Hash PaymentKey] -> TxExtraKeyWitnesses BabbageEra
forall era.
TxExtraKeyWitnessesSupportedInEra era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses
                                TxExtraKeyWitnessesSupportedInEra BabbageEra
ExtraKeyWitnessesInBabbageEra
                                [ KeyHash 'Payment StandardCrypto -> Hash PaymentKey
PaymentKeyHash (KeyHash 'Witness StandardCrypto -> KeyHash 'Payment StandardCrypto
forall (a :: KeyRole -> * -> *) (r :: KeyRole) crypto
       (r' :: KeyRole).
HasKeyRole a =>
a r crypto -> a r' crypto
Shelley.coerceKeyRole KeyHash 'Witness StandardCrypto
keyhash)
                                | KeyHash 'Witness StandardCrypto
keyhash <- Set (KeyHash 'Witness StandardCrypto)
-> [KeyHash 'Witness StandardCrypto]
forall a. Set a -> [a]
Set.toList Set (KeyHash 'Witness StandardCrypto)
Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
keyhashes ]
      where
        keyhashes :: Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
keyhashes = TxBody (BabbageEra StandardCrypto)
-> BabbageBody (BabbageEra StandardCrypto) =>
   Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
forall era.
TxBody era
-> BabbageBody era => Set (KeyHash 'Witness (Crypto era))
Babbage.reqSignerHashes TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerTxWithdrawals
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxWithdrawals ViewTx era
fromLedgerTxWithdrawals :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxWithdrawals ViewTx era
fromLedgerTxWithdrawals ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley
      | Map (RewardAcnt StandardCrypto) Coin -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Wdrl StandardCrypto -> Map (RewardAcnt StandardCrypto) Coin
forall crypto. Wdrl crypto -> Map (RewardAcnt crypto) Coin
Shelley.unWdrl Wdrl StandardCrypto
Wdrl (Crypto (ShelleyEra StandardCrypto))
withdrawals) -> TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
      | Bool
otherwise ->
          WithdrawalsSupportedInEra ShelleyEra
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake ShelleyEra))]
-> TxWithdrawals ViewTx ShelleyEra
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra ShelleyEra
WithdrawalsInShelleyEra ([(StakeAddress, Lovelace,
   BuildTxWith ViewTx (Witness WitCtxStake ShelleyEra))]
 -> TxWithdrawals ViewTx ShelleyEra)
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake ShelleyEra))]
-> TxWithdrawals ViewTx ShelleyEra
forall a b. (a -> b) -> a -> b
$
          Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake ShelleyEra))]
forall era.
Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Wdrl StandardCrypto
Wdrl (Crypto (ShelleyEra StandardCrypto))
withdrawals
      where
        withdrawals :: Wdrl (Crypto (ShelleyEra StandardCrypto))
withdrawals = TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   Wdrl (Crypto (ShelleyEra StandardCrypto))
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   Wdrl (Crypto era)
Shelley._wdrls TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAllegra
      | Map (RewardAcnt StandardCrypto) Coin -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Wdrl StandardCrypto -> Map (RewardAcnt StandardCrypto) Coin
forall crypto. Wdrl crypto -> Map (RewardAcnt crypto) Coin
Shelley.unWdrl Wdrl StandardCrypto
Wdrl (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
withdrawals) -> TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
      | Bool
otherwise ->
          WithdrawalsSupportedInEra AllegraEra
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AllegraEra))]
-> TxWithdrawals ViewTx AllegraEra
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra AllegraEra
WithdrawalsInAllegraEra ([(StakeAddress, Lovelace,
   BuildTxWith ViewTx (Witness WitCtxStake AllegraEra))]
 -> TxWithdrawals ViewTx AllegraEra)
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AllegraEra))]
-> TxWithdrawals ViewTx AllegraEra
forall a b. (a -> b) -> a -> b
$
          Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AllegraEra))]
forall era.
Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Wdrl StandardCrypto
Wdrl (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
withdrawals
      where
        withdrawals :: Wdrl (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
withdrawals = TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> Wdrl (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
forall era. TxBody era -> Wdrl (Crypto era)
Allegra.wdrls' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraMary
      | Map (RewardAcnt StandardCrypto) Coin -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Wdrl StandardCrypto -> Map (RewardAcnt StandardCrypto) Coin
forall crypto. Wdrl crypto -> Map (RewardAcnt crypto) Coin
Shelley.unWdrl Wdrl StandardCrypto
Wdrl (Crypto (ShelleyMAEra 'Mary StandardCrypto))
withdrawals) -> TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
      | Bool
otherwise ->
          WithdrawalsSupportedInEra MaryEra
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake MaryEra))]
-> TxWithdrawals ViewTx MaryEra
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra MaryEra
WithdrawalsInMaryEra ([(StakeAddress, Lovelace,
   BuildTxWith ViewTx (Witness WitCtxStake MaryEra))]
 -> TxWithdrawals ViewTx MaryEra)
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake MaryEra))]
-> TxWithdrawals ViewTx MaryEra
forall a b. (a -> b) -> a -> b
$ Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake MaryEra))]
forall era.
Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Wdrl StandardCrypto
Wdrl (Crypto (ShelleyMAEra 'Mary StandardCrypto))
withdrawals
      where
        withdrawals :: Wdrl (Crypto (ShelleyMAEra 'Mary StandardCrypto))
withdrawals = TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> Wdrl (Crypto (ShelleyMAEra 'Mary StandardCrypto))
forall era. TxBody era -> Wdrl (Crypto era)
Mary.wdrls' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAlonzo
      | Map (RewardAcnt StandardCrypto) Coin -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Wdrl StandardCrypto -> Map (RewardAcnt StandardCrypto) Coin
forall crypto. Wdrl crypto -> Map (RewardAcnt crypto) Coin
Shelley.unWdrl Wdrl StandardCrypto
Wdrl (Crypto (AlonzoEra StandardCrypto))
withdrawals) -> TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
      | Bool
otherwise ->
          WithdrawalsSupportedInEra AlonzoEra
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AlonzoEra))]
-> TxWithdrawals ViewTx AlonzoEra
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra AlonzoEra
WithdrawalsInAlonzoEra ([(StakeAddress, Lovelace,
   BuildTxWith ViewTx (Witness WitCtxStake AlonzoEra))]
 -> TxWithdrawals ViewTx AlonzoEra)
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AlonzoEra))]
-> TxWithdrawals ViewTx AlonzoEra
forall a b. (a -> b) -> a -> b
$ Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake AlonzoEra))]
forall era.
Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Wdrl StandardCrypto
Wdrl (Crypto (AlonzoEra StandardCrypto))
withdrawals
      where
        withdrawals :: Wdrl (Crypto (AlonzoEra StandardCrypto))
withdrawals = TxBody (AlonzoEra StandardCrypto)
-> Wdrl (Crypto (AlonzoEra StandardCrypto))
forall era. TxBody era -> Wdrl (Crypto era)
Alonzo.wdrls' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

    ShelleyBasedEra era
ShelleyBasedEraBabbage
      | Map (RewardAcnt StandardCrypto) Coin -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Wdrl StandardCrypto -> Map (RewardAcnt StandardCrypto) Coin
forall crypto. Wdrl crypto -> Map (RewardAcnt crypto) Coin
Shelley.unWdrl Wdrl StandardCrypto
Wdrl (Crypto (BabbageEra StandardCrypto))
withdrawals) -> TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
      | Bool
otherwise ->
          WithdrawalsSupportedInEra BabbageEra
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake BabbageEra))]
-> TxWithdrawals ViewTx BabbageEra
forall era build.
WithdrawalsSupportedInEra era
-> [(StakeAddress, Lovelace,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals WithdrawalsSupportedInEra BabbageEra
WithdrawalsInBabbageEra ([(StakeAddress, Lovelace,
   BuildTxWith ViewTx (Witness WitCtxStake BabbageEra))]
 -> TxWithdrawals ViewTx BabbageEra)
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake BabbageEra))]
-> TxWithdrawals ViewTx BabbageEra
forall a b. (a -> b) -> a -> b
$ Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake BabbageEra))]
forall era.
Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Wdrl StandardCrypto
Wdrl (Crypto (BabbageEra StandardCrypto))
withdrawals
      where
        withdrawals :: Wdrl (Crypto (BabbageEra StandardCrypto))
withdrawals = TxBody (BabbageEra StandardCrypto)
-> Wdrl (Crypto (BabbageEra StandardCrypto))
forall era. TxBody era -> Wdrl (Crypto era)
Babbage.wdrls' TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerTxCertificates
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxCertificates ViewTx era
fromLedgerTxCertificates :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxCertificates ViewTx era
fromLedgerTxCertificates ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley
      | StrictSeq (DCert StandardCrypto) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
certificates -> TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
      | Bool
otherwise ->
          CertificatesSupportedInEra ShelleyEra
-> [Certificate]
-> BuildTxWith
     ViewTx (Map StakeCredential (Witness WitCtxStake ShelleyEra))
-> TxCertificates ViewTx ShelleyEra
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates
            CertificatesSupportedInEra ShelleyEra
CertificatesInShelleyEra
            ((DCert StandardCrypto -> Certificate)
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> [a] -> [b]
map DCert StandardCrypto -> Certificate
fromShelleyCertificate ([DCert StandardCrypto] -> [Certificate])
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> a -> b
$ StrictSeq (DCert StandardCrypto) -> [DCert StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
certificates)
            BuildTxWith
  ViewTx (Map StakeCredential (Witness WitCtxStake ShelleyEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        certificates :: StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
certificates = TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   StrictSeq (DCert (Crypto era))
Shelley._certs TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAllegra
      | StrictSeq (DCert StandardCrypto) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
certificates -> TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
      | Bool
otherwise ->
          CertificatesSupportedInEra AllegraEra
-> [Certificate]
-> BuildTxWith
     ViewTx (Map StakeCredential (Witness WitCtxStake AllegraEra))
-> TxCertificates ViewTx AllegraEra
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates
            CertificatesSupportedInEra AllegraEra
CertificatesInAllegraEra
            ((DCert StandardCrypto -> Certificate)
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> [a] -> [b]
map DCert StandardCrypto -> Certificate
fromShelleyCertificate ([DCert StandardCrypto] -> [Certificate])
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> a -> b
$ StrictSeq (DCert StandardCrypto) -> [DCert StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
certificates)
            BuildTxWith
  ViewTx (Map StakeCredential (Witness WitCtxStake AllegraEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        certificates :: StrictSeq (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
certificates = TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> StrictSeq
     (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
forall era. TxBody era -> StrictSeq (DCert (Crypto era))
Allegra.certs' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraMary
      | StrictSeq (DCert StandardCrypto) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
certificates -> TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
      | Bool
otherwise ->
          CertificatesSupportedInEra MaryEra
-> [Certificate]
-> BuildTxWith
     ViewTx (Map StakeCredential (Witness WitCtxStake MaryEra))
-> TxCertificates ViewTx MaryEra
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates
            CertificatesSupportedInEra MaryEra
CertificatesInMaryEra
            ((DCert StandardCrypto -> Certificate)
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> [a] -> [b]
map DCert StandardCrypto -> Certificate
fromShelleyCertificate ([DCert StandardCrypto] -> [Certificate])
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> a -> b
$ StrictSeq (DCert StandardCrypto) -> [DCert StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
certificates)
            BuildTxWith
  ViewTx (Map StakeCredential (Witness WitCtxStake MaryEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        certificates :: StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
certificates = TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
forall era. TxBody era -> StrictSeq (DCert (Crypto era))
Mary.certs' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAlonzo
      | StrictSeq (DCert StandardCrypto) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
certificates -> TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
      | Bool
otherwise ->
          CertificatesSupportedInEra AlonzoEra
-> [Certificate]
-> BuildTxWith
     ViewTx (Map StakeCredential (Witness WitCtxStake AlonzoEra))
-> TxCertificates ViewTx AlonzoEra
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates
            CertificatesSupportedInEra AlonzoEra
CertificatesInAlonzoEra
            ((DCert StandardCrypto -> Certificate)
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> [a] -> [b]
map DCert StandardCrypto -> Certificate
fromShelleyCertificate ([DCert StandardCrypto] -> [Certificate])
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> a -> b
$ StrictSeq (DCert StandardCrypto) -> [DCert StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
certificates)
            BuildTxWith
  ViewTx (Map StakeCredential (Witness WitCtxStake AlonzoEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        certificates :: StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
certificates = TxBody (AlonzoEra StandardCrypto)
-> StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
forall era. TxBody era -> StrictSeq (DCert (Crypto era))
Alonzo.certs' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

    ShelleyBasedEra era
ShelleyBasedEraBabbage
      | StrictSeq (DCert StandardCrypto) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
certificates -> TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
      | Bool
otherwise ->
          CertificatesSupportedInEra BabbageEra
-> [Certificate]
-> BuildTxWith
     ViewTx (Map StakeCredential (Witness WitCtxStake BabbageEra))
-> TxCertificates ViewTx BabbageEra
forall era build.
CertificatesSupportedInEra era
-> [Certificate]
-> BuildTxWith
     build (Map StakeCredential (Witness WitCtxStake era))
-> TxCertificates build era
TxCertificates
            CertificatesSupportedInEra BabbageEra
CertificatesInBabbageEra
            ((DCert StandardCrypto -> Certificate)
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> [a] -> [b]
map DCert StandardCrypto -> Certificate
fromShelleyCertificate ([DCert StandardCrypto] -> [Certificate])
-> [DCert StandardCrypto] -> [Certificate]
forall a b. (a -> b) -> a -> b
$ StrictSeq (DCert StandardCrypto) -> [DCert StandardCrypto]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList StrictSeq (DCert StandardCrypto)
StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
certificates)
            BuildTxWith
  ViewTx (Map StakeCredential (Witness WitCtxStake BabbageEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        certificates :: StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
certificates = TxBody (BabbageEra StandardCrypto)
-> StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
forall era. TxBody era -> StrictSeq (DCert (Crypto era))
Babbage.certs' TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

fromLedgerTxUpdateProposal
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxUpdateProposal era
fromLedgerTxUpdateProposal :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
fromLedgerTxUpdateProposal ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      case TxBody (ShelleyEra StandardCrypto)
-> (Era (ShelleyEra StandardCrypto),
    FromCBOR (PParamsDelta (ShelleyEra StandardCrypto)),
    TransTxBody ToCBOR (ShelleyEra StandardCrypto)) =>
   StrictMaybe (Update (ShelleyEra StandardCrypto))
forall era.
TxBody era
-> (Era era, FromCBOR (PParamsDelta era),
    TransTxBody ToCBOR era) =>
   StrictMaybe (Update era)
Shelley._txUpdate TxBody (ShelleyLedgerEra era)
TxBody (ShelleyEra StandardCrypto)
body of
        StrictMaybe (Update (ShelleyEra StandardCrypto))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        SJust Update (ShelleyEra StandardCrypto)
p ->
          UpdateProposalSupportedInEra ShelleyEra
-> UpdateProposal -> TxUpdateProposal ShelleyEra
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra ShelleyEra
UpdateProposalInShelleyEra
                           (ShelleyBasedEra era
-> Update (ShelleyEra StandardCrypto) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
era Update (ShelleyEra StandardCrypto)
p)

    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      case TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> StrictMaybe (Update (ShelleyMAEra 'Allegra StandardCrypto))
forall era. TxBody era -> StrictMaybe (Update era)
Allegra.update' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Allegra StandardCrypto)
body of
        StrictMaybe (Update (ShelleyMAEra 'Allegra StandardCrypto))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        SJust Update (ShelleyMAEra 'Allegra StandardCrypto)
p ->
          UpdateProposalSupportedInEra AllegraEra
-> UpdateProposal -> TxUpdateProposal AllegraEra
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra AllegraEra
UpdateProposalInAllegraEra
                           (ShelleyBasedEra era
-> Update (ShelleyMAEra 'Allegra StandardCrypto) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
era Update (ShelleyMAEra 'Allegra StandardCrypto)
p)

    ShelleyBasedEra era
ShelleyBasedEraMary ->
      case TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> StrictMaybe (Update (ShelleyMAEra 'Mary StandardCrypto))
forall era. TxBody era -> StrictMaybe (Update era)
Mary.update' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body of
        StrictMaybe (Update (ShelleyMAEra 'Mary StandardCrypto))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        SJust Update (ShelleyMAEra 'Mary StandardCrypto)
p ->
          UpdateProposalSupportedInEra MaryEra
-> UpdateProposal -> TxUpdateProposal MaryEra
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra MaryEra
UpdateProposalInMaryEra
                           (ShelleyBasedEra era
-> Update (ShelleyMAEra 'Mary StandardCrypto) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
era Update (ShelleyMAEra 'Mary StandardCrypto)
p)

    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      case TxBody (AlonzoEra StandardCrypto)
-> StrictMaybe (Update (AlonzoEra StandardCrypto))
forall era. TxBody era -> StrictMaybe (Update era)
Alonzo.update' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body of
        StrictMaybe (Update (AlonzoEra StandardCrypto))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        SJust Update (AlonzoEra StandardCrypto)
p ->
          UpdateProposalSupportedInEra AlonzoEra
-> UpdateProposal -> TxUpdateProposal AlonzoEra
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra AlonzoEra
UpdateProposalInAlonzoEra
                           (ShelleyBasedEra era
-> Update (AlonzoEra StandardCrypto) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
era Update (AlonzoEra StandardCrypto)
p)

    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      case TxBody (BabbageEra StandardCrypto)
-> StrictMaybe (Update (BabbageEra StandardCrypto))
forall era. TxBody era -> StrictMaybe (Update era)
Babbage.update' TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body of
        StrictMaybe (Update (BabbageEra StandardCrypto))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
        SJust Update (BabbageEra StandardCrypto)
p ->
          UpdateProposalSupportedInEra BabbageEra
-> UpdateProposal -> TxUpdateProposal BabbageEra
forall era.
UpdateProposalSupportedInEra era
-> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal UpdateProposalSupportedInEra BabbageEra
UpdateProposalInBabbageEra
                           (ShelleyBasedEra era
-> Update (BabbageEra StandardCrypto) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
era Update (BabbageEra StandardCrypto)
p)

fromLedgerTxMintValue
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxMintValue ViewTx era
fromLedgerTxMintValue :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxMintValue ViewTx era
fromLedgerTxMintValue ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley -> TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
    ShelleyBasedEra era
ShelleyBasedEraAllegra -> TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
    ShelleyBasedEra era
ShelleyBasedEraMary
      | Value StandardCrypto -> Bool
forall t. Val t => t -> Bool
isZero Value (ShelleyMAEra 'Mary StandardCrypto)
Value StandardCrypto
mint        -> TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
      | Bool
otherwise          -> MultiAssetSupportedInEra MaryEra
-> Value
-> BuildTxWith
     ViewTx (Map PolicyId (ScriptWitness WitCtxMint MaryEra))
-> TxMintValue ViewTx MaryEra
forall era build.
MultiAssetSupportedInEra era
-> Value
-> BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MultiAssetSupportedInEra MaryEra
MultiAssetInMaryEra
                                          (Value StandardCrypto -> Value
fromMaryValue Value (ShelleyMAEra 'Mary StandardCrypto)
Value StandardCrypto
mint) BuildTxWith
  ViewTx (Map PolicyId (ScriptWitness WitCtxMint MaryEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        mint :: Value (ShelleyMAEra 'Mary StandardCrypto)
mint = TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> Value (ShelleyMAEra 'Mary StandardCrypto)
forall era. TxBody era -> Value era
Mary.mint' TxBody (ShelleyLedgerEra era)
TxBody (ShelleyMAEra 'Mary StandardCrypto)
body

    ShelleyBasedEra era
ShelleyBasedEraAlonzo
      | Value StandardCrypto -> Bool
forall t. Val t => t -> Bool
isZero Value StandardCrypto
Value (Crypto (AlonzoEra StandardCrypto))
mint         -> TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
      | Bool
otherwise           -> MultiAssetSupportedInEra AlonzoEra
-> Value
-> BuildTxWith
     ViewTx (Map PolicyId (ScriptWitness WitCtxMint AlonzoEra))
-> TxMintValue ViewTx AlonzoEra
forall era build.
MultiAssetSupportedInEra era
-> Value
-> BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MultiAssetSupportedInEra AlonzoEra
MultiAssetInAlonzoEra
                                           (Value StandardCrypto -> Value
fromMaryValue Value StandardCrypto
Value (Crypto (AlonzoEra StandardCrypto))
mint) BuildTxWith
  ViewTx (Map PolicyId (ScriptWitness WitCtxMint AlonzoEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        mint :: Value (Crypto (AlonzoEra StandardCrypto))
mint = TxBody (AlonzoEra StandardCrypto)
-> Value (Crypto (AlonzoEra StandardCrypto))
forall era. TxBody era -> Value (Crypto era)
Alonzo.mint' TxBody (AlonzoEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body

    ShelleyBasedEra era
ShelleyBasedEraBabbage
      | Value StandardCrypto -> Bool
forall t. Val t => t -> Bool
isZero Value StandardCrypto
Value (Crypto (BabbageEra StandardCrypto))
mint         -> TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
      | Bool
otherwise           -> MultiAssetSupportedInEra BabbageEra
-> Value
-> BuildTxWith
     ViewTx (Map PolicyId (ScriptWitness WitCtxMint BabbageEra))
-> TxMintValue ViewTx BabbageEra
forall era build.
MultiAssetSupportedInEra era
-> Value
-> BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MultiAssetSupportedInEra BabbageEra
MultiAssetInBabbageEra
                                           (Value StandardCrypto -> Value
fromMaryValue Value StandardCrypto
Value (Crypto (BabbageEra StandardCrypto))
mint) BuildTxWith
  ViewTx (Map PolicyId (ScriptWitness WitCtxMint BabbageEra))
forall a. BuildTxWith ViewTx a
ViewTx
      where
        mint :: Value (Crypto (BabbageEra StandardCrypto))
mint = TxBody (BabbageEra StandardCrypto)
-> Value (Crypto (BabbageEra StandardCrypto))
forall era. TxBody era -> Value (Crypto era)
Babbage.mint' TxBody (BabbageEra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body


makeByronTransactionBody :: TxBodyContent BuildTx ByronEra
                         -> Either TxBodyError (TxBody ByronEra)
makeByronTransactionBody :: TxBodyContent BuildTx ByronEra
-> Either TxBodyError (TxBody ByronEra)
makeByronTransactionBody TxBodyContent { TxIns BuildTx ByronEra
txIns :: TxIns BuildTx ByronEra
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns, [TxOut CtxTx ByronEra]
txOuts :: [TxOut CtxTx ByronEra]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts } = do
    NonEmpty TxIn
ins' <- [TxIn] -> Maybe (NonEmpty TxIn)
forall a. [a] -> Maybe (NonEmpty a)
NonEmpty.nonEmpty (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)) -> TxIn)
-> TxIns BuildTx ByronEra -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx ByronEra
txIns) Maybe (NonEmpty TxIn)
-> TxBodyError -> Either TxBodyError (NonEmpty TxIn)
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    NonEmpty TxIn
-> (TxIn -> Either TxBodyError ()) -> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ NonEmpty TxIn
ins' ((TxIn -> Either TxBodyError ()) -> Either TxBodyError ())
-> (TxIn -> Either TxBodyError ()) -> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)) ->
      Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxByronTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
    let ins'' :: NonEmpty TxIn
ins'' = (TxIn -> TxIn) -> NonEmpty TxIn -> NonEmpty TxIn
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TxIn -> TxIn
toByronTxIn NonEmpty TxIn
ins'

    NonEmpty (TxOut CtxTx ByronEra)
outs'  <- [TxOut CtxTx ByronEra] -> Maybe (NonEmpty (TxOut CtxTx ByronEra))
forall a. [a] -> Maybe (NonEmpty a)
NonEmpty.nonEmpty [TxOut CtxTx ByronEra]
txOuts    Maybe (NonEmpty (TxOut CtxTx ByronEra))
-> TxBodyError
-> Either TxBodyError (NonEmpty (TxOut CtxTx ByronEra))
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxOuts
    NonEmpty TxOut
outs'' <- (TxOut CtxTx ByronEra -> Either TxBodyError TxOut)
-> NonEmpty (TxOut CtxTx ByronEra)
-> Either TxBodyError (NonEmpty TxOut)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
                (\TxOut CtxTx ByronEra
out -> TxOut CtxTx ByronEra -> Maybe TxOut
forall ctx. TxOut ctx ByronEra -> Maybe TxOut
toByronTxOut TxOut CtxTx ByronEra
out Maybe TxOut -> TxBodyError -> Either TxBodyError TxOut
forall a e. Maybe a -> e -> Either e a
?! TxOut CtxTx ByronEra -> TxBodyError
classifyRangeError TxOut CtxTx ByronEra
out)
                NonEmpty (TxOut CtxTx ByronEra)
outs'
    TxBody ByronEra -> Either TxBodyError (TxBody ByronEra)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody ByronEra -> Either TxBodyError (TxBody ByronEra))
-> TxBody ByronEra -> Either TxBodyError (TxBody ByronEra)
forall a b. (a -> b) -> a -> b
$
      Annotated Tx ByteString -> TxBody ByronEra
ByronTxBody (Annotated Tx ByteString -> TxBody ByronEra)
-> Annotated Tx ByteString -> TxBody ByronEra
forall a b. (a -> b) -> a -> b
$
        Annotated Tx () -> Annotated Tx ByteString
forall a b. ToCBOR a => Annotated a b -> Annotated a ByteString
reAnnotate (Annotated Tx () -> Annotated Tx ByteString)
-> Annotated Tx () -> Annotated Tx ByteString
forall a b. (a -> b) -> a -> b
$
          Tx -> () -> Annotated Tx ()
forall b a. b -> a -> Annotated b a
Annotated
            (NonEmpty TxIn -> NonEmpty TxOut -> TxAttributes -> Tx
Byron.UnsafeTx NonEmpty TxIn
ins'' NonEmpty TxOut
outs'' (() -> TxAttributes
forall h. h -> Attributes h
Byron.mkAttributes ()))
            ()
  where
    maxByronTxInIx :: Word
    maxByronTxInIx :: Word
maxByronTxInIx = Word32 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
forall a. Bounded a => a
maxBound :: Word32)

    classifyRangeError :: TxOut CtxTx ByronEra -> TxBodyError
    classifyRangeError :: TxOut CtxTx ByronEra -> TxBodyError
classifyRangeError
      txout :: TxOut CtxTx ByronEra
txout@(TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra ByronAddress{})
                   (TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra Lovelace
value) TxOutDatum CtxTx ByronEra
_ ReferenceScript ByronEra
_)
      | Lovelace
value Lovelace -> Lovelace -> Bool
forall a. Ord a => a -> a -> Bool
< Lovelace
0        = Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative (Lovelace -> Quantity
lovelaceToQuantity Lovelace
value)
                                                (TxOut CtxTx ByronEra -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx ByronEra
txout)
      | Bool
otherwise        = Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow (Lovelace -> Quantity
lovelaceToQuantity Lovelace
value)
                                                (TxOut CtxTx ByronEra -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx ByronEra
txout)

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

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

getByronTxBodyContent :: Annotated Byron.Tx ByteString
                      -> TxBodyContent ViewTx ByronEra
getByronTxBodyContent :: Annotated Tx ByteString -> TxBodyContent ViewTx ByronEra
getByronTxBodyContent (Annotated Byron.UnsafeTx{NonEmpty TxIn
txInputs :: Tx -> NonEmpty TxIn
txInputs :: NonEmpty TxIn
txInputs, NonEmpty TxOut
txOutputs :: Tx -> NonEmpty TxOut
txOutputs :: NonEmpty TxOut
txOutputs} ByteString
_) =
    TxBodyContent :: forall build era.
TxIns build era
-> TxInsCollateral era
-> TxInsReference build era
-> [TxOut CtxTx era]
-> TxTotalCollateral era
-> TxReturnCollateral CtxTx era
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> TxScriptValidity era
-> TxBodyContent build era
TxBodyContent {
      txIns :: TxIns ViewTx ByronEra
txIns              = [ (TxIn -> TxIn
fromByronTxIn TxIn
input, BuildTxWith ViewTx (Witness WitCtxTxIn ByronEra)
forall a. BuildTxWith ViewTx a
ViewTx)
                           | TxIn
input <- NonEmpty TxIn -> [TxIn]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty TxIn
txInputs],
      txInsCollateral :: TxInsCollateral ByronEra
txInsCollateral    = TxInsCollateral ByronEra
forall era. TxInsCollateral era
TxInsCollateralNone,
      txInsReference :: TxInsReference ViewTx ByronEra
txInsReference     = TxInsReference ViewTx ByronEra
forall build era. TxInsReference build era
TxInsReferenceNone,
      txOuts :: [TxOut CtxTx ByronEra]
txOuts             = TxOut -> TxOut CtxTx ByronEra
forall ctx. TxOut -> TxOut ctx ByronEra
fromByronTxOut (TxOut -> TxOut CtxTx ByronEra)
-> [TxOut] -> [TxOut CtxTx ByronEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty TxOut -> [TxOut]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty TxOut
txOutputs,
      txReturnCollateral :: TxReturnCollateral CtxTx ByronEra
txReturnCollateral = TxReturnCollateral CtxTx ByronEra
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone,
      txTotalCollateral :: TxTotalCollateral ByronEra
txTotalCollateral  = TxTotalCollateral ByronEra
forall era. TxTotalCollateral era
TxTotalCollateralNone,
      txFee :: TxFee ByronEra
txFee              = TxFeesImplicitInEra ByronEra -> TxFee ByronEra
forall era. TxFeesImplicitInEra era -> TxFee era
TxFeeImplicit TxFeesImplicitInEra ByronEra
TxFeesImplicitInByronEra,
      txValidityRange :: (TxValidityLowerBound ByronEra, TxValidityUpperBound ByronEra)
txValidityRange    = (TxValidityLowerBound ByronEra
forall era. TxValidityLowerBound era
TxValidityNoLowerBound,
                            ValidityNoUpperBoundSupportedInEra ByronEra
-> TxValidityUpperBound ByronEra
forall era.
ValidityNoUpperBoundSupportedInEra era -> TxValidityUpperBound era
TxValidityNoUpperBound
                              ValidityNoUpperBoundSupportedInEra ByronEra
ValidityNoUpperBoundInByronEra),
      txMetadata :: TxMetadataInEra ByronEra
txMetadata         = TxMetadataInEra ByronEra
forall era. TxMetadataInEra era
TxMetadataNone,
      txAuxScripts :: TxAuxScripts ByronEra
txAuxScripts       = TxAuxScripts ByronEra
forall era. TxAuxScripts era
TxAuxScriptsNone,
      txExtraKeyWits :: TxExtraKeyWitnesses ByronEra
txExtraKeyWits     = TxExtraKeyWitnesses ByronEra
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone,
      txProtocolParams :: BuildTxWith ViewTx (Maybe ProtocolParameters)
txProtocolParams   = BuildTxWith ViewTx (Maybe ProtocolParameters)
forall a. BuildTxWith ViewTx a
ViewTx,
      txWithdrawals :: TxWithdrawals ViewTx ByronEra
txWithdrawals      = TxWithdrawals ViewTx ByronEra
forall build era. TxWithdrawals build era
TxWithdrawalsNone,
      txCertificates :: TxCertificates ViewTx ByronEra
txCertificates     = TxCertificates ViewTx ByronEra
forall build era. TxCertificates build era
TxCertificatesNone,
      txUpdateProposal :: TxUpdateProposal ByronEra
txUpdateProposal   = TxUpdateProposal ByronEra
forall era. TxUpdateProposal era
TxUpdateProposalNone,
      txMintValue :: TxMintValue ViewTx ByronEra
txMintValue        = TxMintValue ViewTx ByronEra
forall build era. TxMintValue build era
TxMintNone,
      txScriptValidity :: TxScriptValidity ByronEra
txScriptValidity   = TxScriptValidity ByronEra
forall era. TxScriptValidity era
TxScriptValidityNone
    }

makeShelleyTransactionBody :: ()
  => ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody :: ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody era :: ShelleyBasedEra era
era@ShelleyBasedEra era
ShelleyBasedEraShelley
                           txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent {
                             TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                             [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts,
                             TxFee era
txFee :: TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee,
                             txValidityRange :: forall build era.
TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange = (TxValidityLowerBound era
_, TxValidityUpperBound era
upperBound),
                             TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata,
                             TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                             TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                             TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal
                           } = do

    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null TxIns BuildTx era
txIns)) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Lovelace
v Lovelace -> Lovelace -> Bool
forall a. Ord a => a -> a -> Bool
>= Lovelace
0) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative (Lovelace -> Quantity
lovelaceToQuantity Lovelace
v)
                                                  (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout)
           Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Lovelace
v Lovelace -> Lovelace -> Bool
forall a. Ord a => a -> a -> Bool
<= Lovelace
maxTxOut) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow (Lovelace -> Quantity
lovelaceToQuantity Lovelace
v)
                                                         (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout)
           TxIns BuildTx era
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ TxIns BuildTx era
txIns (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  -> Either TxBodyError ())
 -> Either TxBodyError ())
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), BuildTxWith BuildTx (Witness WitCtxTxIn era)
_) ->
              Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
      | let maxTxOut :: Lovelace
maxTxOut = Word64 -> Lovelace
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Lovelace
      , txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInShelleyEra Lovelace
v) TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts ]
    case TxMetadataInEra era
txMetadata of
      TxMetadataInEra era
TxMetadataNone      -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMetadataInEra TxMetadataSupportedInEra era
_ TxMetadata
m -> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either [(Word64, TxMetadataRangeError)] ()
-> Either TxBodyError ()
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first [(Word64, TxMetadataRangeError)] -> TxBodyError
TxBodyMetadataError (TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
validateTxMetadata TxMetadata
m)

    TxBody era -> Either TxBodyError (TxBody era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody era -> Either TxBodyError (TxBody era))
-> TxBody era -> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$
      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
        (Set (TxIn (Crypto (ShelleyEra StandardCrypto)))
-> StrictSeq (TxOut (ShelleyEra StandardCrypto))
-> StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
-> Wdrl (Crypto (ShelleyEra StandardCrypto))
-> Coin
-> SlotNo
-> StrictMaybe (Update (ShelleyEra StandardCrypto))
-> StrictMaybe
     (AuxiliaryDataHash (Crypto (ShelleyEra StandardCrypto)))
-> TxBody (ShelleyEra StandardCrypto)
forall era.
(Era era, FromCBOR (PParamsDelta era), TransTxBody ToCBOR era) =>
Set (TxIn (Crypto era))
-> StrictSeq (TxOut era)
-> StrictSeq (DCert (Crypto era))
-> Wdrl (Crypto era)
-> Coin
-> SlotNo
-> StrictMaybe (Update era)
-> StrictMaybe (AuxiliaryDataHash (Crypto era))
-> TxBody era
Shelley.TxBody
          ([TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
 -> TxIn StandardCrypto)
-> TxIns BuildTx era -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn -> TxIn StandardCrypto)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst) TxIns BuildTx era
txIns))
          ([TxOut (ShelleyEra StandardCrypto)]
-> StrictSeq (TxOut (ShelleyEra StandardCrypto))
forall a. [a] -> StrictSeq a
Seq.fromList ((TxOut CtxTx era -> TxOut (ShelleyEra StandardCrypto))
-> [TxOut CtxTx era] -> [TxOut (ShelleyEra StandardCrypto)]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (ShelleyEra StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era) [TxOut CtxTx era]
txOuts))
          (case TxCertificates BuildTx era
txCertificates of
             TxCertificates BuildTx era
TxCertificatesNone    -> StrictSeq (DCert (Crypto (ShelleyEra StandardCrypto)))
forall a. StrictSeq a
Seq.empty
             TxCertificates CertificatesSupportedInEra era
_ [Certificate]
cs BuildTxWith BuildTx (Map StakeCredential (Witness WitCtxStake era))
_ -> [DCert StandardCrypto] -> StrictSeq (DCert StandardCrypto)
forall a. [a] -> StrictSeq a
Seq.fromList ((Certificate -> DCert StandardCrypto)
-> [Certificate] -> [DCert StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map Certificate -> DCert StandardCrypto
toShelleyCertificate [Certificate]
cs))
          (case TxWithdrawals BuildTx era
txWithdrawals of
             TxWithdrawals BuildTx era
TxWithdrawalsNone  -> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
forall k a. Map k a
Map.empty
             TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws -> [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Wdrl StandardCrypto
forall a. [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws)
          (case TxFee era
txFee of
             TxFeeImplicit TxFeesImplicitInEra era
era'  -> case TxFeesImplicitInEra era
era' of {}
             TxFeeExplicit TxFeesExplicitInEra era
_ Lovelace
fee -> Lovelace -> Coin
toShelleyLovelace Lovelace
fee)
          (case TxValidityUpperBound era
upperBound of
             TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
era' -> case ValidityNoUpperBoundSupportedInEra era
era' of {}
             TxValidityUpperBound ValidityUpperBoundSupportedInEra era
_ SlotNo
ttl  -> SlotNo
ttl)
          (case TxUpdateProposal era
txUpdateProposal of
             TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (ShelleyEra StandardCrypto))
forall a. StrictMaybe a
SNothing
             TxUpdateProposal UpdateProposalSupportedInEra era
_ UpdateProposal
p -> Update (ShelleyEra StandardCrypto)
-> StrictMaybe (Update (ShelleyEra StandardCrypto))
forall a. a -> StrictMaybe a
SJust (ShelleyBasedEra era
-> UpdateProposal -> Update (ShelleyEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UpdateProposal -> Update ledgerera
toLedgerUpdate ShelleyBasedEra era
era UpdateProposal
p))
          (Maybe (AuxiliaryDataHash StandardCrypto)
-> StrictMaybe (AuxiliaryDataHash StandardCrypto)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe
            (Metadata (ShelleyEra StandardCrypto)
-> AuxiliaryDataHash StandardCrypto
forall era c.
ValidateAuxiliaryData era c =>
AuxiliaryData era -> AuxiliaryDataHash c
Ledger.hashAuxiliaryData (Metadata (ShelleyEra StandardCrypto)
 -> AuxiliaryDataHash StandardCrypto)
-> Maybe (Metadata (ShelleyEra StandardCrypto))
-> Maybe (AuxiliaryDataHash StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
Maybe (Metadata (ShelleyEra StandardCrypto))
txAuxData)))
        [Script (ShelleyEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
scripts
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
  where

    maxShelleyTxInIx :: Word
    maxShelleyTxInIx :: Word
maxShelleyTxInIx = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ Bounded Word16 => Word16
forall a. Bounded a => a
maxBound @Word16

    scripts :: [Ledger.Script StandardShelley]
    scripts :: [Script (ShelleyEra StandardCrypto)]
scripts = [Maybe (MultiSig StandardCrypto)] -> [MultiSig StandardCrypto]
forall a. [Maybe a] -> [a]
catMaybes
      [ ScriptInEra era -> MultiSig StandardCrypto
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> MultiSig StandardCrypto)
-> Maybe (ScriptInEra era) -> Maybe (MultiSig StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
scriptWitnessScript ScriptWitness witctx era
scriptwitness
      | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness)
          <- TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txbodycontent
      ]

    txAuxData :: Maybe (Ledger.AuxiliaryData StandardShelley)
    txAuxData :: Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
txAuxData
      | Map Word64 TxMetadataValue -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 TxMetadataValue
ms = Maybe (AuxiliaryData (ShelleyEra StandardCrypto))
forall a. Maybe a
Nothing
      | Bool
otherwise   = Metadata (ShelleyEra StandardCrypto)
-> Maybe (Metadata (ShelleyEra StandardCrypto))
forall a. a -> Maybe a
Just (Map Word64 TxMetadataValue
-> AuxiliaryData (ShelleyEra StandardCrypto)
toShelleyAuxiliaryData Map Word64 TxMetadataValue
ms)
      where
        ms :: Map Word64 TxMetadataValue
ms = case TxMetadataInEra era
txMetadata of
               TxMetadataInEra era
TxMetadataNone                     -> Map Word64 TxMetadataValue
forall k a. Map k a
Map.empty
               TxMetadataInEra TxMetadataSupportedInEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue
ms'

makeShelleyTransactionBody era :: ShelleyBasedEra era
era@ShelleyBasedEra era
ShelleyBasedEraAllegra
                           txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent {
                             TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                             [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts,
                             TxFee era
txFee :: TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee,
                             txValidityRange :: forall build era.
TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange = (TxValidityLowerBound era
lowerBound, TxValidityUpperBound era
upperBound),
                             TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata,
                             TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts,
                             TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                             TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                             TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal
                           } = do

    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null TxIns BuildTx era
txIns)) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Lovelace
v Lovelace -> Lovelace -> Bool
forall a. Ord a => a -> a -> Bool
>= Lovelace
0) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative (Lovelace -> Quantity
lovelaceToQuantity Lovelace
v)
                                                  (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout)
           Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Lovelace
v Lovelace -> Lovelace -> Bool
forall a. Ord a => a -> a -> Bool
<= Lovelace
maxTxOut) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow (Lovelace -> Quantity
lovelaceToQuantity Lovelace
v)
                                                         (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout)
           TxIns BuildTx era
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ TxIns BuildTx era
txIns (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  -> Either TxBodyError ())
 -> Either TxBodyError ())
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), BuildTxWith BuildTx (Witness WitCtxTxIn era)
_) ->
              Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
      | let maxTxOut :: Lovelace
maxTxOut = Word64 -> Lovelace
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Lovelace
      , txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInAllegraEra Lovelace
v) TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts
      ]
    case TxMetadataInEra era
txMetadata of
      TxMetadataInEra era
TxMetadataNone      -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMetadataInEra TxMetadataSupportedInEra era
_ TxMetadata
m -> TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
validateTxMetadata TxMetadata
m Either [(Word64, TxMetadataRangeError)] ()
-> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either TxBodyError ()
forall e a e'. Either e a -> (e -> e') -> Either e' a
?!. [(Word64, TxMetadataRangeError)] -> TxBodyError
TxBodyMetadataError

    TxBody era -> Either TxBodyError (TxBody era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody era -> Either TxBodyError (TxBody era))
-> TxBody era -> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$
      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
        (Set (TxIn (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
-> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
-> StrictSeq
     (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
-> Wdrl (Crypto (ShelleyMAEra 'Allegra StandardCrypto))
-> Coin
-> ValidityInterval
-> StrictMaybe (Update (ShelleyMAEra 'Allegra StandardCrypto))
-> StrictMaybe
     (AuxiliaryDataHash (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
-> Value (ShelleyMAEra 'Allegra StandardCrypto)
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto)
forall era.
FamsTo era =>
Set (TxIn (Crypto era))
-> StrictSeq (TxOut era)
-> StrictSeq (DCert (Crypto era))
-> Wdrl (Crypto era)
-> Coin
-> ValidityInterval
-> StrictMaybe (Update era)
-> StrictMaybe (AuxiliaryDataHash (Crypto era))
-> Value era
-> TxBody era
Allegra.TxBody
          ([TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
 -> TxIn StandardCrypto)
-> TxIns BuildTx era -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn -> TxIn StandardCrypto)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst) TxIns BuildTx era
txIns))
          ([TxOut (ShelleyMAEra 'Allegra StandardCrypto)]
-> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
forall a. [a] -> StrictSeq a
Seq.fromList ((TxOut CtxTx era -> TxOut (ShelleyMAEra 'Allegra StandardCrypto))
-> [TxOut CtxTx era]
-> [TxOut (ShelleyMAEra 'Allegra StandardCrypto)]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (ShelleyMAEra 'Allegra StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era) [TxOut CtxTx era]
txOuts))
          (case TxCertificates BuildTx era
txCertificates of
             TxCertificates BuildTx era
TxCertificatesNone    -> StrictSeq (DCert (Crypto (ShelleyMAEra 'Allegra StandardCrypto)))
forall a. StrictSeq a
Seq.empty
             TxCertificates CertificatesSupportedInEra era
_ [Certificate]
cs BuildTxWith BuildTx (Map StakeCredential (Witness WitCtxStake era))
_ -> [DCert StandardCrypto] -> StrictSeq (DCert StandardCrypto)
forall a. [a] -> StrictSeq a
Seq.fromList ((Certificate -> DCert StandardCrypto)
-> [Certificate] -> [DCert StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map Certificate -> DCert StandardCrypto
toShelleyCertificate [Certificate]
cs))
          (case TxWithdrawals BuildTx era
txWithdrawals of
             TxWithdrawals BuildTx era
TxWithdrawalsNone  -> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
forall k a. Map k a
Map.empty
             TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws -> [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Wdrl StandardCrypto
forall a. [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws)
          (case TxFee era
txFee of
             TxFeeImplicit TxFeesImplicitInEra era
era'  -> case TxFeesImplicitInEra era
era' of {}
             TxFeeExplicit TxFeesExplicitInEra era
_ Lovelace
fee -> Lovelace -> Coin
toShelleyLovelace Lovelace
fee)
          (ValidityInterval :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> ValidityInterval
Allegra.ValidityInterval {
             invalidBefore :: StrictMaybe SlotNo
invalidBefore    = case TxValidityLowerBound era
lowerBound of
                                          TxValidityLowerBound era
TxValidityNoLowerBound   -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityLowerBound ValidityLowerBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s,
             invalidHereafter :: StrictMaybe SlotNo
invalidHereafter = case TxValidityUpperBound era
upperBound of
                                          TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
_ -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityUpperBound ValidityUpperBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s
           })
          (case TxUpdateProposal era
txUpdateProposal of
             TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (ShelleyMAEra 'Allegra StandardCrypto))
forall a. StrictMaybe a
SNothing
             TxUpdateProposal UpdateProposalSupportedInEra era
_ UpdateProposal
p -> Update (ShelleyMAEra 'Allegra StandardCrypto)
-> StrictMaybe (Update (ShelleyMAEra 'Allegra StandardCrypto))
forall a. a -> StrictMaybe a
SJust (ShelleyBasedEra era
-> UpdateProposal -> Update (ShelleyMAEra 'Allegra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UpdateProposal -> Update ledgerera
toLedgerUpdate ShelleyBasedEra era
era UpdateProposal
p))
          (Maybe (AuxiliaryDataHash StandardCrypto)
-> StrictMaybe (AuxiliaryDataHash StandardCrypto)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe
            (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto)
-> AuxiliaryDataHash StandardCrypto
forall era c.
ValidateAuxiliaryData era c =>
AuxiliaryData era -> AuxiliaryDataHash c
Ledger.hashAuxiliaryData (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto)
 -> AuxiliaryDataHash StandardCrypto)
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Maybe (AuxiliaryDataHash StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
txAuxData))
          Value (ShelleyMAEra 'Allegra StandardCrypto)
forall a. Monoid a => a
mempty) -- No minting in Allegra, only Mary
        [Script (ShelleyMAEra 'Allegra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
scripts
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
  where

    maxShelleyTxInIx :: Word
    maxShelleyTxInIx :: Word
maxShelleyTxInIx = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ Bounded Word16 => Word16
forall a. Bounded a => a
maxBound @Word16

    scripts :: [Ledger.Script StandardAllegra]
    scripts :: [Script (ShelleyMAEra 'Allegra StandardCrypto)]
scripts = [Maybe (Timelock StandardCrypto)] -> [Timelock StandardCrypto]
forall a. [Maybe a] -> [a]
catMaybes
      [ ScriptInEra era -> Timelock StandardCrypto
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Timelock StandardCrypto)
-> Maybe (ScriptInEra era) -> Maybe (Timelock StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
scriptWitnessScript ScriptWitness witctx era
scriptwitness
      | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness)
          <- TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txbodycontent
      ]

    txAuxData :: Maybe (Ledger.AuxiliaryData StandardAllegra)
    txAuxData :: Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
txAuxData
      | Map Word64 TxMetadataValue -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 TxMetadataValue
ms
      , [ScriptInEra era] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ScriptInEra era]
ss   = Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
forall a. Maybe a
Nothing
      | Bool
otherwise = AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto)
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
forall a. a -> Maybe a
Just (Map Word64 TxMetadataValue
-> [ScriptInEra era]
-> AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 AuxiliaryData ledgerera ~ AuxiliaryData ledgerera,
 AnnotatedData (Script ledgerera), Ord (Script ledgerera)) =>
Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAllegraAuxiliaryData Map Word64 TxMetadataValue
ms [ScriptInEra era]
ss)
      where
        ms :: Map Word64 TxMetadataValue
ms = case TxMetadataInEra era
txMetadata of
               TxMetadataInEra era
TxMetadataNone                     -> Map Word64 TxMetadataValue
forall k a. Map k a
Map.empty
               TxMetadataInEra TxMetadataSupportedInEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue
ms'
        ss :: [ScriptInEra era]
ss = case TxAuxScripts era
txAuxScripts of
               TxAuxScripts era
TxAuxScriptsNone   -> []
               TxAuxScripts AuxScriptsSupportedInEra era
_ [ScriptInEra era]
ss' -> [ScriptInEra era]
ss'

makeShelleyTransactionBody era :: ShelleyBasedEra era
era@ShelleyBasedEra era
ShelleyBasedEraMary
                           txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent {
                             TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                             [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts,
                             TxFee era
txFee :: TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee,
                             txValidityRange :: forall build era.
TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange = (TxValidityLowerBound era
lowerBound, TxValidityUpperBound era
upperBound),
                             TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata,
                             TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts,
                             TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                             TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                             TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal,
                             TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue
                           } = do

    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null TxIns BuildTx era
txIns)) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do Either TxBodyError ()
allPositive
           Either TxBodyError ()
allWithinMaxBound
           TxIns BuildTx era
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ TxIns BuildTx era
txIns (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  -> Either TxBodyError ())
 -> Either TxBodyError ())
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), BuildTxWith BuildTx (Witness WitCtxTxIn era)
_) ->
              Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
      | let maxTxOut :: Quantity
maxTxOut = Word64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Quantity
      , txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ (TxOutValue MultiAssetSupportedInEra era
MultiAssetInMaryEra Value
v) TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts
      , let allPositive :: Either TxBodyError ()
allPositive =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
< Quantity
0 ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
            allWithinMaxBound :: Either TxBodyError ()
allWithinMaxBound =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
> Quantity
maxTxOut ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
      ]
    case TxMetadataInEra era
txMetadata of
      TxMetadataInEra era
TxMetadataNone      -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMetadataInEra TxMetadataSupportedInEra era
_ TxMetadata
m -> TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
validateTxMetadata TxMetadata
m Either [(Word64, TxMetadataRangeError)] ()
-> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either TxBodyError ()
forall e a e'. Either e a -> (e -> e') -> Either e' a
?!. [(Word64, TxMetadataRangeError)] -> TxBodyError
TxBodyMetadataError
    case TxMintValue BuildTx era
txMintValue of
      TxMintValue BuildTx era
TxMintNone        -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Value -> Lovelace
selectLovelace Value
v Lovelace -> Lovelace -> Bool
forall a. Eq a => a -> a -> Bool
== Lovelace
0) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyMintAdaError

    TxBody era -> Either TxBodyError (TxBody era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody era -> Either TxBodyError (TxBody era))
-> TxBody era -> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$
      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
        (Set (TxIn (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
-> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
-> StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
-> Wdrl (Crypto (ShelleyMAEra 'Mary StandardCrypto))
-> Coin
-> ValidityInterval
-> StrictMaybe (Update (ShelleyMAEra 'Mary StandardCrypto))
-> StrictMaybe
     (AuxiliaryDataHash (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
-> Value (ShelleyMAEra 'Mary StandardCrypto)
-> TxBody (ShelleyMAEra 'Mary StandardCrypto)
forall era.
FamsTo era =>
Set (TxIn (Crypto era))
-> StrictSeq (TxOut era)
-> StrictSeq (DCert (Crypto era))
-> Wdrl (Crypto era)
-> Coin
-> ValidityInterval
-> StrictMaybe (Update era)
-> StrictMaybe (AuxiliaryDataHash (Crypto era))
-> Value era
-> TxBody era
Allegra.TxBody
          ([TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
 -> TxIn StandardCrypto)
-> TxIns BuildTx era -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn -> TxIn StandardCrypto)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst) TxIns BuildTx era
txIns))
          ([TxOut (ShelleyMAEra 'Mary StandardCrypto)]
-> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
forall a. [a] -> StrictSeq a
Seq.fromList ((TxOut CtxTx era -> TxOut (ShelleyMAEra 'Mary StandardCrypto))
-> [TxOut CtxTx era] -> [TxOut (ShelleyMAEra 'Mary StandardCrypto)]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (ShelleyMAEra 'Mary StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era) [TxOut CtxTx era]
txOuts))
          (case TxCertificates BuildTx era
txCertificates of
             TxCertificates BuildTx era
TxCertificatesNone    -> StrictSeq (DCert (Crypto (ShelleyMAEra 'Mary StandardCrypto)))
forall a. StrictSeq a
Seq.empty
             TxCertificates CertificatesSupportedInEra era
_ [Certificate]
cs BuildTxWith BuildTx (Map StakeCredential (Witness WitCtxStake era))
_ -> [DCert StandardCrypto] -> StrictSeq (DCert StandardCrypto)
forall a. [a] -> StrictSeq a
Seq.fromList ((Certificate -> DCert StandardCrypto)
-> [Certificate] -> [DCert StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map Certificate -> DCert StandardCrypto
toShelleyCertificate [Certificate]
cs))
          (case TxWithdrawals BuildTx era
txWithdrawals of
             TxWithdrawals BuildTx era
TxWithdrawalsNone  -> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
forall k a. Map k a
Map.empty
             TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws -> [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Wdrl StandardCrypto
forall a. [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws)
          (case TxFee era
txFee of
             TxFeeImplicit TxFeesImplicitInEra era
era'  -> case TxFeesImplicitInEra era
era' of {}
             TxFeeExplicit TxFeesExplicitInEra era
_ Lovelace
fee -> Lovelace -> Coin
toShelleyLovelace Lovelace
fee)
          (ValidityInterval :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> ValidityInterval
Allegra.ValidityInterval {
             invalidBefore :: StrictMaybe SlotNo
invalidBefore    = case TxValidityLowerBound era
lowerBound of
                                          TxValidityLowerBound era
TxValidityNoLowerBound   -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityLowerBound ValidityLowerBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s,
             invalidHereafter :: StrictMaybe SlotNo
invalidHereafter = case TxValidityUpperBound era
upperBound of
                                          TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
_ -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityUpperBound ValidityUpperBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s
           })
          (case TxUpdateProposal era
txUpdateProposal of
             TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (ShelleyMAEra 'Mary StandardCrypto))
forall a. StrictMaybe a
SNothing
             TxUpdateProposal UpdateProposalSupportedInEra era
_ UpdateProposal
p -> Update (ShelleyMAEra 'Mary StandardCrypto)
-> StrictMaybe (Update (ShelleyMAEra 'Mary StandardCrypto))
forall a. a -> StrictMaybe a
SJust (ShelleyBasedEra era
-> UpdateProposal -> Update (ShelleyMAEra 'Mary StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UpdateProposal -> Update ledgerera
toLedgerUpdate ShelleyBasedEra era
era UpdateProposal
p))
          (Maybe (AuxiliaryDataHash StandardCrypto)
-> StrictMaybe (AuxiliaryDataHash StandardCrypto)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe
            (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto)
-> AuxiliaryDataHash StandardCrypto
forall era c.
ValidateAuxiliaryData era c =>
AuxiliaryData era -> AuxiliaryDataHash c
Ledger.hashAuxiliaryData (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto)
 -> AuxiliaryDataHash StandardCrypto)
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
-> Maybe (AuxiliaryDataHash StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
txAuxData))
          (case TxMintValue BuildTx era
txMintValue of
             TxMintValue BuildTx era
TxMintNone        -> Value (ShelleyMAEra 'Mary StandardCrypto)
forall a. Monoid a => a
mempty
             TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Value -> Value StandardCrypto
toMaryValue Value
v))
        [Script (ShelleyMAEra 'Mary StandardCrypto)]
[Script (ShelleyLedgerEra era)]
scripts
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
  where

    maxShelleyTxInIx :: Word
    maxShelleyTxInIx :: Word
maxShelleyTxInIx = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ Bounded Word16 => Word16
forall a. Bounded a => a
maxBound @Word16

    scripts :: [Ledger.Script StandardMary]
    scripts :: [Script (ShelleyMAEra 'Mary StandardCrypto)]
scripts = [Maybe (Timelock StandardCrypto)] -> [Timelock StandardCrypto]
forall a. [Maybe a] -> [a]
catMaybes
      [ ScriptInEra era -> Timelock StandardCrypto
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Timelock StandardCrypto)
-> Maybe (ScriptInEra era) -> Maybe (Timelock StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
scriptWitnessScript ScriptWitness witctx era
scriptwitness
      | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness)
          <- TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txbodycontent
      ]

    txAuxData :: Maybe (Ledger.AuxiliaryData StandardMary)
    txAuxData :: Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
txAuxData
      | Map Word64 TxMetadataValue -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 TxMetadataValue
ms
      , [ScriptInEra era] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ScriptInEra era]
ss   = Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
forall a. Maybe a
Nothing
      | Bool
otherwise = AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto)
-> Maybe (AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto))
forall a. a -> Maybe a
Just (Map Word64 TxMetadataValue
-> [ScriptInEra era]
-> AuxiliaryData (ShelleyMAEra 'Mary StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 AuxiliaryData ledgerera ~ AuxiliaryData ledgerera,
 AnnotatedData (Script ledgerera), Ord (Script ledgerera)) =>
Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAllegraAuxiliaryData Map Word64 TxMetadataValue
ms [ScriptInEra era]
ss)
      where
        ms :: Map Word64 TxMetadataValue
ms = case TxMetadataInEra era
txMetadata of
               TxMetadataInEra era
TxMetadataNone                     -> Map Word64 TxMetadataValue
forall k a. Map k a
Map.empty
               TxMetadataInEra TxMetadataSupportedInEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue
ms'
        ss :: [ScriptInEra era]
ss = case TxAuxScripts era
txAuxScripts of
               TxAuxScripts era
TxAuxScriptsNone   -> []
               TxAuxScripts AuxScriptsSupportedInEra era
_ [ScriptInEra era]
ss' -> [ScriptInEra era]
ss'

makeShelleyTransactionBody era :: ShelleyBasedEra era
era@ShelleyBasedEra era
ShelleyBasedEraAlonzo
                           txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent {
                             TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                             TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral,
                             [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts,
                             TxFee era
txFee :: TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee,
                             txValidityRange :: forall build era.
TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange = (TxValidityLowerBound era
lowerBound, TxValidityUpperBound era
upperBound),
                             TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata,
                             TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts,
                             TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits :: forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits,
                             BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams :: BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe ProtocolParameters)
txProtocolParams,
                             TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                             TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                             TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal,
                             TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue,
                             TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity :: forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity
                           } = do

    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null TxIns BuildTx era
txIns)) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do Either TxBodyError ()
allPositive
           Either TxBodyError ()
allWithinMaxBound
           TxIns BuildTx era
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ TxIns BuildTx era
txIns (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  -> Either TxBodyError ())
 -> Either TxBodyError ())
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), BuildTxWith BuildTx (Witness WitCtxTxIn era)
_) ->
              Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
      | let maxTxOut :: Quantity
maxTxOut = Word64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Quantity
      , txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ (TxOutValue MultiAssetSupportedInEra era
MultiAssetInAlonzoEra Value
v) TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts
      , let allPositive :: Either TxBodyError ()
allPositive =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
< Quantity
0 ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
            allWithinMaxBound :: Either TxBodyError ()
allWithinMaxBound =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
> Quantity
maxTxOut ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
      ]
    case TxMetadataInEra era
txMetadata of
      TxMetadataInEra era
TxMetadataNone      -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMetadataInEra TxMetadataSupportedInEra era
_ TxMetadata
m -> TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
validateTxMetadata TxMetadata
m Either [(Word64, TxMetadataRangeError)] ()
-> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either TxBodyError ()
forall e a e'. Either e a -> (e -> e') -> Either e' a
?!. [(Word64, TxMetadataRangeError)] -> TxBodyError
TxBodyMetadataError
    case TxMintValue BuildTx era
txMintValue of
      TxMintValue BuildTx era
TxMintNone        -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Value -> Lovelace
selectLovelace Value
v Lovelace -> Lovelace -> Bool
forall a. Eq a => a -> a -> Bool
== Lovelace
0) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyMintAdaError
    case TxInsCollateral era
txInsCollateral of
      TxInsCollateral era
TxInsCollateralNone | Bool -> Bool
not (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages)
        -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyEmptyTxInsCollateral
      TxInsCollateral era
_ -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    case BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams of
      BuildTxWith Maybe ProtocolParameters
Nothing | Bool -> Bool
not (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages)
        -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyMissingProtocolParams
      BuildTxWith BuildTx (Maybe ProtocolParameters)
_ -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return () --TODO alonzo: validate protocol params for the Alonzo era.
                     --             All the necessary params must be provided.

    TxBody era -> Either TxBodyError (TxBody era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody era -> Either TxBodyError (TxBody era))
-> TxBody era -> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$
      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
        (Set (TxIn (Crypto (AlonzoEra StandardCrypto)))
-> Set (TxIn (Crypto (AlonzoEra StandardCrypto)))
-> StrictSeq (TxOut (AlonzoEra StandardCrypto))
-> StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
-> Wdrl (Crypto (AlonzoEra StandardCrypto))
-> Coin
-> ValidityInterval
-> StrictMaybe (Update (AlonzoEra StandardCrypto))
-> Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
-> Value (Crypto (AlonzoEra StandardCrypto))
-> StrictMaybe
     (ScriptIntegrityHash (Crypto (AlonzoEra StandardCrypto)))
-> StrictMaybe
     (AuxiliaryDataHash (Crypto (AlonzoEra StandardCrypto)))
-> StrictMaybe Network
-> TxBody (AlonzoEra StandardCrypto)
forall era.
AlonzoBody era =>
Set (TxIn (Crypto era))
-> Set (TxIn (Crypto era))
-> StrictSeq (TxOut era)
-> StrictSeq (DCert (Crypto era))
-> Wdrl (Crypto era)
-> Coin
-> ValidityInterval
-> StrictMaybe (Update era)
-> Set (KeyHash 'Witness (Crypto era))
-> Value (Crypto era)
-> StrictMaybe (ScriptIntegrityHash (Crypto era))
-> StrictMaybe (AuxiliaryDataHash (Crypto era))
-> StrictMaybe Network
-> TxBody era
Alonzo.TxBody
          ([TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
 -> TxIn StandardCrypto)
-> TxIns BuildTx era -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn -> TxIn StandardCrypto)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst) TxIns BuildTx era
txIns))
          (case TxInsCollateral era
txInsCollateral of
             TxInsCollateral era
TxInsCollateralNone     -> Set (TxIn (Crypto (AlonzoEra StandardCrypto)))
forall a. Set a
Set.empty
             TxInsCollateral CollateralSupportedInEra era
_ [TxIn]
txins -> [TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList ((TxIn -> TxIn StandardCrypto) -> [TxIn] -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn StandardCrypto
toShelleyTxIn [TxIn]
txins))
          ([TxOut (AlonzoEra StandardCrypto)]
-> StrictSeq (TxOut (AlonzoEra StandardCrypto))
forall a. [a] -> StrictSeq a
Seq.fromList ((TxOut CtxTx era -> TxOut (AlonzoEra StandardCrypto))
-> [TxOut CtxTx era] -> [TxOut (AlonzoEra StandardCrypto)]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (AlonzoEra StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era) [TxOut CtxTx era]
txOuts))
          (case TxCertificates BuildTx era
txCertificates of
             TxCertificates BuildTx era
TxCertificatesNone    -> StrictSeq (DCert (Crypto (AlonzoEra StandardCrypto)))
forall a. StrictSeq a
Seq.empty
             TxCertificates CertificatesSupportedInEra era
_ [Certificate]
cs BuildTxWith BuildTx (Map StakeCredential (Witness WitCtxStake era))
_ -> [DCert StandardCrypto] -> StrictSeq (DCert StandardCrypto)
forall a. [a] -> StrictSeq a
Seq.fromList ((Certificate -> DCert StandardCrypto)
-> [Certificate] -> [DCert StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map Certificate -> DCert StandardCrypto
toShelleyCertificate [Certificate]
cs))
          (case TxWithdrawals BuildTx era
txWithdrawals of
             TxWithdrawals BuildTx era
TxWithdrawalsNone  -> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
forall k a. Map k a
Map.empty
             TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws -> [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Wdrl StandardCrypto
forall a. [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws)
          (case TxFee era
txFee of
             TxFeeImplicit TxFeesImplicitInEra era
era'  -> case TxFeesImplicitInEra era
era' of {}
             TxFeeExplicit TxFeesExplicitInEra era
_ Lovelace
fee -> Lovelace -> Coin
toShelleyLovelace Lovelace
fee)
          (ValidityInterval :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> ValidityInterval
Allegra.ValidityInterval {
             invalidBefore :: StrictMaybe SlotNo
invalidBefore    = case TxValidityLowerBound era
lowerBound of
                                          TxValidityLowerBound era
TxValidityNoLowerBound   -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityLowerBound ValidityLowerBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s,
             invalidHereafter :: StrictMaybe SlotNo
invalidHereafter = case TxValidityUpperBound era
upperBound of
                                          TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
_ -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                          TxValidityUpperBound ValidityUpperBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s
           })
          (case TxUpdateProposal era
txUpdateProposal of
             TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (AlonzoEra StandardCrypto))
forall a. StrictMaybe a
SNothing
             TxUpdateProposal UpdateProposalSupportedInEra era
_ UpdateProposal
p -> Update (AlonzoEra StandardCrypto)
-> StrictMaybe (Update (AlonzoEra StandardCrypto))
forall a. a -> StrictMaybe a
SJust (ShelleyBasedEra era
-> UpdateProposal -> Update (AlonzoEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UpdateProposal -> Update ledgerera
toLedgerUpdate ShelleyBasedEra era
era UpdateProposal
p))
          (case TxExtraKeyWitnesses era
txExtraKeyWits of
             TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone   -> Set (KeyHash 'Witness (Crypto (AlonzoEra StandardCrypto)))
forall a. Set a
Set.empty
             TxExtraKeyWitnesses TxExtraKeyWitnessesSupportedInEra era
_ [Hash PaymentKey]
khs -> [KeyHash 'Witness StandardCrypto]
-> Set (KeyHash 'Witness StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList
                                            [ KeyHash 'Payment StandardCrypto -> KeyHash 'Witness StandardCrypto
forall (a :: KeyRole -> * -> *) (r :: KeyRole) crypto
       (r' :: KeyRole).
HasKeyRole a =>
a r crypto -> a r' crypto
Shelley.coerceKeyRole KeyHash 'Payment StandardCrypto
kh
                                            | PaymentKeyHash kh <- [Hash PaymentKey]
khs ])
          (case TxMintValue BuildTx era
txMintValue of
             TxMintValue BuildTx era
TxMintNone        -> Value (Crypto (AlonzoEra StandardCrypto))
forall a. Monoid a => a
mempty
             TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Value -> Value StandardCrypto
toMaryValue Value
v)
          (case BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams of
             BuildTxWith Maybe ProtocolParameters
Nothing        -> StrictMaybe
  (ScriptIntegrityHash (Crypto (AlonzoEra StandardCrypto)))
forall a. StrictMaybe a
SNothing
             BuildTxWith (Just ProtocolParameters
pparams) ->
               Set LangDepView
-> Redeemers (AlonzoEra StandardCrypto)
-> TxDats (AlonzoEra StandardCrypto)
-> StrictMaybe
     (ScriptIntegrityHash (Crypto (AlonzoEra StandardCrypto)))
forall era.
Era era =>
Set LangDepView
-> Redeemers era
-> TxDats era
-> StrictMaybe (ScriptIntegrityHash (Crypto era))
Alonzo.hashScriptIntegrity
                 ((Language -> LangDepView) -> Set Language -> Set LangDepView
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map
                    (PParams (AlonzoEra StandardCrypto) -> Language -> LangDepView
forall era.
HasField "_costmdls" (PParams era) CostModels =>
PParams era -> Language -> LangDepView
Alonzo.getLanguageView (ShelleyBasedEra AlonzoEra
-> ProtocolParameters -> PParams (ShelleyLedgerEra AlonzoEra)
forall era.
ShelleyBasedEra era
-> ProtocolParameters -> PParams (ShelleyLedgerEra era)
toLedgerPParams ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo ProtocolParameters
pparams))
                    Set Language
languages
                 )
                 Redeemers (AlonzoEra StandardCrypto)
redeemers
                 TxDats (AlonzoEra StandardCrypto)
datums)
          (Maybe (AuxiliaryDataHash StandardCrypto)
-> StrictMaybe (AuxiliaryDataHash StandardCrypto)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe
            (AuxiliaryData (AlonzoEra StandardCrypto)
-> AuxiliaryDataHash StandardCrypto
forall era c.
ValidateAuxiliaryData era c =>
AuxiliaryData era -> AuxiliaryDataHash c
Ledger.hashAuxiliaryData (AuxiliaryData (AlonzoEra StandardCrypto)
 -> AuxiliaryDataHash StandardCrypto)
-> Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
-> Maybe (AuxiliaryDataHash StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
txAuxData))
          StrictMaybe Network
forall a. StrictMaybe a
SNothing) -- TODO alonzo: support optional network id in TxBodyContent
        [Script (AlonzoEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
scripts
        (ScriptDataSupportedInEra AlonzoEra
-> TxDats (ShelleyLedgerEra AlonzoEra)
-> Redeemers (ShelleyLedgerEra AlonzoEra)
-> TxBodyScriptData AlonzoEra
forall era.
ScriptDataSupportedInEra era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra TxDats (AlonzoEra StandardCrypto)
TxDats (ShelleyLedgerEra AlonzoEra)
datums Redeemers (AlonzoEra StandardCrypto)
Redeemers (ShelleyLedgerEra AlonzoEra)
redeemers)
        Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
txScriptValidity
  where

    maxShelleyTxInIx :: Word
    maxShelleyTxInIx :: Word
maxShelleyTxInIx = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ Bounded Word16 => Word16
forall a. Bounded a => a
maxBound @Word16

    witnesses :: [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
    witnesses :: [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses = TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txbodycontent

    scripts :: [Ledger.Script StandardAlonzo]
    scripts :: [Script (AlonzoEra StandardCrypto)]
scripts = [Maybe (Script (AlonzoEra StandardCrypto))]
-> [Script (AlonzoEra StandardCrypto)]
forall a. [Maybe a] -> [a]
catMaybes
      [ ScriptInEra AlonzoEra -> Script (AlonzoEra StandardCrypto)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra AlonzoEra -> Script (AlonzoEra StandardCrypto))
-> Maybe (ScriptInEra AlonzoEra)
-> Maybe (Script (AlonzoEra StandardCrypto))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx AlonzoEra -> Maybe (ScriptInEra AlonzoEra)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
scriptWitnessScript ScriptWitness witctx AlonzoEra
scriptwitness
      | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx AlonzoEra
scriptwitness) <- [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
      ]

    datums :: Alonzo.TxDats StandardAlonzo
    datums :: TxDats (AlonzoEra StandardCrypto)
datums =
      Map
  (DataHash (Crypto (AlonzoEra StandardCrypto)))
  (Data (AlonzoEra StandardCrypto))
-> TxDats (AlonzoEra StandardCrypto)
forall era.
Typeable era =>
Map (DataHash (Crypto era)) (Data era) -> TxDats era
Alonzo.TxDats (Map
   (DataHash (Crypto (AlonzoEra StandardCrypto)))
   (Data (AlonzoEra StandardCrypto))
 -> TxDats (AlonzoEra StandardCrypto))
-> Map
     (DataHash (Crypto (AlonzoEra StandardCrypto)))
     (Data (AlonzoEra StandardCrypto))
-> TxDats (AlonzoEra StandardCrypto)
forall a b. (a -> b) -> a -> b
$
        [(DataHash StandardCrypto, Data (AlonzoEra StandardCrypto))]
-> Map (DataHash StandardCrypto) (Data (AlonzoEra StandardCrypto))
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
          [ (Data (AlonzoEra StandardCrypto)
-> DataHash (Crypto (AlonzoEra StandardCrypto))
forall era. Era era => Data era -> DataHash (Crypto era)
Alonzo.hashData Data (AlonzoEra StandardCrypto)
d', Data (AlonzoEra StandardCrypto)
d')
          | ScriptData
d <- [ScriptData]
scriptdata
          , let d' :: Data (AlonzoEra StandardCrypto)
d' = ScriptData -> Data (AlonzoEra StandardCrypto)
forall ledgerera. ScriptData -> Data ledgerera
toAlonzoData ScriptData
d
          ]

    scriptdata :: [ScriptData]
    scriptdata :: [ScriptData]
scriptdata =
        [ ScriptData
d | TxOut AddressInEra era
_ TxOutValue era
_ (TxOutDatumInTx ScriptDataSupportedInEra era
_ ScriptData
d) ReferenceScript era
_ <- [TxOut CtxTx era]
txOuts ]
     [ScriptData] -> [ScriptData] -> [ScriptData]
forall a. [a] -> [a] -> [a]
++ [ ScriptData
d | (ScriptWitnessIndex
_, AnyScriptWitness
                    (PlutusScriptWitness
                       ScriptLanguageInEra lang AlonzoEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ (ScriptDatumForTxIn ScriptData
d) ScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
            ]

    redeemers :: Alonzo.Redeemers StandardAlonzo
    redeemers :: Redeemers (AlonzoEra StandardCrypto)
redeemers =
      Map RdmrPtr (Data (AlonzoEra StandardCrypto), ExUnits)
-> Redeemers (AlonzoEra StandardCrypto)
forall era.
Era era =>
Map RdmrPtr (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map RdmrPtr (Data (AlonzoEra StandardCrypto), ExUnits)
 -> Redeemers (AlonzoEra StandardCrypto))
-> Map RdmrPtr (Data (AlonzoEra StandardCrypto), ExUnits)
-> Redeemers (AlonzoEra StandardCrypto)
forall a b. (a -> b) -> a -> b
$
        [(RdmrPtr, (Data (AlonzoEra StandardCrypto), ExUnits))]
-> Map RdmrPtr (Data (AlonzoEra StandardCrypto), ExUnits)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
          [ (ScriptWitnessIndex -> RdmrPtr
toAlonzoRdmrPtr ScriptWitnessIndex
idx, (ScriptData -> Data (AlonzoEra StandardCrypto)
forall ledgerera. ScriptData -> Data ledgerera
toAlonzoData ScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
          | (ScriptWitnessIndex
idx, AnyScriptWitness
                    (PlutusScriptWitness ScriptLanguageInEra lang AlonzoEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptData
d ExecutionUnits
e)) <- [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
          ]

    languages :: Set Alonzo.Language
    languages :: Set Language
languages =
      [Language] -> Set Language
forall a. Ord a => [a] -> Set a
Set.fromList
        [ AnyPlutusScriptVersion -> Language
toAlonzoLanguage (PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang. PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v)
        | (ScriptWitnessIndex
_, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang AlonzoEra
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
        ]

    txAuxData :: Maybe (Ledger.AuxiliaryData StandardAlonzo)
    txAuxData :: Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
txAuxData
      | Map Word64 TxMetadataValue -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 TxMetadataValue
ms
      , [ScriptInEra era] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ScriptInEra era]
ss   = Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
forall a. Maybe a
Nothing
      | Bool
otherwise = AuxiliaryData (AlonzoEra StandardCrypto)
-> Maybe (AuxiliaryData (AlonzoEra StandardCrypto))
forall a. a -> Maybe a
Just (Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData (AlonzoEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 AuxiliaryData ledgerera ~ AuxiliaryData ledgerera,
 Script ledgerera ~ Script ledgerera, Era ledgerera) =>
Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAlonzoAuxiliaryData Map Word64 TxMetadataValue
ms [ScriptInEra era]
ss)
      where
        ms :: Map Word64 TxMetadataValue
ms = case TxMetadataInEra era
txMetadata of
               TxMetadataInEra era
TxMetadataNone                     -> Map Word64 TxMetadataValue
forall k a. Map k a
Map.empty
               TxMetadataInEra TxMetadataSupportedInEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue
ms'
        ss :: [ScriptInEra era]
ss = case TxAuxScripts era
txAuxScripts of
               TxAuxScripts era
TxAuxScriptsNone   -> []
               TxAuxScripts AuxScriptsSupportedInEra era
_ [ScriptInEra era]
ss' -> [ScriptInEra era]
ss'

makeShelleyTransactionBody era :: ShelleyBasedEra era
era@ShelleyBasedEra era
ShelleyBasedEraBabbage
                            txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent {
                             TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                             TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral,
                             TxInsReference BuildTx era
txInsReference :: TxInsReference BuildTx era
txInsReference :: forall build era.
TxBodyContent build era -> TxInsReference build era
txInsReference,
                             TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral :: forall build era.
TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral,
                             TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
txTotalCollateral :: forall build era. TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral,
                             [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts,
                             TxFee era
txFee :: TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee,
                             txValidityRange :: forall build era.
TxBodyContent build era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
txValidityRange = (TxValidityLowerBound era
lowerBound, TxValidityUpperBound era
upperBound),
                             TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata,
                             TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts,
                             TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits :: forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits,
                             BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams :: BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe ProtocolParameters)
txProtocolParams,
                             TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                             TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                             TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal,
                             TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue,
                             TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity :: forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity
                           } = do
    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null TxIns BuildTx era
txIns)) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do Either TxBodyError ()
allPositive
           Either TxBodyError ()
allWithinMaxBound
           TxIns BuildTx era
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ TxIns BuildTx era
txIns (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
  -> Either TxBodyError ())
 -> Either TxBodyError ())
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
    -> Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), BuildTxWith BuildTx (Witness WitCtxTxIn era)
_) ->
              Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin
      | let maxTxOut :: Quantity
maxTxOut = Word64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Quantity
      , txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ (TxOutValue MultiAssetSupportedInEra era
MultiAssetInBabbageEra Value
v) TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts
      , let allPositive :: Either TxBodyError ()
allPositive =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
< Quantity
0 ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
            allWithinMaxBound :: Either TxBodyError ()
allWithinMaxBound =
              case [ Quantity
q | (AssetId
_,Quantity
q) <- Value -> [(AssetId, Quantity)]
valueToList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
> Quantity
maxTxOut ] of
                []  -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
                Quantity
q:[Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow Quantity
q (TxOut CtxTx era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra TxOut CtxTx era
txout))
      ]
    case TxMetadataInEra era
txMetadata of
      TxMetadataInEra era
TxMetadataNone      -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMetadataInEra TxMetadataSupportedInEra era
_ TxMetadata
m -> TxMetadata -> Either [(Word64, TxMetadataRangeError)] ()
validateTxMetadata TxMetadata
m Either [(Word64, TxMetadataRangeError)] ()
-> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either TxBodyError ()
forall e a e'. Either e a -> (e -> e') -> Either e' a
?!. [(Word64, TxMetadataRangeError)] -> TxBodyError
TxBodyMetadataError
    case TxMintValue BuildTx era
txMintValue of
      TxMintValue BuildTx era
TxMintNone        -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Value -> Lovelace
selectLovelace Value
v Lovelace -> Lovelace -> Bool
forall a. Eq a => a -> a -> Bool
== Lovelace
0) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyMintAdaError
    case TxInsCollateral era
txInsCollateral of
      TxInsCollateral era
TxInsCollateralNone | Bool -> Bool
not (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages)
        -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyEmptyTxInsCollateral
      TxInsCollateral era
_ -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    case BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams of
      BuildTxWith Maybe ProtocolParameters
Nothing | Bool -> Bool
not (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages)
        -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyMissingProtocolParams
      BuildTxWith BuildTx (Maybe ProtocolParameters)
_ -> () -> Either TxBodyError ()
forall (m :: * -> *) a. Monad m => a -> m a
return () --TODO alonzo: validate protocol params for the Babbage era.
                     --             All the necessary params must be provided.

    TxBody era -> Either TxBodyError (TxBody era)
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBody era -> Either TxBodyError (TxBody era))
-> TxBody era -> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$
      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
        (TxBody :: forall era.
BabbageBody era =>
Set (TxIn (Crypto era))
-> Set (TxIn (Crypto era))
-> Set (TxIn (Crypto era))
-> StrictSeq (Sized (TxOut era))
-> StrictMaybe (Sized (TxOut era))
-> StrictMaybe Coin
-> StrictSeq (DCert (Crypto era))
-> Wdrl (Crypto era)
-> Coin
-> ValidityInterval
-> StrictMaybe (Update era)
-> Set (KeyHash 'Witness (Crypto era))
-> Value (Crypto era)
-> StrictMaybe (ScriptIntegrityHash (Crypto era))
-> StrictMaybe (AuxiliaryDataHash (Crypto era))
-> StrictMaybe Network
-> TxBody era
Babbage.TxBody
           { inputs :: Set (TxIn (Crypto (BabbageEra StandardCrypto)))
Babbage.inputs = [TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList ([TxIn StandardCrypto] -> Set (TxIn StandardCrypto))
-> [TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a b. (a -> b) -> a -> b
$ ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
 -> TxIn StandardCrypto)
-> TxIns BuildTx era -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn -> TxIn StandardCrypto)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn StandardCrypto
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst) TxIns BuildTx era
txIns
           , collateral :: Set (TxIn (Crypto (BabbageEra StandardCrypto)))
Babbage.collateral =
               case TxInsCollateral era
txInsCollateral of
                TxInsCollateral era
TxInsCollateralNone     -> Set (TxIn (Crypto (BabbageEra StandardCrypto)))
forall a. Set a
Set.empty
                TxInsCollateral CollateralSupportedInEra era
_ [TxIn]
txins -> [TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList ((TxIn -> TxIn StandardCrypto) -> [TxIn] -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn StandardCrypto
toShelleyTxIn [TxIn]
txins)
           , referenceInputs :: Set (TxIn (Crypto (BabbageEra StandardCrypto)))
Babbage.referenceInputs =
               [TxIn StandardCrypto] -> Set (TxIn StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList ((TxIn -> TxIn StandardCrypto) -> [TxIn] -> [TxIn StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn StandardCrypto
toShelleyTxIn [TxIn]
referenceTxIns)

           , outputs :: StrictSeq (Sized (TxOut (BabbageEra StandardCrypto)))
Babbage.outputs = [Sized (TxOut (BabbageEra StandardCrypto))]
-> StrictSeq (Sized (TxOut (BabbageEra StandardCrypto)))
forall a. [a] -> StrictSeq a
Seq.fromList ((TxOut CtxTx era -> Sized (TxOut (BabbageEra StandardCrypto)))
-> [TxOut CtxTx era] -> [Sized (TxOut (BabbageEra StandardCrypto))]
forall a b. (a -> b) -> [a] -> [b]
map (TxOut (BabbageEra StandardCrypto)
-> Sized (TxOut (BabbageEra StandardCrypto))
forall a. ToCBOR a => a -> Sized a
CBOR.mkSized (TxOut (BabbageEra StandardCrypto)
 -> Sized (TxOut (BabbageEra StandardCrypto)))
-> (TxOut CtxTx era -> TxOut (BabbageEra StandardCrypto))
-> TxOut CtxTx era
-> Sized (TxOut (BabbageEra StandardCrypto))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (BabbageEra StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era) [TxOut CtxTx era]
txOuts)
           , collateralReturn :: StrictMaybe (Sized (TxOut (BabbageEra StandardCrypto)))
Babbage.collateralReturn =
               case TxReturnCollateral CtxTx era
txReturnCollateral of
                 TxReturnCollateral CtxTx era
TxReturnCollateralNone -> StrictMaybe (Sized (TxOut (BabbageEra StandardCrypto)))
forall a. StrictMaybe a
SNothing
                 TxReturnCollateral TxTotalAndReturnCollateralSupportedInEra era
_ TxOut CtxTx era
colTxOut -> Sized (TxOut (BabbageEra StandardCrypto))
-> StrictMaybe (Sized (TxOut (BabbageEra StandardCrypto)))
forall a. a -> StrictMaybe a
SJust (Sized (TxOut (BabbageEra StandardCrypto))
 -> StrictMaybe (Sized (TxOut (BabbageEra StandardCrypto))))
-> Sized (TxOut (BabbageEra StandardCrypto))
-> StrictMaybe (Sized (TxOut (BabbageEra StandardCrypto)))
forall a b. (a -> b) -> a -> b
$ TxOut (BabbageEra StandardCrypto)
-> Sized (TxOut (BabbageEra StandardCrypto))
forall a. ToCBOR a => a -> Sized a
CBOR.mkSized (TxOut (BabbageEra StandardCrypto)
 -> Sized (TxOut (BabbageEra StandardCrypto)))
-> TxOut (BabbageEra StandardCrypto)
-> Sized (TxOut (BabbageEra StandardCrypto))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxOut CtxTx era -> TxOut (BabbageEra StandardCrypto)
forall ctx era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era TxOut CtxTx era
colTxOut
           , totalCollateral :: StrictMaybe Coin
Babbage.totalCollateral =
               case TxTotalCollateral era
txTotalCollateral of
                 TxTotalCollateral era
TxTotalCollateralNone -> StrictMaybe Coin
forall a. StrictMaybe a
SNothing
                 TxTotalCollateral TxTotalAndReturnCollateralSupportedInEra era
_ Lovelace
totCollLovelace -> Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust (Coin -> StrictMaybe Coin) -> Coin -> StrictMaybe Coin
forall a b. (a -> b) -> a -> b
$ Lovelace -> Coin
toShelleyLovelace Lovelace
totCollLovelace
           , txcerts :: StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
Babbage.txcerts =
               case TxCertificates BuildTx era
txCertificates of
                 TxCertificates BuildTx era
TxCertificatesNone    -> StrictSeq (DCert (Crypto (BabbageEra StandardCrypto)))
forall a. StrictSeq a
Seq.empty
                 TxCertificates CertificatesSupportedInEra era
_ [Certificate]
cs BuildTxWith BuildTx (Map StakeCredential (Witness WitCtxStake era))
_ -> [DCert StandardCrypto] -> StrictSeq (DCert StandardCrypto)
forall a. [a] -> StrictSeq a
Seq.fromList ((Certificate -> DCert StandardCrypto)
-> [Certificate] -> [DCert StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map Certificate -> DCert StandardCrypto
toShelleyCertificate [Certificate]
cs)
           , txwdrls :: Wdrl (Crypto (BabbageEra StandardCrypto))
Babbage.txwdrls =
               case TxWithdrawals BuildTx era
txWithdrawals of
                 TxWithdrawals BuildTx era
TxWithdrawalsNone  -> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
forall k a. Map k a
Map.empty
                 TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws -> [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Wdrl StandardCrypto
forall a. [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
ws
           , txfee :: Coin
Babbage.txfee =
               case TxFee era
txFee of
                 TxFeeImplicit TxFeesImplicitInEra era
era'  -> case TxFeesImplicitInEra era
era' of {}
                 TxFeeExplicit TxFeesExplicitInEra era
_ Lovelace
fee -> Lovelace -> Coin
toShelleyLovelace Lovelace
fee
           , txvldt :: ValidityInterval
Babbage.txvldt =
               ValidityInterval :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> ValidityInterval
Allegra.ValidityInterval {
                 invalidBefore :: StrictMaybe SlotNo
invalidBefore    = case TxValidityLowerBound era
lowerBound of
                                              TxValidityLowerBound era
TxValidityNoLowerBound   -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                              TxValidityLowerBound ValidityLowerBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s,
                 invalidHereafter :: StrictMaybe SlotNo
invalidHereafter = case TxValidityUpperBound era
upperBound of
                                              TxValidityNoUpperBound ValidityNoUpperBoundSupportedInEra era
_ -> StrictMaybe SlotNo
forall a. StrictMaybe a
SNothing
                                              TxValidityUpperBound ValidityUpperBoundSupportedInEra era
_ SlotNo
s -> SlotNo -> StrictMaybe SlotNo
forall a. a -> StrictMaybe a
SJust SlotNo
s}
           , txUpdates :: StrictMaybe (Update (BabbageEra StandardCrypto))
Babbage.txUpdates =
               case TxUpdateProposal era
txUpdateProposal of
                 TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (BabbageEra StandardCrypto))
forall a. StrictMaybe a
SNothing
                 TxUpdateProposal UpdateProposalSupportedInEra era
_ UpdateProposal
p -> Update (BabbageEra StandardCrypto)
-> StrictMaybe (Update (BabbageEra StandardCrypto))
forall a. a -> StrictMaybe a
SJust (ShelleyBasedEra era
-> UpdateProposal -> Update (BabbageEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UpdateProposal -> Update ledgerera
toLedgerUpdate ShelleyBasedEra era
era UpdateProposal
p)
           , reqSignerHashes :: Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
Babbage.reqSignerHashes =
               case TxExtraKeyWitnesses era
txExtraKeyWits of
                 TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone   -> Set (KeyHash 'Witness (Crypto (BabbageEra StandardCrypto)))
forall a. Set a
Set.empty
                 TxExtraKeyWitnesses TxExtraKeyWitnessesSupportedInEra era
_ [Hash PaymentKey]
khs -> [KeyHash 'Witness StandardCrypto]
-> Set (KeyHash 'Witness StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList
                                                [ KeyHash 'Payment StandardCrypto -> KeyHash 'Witness StandardCrypto
forall (a :: KeyRole -> * -> *) (r :: KeyRole) crypto
       (r' :: KeyRole).
HasKeyRole a =>
a r crypto -> a r' crypto
Shelley.coerceKeyRole KeyHash 'Payment StandardCrypto
kh
                                                | PaymentKeyHash kh <- [Hash PaymentKey]
khs ]
           , mint :: Value (Crypto (BabbageEra StandardCrypto))
Babbage.mint =
               case TxMintValue BuildTx era
txMintValue of
                 TxMintValue BuildTx era
TxMintNone        -> Value (Crypto (BabbageEra StandardCrypto))
forall a. Monoid a => a
mempty
                 TxMintValue MultiAssetSupportedInEra era
_ Value
v BuildTxWith BuildTx (Map PolicyId (ScriptWitness WitCtxMint era))
_ -> Value -> Value StandardCrypto
toMaryValue Value
v
           , scriptIntegrityHash :: StrictMaybe
  (ScriptIntegrityHash (Crypto (BabbageEra StandardCrypto)))
Babbage.scriptIntegrityHash =
               case BuildTxWith BuildTx (Maybe ProtocolParameters)
txProtocolParams of
                 BuildTxWith Maybe ProtocolParameters
Nothing        -> StrictMaybe
  (ScriptIntegrityHash (Crypto (BabbageEra StandardCrypto)))
forall a. StrictMaybe a
SNothing
                 BuildTxWith (Just ProtocolParameters
pparams) ->
                    Set LangDepView
-> Redeemers (BabbageEra StandardCrypto)
-> TxDats (BabbageEra StandardCrypto)
-> StrictMaybe
     (ScriptIntegrityHash (Crypto (BabbageEra StandardCrypto)))
forall era.
Era era =>
Set LangDepView
-> Redeemers era
-> TxDats era
-> StrictMaybe (ScriptIntegrityHash (Crypto era))
Alonzo.hashScriptIntegrity
                      ((Language -> LangDepView) -> Set Language -> Set LangDepView
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map
                         (PParams (BabbageEra StandardCrypto) -> Language -> LangDepView
forall era.
HasField "_costmdls" (PParams era) CostModels =>
PParams era -> Language -> LangDepView
Alonzo.getLanguageView (ShelleyBasedEra BabbageEra
-> ProtocolParameters -> PParams (ShelleyLedgerEra BabbageEra)
forall era.
ShelleyBasedEra era
-> ProtocolParameters -> PParams (ShelleyLedgerEra era)
toLedgerPParams ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage ProtocolParameters
pparams))
                         Set Language
languages
                      )
                      Redeemers (BabbageEra StandardCrypto)
redeemers
                      TxDats (BabbageEra StandardCrypto)
datums
           , adHash :: StrictMaybe
  (AuxiliaryDataHash (Crypto (BabbageEra StandardCrypto)))
Babbage.adHash =
                Maybe (AuxiliaryDataHash StandardCrypto)
-> StrictMaybe (AuxiliaryDataHash StandardCrypto)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe (AuxiliaryData (BabbageEra StandardCrypto)
-> AuxiliaryDataHash StandardCrypto
forall era c.
ValidateAuxiliaryData era c =>
AuxiliaryData era -> AuxiliaryDataHash c
Ledger.hashAuxiliaryData (AuxiliaryData (BabbageEra StandardCrypto)
 -> AuxiliaryDataHash StandardCrypto)
-> Maybe (AuxiliaryData (BabbageEra StandardCrypto))
-> Maybe (AuxiliaryDataHash StandardCrypto)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (BabbageEra StandardCrypto))
txAuxData)
           , txnetworkid :: StrictMaybe Network
Babbage.txnetworkid = StrictMaybe Network
forall a. StrictMaybe a
SNothing
           })
        [Script (BabbageEra StandardCrypto)]
[Script (ShelleyLedgerEra era)]
scripts
        (ScriptDataSupportedInEra BabbageEra
-> TxDats (ShelleyLedgerEra BabbageEra)
-> Redeemers (ShelleyLedgerEra BabbageEra)
-> TxBodyScriptData BabbageEra
forall era.
ScriptDataSupportedInEra era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData ScriptDataSupportedInEra BabbageEra
ScriptDataInBabbageEra
          TxDats (BabbageEra StandardCrypto)
TxDats (ShelleyLedgerEra BabbageEra)
datums Redeemers (BabbageEra StandardCrypto)
Redeemers (ShelleyLedgerEra BabbageEra)
redeemers)
        Maybe (AuxiliaryData (BabbageEra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
txScriptValidity
  where
    referenceTxIns :: [TxIn]
    referenceTxIns :: [TxIn]
referenceTxIns =
      case TxInsReference BuildTx era
txInsReference of
        TxInsReference BuildTx era
TxInsReferenceNone -> []
        TxInsReference ReferenceTxInsScriptsInlineDatumsSupportedInEra era
_ [TxIn]
refTxins -> [TxIn]
refTxins

    maxShelleyTxInIx :: Word
    maxShelleyTxInIx :: Word
maxShelleyTxInIx = Word16 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Word) -> Word16 -> Word
forall a b. (a -> b) -> a -> b
$ Bounded Word16 => Word16
forall a. Bounded a => a
maxBound @Word16

    witnesses :: [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
    witnesses :: [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses = TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent BuildTx era
txbodycontent

    scripts :: [Ledger.Script StandardBabbage]
    scripts :: [Script (BabbageEra StandardCrypto)]
scripts = [Maybe (Script (BabbageEra StandardCrypto))]
-> [Script (BabbageEra StandardCrypto)]
forall a. [Maybe a] -> [a]
catMaybes
      [ ScriptInEra BabbageEra -> Script (BabbageEra StandardCrypto)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra BabbageEra -> Script (BabbageEra StandardCrypto))
-> Maybe (ScriptInEra BabbageEra)
-> Maybe (Script (BabbageEra StandardCrypto))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx BabbageEra -> Maybe (ScriptInEra BabbageEra)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
scriptWitnessScript ScriptWitness witctx BabbageEra
scriptwitness
      | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx BabbageEra
scriptwitness) <- [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses
      ]

    -- Note these do not include inline datums!
    datums :: Alonzo.TxDats StandardBabbage
    datums :: TxDats (BabbageEra StandardCrypto)
datums =
      Map
  (DataHash (Crypto (BabbageEra StandardCrypto)))
  (Data (BabbageEra StandardCrypto))
-> TxDats (BabbageEra StandardCrypto)
forall era.
Typeable era =>
Map (DataHash (Crypto era)) (Data era) -> TxDats era
Alonzo.TxDats (Map
   (DataHash (Crypto (BabbageEra StandardCrypto)))
   (Data (BabbageEra StandardCrypto))
 -> TxDats (BabbageEra StandardCrypto))
-> Map
     (DataHash (Crypto (BabbageEra StandardCrypto)))
     (Data (BabbageEra StandardCrypto))
-> TxDats (BabbageEra StandardCrypto)
forall a b. (a -> b) -> a -> b
$
        [(DataHash StandardCrypto, Data (BabbageEra StandardCrypto))]
-> Map (DataHash StandardCrypto) (Data (BabbageEra StandardCrypto))
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
          [ (Data (BabbageEra StandardCrypto)
-> DataHash (Crypto (BabbageEra StandardCrypto))
forall era. Era era => Data era -> DataHash (Crypto era)
Alonzo.hashData Data (BabbageEra StandardCrypto)
d', Data (BabbageEra StandardCrypto)
d')
          | ScriptData
d <- [ScriptData]
scriptdata
          , let d' :: Data (BabbageEra StandardCrypto)
d' = ScriptData -> Data (BabbageEra StandardCrypto)
forall ledgerera. ScriptData -> Data ledgerera
toAlonzoData ScriptData
d
          ]

    scriptdata :: [ScriptData]
    scriptdata :: [ScriptData]
scriptdata =
        [ ScriptData
d | TxOut AddressInEra era
_ TxOutValue era
_ (TxOutDatumInTx ScriptDataSupportedInEra era
_ ScriptData
d) ReferenceScript era
_ <- [TxOut CtxTx era]
txOuts ]
     [ScriptData] -> [ScriptData] -> [ScriptData]
forall a. [a] -> [a] -> [a]
++ [ ScriptData
d | (ScriptWitnessIndex
_, AnyScriptWitness
                    (PlutusScriptWitness
                       ScriptLanguageInEra lang BabbageEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ (ScriptDatumForTxIn ScriptData
d) ScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses
            ]

    redeemers :: Alonzo.Redeemers StandardBabbage
    redeemers :: Redeemers (BabbageEra StandardCrypto)
redeemers =
      Map RdmrPtr (Data (BabbageEra StandardCrypto), ExUnits)
-> Redeemers (BabbageEra StandardCrypto)
forall era.
Era era =>
Map RdmrPtr (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map RdmrPtr (Data (BabbageEra StandardCrypto), ExUnits)
 -> Redeemers (BabbageEra StandardCrypto))
-> Map RdmrPtr (Data (BabbageEra StandardCrypto), ExUnits)
-> Redeemers (BabbageEra StandardCrypto)
forall a b. (a -> b) -> a -> b
$
        [(RdmrPtr, (Data (BabbageEra StandardCrypto), ExUnits))]
-> Map RdmrPtr (Data (BabbageEra StandardCrypto), ExUnits)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
          [ (ScriptWitnessIndex -> RdmrPtr
toAlonzoRdmrPtr ScriptWitnessIndex
idx, (ScriptData -> Data (BabbageEra StandardCrypto)
forall ledgerera. ScriptData -> Data ledgerera
toAlonzoData ScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
          | (ScriptWitnessIndex
idx, AnyScriptWitness
                    (PlutusScriptWitness ScriptLanguageInEra lang BabbageEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptData
d ExecutionUnits
e)) <- [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses
          ]

    languages :: Set Alonzo.Language
    languages :: Set Language
languages =
      [Language] -> Set Language
forall a. Ord a => [a] -> Set a
Set.fromList ([Language] -> Set Language) -> [Language] -> Set Language
forall a b. (a -> b) -> a -> b
$ [Maybe Language] -> [Language]
forall a. [Maybe a] -> [a]
catMaybes
        [ ScriptWitness witctx BabbageEra -> Maybe Language
forall witctx era. ScriptWitness witctx era -> Maybe Language
getScriptLanguage ScriptWitness witctx BabbageEra
sw
        | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx BabbageEra
sw) <- [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses
        ]

    getScriptLanguage :: ScriptWitness witctx era -> Maybe Alonzo.Language
    getScriptLanguage :: ScriptWitness witctx era -> Maybe Language
getScriptLanguage (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ ScriptData
_ ExecutionUnits
_) =
      Language -> Maybe Language
forall a. a -> Maybe a
Just (Language -> Maybe Language) -> Language -> Maybe Language
forall a b. (a -> b) -> a -> b
$ AnyPlutusScriptVersion -> Language
toAlonzoLanguage (PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang. PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v)
    getScriptLanguage SimpleScriptWitness{} = Maybe Language
forall a. Maybe a
Nothing

    txAuxData :: Maybe (Ledger.AuxiliaryData StandardBabbage)
    txAuxData :: Maybe (AuxiliaryData (BabbageEra StandardCrypto))
txAuxData
      | Map Word64 TxMetadataValue -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 TxMetadataValue
ms
      , [ScriptInEra era] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ScriptInEra era]
ss   = Maybe (AuxiliaryData (BabbageEra StandardCrypto))
forall a. Maybe a
Nothing
      | Bool
otherwise = AuxiliaryData (BabbageEra StandardCrypto)
-> Maybe (AuxiliaryData (BabbageEra StandardCrypto))
forall a. a -> Maybe a
Just (Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData (BabbageEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 AuxiliaryData ledgerera ~ AuxiliaryData ledgerera,
 Script ledgerera ~ Script ledgerera, Era ledgerera) =>
Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAlonzoAuxiliaryData Map Word64 TxMetadataValue
ms [ScriptInEra era]
ss)
      where
        ms :: Map Word64 TxMetadataValue
ms = case TxMetadataInEra era
txMetadata of
               TxMetadataInEra era
TxMetadataNone                     -> Map Word64 TxMetadataValue
forall k a. Map k a
Map.empty
               TxMetadataInEra TxMetadataSupportedInEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue
ms'
        ss :: [ScriptInEra era]
ss = case TxAuxScripts era
txAuxScripts of
               TxAuxScripts era
TxAuxScriptsNone   -> []
               TxAuxScripts AuxScriptsSupportedInEra era
_ [ScriptInEra era]
ss' -> [ScriptInEra era]
ss'


-- | A variant of 'toShelleyTxOutAny that is used only internally to this module
-- that works with a 'TxOut' in any context (including CtxTx) by ignoring
-- embedded datums (taking only their hash).
--
toShelleyTxOutAny :: forall ctx era ledgerera.
                   ShelleyLedgerEra era ~ ledgerera
                => ShelleyBasedEra era
                -> TxOut ctx era
                -> Ledger.TxOut ledgerera
toShelleyTxOutAny :: ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
era (TxOut AddressInEra era
_ (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInByronEra Lovelace
_) TxOutDatum ctx era
_ ReferenceScript era
_) =
    case ShelleyBasedEra era
era of {}

toShelleyTxOutAny ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInShelleyEra Lovelace
value) TxOutDatum ctx 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)

toShelleyTxOutAny ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInAllegraEra Lovelace
value) TxOutDatum ctx 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)

toShelleyTxOutAny ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInMaryEra Value
value) TxOutDatum ctx 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)

toShelleyTxOutAny ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInAlonzoEra Value
value) TxOutDatum ctx 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 ctx AlonzoEra -> StrictMaybe (DataHash StandardCrypto)
forall ctx.
TxOutDatum ctx AlonzoEra -> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash' TxOutDatum ctx era
TxOutDatum ctx AlonzoEra
txoutdata)

toShelleyTxOutAny ShelleyBasedEra era
era (TxOut AddressInEra era
addr (TxOutValue MultiAssetSupportedInEra era
MultiAssetInBabbageEra Value
value) TxOutDatum ctx 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 ctx era -> Datum (ShelleyLedgerEra era)
forall era ctx.
(Crypto (ShelleyLedgerEra era) ~ StandardCrypto) =>
TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum' TxOutDatum ctx 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)


toAlonzoTxOutDataHash' :: TxOutDatum ctx AlonzoEra
                       -> StrictMaybe (Alonzo.DataHash StandardCrypto)
toAlonzoTxOutDataHash' :: TxOutDatum ctx AlonzoEra -> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash'  TxOutDatum ctx 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' (TxOutDatumInTx' ScriptDataSupportedInEra AlonzoEra
_ (ScriptDataHash dh) ScriptData
_) = 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 {}

-- TODO: Consolidate with alonzo function and rename
toBabbageTxOutDatum'
  :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
  => TxOutDatum ctx era -> Babbage.Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum' :: TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum'  TxOutDatum ctx 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' (TxOutDatumInTx' ScriptDataSupportedInEra era
_ (ScriptDataHash dh) ScriptData
_) = 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


-- ----------------------------------------------------------------------------
-- Script witnesses within the tx body
--

-- | A 'ScriptWitness' in any 'WitCtx'. This lets us handle heterogeneous
-- collections of script witnesses from multiple contexts.
--
data AnyScriptWitness era where
     AnyScriptWitness :: ScriptWitness witctx era -> AnyScriptWitness era

-- | Identify the location of a 'ScriptWitness' within the context of a
-- 'TxBody'. These are indexes of the objects within the transaction that
-- need or can use script witnesses: inputs, minted assets, withdrawals and
-- certificates. These are simple numeric indices, enumerated from zero.
-- Thus the indices are not stable if the transaction body is modified.
--
data ScriptWitnessIndex =

     -- | The n'th transaction input, in the order of the 'TxId's.
     ScriptWitnessIndexTxIn !Word

     -- | The n'th minting 'PolicyId', in the order of the 'PolicyId's.
   | ScriptWitnessIndexMint !Word

     -- | The n'th certificate, in the list order of the certificates.
   | ScriptWitnessIndexCertificate !Word

     -- | The n'th withdrawal, in the order of the 'StakeAddress's.
   | ScriptWitnessIndexWithdrawal !Word
  deriving (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
(ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> Eq ScriptWitnessIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c/= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
== :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c== :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
Eq, Eq ScriptWitnessIndex
Eq ScriptWitnessIndex
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex)
-> Ord ScriptWitnessIndex
ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
$cmin :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
max :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
$cmax :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
>= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c>= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
> :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c> :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
<= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c<= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
< :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c< :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
compare :: ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
$ccompare :: ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
$cp1Ord :: Eq ScriptWitnessIndex
Ord, Int -> ScriptWitnessIndex -> ShowS
[ScriptWitnessIndex] -> ShowS
ScriptWitnessIndex -> String
(Int -> ScriptWitnessIndex -> ShowS)
-> (ScriptWitnessIndex -> String)
-> ([ScriptWitnessIndex] -> ShowS)
-> Show ScriptWitnessIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScriptWitnessIndex] -> ShowS
$cshowList :: [ScriptWitnessIndex] -> ShowS
show :: ScriptWitnessIndex -> String
$cshow :: ScriptWitnessIndex -> String
showsPrec :: Int -> ScriptWitnessIndex -> ShowS
$cshowsPrec :: Int -> ScriptWitnessIndex -> ShowS
Show)

renderScriptWitnessIndex :: ScriptWitnessIndex -> String
renderScriptWitnessIndex :: ScriptWitnessIndex -> String
renderScriptWitnessIndex (ScriptWitnessIndexTxIn Word
index) =
  String
"transaction input " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
index String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (in the order of the TxIds)"
renderScriptWitnessIndex (ScriptWitnessIndexMint Word
index) =
  String
"policyId " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
index String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (in the order of the PolicyIds)"
renderScriptWitnessIndex (ScriptWitnessIndexCertificate Word
index) =
  String
"certificate " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
index String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (in the list order of the certificates)"
renderScriptWitnessIndex (ScriptWitnessIndexWithdrawal Word
index) =
  String
"withdrawal " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
index String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (in the order of the StakeAddresses)"

toAlonzoRdmrPtr :: ScriptWitnessIndex -> Alonzo.RdmrPtr
toAlonzoRdmrPtr :: ScriptWitnessIndex -> RdmrPtr
toAlonzoRdmrPtr ScriptWitnessIndex
widx =
    case ScriptWitnessIndex
widx of
      ScriptWitnessIndexTxIn        Word
n -> Tag -> Word64 -> RdmrPtr
Alonzo.RdmrPtr Tag
Alonzo.Spend (Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n)
      ScriptWitnessIndexMint        Word
n -> Tag -> Word64 -> RdmrPtr
Alonzo.RdmrPtr Tag
Alonzo.Mint  (Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n)
      ScriptWitnessIndexCertificate Word
n -> Tag -> Word64 -> RdmrPtr
Alonzo.RdmrPtr Tag
Alonzo.Cert  (Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n)
      ScriptWitnessIndexWithdrawal  Word
n -> Tag -> Word64 -> RdmrPtr
Alonzo.RdmrPtr Tag
Alonzo.Rewrd (Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n)

fromAlonzoRdmrPtr :: Alonzo.RdmrPtr -> ScriptWitnessIndex
fromAlonzoRdmrPtr :: RdmrPtr -> ScriptWitnessIndex
fromAlonzoRdmrPtr (Alonzo.RdmrPtr Tag
tag Word64
n) =
    case Tag
tag of
      Tag
Alonzo.Spend -> Word -> ScriptWitnessIndex
ScriptWitnessIndexTxIn        (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n)
      Tag
Alonzo.Mint  -> Word -> ScriptWitnessIndex
ScriptWitnessIndexMint        (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n)
      Tag
Alonzo.Cert  -> Word -> ScriptWitnessIndex
ScriptWitnessIndexCertificate (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n)
      Tag
Alonzo.Rewrd -> Word -> ScriptWitnessIndex
ScriptWitnessIndexWithdrawal  (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n)

collectTxBodyScriptWitnesses :: forall era.
                                TxBodyContent BuildTx era
                             -> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses :: TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses TxBodyContent {
                               TxIns BuildTx era
txIns :: TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns,
                               TxWithdrawals BuildTx era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals,
                               TxCertificates BuildTx era
txCertificates :: TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates,
                               TxMintValue BuildTx era
txMintValue :: TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue
                             } =
    [[(ScriptWitnessIndex, AnyScriptWitness era)]]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
      [ TxIns BuildTx era -> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesTxIns        TxIns BuildTx era
txIns
      , TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesWithdrawals  TxWithdrawals BuildTx era
txWithdrawals
      , TxCertificates BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesCertificates TxCertificates BuildTx era
txCertificates
      , TxMintValue BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesMinting      TxMintValue BuildTx era
txMintValue
      ]
  where
    scriptWitnessesTxIns
      :: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesTxIns :: TxIns BuildTx era -> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesTxIns TxIns BuildTx era
txins =
        [ (Word -> ScriptWitnessIndex
ScriptWitnessIndexTxIn Word
ix, ScriptWitness WitCtxTxIn era -> AnyScriptWitness era
forall witctx era. ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxTxIn era
witness)
          -- The tx ins are indexed in the map order by txid
        | (Word
ix, (TxIn
_, BuildTxWith (ScriptWitness ScriptWitnessInCtx WitCtxTxIn
_ ScriptWitness WitCtxTxIn era
witness)))
            <- [Word]
-> TxIns BuildTx era
-> [(Word, (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word
0..] (TxIns BuildTx era -> TxIns BuildTx era
forall v. [(TxIn, v)] -> [(TxIn, v)]
orderTxIns TxIns BuildTx era
txins)
        ]

    scriptWitnessesWithdrawals
      :: TxWithdrawals BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesWithdrawals :: TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesWithdrawals  TxWithdrawals BuildTx era
TxWithdrawalsNone = []
    scriptWitnessesWithdrawals (TxWithdrawals WithdrawalsSupportedInEra era
_ [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
withdrawals) =
        [ (Word -> ScriptWitnessIndex
ScriptWitnessIndexWithdrawal Word
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era. ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
          -- The withdrawals are indexed in the map order by stake credential
        | (Word
ix, (StakeAddress
_, Lovelace
_, BuildTxWith (ScriptWitness ScriptWitnessInCtx WitCtxStake
_ ScriptWitness WitCtxStake era
witness)))
             <- [Word]
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(Word,
     (StakeAddress, Lovelace,
      BuildTxWith BuildTx (Witness WitCtxStake era)))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word
0..] ([(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(StakeAddress, Lovelace,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall x v. [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
orderStakeAddrs [(StakeAddress, Lovelace,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
withdrawals)
        ]

    scriptWitnessesCertificates
      :: TxCertificates BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesCertificates :: TxCertificates BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesCertificates  TxCertificates BuildTx era
TxCertificatesNone = []
    scriptWitnessesCertificates (TxCertificates CertificatesSupportedInEra era
_ [Certificate]
certs (BuildTxWith Map StakeCredential (Witness WitCtxStake era)
witnesses)) =
        [ (Word -> ScriptWitnessIndex
ScriptWitnessIndexCertificate Word
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era. ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
          -- The certs are indexed in list order
        | (Word
ix, Certificate
cert) <- [Word] -> [Certificate] -> [(Word, Certificate)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word
0..] [Certificate]
certs
        , ScriptWitness ScriptWitnessInCtx WitCtxStake
_ ScriptWitness WitCtxStake era
witness <- Maybe (Witness WitCtxStake era) -> [Witness WitCtxStake era]
forall a. Maybe a -> [a]
maybeToList (Maybe (Witness WitCtxStake era) -> [Witness WitCtxStake era])
-> Maybe (Witness WitCtxStake era) -> [Witness WitCtxStake era]
forall a b. (a -> b) -> a -> b
$ do
                                       StakeCredential
stakecred <- Certificate -> Maybe StakeCredential
selectStakeCredential Certificate
cert
                                       StakeCredential
-> Map StakeCredential (Witness WitCtxStake era)
-> Maybe (Witness WitCtxStake era)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup StakeCredential
stakecred Map StakeCredential (Witness WitCtxStake era)
witnesses
        ]

    selectStakeCredential :: Certificate -> Maybe StakeCredential
selectStakeCredential Certificate
cert =
      case Certificate
cert of
        StakeAddressDeregistrationCertificate StakeCredential
stakecred   -> StakeCredential -> Maybe StakeCredential
forall a. a -> Maybe a
Just StakeCredential
stakecred
        StakeAddressDelegationCertificate     StakeCredential
stakecred PoolId
_ -> StakeCredential -> Maybe StakeCredential
forall a. a -> Maybe a
Just StakeCredential
stakecred
        Certificate
_                                                 -> Maybe StakeCredential
forall a. Maybe a
Nothing

    scriptWitnessesMinting
      :: TxMintValue BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesMinting :: TxMintValue BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesMinting  TxMintValue BuildTx era
TxMintNone = []
    scriptWitnessesMinting (TxMintValue MultiAssetSupportedInEra era
_ Value
value (BuildTxWith Map PolicyId (ScriptWitness WitCtxMint era)
witnesses)) =
        [ (Word -> ScriptWitnessIndex
ScriptWitnessIndexMint Word
ix, ScriptWitness WitCtxMint era -> AnyScriptWitness era
forall witctx era. ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxMint era
witness)
          -- The minting policies are indexed in policy id order in the value
        | let ValueNestedRep [ValueNestedBundle]
bundle = Value -> ValueNestedRep
valueToNestedRep Value
value
        , (Word
ix, ValueNestedBundle PolicyId
policyid Map AssetName Quantity
_) <- [Word] -> [ValueNestedBundle] -> [(Word, ValueNestedBundle)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word
0..] [ValueNestedBundle]
bundle
        , ScriptWitness WitCtxMint era
witness <- Maybe (ScriptWitness WitCtxMint era)
-> [ScriptWitness WitCtxMint era]
forall a. Maybe a -> [a]
maybeToList (PolicyId
-> Map PolicyId (ScriptWitness WitCtxMint era)
-> Maybe (ScriptWitness WitCtxMint era)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PolicyId
policyid Map PolicyId (ScriptWitness WitCtxMint era)
witnesses)
        ]

-- This relies on the TxId Ord instance being consistent with the
-- Ledger.TxId Ord instance via the toShelleyTxId conversion
-- This is checked by prop_ord_distributive_TxId
orderTxIns :: [(TxIn, v)] -> [(TxIn, v)]
orderTxIns :: [(TxIn, v)] -> [(TxIn, v)]
orderTxIns = ((TxIn, v) -> (TxIn, v) -> Ordering) -> [(TxIn, v)] -> [(TxIn, v)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (TxIn -> TxIn -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (TxIn -> TxIn -> Ordering)
-> ((TxIn, v) -> TxIn) -> (TxIn, v) -> (TxIn, v) -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (TxIn, v) -> TxIn
forall a b. (a, b) -> a
fst)

-- This relies on the StakeAddress Ord instance being consistent with the
-- Shelley.RewardAcnt Ord instance via the toShelleyStakeAddr conversion
-- This is checked by prop_ord_distributive_StakeAddress
orderStakeAddrs :: [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
orderStakeAddrs :: [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
orderStakeAddrs = ((StakeAddress, x, v) -> (StakeAddress, x, v) -> Ordering)
-> [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (StakeAddress -> StakeAddress -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (StakeAddress -> StakeAddress -> Ordering)
-> ((StakeAddress, x, v) -> StakeAddress)
-> (StakeAddress, x, v)
-> (StakeAddress, x, v)
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (\(StakeAddress
k, x
_, v
_) -> StakeAddress
k))


toShelleyWithdrawal :: [(StakeAddress, Lovelace, a)] -> Shelley.Wdrl StandardCrypto
toShelleyWithdrawal :: [(StakeAddress, Lovelace, a)] -> Wdrl StandardCrypto
toShelleyWithdrawal [(StakeAddress, Lovelace, a)]
withdrawals =
    Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall crypto. Map (RewardAcnt crypto) Coin -> Wdrl crypto
Shelley.Wdrl (Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto)
-> Map (RewardAcnt StandardCrypto) Coin -> Wdrl StandardCrypto
forall a b. (a -> b) -> a -> b
$
      [(RewardAcnt StandardCrypto, Coin)]
-> Map (RewardAcnt StandardCrypto) Coin
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
        [ (StakeAddress -> RewardAcnt StandardCrypto
toShelleyStakeAddr StakeAddress
stakeAddr, Lovelace -> Coin
toShelleyLovelace Lovelace
value)
        | (StakeAddress
stakeAddr, Lovelace
value, a
_) <- [(StakeAddress, Lovelace, a)]
withdrawals ]


fromShelleyWithdrawal
  :: Shelley.Wdrl StandardCrypto
  -> [(StakeAddress, Lovelace, BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal :: Wdrl StandardCrypto
-> [(StakeAddress, Lovelace,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal (Shelley.Wdrl Map (RewardAcnt StandardCrypto) Coin
withdrawals) =
  [ (RewardAcnt StandardCrypto -> StakeAddress
fromShelleyStakeAddr RewardAcnt StandardCrypto
stakeAddr, Coin -> Lovelace
fromShelleyLovelace Coin
value, BuildTxWith ViewTx (Witness WitCtxStake era)
forall a. BuildTxWith ViewTx a
ViewTx)
  | (RewardAcnt StandardCrypto
stakeAddr, Coin
value) <- Map (RewardAcnt StandardCrypto) Coin
-> [(RewardAcnt StandardCrypto, Coin)]
forall k a. Map k a -> [(k, a)]
Map.assocs Map (RewardAcnt StandardCrypto) Coin
withdrawals
  ]


-- | In the Shelley era the auxiliary data consists only of the tx metadata
toShelleyAuxiliaryData :: Map Word64 TxMetadataValue
                       -> Ledger.AuxiliaryData StandardShelley
toShelleyAuxiliaryData :: Map Word64 TxMetadataValue
-> AuxiliaryData (ShelleyEra StandardCrypto)
toShelleyAuxiliaryData Map Word64 TxMetadataValue
m =
    Map Word64 Metadatum -> Metadata (ShelleyEra StandardCrypto)
forall era. Map Word64 Metadatum -> Metadata era
Shelley.Metadata
      (Map Word64 TxMetadataValue -> Map Word64 Metadatum
toShelleyMetadata Map Word64 TxMetadataValue
m)


-- | In the Allegra and Mary eras the auxiliary data consists of the tx metadata
-- and the axiliary scripts.
--
toAllegraAuxiliaryData :: forall era ledgerera.
                          ShelleyLedgerEra era ~ ledgerera
                       => Ledger.AuxiliaryData ledgerera ~ Allegra.AuxiliaryData ledgerera
                       => Ledger.AnnotatedData (Ledger.Script ledgerera)
                       => Ord (Ledger.Script ledgerera)
                       => Map Word64 TxMetadataValue
                       -> [ScriptInEra era]
                       -> Ledger.AuxiliaryData ledgerera
toAllegraAuxiliaryData :: Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAllegraAuxiliaryData Map Word64 TxMetadataValue
m [ScriptInEra era]
ss =
    Map Word64 Metadatum
-> StrictSeq (Script ledgerera) -> AuxiliaryData ledgerera
forall era.
(AnnotatedData (Script era), Ord (Script era)) =>
Map Word64 Metadatum -> StrictSeq (Script era) -> AuxiliaryData era
Allegra.AuxiliaryData
      (Map Word64 TxMetadataValue -> Map Word64 Metadatum
toShelleyMetadata Map Word64 TxMetadataValue
m)
      ([Script ledgerera] -> StrictSeq (Script ledgerera)
forall a. [a] -> StrictSeq a
Seq.fromList ((ScriptInEra era -> Script ledgerera)
-> [ScriptInEra era] -> [Script ledgerera]
forall a b. (a -> b) -> [a] -> [b]
map ScriptInEra era -> Script ledgerera
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript [ScriptInEra era]
ss))


-- | In the Alonzo and later eras the auxiliary data consists of the tx metadata
-- and the axiliary scripts, and the axiliary script data.
--
toAlonzoAuxiliaryData :: forall era ledgerera.
                         ShelleyLedgerEra era ~ ledgerera
                      => Ledger.AuxiliaryData ledgerera ~ Alonzo.AuxiliaryData ledgerera
                      => Ledger.Script ledgerera ~ Alonzo.Script ledgerera
                      => Ledger.Era ledgerera
                      => Map Word64 TxMetadataValue
                      -> [ScriptInEra era]
                      -> Ledger.AuxiliaryData ledgerera
toAlonzoAuxiliaryData :: Map Word64 TxMetadataValue
-> [ScriptInEra era] -> AuxiliaryData ledgerera
toAlonzoAuxiliaryData Map Word64 TxMetadataValue
m [ScriptInEra era]
ss =
    Map Word64 Metadatum
-> StrictSeq (Script ledgerera) -> AuxiliaryData ledgerera
forall era.
(Era era, ToCBOR (Script era), Script era ~ Script era,
 Ord (Script era)) =>
Map Word64 Metadatum -> StrictSeq (Script era) -> AuxiliaryData era
Alonzo.AuxiliaryData
      (Map Word64 TxMetadataValue -> Map Word64 Metadatum
toShelleyMetadata Map Word64 TxMetadataValue
m)
      ([Script ledgerera] -> StrictSeq (Script ledgerera)
forall a. [a] -> StrictSeq a
Seq.fromList ((ScriptInEra era -> Script ledgerera)
-> [ScriptInEra era] -> [Script ledgerera]
forall a b. (a -> b) -> [a] -> [b]
map ScriptInEra era -> Script ledgerera
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript [ScriptInEra era]
ss))


-- ----------------------------------------------------------------------------
-- Other utilities helpful with making transaction bodies
--

-- | Compute the 'TxIn' of the initial UTxO pseudo-transaction corresponding
-- to the given address in the genesis initial funds.
--
-- The Shelley initial UTxO is constructed from the 'sgInitialFunds' which
-- is not a full UTxO but just a map from addresses to coin values.
--
-- This gets turned into a UTxO by making a pseudo-transaction for each address,
-- with the 0th output being the coin value. So to spend from the initial UTxO
-- we need this same 'TxIn' to use as an input to the spending transaction.
--
genesisUTxOPseudoTxIn :: NetworkId -> Hash GenesisUTxOKey -> TxIn
genesisUTxOPseudoTxIn :: NetworkId -> Hash GenesisUTxOKey -> TxIn
genesisUTxOPseudoTxIn NetworkId
nw (GenesisUTxOKeyHash kh) =
    --TODO: should handle Byron UTxO case too.
    TxIn StandardCrypto -> TxIn
fromShelleyTxIn (Addr StandardCrypto -> TxIn StandardCrypto
forall crypto. Crypto crypto => Addr crypto -> TxIn crypto
Shelley.initialFundsPseudoTxIn Addr StandardCrypto
addr)
  where
    addr :: Shelley.Addr StandardCrypto
    addr :: Addr StandardCrypto
addr = Network
-> PaymentCredential StandardCrypto
-> StakeReference StandardCrypto
-> Addr StandardCrypto
forall crypto.
Network
-> PaymentCredential crypto -> StakeReference crypto -> Addr crypto
Shelley.Addr
             (NetworkId -> Network
toShelleyNetwork NetworkId
nw)
             (KeyHash 'Payment StandardCrypto -> PaymentCredential StandardCrypto
forall (kr :: KeyRole) crypto.
KeyHash kr crypto -> Credential kr crypto
Shelley.KeyHashObj KeyHash 'Payment StandardCrypto
kh)
             StakeReference StandardCrypto
forall crypto. StakeReference crypto
Shelley.StakeRefNull

calculateExecutionUnitsLovelace :: ExecutionUnitPrices -> ExecutionUnits -> Maybe Lovelace
calculateExecutionUnitsLovelace :: ExecutionUnitPrices -> ExecutionUnits -> Maybe Lovelace
calculateExecutionUnitsLovelace ExecutionUnitPrices
euPrices ExecutionUnits
eUnits =
  case ExecutionUnitPrices -> Maybe Prices
toAlonzoPrices ExecutionUnitPrices
euPrices of
    Maybe Prices
Nothing -> Maybe Lovelace
forall a. Maybe a
Nothing
    Just Prices
prices ->
      Lovelace -> Maybe Lovelace
forall (m :: * -> *) a. Monad m => a -> m a
return (Lovelace -> Maybe Lovelace)
-> (Coin -> Lovelace) -> Coin -> Maybe Lovelace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coin -> Lovelace
fromShelleyLovelace (Coin -> Maybe Lovelace) -> Coin -> Maybe Lovelace
forall a b. (a -> b) -> a -> b
$ Prices -> ExUnits -> Coin
Alonzo.txscriptfee Prices
prices (ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
eUnits)

-- ----------------------------------------------------------------------------
-- Inline data
--
-- | Conversion of ScriptData to binary data which allows for the storage of data
-- onchain within a transaction output.
--

scriptDataToInlineDatum :: ScriptData -> Babbage.Datum ledgerera
scriptDataToInlineDatum :: ScriptData -> Datum ledgerera
scriptDataToInlineDatum = BinaryData ledgerera -> Datum ledgerera
forall era. BinaryData era -> Datum era
Babbage.Datum (BinaryData ledgerera -> Datum ledgerera)
-> (ScriptData -> BinaryData ledgerera)
-> ScriptData
-> Datum ledgerera
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Data ledgerera -> BinaryData ledgerera
forall era. Data era -> BinaryData era
Alonzo.dataToBinaryData (Data ledgerera -> BinaryData ledgerera)
-> (ScriptData -> Data ledgerera)
-> ScriptData
-> BinaryData ledgerera
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScriptData -> Data ledgerera
forall ledgerera. ScriptData -> Data ledgerera
toAlonzoData

binaryDataToScriptData
  :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era -> Alonzo.BinaryData ledgerera -> ScriptData
binaryDataToScriptData :: ReferenceTxInsScriptsInlineDatumsSupportedInEra era
-> BinaryData ledgerera -> ScriptData
binaryDataToScriptData ReferenceTxInsScriptsInlineDatumsSupportedInEra era
ReferenceTxInsScriptsInlineDatumsInBabbageEra  BinaryData ledgerera
d =
  Data ledgerera -> ScriptData
forall ledgerera. Data ledgerera -> ScriptData
fromAlonzoData (Data ledgerera -> ScriptData) -> Data ledgerera -> ScriptData
forall a b. (a -> b) -> a -> b
$ BinaryData ledgerera -> Data ledgerera
forall era. BinaryData era -> Data era
Alonzo.binaryDataToData BinaryData ledgerera
d