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


-- | Transaction bodies
--
module Cardano.Api.TxBody (

    -- * Transaction bodies
    TxBody(.., TxBody),
    makeTransactionBody,
    TxBodyContent(..),
    TxBodyError(..),
    TxBodyScriptData(..),
    TxScriptValidity(..),
    TxScriptValiditySupportedInEra(..),

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

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

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

    -- * Transaction outputs
    TxOut(..),
    TxOutValue(..),
    lovelaceToTxOutValue,
    prettyRenderTxOut,
    txOutValueToLovelace,
    txOutValueToValue,
    serialiseAddressForTxOut,
    TxOutDatumHash(..),
    TxOutInAnyEra(..),
    txOutInAnyEra,

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

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

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

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

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

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

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

import           Prelude

import           Control.Monad (guard)
import           Data.Aeson (object, (.=))
import qualified Data.Aeson as Aeson
import           Data.Aeson.Types (ToJSONKey (..), toJSONKeyText)
import           Data.Bifunctor (first)
import           Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LBS
import           Data.Foldable (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 (fromMaybe, maybeToList)
import qualified Data.Sequence.Strict as Seq
import           Data.Set (Set)
import qualified Data.Set as Set
import           Data.String (IsString)
import           Data.Text (Text)
import qualified Data.Text as Text
import           Data.Word (Word64)
import           GHC.Generics

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)
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.Core as Core
import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Credential as Shelley
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 Shelley.Spec.Ledger.Genesis as Shelley
import qualified Shelley.Spec.Ledger.Metadata as Shelley
import qualified Shelley.Spec.Ledger.Tx as Shelley
import qualified Shelley.Spec.Ledger.TxBody as Shelley
import qualified Shelley.Spec.Ledger.UTxO as Shelley

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.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           Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardAlonzo, StandardMary,
                   StandardShelley)

import           Cardano.Api.Address
import           Cardano.Api.Certificate
import           Cardano.Api.Eras
import           Cardano.Api.Error
import           Cardano.Api.HasTypeProxy
import           Cardano.Api.Hash
import           Cardano.Api.KeysByron
import           Cardano.Api.KeysShelley
import           Cardano.Api.NetworkId
import           Cardano.Api.ProtocolParameters
import           Cardano.Api.Script
import           Cardano.Api.SerialiseBech32
import           Cardano.Api.SerialiseCBOR
import           Cardano.Api.SerialiseJSON
import           Cardano.Api.SerialiseRaw
import           Cardano.Api.SerialiseTextEnvelope
import           Cardano.Api.SerialiseUsing
import           Cardano.Api.TxMetadata
import           Cardano.Api.Utils
import           Cardano.Api.Value
import           Cardano.Ledger.Crypto (StandardCrypto)

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

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

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

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

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

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

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

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

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

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

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

data TxScriptValiditySupportedInEra era where
  TxScriptValiditySupportedInAlonzoEra :: TxScriptValiditySupportedInEra AlonzoEra

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

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

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

newtype TxId = TxId (Shelley.Hash StandardCrypto Shelley.EraIndependentTxBody)
  -- We use the Shelley representation and convert to/from the Byron one
  deriving stock (TxId -> TxId -> Bool
(TxId -> TxId -> Bool) -> (TxId -> TxId -> Bool) -> Eq TxId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxId -> TxId -> Bool
$c/= :: TxId -> TxId -> Bool
== :: TxId -> TxId -> Bool
$c== :: TxId -> TxId -> Bool
Eq, Eq TxId
Eq TxId
-> (TxId -> TxId -> Ordering)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> Bool)
-> (TxId -> TxId -> TxId)
-> (TxId -> TxId -> TxId)
-> Ord TxId
TxId -> TxId -> Bool
TxId -> TxId -> Ordering
TxId -> TxId -> TxId
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 :: TxId -> TxId -> TxId
$cmin :: TxId -> TxId -> TxId
max :: TxId -> TxId -> TxId
$cmax :: TxId -> TxId -> TxId
>= :: TxId -> TxId -> Bool
$c>= :: TxId -> TxId -> Bool
> :: TxId -> TxId -> Bool
$c> :: TxId -> TxId -> Bool
<= :: TxId -> TxId -> Bool
$c<= :: TxId -> TxId -> Bool
< :: TxId -> TxId -> Bool
$c< :: TxId -> TxId -> Bool
compare :: TxId -> TxId -> Ordering
$ccompare :: TxId -> TxId -> Ordering
$cp1Ord :: Eq TxId
Ord)
  deriving (Int -> TxId -> ShowS
[TxId] -> ShowS
TxId -> String
(Int -> TxId -> ShowS)
-> (TxId -> String) -> ([TxId] -> ShowS) -> Show TxId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxId] -> ShowS
$cshowList :: [TxId] -> ShowS
show :: TxId -> String
$cshow :: TxId -> String
showsPrec :: Int -> TxId -> ShowS
$cshowsPrec :: Int -> TxId -> ShowS
Show, String -> TxId
(String -> TxId) -> IsString TxId
forall a. (String -> a) -> IsString a
fromString :: String -> TxId
$cfromString :: String -> TxId
IsString)         via UsingRawBytesHex TxId
  deriving ([TxId] -> Value
[TxId] -> Encoding
TxId -> Value
TxId -> Encoding
(TxId -> Value)
-> (TxId -> Encoding)
-> ([TxId] -> Value)
-> ([TxId] -> Encoding)
-> ToJSON TxId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [TxId] -> Encoding
$ctoEncodingList :: [TxId] -> Encoding
toJSONList :: [TxId] -> Value
$ctoJSONList :: [TxId] -> Value
toEncoding :: TxId -> Encoding
$ctoEncoding :: TxId -> Encoding
toJSON :: TxId -> Value
$ctoJSON :: TxId -> Value
ToJSON, Value -> Parser [TxId]
Value -> Parser TxId
(Value -> Parser TxId) -> (Value -> Parser [TxId]) -> FromJSON TxId
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [TxId]
$cparseJSONList :: Value -> Parser [TxId]
parseJSON :: Value -> Parser TxId
$cparseJSON :: Value -> Parser TxId
FromJSON)       via UsingRawBytesHex TxId
  deriving (ToJSONKeyFunction [TxId]
ToJSONKeyFunction TxId
ToJSONKeyFunction TxId
-> ToJSONKeyFunction [TxId] -> ToJSONKey TxId
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [TxId]
$ctoJSONKeyList :: ToJSONKeyFunction [TxId]
toJSONKey :: ToJSONKeyFunction TxId
$ctoJSONKey :: ToJSONKeyFunction TxId
ToJSONKey, FromJSONKeyFunction [TxId]
FromJSONKeyFunction TxId
FromJSONKeyFunction TxId
-> FromJSONKeyFunction [TxId] -> FromJSONKey TxId
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [TxId]
$cfromJSONKeyList :: FromJSONKeyFunction [TxId]
fromJSONKey :: FromJSONKeyFunction TxId
$cfromJSONKey :: FromJSONKeyFunction TxId
FromJSONKey) via UsingRawBytesHex TxId

instance HasTypeProxy TxId where
    data AsType TxId = AsTxId
    proxyToAsType :: Proxy TxId -> AsType TxId
proxyToAsType Proxy TxId
_ = AsType TxId
AsTxId

instance SerialiseAsRawBytes TxId where
    serialiseToRawBytes :: TxId -> ByteString
serialiseToRawBytes (TxId Hash StandardCrypto EraIndependentTxBody
h) = Hash Blake2b_256 EraIndependentTxBody -> ByteString
forall h a. Hash h a -> ByteString
Crypto.hashToBytes Hash StandardCrypto EraIndependentTxBody
Hash Blake2b_256 EraIndependentTxBody
h
    deserialiseFromRawBytes :: AsType TxId -> ByteString -> Maybe TxId
deserialiseFromRawBytes AsType TxId
AsTxId ByteString
bs = Hash StandardCrypto EraIndependentTxBody -> TxId
Hash Blake2b_256 EraIndependentTxBody -> TxId
TxId (Hash Blake2b_256 EraIndependentTxBody -> TxId)
-> Maybe (Hash Blake2b_256 EraIndependentTxBody) -> Maybe TxId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (Hash Blake2b_256 EraIndependentTxBody)
forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
Crypto.hashFromBytes ByteString
bs

toByronTxId :: TxId -> Byron.TxId
toByronTxId :: TxId -> TxId
toByronTxId (TxId Hash StandardCrypto EraIndependentTxBody
h) =
    ByteString -> TxId
forall a. ByteString -> Hash a
Byron.unsafeHashFromBytes (Hash Blake2b_256 EraIndependentTxBody -> ByteString
forall h a. Hash h a -> ByteString
Crypto.hashToBytes Hash StandardCrypto EraIndependentTxBody
Hash Blake2b_256 EraIndependentTxBody
h)

toShelleyTxId :: TxId -> Shelley.TxId StandardCrypto
toShelleyTxId :: TxId -> TxId StandardCrypto
toShelleyTxId (TxId Hash StandardCrypto EraIndependentTxBody
h) =
    SafeHash StandardCrypto EraIndependentTxBody -> TxId StandardCrypto
forall crypto. SafeHash crypto EraIndependentTxBody -> TxId crypto
Shelley.TxId (Hash StandardCrypto EraIndependentTxBody
-> SafeHash StandardCrypto EraIndependentTxBody
forall crypto index.
Hash (HASH crypto) index -> SafeHash crypto index
SafeHash.unsafeMakeSafeHash (Hash Blake2b_256 EraIndependentTxBody
-> Hash Blake2b_256 EraIndependentTxBody
forall h a b. Hash h a -> Hash h b
Crypto.castHash Hash StandardCrypto EraIndependentTxBody
Hash Blake2b_256 EraIndependentTxBody
h))

fromShelleyTxId :: Shelley.TxId StandardCrypto -> TxId
fromShelleyTxId :: TxId StandardCrypto -> TxId
fromShelleyTxId (Shelley.TxId SafeHash StandardCrypto EraIndependentTxBody
h) =
    Hash StandardCrypto EraIndependentTxBody -> TxId
TxId (Hash Blake2b_256 EraIndependentTxBody
-> Hash Blake2b_256 EraIndependentTxBody
forall h a b. Hash h a -> Hash h b
Crypto.castHash (SafeHash StandardCrypto EraIndependentTxBody
-> Hash StandardCrypto EraIndependentTxBody
forall crypto i. SafeHash crypto i -> Hash (HASH crypto) i
SafeHash.extractHash SafeHash StandardCrypto EraIndependentTxBody
h))

-- | Calculate the transaction identifier for a 'TxBody'.
--
getTxId :: forall era. TxBody era -> TxId
getTxId :: TxBody era -> TxId
getTxId (ByronTxBody Annotated Tx ByteString
tx) =
    Hash StandardCrypto EraIndependentTxBody -> TxId
Hash Blake2b_256 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
. TxId -> ShortByteString
forall algo a. AbstractHash algo a -> ShortByteString
Byron.abstractHashToShort
  (TxId -> ShortByteString)
-> (Annotated Tx ByteString -> TxId)
-> Annotated Tx ByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotated Tx ByteString -> TxId
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
_) =
    case ShelleyBasedEra era
era of
      ShelleyBasedEra era
ShelleyBasedEraShelley -> (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
TxBody (ShelleyLedgerEra era) -> TxId
TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley TxBody (ShelleyLedgerEra era)
tx
      ShelleyBasedEra era
ShelleyBasedEraAllegra -> (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
TxBody (ShelleyLedgerEra era) -> TxId
TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley TxBody (ShelleyLedgerEra era)
tx
      ShelleyBasedEra era
ShelleyBasedEraMary    -> (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
TxBody (ShelleyLedgerEra era) -> TxId
TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley TxBody (ShelleyLedgerEra era)
tx
      ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> (Crypto (ShelleyLedgerEra era) ~ StandardCrypto,
 UsesTxBody (ShelleyLedgerEra era)) =>
TxBody (ShelleyLedgerEra era) -> TxId
TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley TxBody (ShelleyLedgerEra era)
tx
  where
    getTxIdShelley :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
                   => Ledger.UsesTxBody (ShelleyLedgerEra era)
                   => Ledger.TxBody (ShelleyLedgerEra era) -> TxId
    getTxIdShelley :: TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley =
        Hash StandardCrypto EraIndependentTxBody -> TxId
Hash Blake2b_256 EraIndependentTxBody -> TxId
TxId
      (Hash Blake2b_256 EraIndependentTxBody -> TxId)
-> (TxBody (ShelleyLedgerEra era)
    -> Hash Blake2b_256 EraIndependentTxBody)
-> TxBody (ShelleyLedgerEra era)
-> 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)
-> (TxBody (ShelleyLedgerEra era)
    -> Hash Blake2b_256 EraIndependentTxBody)
-> TxBody (ShelleyLedgerEra era)
-> Hash Blake2b_256 EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(Shelley.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 -> Hash Blake2b_256 EraIndependentTxBody)
-> (TxBody (ShelleyLedgerEra era) -> TxId StandardCrypto)
-> TxBody (ShelleyLedgerEra era)
-> Hash Blake2b_256 EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxBody (ShelleyLedgerEra era) -> TxId StandardCrypto
forall era. Era era => TxBody era -> TxId (Crypto era)
Shelley.txid


-- ----------------------------------------------------------------------------
-- Transaction inputs
--

data TxIn = TxIn TxId TxIx
  deriving (TxIn -> TxIn -> Bool
(TxIn -> TxIn -> Bool) -> (TxIn -> TxIn -> Bool) -> Eq TxIn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxIn -> TxIn -> Bool
$c/= :: TxIn -> TxIn -> Bool
== :: TxIn -> TxIn -> Bool
$c== :: TxIn -> TxIn -> Bool
Eq, Eq TxIn
Eq TxIn
-> (TxIn -> TxIn -> Ordering)
-> (TxIn -> TxIn -> Bool)
-> (TxIn -> TxIn -> Bool)
-> (TxIn -> TxIn -> Bool)
-> (TxIn -> TxIn -> Bool)
-> (TxIn -> TxIn -> TxIn)
-> (TxIn -> TxIn -> TxIn)
-> Ord TxIn
TxIn -> TxIn -> Bool
TxIn -> TxIn -> Ordering
TxIn -> TxIn -> TxIn
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 :: TxIn -> TxIn -> TxIn
$cmin :: TxIn -> TxIn -> TxIn
max :: TxIn -> TxIn -> TxIn
$cmax :: TxIn -> TxIn -> TxIn
>= :: TxIn -> TxIn -> Bool
$c>= :: TxIn -> TxIn -> Bool
> :: TxIn -> TxIn -> Bool
$c> :: TxIn -> TxIn -> Bool
<= :: TxIn -> TxIn -> Bool
$c<= :: TxIn -> TxIn -> Bool
< :: TxIn -> TxIn -> Bool
$c< :: TxIn -> TxIn -> Bool
compare :: TxIn -> TxIn -> Ordering
$ccompare :: TxIn -> TxIn -> Ordering
$cp1Ord :: Eq TxIn
Ord, Int -> TxIn -> ShowS
[TxIn] -> ShowS
TxIn -> String
(Int -> TxIn -> ShowS)
-> (TxIn -> String) -> ([TxIn] -> ShowS) -> Show TxIn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxIn] -> ShowS
$cshowList :: [TxIn] -> ShowS
show :: TxIn -> String
$cshow :: TxIn -> String
showsPrec :: Int -> TxIn -> ShowS
$cshowsPrec :: Int -> TxIn -> ShowS
Show)

instance ToJSON TxIn where
  toJSON :: TxIn -> Value
toJSON TxIn
txIn = Text -> Value
Aeson.String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ TxIn -> Text
renderTxIn TxIn
txIn

instance ToJSONKey TxIn where
  toJSONKey :: ToJSONKeyFunction TxIn
toJSONKey = (TxIn -> Text) -> ToJSONKeyFunction TxIn
forall a. (a -> Text) -> ToJSONKeyFunction a
toJSONKeyText TxIn -> Text
renderTxIn

renderTxIn :: TxIn -> Text
renderTxIn :: TxIn -> Text
renderTxIn (TxIn TxId
txId (TxIx Word
ix)) =
  TxId -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText TxId
txId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Word -> String
forall a. Show a => a -> String
show Word
ix)


newtype TxIx = TxIx Word
  deriving stock (TxIx -> TxIx -> Bool
(TxIx -> TxIx -> Bool) -> (TxIx -> TxIx -> Bool) -> Eq TxIx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxIx -> TxIx -> Bool
$c/= :: TxIx -> TxIx -> Bool
== :: TxIx -> TxIx -> Bool
$c== :: TxIx -> TxIx -> Bool
Eq, Eq TxIx
Eq TxIx
-> (TxIx -> TxIx -> Ordering)
-> (TxIx -> TxIx -> Bool)
-> (TxIx -> TxIx -> Bool)
-> (TxIx -> TxIx -> Bool)
-> (TxIx -> TxIx -> Bool)
-> (TxIx -> TxIx -> TxIx)
-> (TxIx -> TxIx -> TxIx)
-> Ord TxIx
TxIx -> TxIx -> Bool
TxIx -> TxIx -> Ordering
TxIx -> TxIx -> TxIx
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 :: TxIx -> TxIx -> TxIx
$cmin :: TxIx -> TxIx -> TxIx
max :: TxIx -> TxIx -> TxIx
$cmax :: TxIx -> TxIx -> TxIx
>= :: TxIx -> TxIx -> Bool
$c>= :: TxIx -> TxIx -> Bool
> :: TxIx -> TxIx -> Bool
$c> :: TxIx -> TxIx -> Bool
<= :: TxIx -> TxIx -> Bool
$c<= :: TxIx -> TxIx -> Bool
< :: TxIx -> TxIx -> Bool
$c< :: TxIx -> TxIx -> Bool
compare :: TxIx -> TxIx -> Ordering
$ccompare :: TxIx -> TxIx -> Ordering
$cp1Ord :: Eq TxIx
Ord, Int -> TxIx -> ShowS
[TxIx] -> ShowS
TxIx -> String
(Int -> TxIx -> ShowS)
-> (TxIx -> String) -> ([TxIx] -> ShowS) -> Show TxIx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxIx] -> ShowS
$cshowList :: [TxIx] -> ShowS
show :: TxIx -> String
$cshow :: TxIx -> String
showsPrec :: Int -> TxIx -> ShowS
$cshowsPrec :: Int -> TxIx -> ShowS
Show)
  deriving newtype (Int -> TxIx
TxIx -> Int
TxIx -> [TxIx]
TxIx -> TxIx
TxIx -> TxIx -> [TxIx]
TxIx -> TxIx -> TxIx -> [TxIx]
(TxIx -> TxIx)
-> (TxIx -> TxIx)
-> (Int -> TxIx)
-> (TxIx -> Int)
-> (TxIx -> [TxIx])
-> (TxIx -> TxIx -> [TxIx])
-> (TxIx -> TxIx -> [TxIx])
-> (TxIx -> TxIx -> TxIx -> [TxIx])
-> Enum TxIx
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: TxIx -> TxIx -> TxIx -> [TxIx]
$cenumFromThenTo :: TxIx -> TxIx -> TxIx -> [TxIx]
enumFromTo :: TxIx -> TxIx -> [TxIx]
$cenumFromTo :: TxIx -> TxIx -> [TxIx]
enumFromThen :: TxIx -> TxIx -> [TxIx]
$cenumFromThen :: TxIx -> TxIx -> [TxIx]
enumFrom :: TxIx -> [TxIx]
$cenumFrom :: TxIx -> [TxIx]
fromEnum :: TxIx -> Int
$cfromEnum :: TxIx -> Int
toEnum :: Int -> TxIx
$ctoEnum :: Int -> TxIx
pred :: TxIx -> TxIx
$cpred :: TxIx -> TxIx
succ :: TxIx -> TxIx
$csucc :: TxIx -> TxIx
Enum)
  deriving newtype ([TxIx] -> Value
[TxIx] -> Encoding
TxIx -> Value
TxIx -> Encoding
(TxIx -> Value)
-> (TxIx -> Encoding)
-> ([TxIx] -> Value)
-> ([TxIx] -> Encoding)
-> ToJSON TxIx
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [TxIx] -> Encoding
$ctoEncodingList :: [TxIx] -> Encoding
toJSONList :: [TxIx] -> Value
$ctoJSONList :: [TxIx] -> Value
toEncoding :: TxIx -> Encoding
$ctoEncoding :: TxIx -> Encoding
toJSON :: TxIx -> Value
$ctoJSON :: TxIx -> Value
ToJSON, Value -> Parser [TxIx]
Value -> Parser TxIx
(Value -> Parser TxIx) -> (Value -> Parser [TxIx]) -> FromJSON TxIx
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [TxIx]
$cparseJSONList :: Value -> Parser [TxIx]
parseJSON :: Value -> Parser TxIx
$cparseJSON :: Value -> Parser TxIx
FromJSON)

fromByronTxIn :: Byron.TxIn -> TxIn
fromByronTxIn :: TxIn -> TxIn
fromByronTxIn (Byron.TxInUtxo TxId
txId Word32
index) =
  let shortBs :: ShortByteString
shortBs = TxId -> ShortByteString
forall algo a. AbstractHash algo a -> ShortByteString
Byron.abstractHashToShort TxId
txId
      mApiHash :: Maybe (Hash Blake2b_256 EraIndependentTxBody)
mApiHash = ShortByteString -> Maybe (Hash Blake2b_256 EraIndependentTxBody)
forall h a. HashAlgorithm h => ShortByteString -> Maybe (Hash h a)
Crypto.hashFromBytesShort ShortByteString
shortBs
  in case Maybe (Hash Blake2b_256 EraIndependentTxBody)
mApiHash of
       Just Hash Blake2b_256 EraIndependentTxBody
apiHash -> TxId -> TxIx -> TxIn
TxIn (Hash StandardCrypto EraIndependentTxBody -> TxId
TxId Hash StandardCrypto EraIndependentTxBody
Hash Blake2b_256 EraIndependentTxBody
apiHash) (Word -> TxIx
TxIx (Word -> TxIx) -> (Integer -> Word) -> Integer -> TxIx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> TxIx) -> Integer -> TxIx
forall a b. (a -> b) -> a -> b
$ Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger Word32
index)
       Maybe (Hash Blake2b_256 EraIndependentTxBody)
Nothing -> String -> TxIn
forall a. HasCallStack => String -> a
error (String -> TxIn) -> String -> TxIn
forall a b. (a -> b) -> a -> b
$ String
"Error converting Byron era TxId: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TxId -> String
forall a. Show a => a -> String
show TxId
txId

toByronTxIn :: TxIn -> Byron.TxIn
toByronTxIn :: TxIn -> TxIn
toByronTxIn (TxIn TxId
txid (TxIx Word
txix)) =
    TxId -> Word32 -> TxIn
Byron.TxInUtxo (TxId -> TxId
toByronTxId TxId
txid) (Word -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix)

toShelleyTxIn :: TxIn -> Shelley.TxIn StandardCrypto
toShelleyTxIn :: TxIn -> TxIn StandardCrypto
toShelleyTxIn (TxIn TxId
txid (TxIx Word
txix)) =
    TxId StandardCrypto -> Natural -> TxIn StandardCrypto
forall crypto.
Crypto crypto =>
TxId crypto -> Natural -> TxIn crypto
Shelley.TxIn (TxId -> TxId StandardCrypto
toShelleyTxId TxId
txid) (Word -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix)

fromShelleyTxIn :: Shelley.TxIn StandardCrypto -> TxIn
fromShelleyTxIn :: TxIn StandardCrypto -> TxIn
fromShelleyTxIn (Shelley.TxIn TxId StandardCrypto
txid Natural
txix) =
    TxId -> TxIx -> TxIn
TxIn (TxId StandardCrypto -> TxId
fromShelleyTxId TxId StandardCrypto
txid) (Word -> TxIx
TxIx (Natural -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
txix))


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

data TxOut era = TxOut (AddressInEra era)
                       (TxOutValue era)
                       (TxOutDatumHash era)
  deriving (forall x. TxOut era -> Rep (TxOut era) x)
-> (forall x. Rep (TxOut era) x -> TxOut era)
-> Generic (TxOut era)
forall x. Rep (TxOut era) x -> TxOut era
forall x. TxOut era -> Rep (TxOut era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (TxOut era) x -> TxOut era
forall era x. TxOut era -> Rep (TxOut era) x
$cto :: forall era x. Rep (TxOut era) x -> TxOut era
$cfrom :: forall era x. TxOut era -> Rep (TxOut era) x
Generic

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

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

deriving instance Show TxOutInAnyEra

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

instance IsCardanoEra era => ToJSON (TxOut era) where
  toJSON :: TxOut era -> Value
toJSON (TxOut AddressInEra era
addr TxOutValue era
val TxOutDatumHash era
TxOutDatumHashNone) =
    [Pair] -> Value
object [ Text
"address" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= AddressInEra era -> Text
forall era. AddressInEra era -> Text
serialiseAddressForTxOut AddressInEra era
addr
           , Text
"value"   Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= TxOutValue era -> Value
forall a. ToJSON a => a -> Value
toJSON TxOutValue era
val
           ]
  toJSON (TxOut AddressInEra era
addr TxOutValue era
val (TxOutDatumHash ScriptDataSupportedInEra era
_ Hash ScriptData
d)) =
    [Pair] -> Value
object [ Text
"address" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= AddressInEra era -> Text
forall era. AddressInEra era -> Text
serialiseAddressForTxOut AddressInEra era
addr
           , Text
"value"   Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= TxOutValue era -> Value
forall a. ToJSON a => a -> Value
toJSON TxOutValue era
val
           , Text
"data"    Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Hash ScriptData -> Value
forall a. ToJSON a => a -> Value
toJSON Hash ScriptData
d
           ]

serialiseAddressForTxOut :: AddressInEra era -> Text
serialiseAddressForTxOut :: AddressInEra era -> Text
serialiseAddressForTxOut (AddressInEra AddressTypeInEra addrtype era
addrType Address addrtype
addr) =
  case AddressTypeInEra addrtype era
addrType of
    AddressTypeInEra addrtype era
ByronAddressInAnyEra  -> Address addrtype -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText Address addrtype
addr
    ShelleyAddressInEra ShelleyBasedEra era
_ -> Address addrtype -> Text
forall a. SerialiseAsBech32 a => a -> Text
serialiseToBech32 Address addrtype
addr


fromByronTxOut :: Byron.TxOut -> TxOut ByronEra
fromByronTxOut :: TxOut -> TxOut ByronEra
fromByronTxOut (Byron.TxOut Address
addr Lovelace
value) =
  AddressInEra ByronEra
-> TxOutValue ByronEra -> TxOutDatumHash ByronEra -> TxOut ByronEra
forall era.
AddressInEra era
-> TxOutValue era -> TxOutDatumHash era -> TxOut 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))
     TxOutDatumHash ByronEra
forall era. TxOutDatumHash era
TxOutDatumHashNone


toByronTxOut :: TxOut ByronEra -> Maybe Byron.TxOut
toByronTxOut :: TxOut ByronEra -> Maybe TxOut
toByronTxOut (TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
addr))
                    (TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra Lovelace
value) TxOutDatumHash 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
_) TxOutDatumHash ByronEra
_) = case MultiAssetSupportedInEra ByronEra
era of {}

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


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

toShelleyTxOut ShelleyBasedEra era
_ (TxOut AddressInEra era
addr (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInShelleyEra Lovelace
value) TxOutDatumHash 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) TxOutDatumHash 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) TxOutDatumHash 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) TxOutDatumHash era
txoutdata) =
    Addr (Crypto (AlonzoEra StandardCrypto))
-> Value (AlonzoEra StandardCrypto)
-> StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
-> TxOut (AlonzoEra StandardCrypto)
forall era.
(Era era, Compactible (Value era), Show (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)
                 (TxOutDatumHash era -> StrictMaybe (DataHash StandardCrypto)
forall era.
TxOutDatumHash era -> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash TxOutDatumHash era
txoutdata)

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

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

    ShelleyBasedEra era
ShelleyBasedEraMary ->
        AddressInEra MaryEra
-> TxOutValue MaryEra -> TxOutDatumHash MaryEra -> TxOut MaryEra
forall era.
AddressInEra era
-> TxOutValue era -> TxOutDatumHash era -> TxOut era
TxOut (Addr StandardCrypto -> AddressInEra MaryEra
forall era.
IsShelleyBasedEra era =>
Addr StandardCrypto -> AddressInEra era
fromShelleyAddr 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))
               TxOutDatumHash MaryEra
forall era. TxOutDatumHash era
TxOutDatumHashNone
      where
        Shelley.TxOut Addr (Crypto (ShelleyMAEra 'Mary StandardCrypto))
addr Value (ShelleyMAEra 'Mary StandardCrypto)
value = TxOut (ShelleyMAEra 'Mary StandardCrypto)
TxOut ledgerera
ledgerTxOut

    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
       AddressInEra AlonzoEra
-> TxOutValue AlonzoEra
-> TxOutDatumHash AlonzoEra
-> TxOut AlonzoEra
forall era.
AddressInEra era
-> TxOutValue era -> TxOutDatumHash era -> TxOut era
TxOut (Addr StandardCrypto -> AddressInEra AlonzoEra
forall era.
IsShelleyBasedEra era =>
Addr StandardCrypto -> AddressInEra era
fromShelleyAddr 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)
-> TxOutDatumHash AlonzoEra
forall era.
ScriptDataSupportedInEra era
-> StrictMaybe (DataHash StandardCrypto) -> TxOutDatumHash era
fromAlonzoTxOutDataHash ScriptDataSupportedInEra AlonzoEra
ScriptDataInAlonzoEra StrictMaybe (DataHash StandardCrypto)
StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
datahash)
      where
        Alonzo.TxOut Addr (Crypto (AlonzoEra StandardCrypto))
addr Value (AlonzoEra StandardCrypto)
value StrictMaybe (DataHash (Crypto (AlonzoEra StandardCrypto)))
datahash = TxOut (AlonzoEra StandardCrypto)
TxOut ledgerera
ledgerTxOut

toAlonzoTxOutDataHash :: TxOutDatumHash era
                      -> StrictMaybe (Alonzo.DataHash StandardCrypto)
toAlonzoTxOutDataHash :: TxOutDatumHash era -> StrictMaybe (DataHash StandardCrypto)
toAlonzoTxOutDataHash TxOutDatumHash era
TxOutDatumHashNone    = StrictMaybe (DataHash StandardCrypto)
forall a. StrictMaybe a
SNothing
toAlonzoTxOutDataHash (TxOutDatumHash ScriptDataSupportedInEra era
_ (ScriptDataHash dh)) = DataHash StandardCrypto -> StrictMaybe (DataHash StandardCrypto)
forall a. a -> StrictMaybe a
SJust DataHash StandardCrypto
dh

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


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

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


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

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


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

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


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

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


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

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


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

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

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

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


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

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


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


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


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

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


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

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


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

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


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

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


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

unBuildTxWith :: BuildTxWith BuildTx a -> a
unBuildTxWith :: BuildTxWith BuildTx a -> a
unBuildTxWith (BuildTxWith a
a) = a
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)


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

data TxOutValue era where

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

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

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

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


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

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

data TxOutDatumHash era where

     TxOutDatumHashNone :: TxOutDatumHash era

     TxOutDatumHash     :: ScriptDataSupportedInEra era
                        -> Hash ScriptData
                        -> TxOutDatumHash era

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


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

-- ----------------------------------------------------------------------------
-- Auxiliary script data (era-dependent)
--

data TxExtraScriptData era where

     TxExtraScriptDataNone :: TxExtraScriptData era

     TxExtraScriptData     :: ScriptDataSupportedInEra era
                           -> [ScriptData]
                           -> TxExtraScriptData era

deriving instance Eq   (TxExtraScriptData era)
deriving instance Show (TxExtraScriptData 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 metadata (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 -> [TxOut era]
txOuts           :: [TxOut 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
-> BuildTxWith build (TxExtraScriptData era)
txExtraScriptData:: BuildTxWith build (TxExtraScriptData 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 -> BuildTxWith build (TxScriptValidity era)
txScriptValidity :: BuildTxWith build (TxScriptValidity era)
     }


-- ----------------------------------------------------------------------------
-- 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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyA     TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbodyB
                                  Bool -> Bool -> Bool
&& [Timelock StandardCrypto]
[Script (ShelleyLedgerEra era)]
txscriptsA  [Timelock StandardCrypto] -> [Timelock StandardCrypto] -> Bool
forall a. Eq a => a -> a -> Bool
== [Timelock StandardCrypto]
[Script (ShelleyLedgerEra era)]
txscriptsB
                                  Bool -> Bool -> Bool
&& Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataA Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
-> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadataB

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

           ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> TxBody (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
txbodyA         TxBody (AlonzoEra StandardCrypto)
-> TxBody (AlonzoEra StandardCrypto) -> Bool
forall a. Eq a => a -> a -> Bool
== TxBody (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
txbodyB
                                  Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)]
[Script (AlonzoEra StandardCrypto)]
txscriptsA      [Script (AlonzoEra StandardCrypto)]
-> [Script (AlonzoEra StandardCrypto)] -> Bool
forall a. Eq a => a -> a -> Bool
== [Script (ShelleyLedgerEra era)]
[Script (AlonzoEra StandardCrypto)]
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

    (==) 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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
txbody
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Timelock StandardCrypto] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Timelock 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 (ShelleyMAEra 'Allegra StandardCrypto))
-> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Maybe (AuxiliaryData (ShelleyMAEra 'Allegra StandardCrypto))
Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TxScriptValidity era -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 TxScriptValidity era
scriptValidity
        )

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

    showsPrec Int
p (ShelleyTxBody ShelleyBasedEra era
ShelleyBasedEraAlonzo
                               TxBody (ShelleyLedgerEra era)
txbody [Script (ShelleyLedgerEra era)]
txscripts TxBodyScriptData era
redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
txmetadata TxScriptValidity era
scriptValidity) =
      Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11)
        ( String -> ShowS
showString String
"ShelleyTxBody ShelleyBasedEraMary "
        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 (ShelleyLedgerEra era)
TxBody (AlonzoEra 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 -> [Script (AlonzoEra StandardCrypto)] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [Script (ShelleyLedgerEra era)]
[Script (AlonzoEra 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 (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
        )


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

    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

-- | 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 ledgerera
TxBody (AlonzoEra StandardCrypto)
txbody
         Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [Script (AlonzoEra StandardCrypto)] -> Encoding
forall a. ToCBOR a => a -> Encoding
CBOR.toCBOR [Script ledgerera]
[Script (AlonzoEra StandardCrypto)]
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
 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
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
"expected tx body tuple of size 3, 4 or 6"

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"


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

data TxBodyError =
       TxBodyEmptyTxIns
     | TxBodyEmptyTxInsCollateral
     | TxBodyEmptyTxOuts
     | TxBodyOutputNegative Quantity TxOutInAnyEra
     | TxBodyOutputOverflow Quantity TxOutInAnyEra
     | TxBodyMetadataError [(Word64, TxMetadataRangeError)]
     | TxBodyMintAdaError
     | TxBodyAuxDataHashInvalidError
     | TxBodyMintBeforeMaryError
     | TxBodyMissingProtocolParams
     deriving 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
TxBodyMintBeforeMaryError =
      String
"Transaction can mint in Mary era or later"
    displayError TxBodyError
TxBodyAuxDataHashInvalidError =
      String
"Auxiliary data hash is invalid"
    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"


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
_redeemers Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux TxScriptValidity era
_scriptValidity) =
    ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux


fromLedgerTxBody
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> Maybe (Ledger.AuxiliaryData (ShelleyLedgerEra era))
  -> TxBodyContent ViewTx era
fromLedgerTxBody :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (AuxiliaryData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body Maybe (AuxiliaryData (ShelleyLedgerEra era))
mAux =
    TxBodyContent :: forall build era.
TxIns build era
-> TxInsCollateral era
-> [TxOut era]
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> BuildTxWith build (TxExtraScriptData era)
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> BuildTxWith build (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
      , txOuts :: [TxOut era]
txOuts           = ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> [TxOut era]
forall era.
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> [TxOut era]
fromLedgerTxOuts           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
      , txExtraScriptData :: BuildTxWith ViewTx (TxExtraScriptData era)
txExtraScriptData = BuildTxWith ViewTx (TxExtraScriptData era)
forall a. BuildTxWith ViewTx a
ViewTx
      , txScriptValidity :: BuildTxWith ViewTx (TxScriptValidity era)
txScriptValidity = BuildTxWith ViewTx (TxScriptValidity era)
forall a. BuildTxWith ViewTx a
ViewTx
      }
  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 (Shelley.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'


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 StandardCrypto -> TxIn
fromShelleyTxIn TxIn StandardCrypto
input
                          | TxIn StandardCrypto
input <- Set (TxIn StandardCrypto) -> [TxIn StandardCrypto]
forall a. Set a -> [a]
Set.toList (ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
collateral ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body) ]
  where
    collateral :: ShelleyBasedEra era
               -> Ledger.TxBody (ShelleyLedgerEra era)
               -> Set (Shelley.TxIn StandardCrypto)
    collateral :: ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
collateral ShelleyBasedEra era
ShelleyBasedEraShelley = Set (TxIn StandardCrypto)
-> TxBody (ShelleyEra StandardCrypto) -> Set (TxIn StandardCrypto)
forall a b. a -> b -> a
const Set (TxIn StandardCrypto)
forall a. Set a
Set.empty
    collateral ShelleyBasedEra era
ShelleyBasedEraAllegra = Set (TxIn StandardCrypto)
-> TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> Set (TxIn StandardCrypto)
forall a b. a -> b -> a
const Set (TxIn StandardCrypto)
forall a. Set a
Set.empty
    collateral ShelleyBasedEra era
ShelleyBasedEraMary    = Set (TxIn StandardCrypto)
-> TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> Set (TxIn StandardCrypto)
forall a b. a -> b -> a
const Set (TxIn StandardCrypto)
forall a. Set a
Set.empty
    collateral ShelleyBasedEra era
ShelleyBasedEraAlonzo  = TxBody (ShelleyLedgerEra era) -> Set (TxIn StandardCrypto)
forall era. TxBody era -> Set (TxIn (Crypto era))
Alonzo.collateral'


fromLedgerTxOuts
  :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> [TxOut era]
fromLedgerTxOuts :: ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> [TxOut era]
fromLedgerTxOuts ShelleyBasedEra era
era TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era -> TxOut (ShelleyLedgerEra era) -> TxOut era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut era
fromShelleyTxOut ShelleyBasedEra era
era (TxOut (ShelleyLedgerEra era) -> TxOut era)
-> [TxOut (ShelleyLedgerEra era)] -> [TxOut era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
  case ShelleyBasedEra era
era of
    ShelleyBasedEra era
ShelleyBasedEraShelley -> StrictSeq (TxOut (ShelleyLedgerEra era))
-> [TxOut (ShelleyLedgerEra era)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StrictSeq (TxOut (ShelleyLedgerEra era))
 -> [TxOut (ShelleyLedgerEra era)])
-> StrictSeq (TxOut (ShelleyLedgerEra era))
-> [TxOut (ShelleyLedgerEra era)]
forall a b. (a -> b) -> a -> b
$ 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 -> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
-> [TxOut (ShelleyMAEra 'Allegra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
 -> [TxOut (ShelleyMAEra 'Allegra StandardCrypto)])
-> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
-> [TxOut (ShelleyMAEra 'Allegra StandardCrypto)]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyMAEra 'Allegra StandardCrypto)
-> StrictSeq (TxOut (ShelleyMAEra 'Allegra StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Allegra.outputs' TxBody (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
body
    ShelleyBasedEra era
ShelleyBasedEraMary    -> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
-> [TxOut (ShelleyMAEra 'Mary StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
 -> [TxOut (ShelleyMAEra 'Mary StandardCrypto)])
-> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
-> [TxOut (ShelleyMAEra 'Mary StandardCrypto)]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyMAEra 'Mary StandardCrypto)
-> StrictSeq (TxOut (ShelleyMAEra 'Mary StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Mary.outputs'    TxBody (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
body
    ShelleyBasedEra era
ShelleyBasedEraAlonzo  -> StrictSeq (TxOut (AlonzoEra StandardCrypto))
-> [TxOut (AlonzoEra StandardCrypto)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StrictSeq (TxOut (AlonzoEra StandardCrypto))
 -> [TxOut (AlonzoEra StandardCrypto)])
-> StrictSeq (TxOut (AlonzoEra StandardCrypto))
-> [TxOut (AlonzoEra StandardCrypto)]
forall a b. (a -> b) -> a -> b
$ TxBody (AlonzoEra StandardCrypto)
-> StrictSeq (TxOut (AlonzoEra StandardCrypto))
forall era. TxBody era -> StrictSeq (TxOut era)
Alonzo.outputs'  TxBody (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
body

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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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 (Timelock StandardCrypto)
StrictSeq (Script (ShelleyMAEra 'Allegra 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 (Timelock StandardCrypto)
StrictSeq (Script (ShelleyMAEra 'Mary 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
  )

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
      )
  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  -> 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)
                                | let 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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
body
                                , 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 ]

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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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 (ShelleyMAEra 'Allegra StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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)


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 (ShelleyMAEra 'Mary StandardCrypto)
TxBody (ShelleyLedgerEra era)
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 (ShelleyLedgerEra era)
TxBody (AlonzoEra StandardCrypto)
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 ByronEra]
txOuts :: [TxOut ByronEra]
txOuts :: forall build era. TxBodyContent build era -> [TxOut era]
txOuts } = do
    NonEmpty (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra))
ins'  <- TxIns BuildTx ByronEra
-> Maybe
     (NonEmpty
        (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)))
forall a. [a] -> Maybe (NonEmpty a)
NonEmpty.nonEmpty TxIns BuildTx ByronEra
txIns      Maybe
  (NonEmpty
     (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)))
-> TxBodyError
-> Either
     TxBodyError
     (NonEmpty
        (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)))
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxIns
    let ins'' :: NonEmpty TxIn
ins'' = ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)) -> TxIn)
-> NonEmpty
     (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra))
-> NonEmpty TxIn
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NonEmpty.map (TxIn -> TxIn
toByronTxIn (TxIn -> TxIn)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra))
    -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra))
-> TxIn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra)) -> TxIn
forall a b. (a, b) -> a
fst) NonEmpty (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn ByronEra))
ins'

    NonEmpty (TxOut ByronEra)
outs'  <- [TxOut ByronEra] -> Maybe (NonEmpty (TxOut ByronEra))
forall a. [a] -> Maybe (NonEmpty a)
NonEmpty.nonEmpty [TxOut ByronEra]
txOuts    Maybe (NonEmpty (TxOut ByronEra))
-> TxBodyError -> Either TxBodyError (NonEmpty (TxOut ByronEra))
forall a e. Maybe a -> e -> Either e a
?! TxBodyError
TxBodyEmptyTxOuts
    NonEmpty TxOut
outs'' <- (TxOut ByronEra -> Either TxBodyError TxOut)
-> NonEmpty (TxOut ByronEra) -> Either TxBodyError (NonEmpty TxOut)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
                (\TxOut ByronEra
out -> TxOut ByronEra -> Maybe TxOut
toByronTxOut TxOut ByronEra
out Maybe TxOut -> TxBodyError -> Either TxBodyError TxOut
forall a e. Maybe a -> e -> Either e a
?! TxOut ByronEra -> TxBodyError
classifyRangeError TxOut ByronEra
out)
                NonEmpty (TxOut 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
    classifyRangeError :: TxOut ByronEra -> TxBodyError
    classifyRangeError :: TxOut ByronEra -> TxBodyError
classifyRangeError
      txout :: TxOut ByronEra
txout@(TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra ByronAddress{})
                   (TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra Lovelace
value) TxOutDatumHash 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 ByronEra -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut ByronEra
txout)
      | Bool
otherwise        = Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow (Lovelace -> Quantity
lovelaceToQuantity Lovelace
value)
                                                (TxOut ByronEra -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut ByronEra
txout)

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

    classifyRangeError
      (TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEra ByronEra
era) ShelleyAddress{})
             TxOutValue ByronEra
_ TxOutDatumHash 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
-> [TxOut era]
-> TxFee era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> TxMetadataInEra era
-> TxAuxScripts era
-> BuildTxWith build (TxExtraScriptData era)
-> TxExtraKeyWitnesses era
-> BuildTxWith build (Maybe ProtocolParameters)
-> TxWithdrawals build era
-> TxCertificates build era
-> TxUpdateProposal era
-> TxMintValue build era
-> BuildTxWith build (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,
      txOuts :: [TxOut ByronEra]
txOuts           = TxOut -> TxOut ByronEra
fromByronTxOut (TxOut -> TxOut ByronEra) -> [TxOut] -> [TxOut 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,
      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,
      txExtraScriptData :: BuildTxWith ViewTx (TxExtraScriptData ByronEra)
txExtraScriptData= BuildTxWith ViewTx (TxExtraScriptData ByronEra)
forall a. BuildTxWith ViewTx a
ViewTx,
      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 :: BuildTxWith ViewTx (TxScriptValidity ByronEra)
txScriptValidity = BuildTxWith ViewTx (TxScriptValidity ByronEra)
forall a. BuildTxWith ViewTx a
ViewTx
    }

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 era]
txOuts :: [TxOut era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut 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 era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut 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 era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut era
txout)
      | 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 era
txout@(TxOut AddressInEra era
_ (TxOutAdaOnly OnlyAdaSupportedInEra era
AdaOnlyInShelleyEra Lovelace
v) TxOutDatumHash era
_) <- [TxOut 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 era -> TxOut (ShelleyEra StandardCrypto))
-> [TxOut era] -> [TxOut (ShelleyEra StandardCrypto)]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era
-> TxOut era -> TxOut (ShelleyEra StandardCrypto)
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut era -> TxOut ledgerera
toShelleyTxOut ShelleyBasedEra era
era) [TxOut 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
    scripts :: [Ledger.Script StandardShelley]
    scripts :: [Script (ShelleyEra StandardCrypto)]
scripts =
      [ ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptWitness witctx era -> ScriptInEra era
forall witctx era. ScriptWitness witctx era -> 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 era]
txOuts :: [TxOut era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut 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 era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut 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 era -> TxOutInAnyEra
forall era. IsCardanoEra era => TxOut era -> TxOutInAnyEra
txOutInAnyEra TxOut era
txout