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

module Cardano.Api.Internal.Tx.Body
  ( -- * Creating transactions using the old API

    -- |
    -- Both the old and new APIs support transaction creation. Transactions can be
    -- converted between formats, as they share the same underlying representation.
    -- @cardano-api@ will be moving towards using the new API and deprecating
    -- the old way to ensure simplicity, closer alignment with the ledger, and
    -- easier maintenance.
    --
    -- In both the new and old APIs, to construct a transaction, you need
    -- to construct a 'TxBodyContent', and you will need at least a
    -- witness (for example, a 'ShelleyWitnessSigningKey'), to sign the transaction.
    -- This process remains unchanged.
    --
    -- To learn how to create a transaction using the new API, refer to
    -- "Cardano.Api.Internal.Experimental.Tx" documentation.
    --
    -- The next examples use the following qualified modules:
    --
    -- @
    -- import qualified Cardano.Api as Api                -- the general `cardano-api` exports (including the old API)
    -- import qualified Cardano.Api.Script as Script      -- types related to scripts (Plutus and native)
    -- import qualified Cardano.Api.Ledger as Ledger      -- cardano-ledger re-exports
    -- @

    -- ** Creating a 'TxBodyContent'

    -- |
    --
    -- To create a transaction, you first need to define the contents of its body. This section
    -- will show how to use the API to create a 'TxBodyContent' for a simple transaction.
    --
    -- 'TxBodyContent' datatype provides several fields because transactions can serve multiple
    -- purposes, but the function 'defaultTxBodyContent' (exported from "Cardano.Api") already provides
    -- a base 'TxBodyContent' with all fields set to their default values that you can use as a starting point
    -- so as not to have to set all fields manually.
    --
    -- The 'defaultTxBodyContent' takes, as the only parameter, the 'ShelleyBasedEra' witness for the era
    -- you are working with. For example, if you are working with the 'ConwayEra', use 'shelleyBasedEra'
    -- available in "Cardano.Api", as follows:
    --
    -- @
    -- let sbe :: Api.ShelleyBasedEra Api.ConwayEra = Api.shelleyBasedEra
    -- @
    --
    -- This is what creating a simple 'TxBodyContent' would look like.
    --
    -- First, choose a transaction output to spend (a UTXO). Specify which UTXO to spend by
    -- providing the transaction ID and the index of the output in that transaction that you want
    -- to spend.
    --
    -- To specify the transaction ID, you can use the 'deserialiseFromRawBytesHex' function on the
    -- hexadecimal representation of the transaction hash. For example:
    --
    -- @
    -- let (Right srcTxId) = Api.deserialiseFromRawBytesHex Api.AsTxId "be6efd42a3d7b9a00d09d77a5d41e55ceaf0bd093a8aa8a893ce70d9caafd978"
    -- @
    --
    -- In real implementations, failure cases should be handled appropriately.
    --
    -- To specify the transaction index, use the 'TxIx' constructor. For example:
    --
    -- @
    -- let srcTxIx = Api.TxIx 0
    -- @
    --
    -- Now, combine both to create a 'TxIn' value and pair it with a witness requirement using 'BuildTxWith' :
    --
    -- @
    -- let txIn = ( Api.TxIn srcTxId srcTxIx
    --            , Api.BuildTxWith (Api.KeyWitness Api.KeyWitnessForSpending)
    --            )
    -- @
    --
    -- Next, specify the address of the recipient of the transaction. If you have the bech32 representation,
    -- you can use the 'deserialiseAddress' function to get the 'AddressInEra' type. For example:
    --
    -- @
    -- let (Just destAddress) = Api.deserialiseAddress (Api.AsAddressInEra eraAsType) "addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v"
    -- @
    --
    -- Now, you can create a 'TxOut' value. For simplicity, assume the output is a simple payment output
    -- of 10 ada, with no datum or reference script attached to it:
    --
    -- @
    -- let txOut = Api.TxOut
    --               destAddress
    --               (Api.lovelaceToTxOutValue sbe 10_000_000)
    --               Api.TxOutDatumNone
    --               Script.ReferenceScriptNone
    -- @
    --
    -- Note to set the transaction fee. For example, set it to 2 ada:
    --
    -- @
    -- let txFee = Api.TxFeeExplicit sbe 2_000_000
    -- @
    --
    -- Finally, you can create the 'TxBodyContent' by using the 'defaultTxBodyContent' function and
    -- putting everything together:
    --
    -- @
    -- let txBodyContent = Api.defaultTxBodyContent sbe
    --                      & Api.setTxIns [txIn]
    --                      & Api.setTxOuts [txOut]
    --                      & Api.setTxFee txFee
    -- @
    --
    -- The 'txBodyContent' can now be used to create a transaction using the old or the new API.

    -- ** Balancing a transaction

    -- |
    -- If you have a UTXO with exactly 12 ada, you could just construct the transaction as in the
    -- previous section directly, and it would be a valid transaction, but:
    --
    --   * It is probably wasting ADA
    --   * There may not be exactly one UTXO of 12 ada
    --   * The transaciton may not be this simple.
    --
    -- For these reasons, it is recommended that you balance the transaction before proceeding with
    -- signing and submitting.
    --
    -- See how to balance a transaction in the "Cardano.Api.Internal.Fees" documentation.

    -- ** Creating a 'ShelleyWitnessSigningKey'

    -- |
    -- Signing a transaction requires a witness, for example, a 'ShelleyWitnessSigningKey'.
    --
    -- Learn how to create a 'ShelleyWitnessSigningKey' in the "Cardano.Api.Internal.Tx.Sign" documentation.

    -- ** Creating a transaction using the old API

    -- |
    -- Now that you have a 'TxBodyContent' and a 'ShelleyWitnessSigningKey', you can easily create a transaction using the old API.
    -- First, create a transaction body using the 'createTransactionBody' function and the 'ShelleyBasedEra' witness
    -- defined earlier.
    --
    -- Create the transaction body using the 'TransactionBodyContent' created earlier:
    --
    -- @
    -- let (Right txBody) = Api.createTransactionBody sbe txBodyContent
    -- @
    --
    -- Then, sign the transaction using the 'signShelleyTransaction' function and the witness:
    --
    -- @
    -- let oldApiSignedTx :: Api.Tx Api.ConwayEra = Api.signShelleyTransaction sbe txBody [witness]
    -- @
    --
    -- We now have a signed transaction.

    -- ** Inspecting transactions

    -- |
    -- To deconstruct an old-style 'TxBody' into a 'TxBodyContent', you can also use the
    -- 'TxBody' pattern. Note that this cannot be used for constructing. For that, use 'ShelleyTxBody'
    -- or 'createTransactionBody', as in the example.
    --
    -- To extract the 'TxBody' and the 'KeyWitness'es from an old-style 'Tx', use
    -- the functions 'getTxBody' and 'getTxWitnesses' respectively, from "Cardano.Api".

    -- ** Appendix: Getting Shelley-based era witness from the new API

    -- |
    -- If you are using the new API, you can also derive the 'ShelleyBasedEra' of it from 'ConwayEra'
    -- from "Cardano.Api.Internal.Experimental" using the 'convert' function:
    --
    -- @
    -- let era = Exp.ConwayEra
    -- let sbe = Api.convert era
    -- @

    -- * Contents
    parseTxId

    -- ** Transaction bodies
  , TxBody (.., TxBody)
  , createTransactionBody
  , createAndValidateTransactionBody
  , TxBodyContent (..)

    -- ** Byron only
  , makeByronTransactionBody

    -- *** Transaction body builders
  , defaultTxBodyContent
  , defaultTxFee
  , defaultTxValidityUpperBound
  , setTxIns
  , modTxIns
  , addTxIn
  , addTxIns
  , setTxInsCollateral
  , modTxInsCollateral
  , addTxInsCollateral
  , addTxInCollateral
  , setTxInsReference
  , modTxInsReference
  , addTxInsReference
  , addTxInReference
  , setTxOuts
  , modTxOuts
  , addTxOut
  , addTxOuts
  , setTxTotalCollateral
  , modTxTotalCollateral
  , setTxReturnCollateral
  , modTxReturnCollateral
  , setTxFee
  , modTxFee
  , setTxValidityLowerBound
  , modTxValidityLowerBound
  , setTxValidityUpperBound
  , modTxValidityUpperBound
  , setTxMetadata
  , modTxMetadata
  , setTxAuxScripts
  , modTxAuxScripts
  , setTxExtraKeyWits
  , modTxExtraKeyWits
  , addTxExtraKeyWits
  , setTxProtocolParams
  , setTxWithdrawals
  , modTxWithdrawals
  , setTxCertificates
  , modTxCertificates
  , setTxUpdateProposal
  , modTxUpdateProposal
  , setTxProposalProcedures
  , setTxVotingProcedures
  , setTxMintValue
  , modTxMintValue
  , addTxMintValue
  , subtractTxMintValue
  , setTxScriptValidity
  , modTxScriptValidity
  , setTxCurrentTreasuryValue
  , setTxTreasuryDonation
  , TxBodyError (..)
  , TxBodyScriptData (..)
  , TxScriptValidity (..)
  , ScriptValidity (..)
  , scriptValidityToIsValid
  , isValidToScriptValidity
  , txScriptValidityToIsValid
  , txScriptValidityToScriptValidity

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

    -- ** Transaction inputs
  , TxIn (..)
  , TxIns
  , indexTxIns
  , TxIx (..)
  , genesisUTxOPseudoTxIn
  , getReferenceInputsSizeForTxIds

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

    -- ** Other transaction body types
  , TxInsCollateral (..)
  , TxInsReference (..)
  , TxReturnCollateral (..)
  , TxTotalCollateral (..)
  , TxFee (..)
  , TxValidityLowerBound (..)
  , TxValidityUpperBound (..)
  , TxMetadataInEra (..)
  , TxAuxScripts (..)
  , TxExtraKeyWitnesses (..)
  , TxWithdrawals (..)
  , indexTxWithdrawals
  , TxCertificates (..)
  , mkTxCertificates
  , indexTxCertificates
  , TxUpdateProposal (..)
  , TxMintValue (..)
  , mkTxMintValue
  , txMintValueToValue
  , indexTxMintValue
  , TxVotingProcedures (..)
  , mkTxVotingProcedures
  , indexTxVotingProcedures
  , TxProposalProcedures (..)
  , mkTxProposalProcedures
  , indexTxProposalProcedures
  , indexWitnessedTxProposalProcedures
  , convProposalProcedures

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

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

    -- ** Conversion to inline data
  , scriptDataToInlineDatum

    -- ** Internal conversion functions & types
  , convCertificates
  , convCollateralTxIns
  , convExtraKeyWitnesses
  , convLanguages
  , convMintValue
  , convPParamsToScriptIntegrityHash
  , convReferenceInputs
  , convReturnCollateral
  , convScripts
  , convScriptData
  , convTotalCollateral
  , convTransactionFee
  , convTxIns
  , convTxOuts
  , convTxUpdateProposal
  , convValidityLowerBound
  , convValidityUpperBound
  , convVotingProcedures
  , convWithdrawals
  , getScriptIntegrityHash
  , mkCommonTxBody
  , toAuxiliaryData
  , toByronTxId
  , toShelleyTxId
  , toShelleyTxIn
  , toShelleyTxOut
  , toShelleyTxOutAny
  , fromShelleyTxId
  , fromShelleyTxIn
  , fromShelleyTxOut
  , fromByronTxIn
  , fromLedgerTxOuts
  , renderTxIn

    -- ** Misc helpers
  , calculateExecutionUnitsLovelace

    -- ** Data family instances
  , AsType (AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody, AsMaryTxBody)
  , getTxBodyContent
  -- Temp
  , validateTxIns
  , guardShelleyTxInsOverflow
  , validateTxOuts
  , validateMetadata
  , validateTxInsCollateral
  , validateProtocolParameters
  )
where

import Cardano.Api.Internal.Address
import Cardano.Api.Internal.Certificate
import Cardano.Api.Internal.Eon.AllegraEraOnwards
import Cardano.Api.Internal.Eon.AlonzoEraOnwards
import Cardano.Api.Internal.Eon.BabbageEraOnwards
import Cardano.Api.Internal.Eon.Convert
import Cardano.Api.Internal.Eon.ConwayEraOnwards
import Cardano.Api.Internal.Eon.MaryEraOnwards
import Cardano.Api.Internal.Eon.ShelleyBasedEra
import Cardano.Api.Internal.Eon.ShelleyToBabbageEra
import Cardano.Api.Internal.Eras.Case
import Cardano.Api.Internal.Eras.Core
import Cardano.Api.Internal.Error (Error (..), displayError)
import Cardano.Api.Internal.Experimental.Plutus.IndexedPlutusScriptWitness
  ( Witnessable (..)
  , WitnessableItem (..)
  , obtainAlonzoScriptPurposeConstraints
  )
import Cardano.Api.Internal.Experimental.Plutus.Shim.LegacyScripts
import Cardano.Api.Internal.Experimental.Witness.TxScriptWitnessRequirements
import Cardano.Api.Internal.Feature
import Cardano.Api.Internal.Governance.Actions.ProposalProcedure
import Cardano.Api.Internal.Governance.Actions.VotingProcedure
import Cardano.Api.Internal.Hash
import Cardano.Api.Internal.Keys.Byron
import Cardano.Api.Internal.Keys.Shelley
import Cardano.Api.Internal.NetworkId
import Cardano.Api.Internal.Pretty
import Cardano.Api.Internal.ProtocolParameters
import Cardano.Api.Internal.ReexposeLedger qualified as Ledger
import Cardano.Api.Internal.Script
import Cardano.Api.Internal.ScriptData
import Cardano.Api.Internal.SerialiseCBOR
import Cardano.Api.Internal.SerialiseJSON
import Cardano.Api.Internal.SerialiseRaw
import Cardano.Api.Internal.Tx.BuildTxWith
import Cardano.Api.Internal.Tx.Sign
import Cardano.Api.Internal.TxIn
import Cardano.Api.Internal.TxMetadata
import Cardano.Api.Internal.Utils
import Cardano.Api.Internal.Value
import Cardano.Api.Internal.ValueParser
import Cardano.Api.Ledger.Lens qualified as A

import Cardano.Chain.Common qualified as Byron
import Cardano.Chain.UTxO qualified as Byron
import Cardano.Crypto.Hash.Class qualified as Crypto
import Cardano.Crypto.Hashing qualified as Byron
import Cardano.Ledger.Allegra.Core qualified as L
import Cardano.Ledger.Alonzo.Core qualified as L
import Cardano.Ledger.Alonzo.Scripts qualified as Alonzo
import Cardano.Ledger.Alonzo.Tx qualified as Alonzo (hashScriptIntegrity)
import Cardano.Ledger.Alonzo.TxWits qualified as Alonzo
import Cardano.Ledger.Api qualified as L
import Cardano.Ledger.Babbage.UTxO qualified as L
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
import Cardano.Ledger.Binary (Annotated (..))
import Cardano.Ledger.Binary qualified as CBOR
import Cardano.Ledger.Coin qualified as L
import Cardano.Ledger.Conway.Core qualified as L
import Cardano.Ledger.Core ()
import Cardano.Ledger.Core qualified as Core
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Credential qualified as Shelley
import Cardano.Ledger.Hashes qualified as SafeHash
import Cardano.Ledger.Keys qualified as Shelley
import Cardano.Ledger.Mary.Value as L (MaryValue (..), MultiAsset)
import Cardano.Ledger.Plutus.Data qualified as Plutus
import Cardano.Ledger.Plutus.Language qualified as Plutus
import Cardano.Ledger.Shelley.API qualified as Ledger
import Cardano.Ledger.Shelley.Genesis qualified as Shelley
import Cardano.Ledger.Shelley.TxCert qualified as Shelley
import Cardano.Ledger.TxIn qualified as L
import Cardano.Ledger.Val as L (isZero)
import Cardano.Slotting.Slot (SlotNo (..))
import Ouroboros.Consensus.Shelley.Eras qualified as E
  ( AllegraEra
  , AlonzoEra
  , BabbageEra
  , ConwayEra
  , MaryEra
  , ShelleyEra
  )

import Control.Applicative
import Control.Monad
import Data.Aeson (object, withObject, (.:), (.:?), (.=))
import Data.Aeson qualified as Aeson
import Data.Aeson.Key qualified as Aeson
import Data.Aeson.Types qualified as Aeson
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import Data.ByteString.Base16 qualified as Base16
import Data.ByteString.Char8 qualified as BSC
import Data.Foldable (for_)
import Data.Function (on)
import Data.Functor (($>))
import Data.List (sortBy)
import Data.List qualified as List
import Data.List.NonEmpty qualified as NonEmpty
import Data.Map.Ordered.Strict (OMap)
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe
import Data.MonoTraversable (omap)
import Data.Monoid
import Data.OSet.Strict (OSet)
import Data.OSet.Strict qualified as OSet
import Data.Scientific (toBoundedInteger)
import Data.Sequence.Strict qualified as Seq
import Data.Set (Set)
import Data.Set qualified as Set
import Data.String
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text
import Data.Text.Lazy qualified as LText
import Data.Text.Lazy.Builder qualified as LText
import Data.Type.Equality
import Data.Typeable
import Data.Word (Word16, Word32, Word64)
import Formatting.Buildable (Buildable)
import Formatting.Buildable qualified as Build
import GHC.Exts (IsList (..))
import GHC.Stack
import Lens.Micro hiding (ix)
import Lens.Micro.Extras (view)
import Text.Parsec ((<?>))
import Text.Parsec qualified as Parsec
import Text.Parsec.String qualified as Parsec

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

-- | The context is a transaction body
data CtxTx

-- | The context is the UTxO
data CtxUTxO

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

deriving instance Eq (TxOut ctx era)

deriving instance Show (TxOut ctx era)

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

deriving instance Show TxOutInAnyEra

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

deriving via (ShowOf TxOutInAnyEra) instance Pretty TxOutInAnyEra

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

toCtxUTxOTxOut :: TxOut CtxTx era -> TxOut CtxUTxO era
toCtxUTxOTxOut :: forall era. TxOut CtxTx era -> TxOut CtxUTxO era
toCtxUTxOTxOut (TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxTx era
d ReferenceScript era
refS) =
  let dat :: TxOutDatum CtxUTxO era
dat = case TxOutDatum CtxTx era
d of
        TxOutDatum CtxTx era
TxOutDatumNone -> TxOutDatum CtxUTxO era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
        TxOutDatumHash AlonzoEraOnwards era
s Hash ScriptData
h -> AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
s Hash ScriptData
h
        TxOutSupplementalDatum AlonzoEraOnwards era
s HashableScriptData
datum -> AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
s (Hash ScriptData -> TxOutDatum CtxUTxO era)
-> Hash ScriptData -> TxOutDatum CtxUTxO era
forall a b. (a -> b) -> a -> b
$ HashableScriptData -> Hash ScriptData
hashScriptDataBytes HashableScriptData
datum
        TxOutDatumInline BabbageEraOnwards era
s HashableScriptData
sd -> BabbageEraOnwards era
-> HashableScriptData -> TxOutDatum CtxUTxO era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
s HashableScriptData
sd
   in AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxUTxO era
-> ReferenceScript era
-> TxOut CtxUTxO era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxUTxO era
dat ReferenceScript era
refS

fromCtxUTxOTxOut :: TxOut CtxUTxO era -> TxOut CtxTx era
fromCtxUTxOTxOut :: forall era. TxOut CtxUTxO era -> TxOut CtxTx era
fromCtxUTxOTxOut (TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxUTxO era
d ReferenceScript era
refS) =
  let dat :: TxOutDatum CtxTx era
dat = case TxOutDatum CtxUTxO era
d of
        TxOutDatum CtxUTxO era
TxOutDatumNone -> TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
        TxOutDatumHash AlonzoEraOnwards era
s Hash ScriptData
h -> AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
s Hash ScriptData
h
        TxOutDatumInline BabbageEraOnwards era
s HashableScriptData
sd -> BabbageEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
s HashableScriptData
sd
   in AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addr TxOutValue era
val TxOutDatum CtxTx era
dat ReferenceScript era
refS

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

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

  datJsonVal :: TxOutDatum ctx era -> Aeson.Value
  datJsonVal :: forall ctx era. TxOutDatum ctx era -> Value
datJsonVal TxOutDatum ctx era
d =
    case TxOutDatum ctx era
d of
      TxOutDatum ctx era
TxOutDatumNone -> Value
Aeson.Null
      TxOutDatumHash AlonzoEraOnwards era
_ Hash ScriptData
_ -> Value
Aeson.Null
      TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
datum -> ScriptDataJsonSchema -> HashableScriptData -> Value
scriptDataToJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema HashableScriptData
datum
      TxOutDatumInline BabbageEraOnwards era
_ HashableScriptData
_ -> Value
Aeson.Null

  inlineDatumJsonVal :: TxOutDatum ctx era -> Aeson.Value
  inlineDatumJsonVal :: forall ctx era. TxOutDatum ctx era -> Value
inlineDatumJsonVal TxOutDatum ctx era
d =
    case TxOutDatum ctx era
d of
      TxOutDatum ctx era
TxOutDatumNone -> Value
Aeson.Null
      TxOutDatumHash{} -> Value
Aeson.Null
      TxOutSupplementalDatum{} -> Value
Aeson.Null
      TxOutDatumInline BabbageEraOnwards era
_ HashableScriptData
datum -> ScriptDataJsonSchema -> HashableScriptData -> Value
scriptDataToJson ScriptDataJsonSchema
ScriptDataJsonDetailedSchema HashableScriptData
datum

  inlineDatumRawJsonCbor :: TxOutDatum ctx era -> Aeson.Value
  inlineDatumRawJsonCbor :: forall ctx era. TxOutDatum ctx era -> Value
inlineDatumRawJsonCbor TxOutDatum ctx era
d =
    case TxOutDatum ctx era
d of
      TxOutDatum ctx era
TxOutDatumNone -> Value
Aeson.Null
      TxOutDatumHash{} -> Value
Aeson.Null
      TxOutSupplementalDatum{} -> Value
Aeson.Null
      TxOutDatumInline BabbageEraOnwards era
_ HashableScriptData
datum ->
        Text -> Value
Aeson.String
          (Text -> Value)
-> (HashableScriptData -> Text) -> HashableScriptData -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8
          (ByteString -> Text)
-> (HashableScriptData -> ByteString) -> HashableScriptData -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Base16.encode
          (ByteString -> ByteString)
-> (HashableScriptData -> ByteString)
-> HashableScriptData
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashableScriptData -> ByteString
forall a. SerialiseAsCBOR a => a -> ByteString
serialiseToCBOR
          (HashableScriptData -> Value) -> HashableScriptData -> Value
forall a b. (a -> b) -> a -> b
$ HashableScriptData
datum

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

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

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

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

        TxOut CtxTx BabbageEra
-> TxOutDatum CtxTx BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxTx BabbageEra)
reconcileBabbage TxOut CtxTx era
TxOut CtxTx BabbageEra
alonzoTxOutInBabbage TxOutDatum CtxTx BabbageEra
mInlineDatum Maybe ScriptInAnyLang
mReferenceScript
      ShelleyBasedEra era
ShelleyBasedEraConway -> do
        TxOut CtxTx era
alonzoTxOutInConway <- AlonzoEraOnwards era -> Object -> Parser (TxOut CtxTx era)
alonzoTxOutParser AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway Object
o

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

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

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

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

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

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

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

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

        TxOut CtxUTxO BabbageEra
-> TxOutDatum CtxUTxO BabbageEra
-> Maybe ScriptInAnyLang
-> Parser (TxOut CtxUTxO BabbageEra)
reconcileBabbage TxOut CtxUTxO era
TxOut CtxUTxO BabbageEra
alonzoTxOutInBabbage TxOutDatum CtxUTxO BabbageEra
mInlineDatum Maybe ScriptInAnyLang
mReferenceScript
      ShelleyBasedEra era
ShelleyBasedEraConway -> do
        TxOut CtxUTxO era
alonzoTxOutInConway <- AlonzoEraOnwards era -> Object -> Parser (TxOut CtxUTxO era)
alonzoTxOutParser AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway Object
o

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

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

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

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

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

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

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

toByronTxOut :: TxOut ctx ByronEra -> Maybe Byron.TxOut
toByronTxOut :: forall ctx. TxOut ctx ByronEra -> Maybe TxOut
toByronTxOut = \case
  TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
addr)) (TxOutValueByron Coin
value) TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_ ->
    Address -> Lovelace -> TxOut
Byron.TxOut Address
addr (Lovelace -> TxOut) -> Maybe Lovelace -> Maybe TxOut
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Coin -> Maybe Lovelace
toByronLovelace Coin
value
  TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
_)) (TxOutValueShelleyBased ShelleyBasedEra ByronEra
w Value (ShelleyLedgerEra ByronEra)
_) TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_ ->
    case ShelleyBasedEra ByronEra
w of {}
  TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEra ByronEra
sbe) ShelleyAddress{}) TxOutValue ByronEra
_ TxOutDatum ctx ByronEra
_ ReferenceScript ByronEra
_ ->
    case ShelleyBasedEra ByronEra
sbe of {}

toShelleyTxOut
  :: forall era ledgerera
   . HasCallStack
  => ShelleyLedgerEra era ~ ledgerera
  => ShelleyBasedEra era
  -> TxOut CtxUTxO era
  -> Ledger.TxOut ledgerera
toShelleyTxOut :: forall era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut CtxUTxO era -> TxOut ledgerera
toShelleyTxOut ShelleyBasedEra era
_ = \case
  -- jky simplify
  TxOut AddressInEra era
_ (TxOutValueByron Coin
_) TxOutDatum CtxUTxO era
_ ReferenceScript era
_ ->
    -- TODO: Temporary until we have basic tx
    -- construction functionality
    String -> TxOut ledgerera
forall a. HasCallStack => String -> a
error String
"toShelleyTxOut: Expected a Shelley value"
  TxOut AddressInEra era
addr (TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
value) TxOutDatum CtxUTxO era
txoutdata ReferenceScript era
refScript ->
    (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era -> TxOut ledgerera)
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era -> TxOut ledgerera)
-> ShelleyBasedEra era
-> TxOut ledgerera
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
      (TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera
forall a b. a -> b -> a
const (TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera)
-> TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera
forall a b. (a -> b) -> a -> b
$ Addr -> Value ledgerera -> TxOut ledgerera
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value ledgerera
Value (ShelleyLedgerEra era)
value)
      ( \case
          AlonzoEraOnwards era
AlonzoEraOnwardsAlonzo ->
            Addr -> Value AlonzoEra -> TxOut AlonzoEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value AlonzoEra
Value (ShelleyLedgerEra era)
value
              TxOut AlonzoEra
-> (TxOut AlonzoEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
-> TxOut AlonzoEra -> Identity (TxOut ledgerera)
(StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
-> TxOut AlonzoEra -> Identity (TxOut AlonzoEra)
forall era.
AlonzoEraTxOut era =>
Lens' (TxOut era) (StrictMaybe DataHash)
Lens' (TxOut AlonzoEra) (StrictMaybe DataHash)
L.dataHashTxOutL ((StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
 -> TxOut AlonzoEra -> Identity (TxOut ledgerera))
-> StrictMaybe DataHash -> TxOut AlonzoEra -> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum CtxUTxO era -> StrictMaybe DataHash
forall era. TxOutDatum CtxUTxO era -> StrictMaybe DataHash
toAlonzoTxOutDatumHashUTxO TxOutDatum CtxUTxO era
txoutdata
          AlonzoEraOnwards era
AlonzoEraOnwardsBabbage ->
            Addr -> Value BabbageEra -> TxOut BabbageEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value BabbageEra
Value (ShelleyLedgerEra era)
value
              TxOut BabbageEra
-> (TxOut BabbageEra -> TxOut BabbageEra) -> TxOut BabbageEra
forall a b. a -> (a -> b) -> b
& (Datum BabbageEra -> Identity (Datum BabbageEra))
-> TxOut BabbageEra -> Identity (TxOut BabbageEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut BabbageEra) (Datum BabbageEra)
L.datumTxOutL ((Datum BabbageEra -> Identity (Datum BabbageEra))
 -> TxOut BabbageEra -> Identity (TxOut BabbageEra))
-> Datum BabbageEra -> TxOut BabbageEra -> TxOut BabbageEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
forall era ctx.
Era (ShelleyLedgerEra era) =>
TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum TxOutDatum CtxUTxO era
txoutdata
              TxOut BabbageEra
-> (TxOut BabbageEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe (Script BabbageEra)
 -> Identity (StrictMaybe (Script BabbageEra)))
-> TxOut BabbageEra -> Identity (TxOut ledgerera)
(StrictMaybe (Script BabbageEra)
 -> Identity (StrictMaybe (Script BabbageEra)))
-> TxOut BabbageEra -> Identity (TxOut BabbageEra)
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut BabbageEra) (StrictMaybe (Script BabbageEra))
L.referenceScriptTxOutL ((StrictMaybe (Script BabbageEra)
  -> Identity (StrictMaybe (Script BabbageEra)))
 -> TxOut BabbageEra -> Identity (TxOut ledgerera))
-> StrictMaybe (Script BabbageEra)
-> TxOut BabbageEra
-> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
refScriptToShelleyScript ShelleyBasedEra era
sbe ReferenceScript era
refScript
          AlonzoEraOnwards era
AlonzoEraOnwardsConway ->
            Addr -> Value ConwayEra -> TxOut ConwayEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value ConwayEra
Value (ShelleyLedgerEra era)
value
              TxOut ConwayEra
-> (TxOut ConwayEra -> TxOut ConwayEra) -> TxOut ConwayEra
forall a b. a -> (a -> b) -> b
& (Datum ConwayEra -> Identity (Datum ConwayEra))
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut ConwayEra) (Datum ConwayEra)
L.datumTxOutL ((Datum ConwayEra -> Identity (Datum ConwayEra))
 -> TxOut ConwayEra -> Identity (TxOut ConwayEra))
-> Datum ConwayEra -> TxOut ConwayEra -> TxOut ConwayEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
forall era.
Era (ShelleyLedgerEra era) =>
TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatumUTxO TxOutDatum CtxUTxO era
txoutdata
              TxOut ConwayEra
-> (TxOut ConwayEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe (Script ConwayEra)
 -> Identity (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra -> Identity (TxOut ledgerera)
(StrictMaybe (Script ConwayEra)
 -> Identity (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut ConwayEra) (StrictMaybe (Script ConwayEra))
L.referenceScriptTxOutL ((StrictMaybe (Script ConwayEra)
  -> Identity (StrictMaybe (Script ConwayEra)))
 -> TxOut ConwayEra -> Identity (TxOut ledgerera))
-> StrictMaybe (Script ConwayEra)
-> TxOut ConwayEra
-> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
refScriptToShelleyScript ShelleyBasedEra era
sbe ReferenceScript era
refScript
      )
      ShelleyBasedEra era
sbe

toAlonzoTxOutDatumHashUTxO
  :: TxOutDatum CtxUTxO era -> StrictMaybe Plutus.DataHash
toAlonzoTxOutDatumHashUTxO :: forall era. TxOutDatum CtxUTxO era -> StrictMaybe DataHash
toAlonzoTxOutDatumHashUTxO TxOutDatum CtxUTxO era
TxOutDatumNone = StrictMaybe DataHash
forall a. StrictMaybe a
SNothing
toAlonzoTxOutDatumHashUTxO (TxOutDatumHash AlonzoEraOnwards era
_ (ScriptDataHash DataHash
dh)) = DataHash -> StrictMaybe DataHash
forall a. a -> StrictMaybe a
SJust DataHash
dh
toAlonzoTxOutDatumHashUTxO (TxOutDatumInline{}) = StrictMaybe DataHash
forall a. StrictMaybe a
SNothing

toBabbageTxOutDatumUTxO
  :: L.Era (ShelleyLedgerEra era)
  => TxOutDatum CtxUTxO era
  -> Plutus.Datum (ShelleyLedgerEra era)
toBabbageTxOutDatumUTxO :: forall era.
Era (ShelleyLedgerEra era) =>
TxOutDatum CtxUTxO era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatumUTxO TxOutDatum CtxUTxO era
TxOutDatumNone = Datum (ShelleyLedgerEra era)
forall era. Datum era
Plutus.NoDatum
toBabbageTxOutDatumUTxO (TxOutDatumHash AlonzoEraOnwards era
_ (ScriptDataHash DataHash
dh)) = DataHash -> Datum (ShelleyLedgerEra era)
forall era. DataHash -> Datum era
Plutus.DatumHash DataHash
dh
toBabbageTxOutDatumUTxO (TxOutDatumInline BabbageEraOnwards era
_ HashableScriptData
sd) = HashableScriptData -> Datum (ShelleyLedgerEra era)
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Datum ledgerera
scriptDataToInlineDatum HashableScriptData
sd

fromShelleyTxOut
  :: forall era ctx
   . ()
  => ShelleyBasedEra era
  -> Core.TxOut (ShelleyLedgerEra era)
  -> TxOut ctx era
fromShelleyTxOut :: forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
sbe TxOut (ShelleyLedgerEra era)
ledgerTxOut = ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxOut ctx era)
-> TxOut ctx era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxOut ctx era)
 -> TxOut ctx era)
-> (ShelleyBasedEraConstraints era => TxOut ctx era)
-> TxOut ctx era
forall a b. (a -> b) -> a -> b
$ do
  let txOutValue :: TxOutValue era
txOutValue = ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (Value (ShelleyLedgerEra era) -> TxOutValue era)
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall a b. (a -> b) -> a -> b
$ TxOut (ShelleyLedgerEra era)
ledgerTxOut TxOut (ShelleyLedgerEra era)
-> Getting
     (Value (ShelleyLedgerEra era))
     (TxOut (ShelleyLedgerEra era))
     (Value (ShelleyLedgerEra era))
-> Value (ShelleyLedgerEra era)
forall s a. s -> Getting a s a -> a
^. ShelleyBasedEra era
-> Lens'
     (TxOut (ShelleyLedgerEra era)) (Value (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> Lens'
     (TxOut (ShelleyLedgerEra era)) (Value (ShelleyLedgerEra era))
A.valueTxOutL ShelleyBasedEra era
sbe
  let addressInEra :: AddressInEra era
addressInEra = ShelleyBasedEra era -> Addr -> AddressInEra era
forall era. ShelleyBasedEra era -> Addr -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
sbe (Addr -> AddressInEra era) -> Addr -> AddressInEra era
forall a b. (a -> b) -> a -> b
$ TxOut (ShelleyLedgerEra era)
ledgerTxOut TxOut (ShelleyLedgerEra era)
-> Getting Addr (TxOut (ShelleyLedgerEra era)) Addr -> Addr
forall s a. s -> Getting a s a -> a
^. Getting Addr (TxOut (ShelleyLedgerEra era)) Addr
forall era. EraTxOut era => Lens' (TxOut era) Addr
Lens' (TxOut (ShelleyLedgerEra era)) Addr
L.addrTxOutL

  case ShelleyBasedEra era
sbe of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addressInEra TxOutValue era
txOutValue TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addressInEra TxOutValue era
txOutValue TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
    ShelleyBasedEra era
ShelleyBasedEraMary ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut AddressInEra era
addressInEra TxOutValue era
txOutValue TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
        AddressInEra era
addressInEra
        TxOutValue era
txOutValue
        (AlonzoEraOnwards era -> StrictMaybe DataHash -> TxOutDatum ctx era
forall era ctx.
AlonzoEraOnwards era -> StrictMaybe DataHash -> TxOutDatum ctx era
fromAlonzoTxOutDatumHash AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
AlonzoEraOnwardsAlonzo StrictMaybe DataHash
mDatumHash)
        ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
     where
      mDatumHash :: StrictMaybe DataHash
mDatumHash = TxOut (ShelleyLedgerEra era)
AlonzoTxOut AlonzoEra
ledgerTxOut AlonzoTxOut AlonzoEra
-> Getting
     (StrictMaybe DataHash)
     (AlonzoTxOut AlonzoEra)
     (StrictMaybe DataHash)
-> StrictMaybe DataHash
forall s a. s -> Getting a s a -> a
^. (StrictMaybe DataHash
 -> Const (StrictMaybe DataHash) (StrictMaybe DataHash))
-> TxOut AlonzoEra
-> Const (StrictMaybe DataHash) (TxOut AlonzoEra)
Getting
  (StrictMaybe DataHash)
  (AlonzoTxOut AlonzoEra)
  (StrictMaybe DataHash)
forall era.
AlonzoEraTxOut era =>
Lens' (TxOut era) (StrictMaybe DataHash)
Lens' (TxOut AlonzoEra) (StrictMaybe DataHash)
L.dataHashTxOutL
    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
        AddressInEra era
addressInEra
        TxOutValue era
txOutValue
        ( AlonzoEraOnwards era
-> BabbageEraOnwards era -> Datum BabbageEra -> TxOutDatum ctx era
forall ledgerera era ctx.
Era ledgerera =>
AlonzoEraOnwards era
-> BabbageEraOnwards era -> Datum ledgerera -> TxOutDatum ctx era
fromBabbageTxOutDatum
            AlonzoEraOnwards era
AlonzoEraOnwards BabbageEra
AlonzoEraOnwardsBabbage
            BabbageEraOnwards era
BabbageEraOnwards BabbageEra
BabbageEraOnwardsBabbage
            Datum BabbageEra
datum
        )
        ( case StrictMaybe (Script BabbageEra)
mRefScript of
            StrictMaybe (Script BabbageEra)
SNothing -> ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
            SJust Script BabbageEra
refScript ->
              ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
fromShelleyScriptToReferenceScript ShelleyBasedEra era
ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage Script BabbageEra
Script (ShelleyLedgerEra era)
refScript
        )
     where
      datum :: Datum BabbageEra
datum = TxOut (ShelleyLedgerEra era)
BabbageTxOut BabbageEra
ledgerTxOut BabbageTxOut BabbageEra
-> Getting
     (Datum BabbageEra) (BabbageTxOut BabbageEra) (Datum BabbageEra)
-> Datum BabbageEra
forall s a. s -> Getting a s a -> a
^. (Datum BabbageEra -> Const (Datum BabbageEra) (Datum BabbageEra))
-> TxOut BabbageEra -> Const (Datum BabbageEra) (TxOut BabbageEra)
Getting
  (Datum BabbageEra) (BabbageTxOut BabbageEra) (Datum BabbageEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut BabbageEra) (Datum BabbageEra)
L.datumTxOutL
      mRefScript :: StrictMaybe (Script BabbageEra)
mRefScript = TxOut (ShelleyLedgerEra era)
BabbageTxOut BabbageEra
ledgerTxOut BabbageTxOut BabbageEra
-> Getting
     (StrictMaybe (Script BabbageEra))
     (BabbageTxOut BabbageEra)
     (StrictMaybe (Script BabbageEra))
-> StrictMaybe (Script BabbageEra)
forall s a. s -> Getting a s a -> a
^. (StrictMaybe (Script BabbageEra)
 -> Const
      (StrictMaybe (Script BabbageEra))
      (StrictMaybe (Script BabbageEra)))
-> TxOut BabbageEra
-> Const (StrictMaybe (Script BabbageEra)) (TxOut BabbageEra)
Getting
  (StrictMaybe (Script BabbageEra))
  (BabbageTxOut BabbageEra)
  (StrictMaybe (Script BabbageEra))
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut BabbageEra) (StrictMaybe (Script BabbageEra))
L.referenceScriptTxOutL
    ShelleyBasedEra era
ShelleyBasedEraConway ->
      AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
        AddressInEra era
addressInEra
        TxOutValue era
txOutValue
        ( AlonzoEraOnwards era
-> BabbageEraOnwards era -> Datum ConwayEra -> TxOutDatum ctx era
forall ledgerera era ctx.
Era ledgerera =>
AlonzoEraOnwards era
-> BabbageEraOnwards era -> Datum ledgerera -> TxOutDatum ctx era
fromBabbageTxOutDatum
            AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway
            BabbageEraOnwards era
BabbageEraOnwards ConwayEra
BabbageEraOnwardsConway
            Datum ConwayEra
datum
        )
        ( case StrictMaybe (Script ConwayEra)
mRefScript of
            StrictMaybe (Script ConwayEra)
SNothing -> ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
            SJust Script ConwayEra
refScript ->
              ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
fromShelleyScriptToReferenceScript ShelleyBasedEra era
ShelleyBasedEra ConwayEra
ShelleyBasedEraConway Script ConwayEra
Script (ShelleyLedgerEra era)
refScript
        )
     where
      datum :: Datum ConwayEra
datum = TxOut (ShelleyLedgerEra era)
BabbageTxOut ConwayEra
ledgerTxOut BabbageTxOut ConwayEra
-> Getting
     (Datum ConwayEra) (BabbageTxOut ConwayEra) (Datum ConwayEra)
-> Datum ConwayEra
forall s a. s -> Getting a s a -> a
^. (Datum ConwayEra -> Const (Datum ConwayEra) (Datum ConwayEra))
-> TxOut ConwayEra -> Const (Datum ConwayEra) (TxOut ConwayEra)
Getting
  (Datum ConwayEra) (BabbageTxOut ConwayEra) (Datum ConwayEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut ConwayEra) (Datum ConwayEra)
L.datumTxOutL
      mRefScript :: StrictMaybe (Script ConwayEra)
mRefScript = TxOut (ShelleyLedgerEra era)
BabbageTxOut ConwayEra
ledgerTxOut BabbageTxOut ConwayEra
-> Getting
     (StrictMaybe (Script ConwayEra))
     (BabbageTxOut ConwayEra)
     (StrictMaybe (Script ConwayEra))
-> StrictMaybe (Script ConwayEra)
forall s a. s -> Getting a s a -> a
^. (StrictMaybe (Script ConwayEra)
 -> Const
      (StrictMaybe (Script ConwayEra)) (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra
-> Const (StrictMaybe (Script ConwayEra)) (TxOut ConwayEra)
Getting
  (StrictMaybe (Script ConwayEra))
  (BabbageTxOut ConwayEra)
  (StrictMaybe (Script ConwayEra))
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut ConwayEra) (StrictMaybe (Script ConwayEra))
L.referenceScriptTxOutL

toAlonzoTxOutDatumHash
  :: TxOutDatum ctx era -> StrictMaybe Plutus.DataHash
toAlonzoTxOutDatumHash :: forall ctx era. TxOutDatum ctx era -> StrictMaybe DataHash
toAlonzoTxOutDatumHash TxOutDatum ctx era
TxOutDatumNone = StrictMaybe DataHash
forall a. StrictMaybe a
SNothing
toAlonzoTxOutDatumHash (TxOutDatumHash AlonzoEraOnwards era
_ (ScriptDataHash DataHash
dh)) = DataHash -> StrictMaybe DataHash
forall a. a -> StrictMaybe a
SJust DataHash
dh
toAlonzoTxOutDatumHash (TxOutDatumInline{}) = StrictMaybe DataHash
forall a. StrictMaybe a
SNothing
toAlonzoTxOutDatumHash (TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
d) =
  let ScriptDataHash DataHash
dh = HashableScriptData -> Hash ScriptData
hashScriptDataBytes HashableScriptData
d
   in DataHash -> StrictMaybe DataHash
forall a. a -> StrictMaybe a
SJust DataHash
dh

fromAlonzoTxOutDatumHash
  :: AlonzoEraOnwards era
  -> StrictMaybe Plutus.DataHash
  -> TxOutDatum ctx era
fromAlonzoTxOutDatumHash :: forall era ctx.
AlonzoEraOnwards era -> StrictMaybe DataHash -> TxOutDatum ctx era
fromAlonzoTxOutDatumHash AlonzoEraOnwards era
_ StrictMaybe DataHash
SNothing = TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
fromAlonzoTxOutDatumHash AlonzoEraOnwards era
w (SJust DataHash
hash) = AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
w (Hash ScriptData -> TxOutDatum ctx era)
-> Hash ScriptData -> TxOutDatum ctx era
forall a b. (a -> b) -> a -> b
$ DataHash -> Hash ScriptData
ScriptDataHash DataHash
hash

toBabbageTxOutDatum
  :: L.Era (ShelleyLedgerEra era)
  => TxOutDatum ctx era
  -> Plutus.Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum :: forall era ctx.
Era (ShelleyLedgerEra era) =>
TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum TxOutDatum ctx era
TxOutDatumNone = Datum (ShelleyLedgerEra era)
forall era. Datum era
Plutus.NoDatum
toBabbageTxOutDatum (TxOutDatumHash AlonzoEraOnwards era
_ (ScriptDataHash DataHash
dh)) = DataHash -> Datum (ShelleyLedgerEra era)
forall era. DataHash -> Datum era
Plutus.DatumHash DataHash
dh
toBabbageTxOutDatum (TxOutDatumInline BabbageEraOnwards era
_ HashableScriptData
sd) = HashableScriptData -> Datum (ShelleyLedgerEra era)
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Datum ledgerera
scriptDataToInlineDatum HashableScriptData
sd
toBabbageTxOutDatum (TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
d) =
  let ScriptDataHash DataHash
dh = HashableScriptData -> Hash ScriptData
hashScriptDataBytes HashableScriptData
d
   in DataHash -> Datum (ShelleyLedgerEra era)
forall era. DataHash -> Datum era
Plutus.DatumHash DataHash
dh

fromBabbageTxOutDatum
  :: L.Era ledgerera
  => AlonzoEraOnwards era
  -> BabbageEraOnwards era
  -> Plutus.Datum ledgerera
  -> TxOutDatum ctx era
fromBabbageTxOutDatum :: forall ledgerera era ctx.
Era ledgerera =>
AlonzoEraOnwards era
-> BabbageEraOnwards era -> Datum ledgerera -> TxOutDatum ctx era
fromBabbageTxOutDatum AlonzoEraOnwards era
_ BabbageEraOnwards era
_ Datum ledgerera
Plutus.NoDatum = TxOutDatum ctx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
fromBabbageTxOutDatum AlonzoEraOnwards era
w BabbageEraOnwards era
_ (Plutus.DatumHash DataHash
dh) =
  AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
w (Hash ScriptData -> TxOutDatum ctx era)
-> Hash ScriptData -> TxOutDatum ctx era
forall a b. (a -> b) -> a -> b
$ DataHash -> Hash ScriptData
ScriptDataHash DataHash
dh
fromBabbageTxOutDatum AlonzoEraOnwards era
_ BabbageEraOnwards era
w (Plutus.Datum BinaryData ledgerera
binData) =
  BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
w (HashableScriptData -> TxOutDatum ctx era)
-> HashableScriptData -> TxOutDatum ctx era
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era -> BinaryData ledgerera -> HashableScriptData
forall ledgerera era.
Era ledgerera =>
BabbageEraOnwards era -> BinaryData ledgerera -> HashableScriptData
binaryDataToScriptData BabbageEraOnwards era
w BinaryData ledgerera
binData

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

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

-- | Index transaction inputs ordered by TxIn
-- Please note that the result can contain also 'KeyWitness'es.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
indexTxIns
  :: TxIns BuildTx era
  -> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)]
indexTxIns :: forall era.
TxIns BuildTx era
-> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)]
indexTxIns TxIns BuildTx era
txins =
  [ (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexTxIn Word32
ix, TxIn
txIn, Witness WitCtxTxIn era
witness)
  | (Word32
ix, (TxIn
txIn, BuildTxWith Witness WitCtxTxIn era
witness)) <- [Word32]
-> TxIns BuildTx era
-> [(Word32, (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word32
0 ..] (TxIns BuildTx era
 -> [(Word32,
      (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))])
-> TxIns BuildTx era
-> [(Word32, (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)))]
forall a b. (a -> b) -> a -> b
$ TxIns BuildTx era -> TxIns BuildTx era
forall v. [(TxIn, v)] -> [(TxIn, v)]
orderTxIns TxIns BuildTx era
txins
  ]
 where
  -- This relies on the TxId Ord instance being consistent with the
  -- Ledger.TxId Ord instance via the toShelleyTxId conversion
  -- This is checked by prop_ord_distributive_TxId
  orderTxIns :: [(TxIn, v)] -> [(TxIn, v)]
  orderTxIns :: forall v. [(TxIn, v)] -> [(TxIn, v)]
orderTxIns = ((TxIn, v) -> (TxIn, v) -> Ordering) -> [(TxIn, v)] -> [(TxIn, v)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (TxIn -> TxIn -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (TxIn -> TxIn -> Ordering)
-> ((TxIn, v) -> TxIn) -> (TxIn, v) -> (TxIn, v) -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (TxIn, v) -> TxIn
forall a b. (a, b) -> a
fst)

data TxInsCollateral era where
  TxInsCollateralNone
    :: TxInsCollateral era
  TxInsCollateral
    :: AlonzoEraOnwards era
    -> [TxIn] -- Only key witnesses, no scripts.
    -> TxInsCollateral era

deriving instance Eq (TxInsCollateral era)

deriving instance Show (TxInsCollateral era)

data TxInsReference era where
  TxInsReferenceNone :: TxInsReference era
  TxInsReference
    :: BabbageEraOnwards era
    -> [TxIn]
    -> TxInsReference era

deriving instance Eq (TxInsReference era)

deriving instance Show (TxInsReference era)

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

data TxOutValue era where
  TxOutValueByron
    :: L.Coin
    -> TxOutValue era
  TxOutValueShelleyBased
    :: ( Eq (Ledger.Value (ShelleyLedgerEra era))
       , Show (Ledger.Value (ShelleyLedgerEra era))
       )
    => ShelleyBasedEra era
    -> L.Value (ShelleyLedgerEra era)
    -> TxOutValue era

deriving instance Eq (TxOutValue era)

deriving instance Show (TxOutValue era)

instance IsCardanoEra era => ToJSON (TxOutValue era) where
  toJSON :: TxOutValue era -> Value
toJSON = \case
    TxOutValueByron Coin
ll ->
      Coin -> Value
forall a. ToJSON a => a -> Value
toJSON Coin
ll
    TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
val ->
      ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => Value) -> Value
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => Value) -> Value)
-> (ShelleyBasedEraConstraints era => Value) -> Value
forall a b. (a -> b) -> a -> b
$ Value -> Value
forall a. ToJSON a => a -> Value
toJSON (ShelleyBasedEra era -> Value (ShelleyLedgerEra era) -> Value
forall era.
ShelleyBasedEra era -> Value (ShelleyLedgerEra era) -> Value
fromLedgerValue ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
val)

instance IsShelleyBasedEra era => FromJSON (TxOutValue era) where
  parseJSON :: Value -> Parser (TxOutValue era)
parseJSON = String
-> (Object -> Parser (TxOutValue era))
-> Value
-> Parser (TxOutValue era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TxOutValue" ((Object -> Parser (TxOutValue era))
 -> Value -> Parser (TxOutValue era))
-> (Object -> Parser (TxOutValue era))
-> Value
-> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    (ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> Parser (TxOutValue era))
-> (MaryEraOnwardsConstraints era =>
    MaryEraOnwards era -> Parser (TxOutValue era))
-> ShelleyBasedEra era
-> Parser (TxOutValue era)
forall era a.
(ShelleyToAllegraEraConstraints era =>
 ShelleyToAllegraEra era -> a)
-> (MaryEraOnwardsConstraints era => MaryEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAllegraOrMaryEraOnwards
      ( \ShelleyToAllegraEra era
shelleyToAlleg -> do
          Coin
ll <- Object
o Object -> Key -> Parser Coin
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"lovelace"
          let sbe :: ShelleyBasedEra era
sbe = ShelleyToAllegraEra era -> ShelleyBasedEra era
forall era. ShelleyToAllegraEra era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert ShelleyToAllegraEra era
shelleyToAlleg
          TxOutValue era -> Parser (TxOutValue era)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutValue era -> Parser (TxOutValue era))
-> TxOutValue era -> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$
            ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxOutValue era)
 -> TxOutValue era)
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall a b. (a -> b) -> a -> b
$
              ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (Value (ShelleyLedgerEra era) -> TxOutValue era)
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall a b. (a -> b) -> a -> b
$
                ShelleyBasedEra era -> Coin -> Value (ShelleyLedgerEra era)
forall era.
ShelleyBasedEra era -> Coin -> Value (ShelleyLedgerEra era)
A.mkAdaValue ShelleyBasedEra era
sbe Coin
ll
      )
      ( \MaryEraOnwards era
w -> do
          let l :: [Item Object]
l = Object -> [Item Object]
forall l. IsList l => l -> [Item l]
toList Object
o
              sbe :: ShelleyBasedEra era
sbe = MaryEraOnwards era -> ShelleyBasedEra era
forall era. MaryEraOnwards era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert MaryEraOnwards era
w
          [Value]
vals <- (Pair -> Parser Value) -> [Pair] -> Parser [Value]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Pair -> Parser Value
decodeAssetId [Pair]
[Item Object]
l
          TxOutValue era -> Parser (TxOutValue era)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxOutValue era -> Parser (TxOutValue era))
-> TxOutValue era -> Parser (TxOutValue era)
forall a b. (a -> b) -> a -> b
$
            ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxOutValue era)
 -> TxOutValue era)
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall a b. (a -> b) -> a -> b
$
              ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (Value (ShelleyLedgerEra era) -> TxOutValue era)
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall a b. (a -> b) -> a -> b
$
                MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
forall era.
MaryEraOnwards era -> Value -> Value (ShelleyLedgerEra era)
toLedgerValue MaryEraOnwards era
w (Value -> Value (ShelleyLedgerEra era))
-> Value -> Value (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
                  [Value] -> Value
forall a. Monoid a => [a] -> a
mconcat [Value]
vals
      )
      (forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @era)
   where
    decodeAssetId :: (Aeson.Key, Aeson.Value) -> Aeson.Parser Value
    decodeAssetId :: Pair -> Parser Value
decodeAssetId (Key
polid, Aeson.Object Object
assetNameHm) = do
      let polId :: PolicyId
polId = String -> PolicyId
forall a. IsString a => String -> a
fromString (String -> PolicyId) -> (Text -> String) -> Text -> PolicyId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack (Text -> PolicyId) -> Text -> PolicyId
forall a b. (a -> b) -> a -> b
$ Key -> Text
Aeson.toText Key
polid
      [(AssetName, Quantity)]
aNameQuantity <- Object -> Parser [(AssetName, Quantity)]
decodeAssets Object
assetNameHm
      Value -> Parser Value
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Parser Value)
-> ([(AssetId, Quantity)] -> Value)
-> [(AssetId, Quantity)]
-> Parser Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(AssetId, Quantity)] -> Value
[Item Value] -> Value
forall l. IsList l => [Item l] -> l
fromList ([(AssetId, Quantity)] -> Parser Value)
-> [(AssetId, Quantity)] -> Parser Value
forall a b. (a -> b) -> a -> b
$
        ((AssetName, Quantity) -> (AssetId, Quantity))
-> [(AssetName, Quantity)] -> [(AssetId, Quantity)]
forall a b. (a -> b) -> [a] -> [b]
map ((AssetName -> AssetId)
-> (AssetName, Quantity) -> (AssetId, Quantity)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((AssetName -> AssetId)
 -> (AssetName, Quantity) -> (AssetId, Quantity))
-> (AssetName -> AssetId)
-> (AssetName, Quantity)
-> (AssetId, Quantity)
forall a b. (a -> b) -> a -> b
$ PolicyId -> AssetName -> AssetId
AssetId PolicyId
polId) [(AssetName, Quantity)]
aNameQuantity
    decodeAssetId (Key
"lovelace", Aeson.Number Scientific
sci) =
      case Scientific -> Maybe Word64
forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger Scientific
sci of
        Just (Word64
ll :: Word64) ->
          Value -> Parser Value
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Parser Value) -> Value -> Parser Value
forall a b. (a -> b) -> a -> b
$ [Item Value] -> Value
forall l. IsList l => [Item l] -> l
fromList [(AssetId
AdaAssetId, Integer -> Quantity
Quantity (Integer -> Quantity) -> Integer -> Quantity
forall a b. (a -> b) -> a -> b
$ Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
ll)]
        Maybe Word64
Nothing ->
          String -> Parser Value
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Value) -> String -> Parser Value
forall a b. (a -> b) -> a -> b
$ String
"Expected a Bounded number but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
sci
    decodeAssetId Pair
wrong = String -> Parser Value
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Value) -> String -> Parser Value
forall a b. (a -> b) -> a -> b
$ String
"Expected a policy id and a JSON object but got: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Pair -> String
forall a. Show a => a -> String
show Pair
wrong

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

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

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

lovelaceToTxOutValue
  :: ()
  => ShelleyBasedEra era
  -> L.Coin
  -> TxOutValue era
lovelaceToTxOutValue :: forall era. ShelleyBasedEra era -> Coin -> TxOutValue era
lovelaceToTxOutValue ShelleyBasedEra era
era Coin
ll =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
era ((ShelleyBasedEraConstraints era => TxOutValue era)
 -> TxOutValue era)
-> (ShelleyBasedEraConstraints era => TxOutValue era)
-> TxOutValue era
forall a b. (a -> b) -> a -> b
$
    ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
era (Value (ShelleyLedgerEra era) -> TxOutValue era)
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall a b. (a -> b) -> a -> b
$
      ShelleyBasedEra era -> Coin -> Value (ShelleyLedgerEra era)
forall era.
ShelleyBasedEra era -> Coin -> Value (ShelleyLedgerEra era)
A.mkAdaValue ShelleyBasedEra era
era Coin
ll

txOutValueToLovelace :: TxOutValue era -> L.Coin
txOutValueToLovelace :: forall era. TxOutValue era -> Coin
txOutValueToLovelace TxOutValue era
tv =
  case TxOutValue era
tv of
    TxOutValueByron Coin
l -> Coin
l
    TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
v -> Value (ShelleyLedgerEra era)
v Value (ShelleyLedgerEra era)
-> Getting Coin (Value (ShelleyLedgerEra era)) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. ShelleyBasedEra era -> Lens' (Value (ShelleyLedgerEra era)) Coin
forall era.
ShelleyBasedEra era -> Lens' (Value (ShelleyLedgerEra era)) Coin
A.adaAssetL ShelleyBasedEra era
sbe

txOutValueToValue :: TxOutValue era -> Value
txOutValueToValue :: forall era. TxOutValue era -> Value
txOutValueToValue TxOutValue era
tv =
  case TxOutValue era
tv of
    TxOutValueByron Coin
l -> Coin -> Value
lovelaceToValue Coin
l
    TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
v -> ShelleyBasedEra era -> Value (ShelleyLedgerEra era) -> Value
forall era.
ShelleyBasedEra era -> Value (ShelleyLedgerEra era) -> Value
fromLedgerValue ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
v

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

data TxReturnCollateral ctx era where
  TxReturnCollateralNone
    :: TxReturnCollateral ctx era
  TxReturnCollateral
    :: BabbageEraOnwards era
    -> TxOut ctx era
    -> TxReturnCollateral ctx era

deriving instance Eq (TxReturnCollateral ctx era)

deriving instance Show (TxReturnCollateral ctx era)

data TxTotalCollateral era where
  TxTotalCollateralNone
    :: TxTotalCollateral era
  TxTotalCollateral
    :: BabbageEraOnwards era
    -> L.Coin
    -> TxTotalCollateral era

deriving instance Eq (TxTotalCollateral era)

deriving instance Show (TxTotalCollateral era)

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

data TxOutDatum ctx era where
  TxOutDatumNone :: TxOutDatum ctx era
  -- | A transaction output that only specifies the hash of the datum, but
  -- not the full datum value.
  TxOutDatumHash
    :: AlonzoEraOnwards era
    -> Hash ScriptData
    -> TxOutDatum ctx era
  -- | A transaction output that specifies the whole datum value. This can
  -- only be used in the context of the transaction body (i.e this is a supplemental datum),
  -- and does not occur in the UTxO. The UTxO only contains the datum hash.
  TxOutSupplementalDatum
    :: AlonzoEraOnwards era
    -> HashableScriptData
    -> TxOutDatum CtxTx era
  -- | A transaction output that specifies the whole datum instead of the
  -- datum hash. Note that the datum map will not be updated with this datum,
  -- it only exists at the transaction output.
  TxOutDatumInline
    :: BabbageEraOnwards era
    -> HashableScriptData
    -> TxOutDatum ctx era

deriving instance Eq (TxOutDatum ctx era)

deriving instance Show (TxOutDatum ctx era)

{-# COMPLETE TxOutDatumNone, TxOutDatumHash, TxOutSupplementalDatum, TxOutDatumInline #-}

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

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

data TxFee era where
  TxFeeExplicit :: ShelleyBasedEra era -> L.Coin -> TxFee era

deriving instance Eq (TxFee era)

deriving instance Show (TxFee era)

defaultTxFee :: ShelleyBasedEra era -> TxFee era
defaultTxFee :: forall era. ShelleyBasedEra era -> TxFee era
defaultTxFee ShelleyBasedEra era
w = ShelleyBasedEra era -> Coin -> TxFee era
forall era. ShelleyBasedEra era -> Coin -> TxFee era
TxFeeExplicit ShelleyBasedEra era
w Coin
forall a. Monoid a => a
mempty

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

-- | This was formerly known as the TTL.
data TxValidityUpperBound era where
  TxValidityUpperBound
    :: ShelleyBasedEra era
    -> Maybe SlotNo
    -> TxValidityUpperBound era

deriving instance Eq (TxValidityUpperBound era)

deriving instance Show (TxValidityUpperBound era)

defaultTxValidityUpperBound
  :: ()
  => ShelleyBasedEra era
  -> TxValidityUpperBound era
defaultTxValidityUpperBound :: forall era. ShelleyBasedEra era -> TxValidityUpperBound era
defaultTxValidityUpperBound ShelleyBasedEra era
sbe = ShelleyBasedEra era -> Maybe SlotNo -> TxValidityUpperBound era
forall era.
ShelleyBasedEra era -> Maybe SlotNo -> TxValidityUpperBound era
TxValidityUpperBound ShelleyBasedEra era
sbe Maybe SlotNo
forall a. Maybe a
Nothing

data TxValidityLowerBound era where
  TxValidityNoLowerBound
    :: TxValidityLowerBound era
  TxValidityLowerBound
    :: AllegraEraOnwards 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
    :: ShelleyBasedEra 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
    :: AllegraEraOnwards 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
    :: AlonzoEraOnwards era
    -> [Hash PaymentKey]
    -> TxExtraKeyWitnesses era

deriving instance Eq (TxExtraKeyWitnesses era)

deriving instance Show (TxExtraKeyWitnesses era)

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

data TxWithdrawals build era where
  TxWithdrawalsNone
    :: TxWithdrawals build era
  TxWithdrawals
    :: ShelleyBasedEra era
    -> [(StakeAddress, L.Coin, BuildTxWith build (Witness WitCtxStake era))]
    -> TxWithdrawals build era

deriving instance Eq (TxWithdrawals build era)

deriving instance Show (TxWithdrawals build era)

-- | Index the withdrawals with witnesses in the order of stake addresses.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
indexTxWithdrawals
  :: TxWithdrawals BuildTx era
  -> [(ScriptWitnessIndex, StakeAddress, L.Coin, Witness WitCtxStake era)]
indexTxWithdrawals :: forall era.
TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, StakeAddress, Coin,
     Witness WitCtxStake era)]
indexTxWithdrawals TxWithdrawals BuildTx era
TxWithdrawalsNone = []
indexTxWithdrawals (TxWithdrawals ShelleyBasedEra era
_ [(StakeAddress, Coin,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
withdrawals) =
  [ (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexWithdrawal Word32
ix, StakeAddress
addr, Coin
coin, Witness WitCtxStake era
witness)
  | (Word32
ix, (StakeAddress
addr, Coin
coin, BuildTxWith Witness WitCtxStake era
witness)) <- [Word32]
-> [(StakeAddress, Coin,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(Word32,
     (StakeAddress, Coin,
      BuildTxWith BuildTx (Witness WitCtxStake era)))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word32
0 ..] ([(StakeAddress, Coin,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(StakeAddress, Coin,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall x v. [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
orderStakeAddrs [(StakeAddress, Coin,
  BuildTxWith BuildTx (Witness WitCtxStake era))]
withdrawals)
  ]
 where
  -- This relies on the StakeAddress Ord instance being consistent with the
  -- Shelley.RewardAcnt Ord instance via the toShelleyStakeAddr conversion
  -- This is checked by prop_ord_distributive_StakeAddress
  orderStakeAddrs :: [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
  orderStakeAddrs :: forall x v. [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
orderStakeAddrs = ((StakeAddress, x, v) -> (StakeAddress, x, v) -> Ordering)
-> [(StakeAddress, x, v)] -> [(StakeAddress, x, v)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (StakeAddress -> StakeAddress -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (StakeAddress -> StakeAddress -> Ordering)
-> ((StakeAddress, x, v) -> StakeAddress)
-> (StakeAddress, x, v)
-> (StakeAddress, x, v)
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (\(StakeAddress
k, x
_, v
_) -> StakeAddress
k))

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

data TxCertificates build era where
  -- | No certificates
  TxCertificatesNone
    :: TxCertificates build era
  -- | Represents certificates present in transaction. Prefer using 'mkTxCertificates' to constructing
  -- this type with a constructor
  TxCertificates
    :: ShelleyBasedEra era
    -> OMap
         (Certificate era)
         ( BuildTxWith
             build
             (Maybe (StakeCredential, Witness WitCtxStake era))
         )
    -> TxCertificates build era

deriving instance Eq (TxCertificates build era)

deriving instance Show (TxCertificates build era)

-- | Create 'TxCertificates'. Note that 'Certificate era' will be deduplicated. Only Certificates with a
-- stake credential will be in the result.
--
-- Note that, when building a transaction in Conway era, a witness is not required for staking credential
-- registration, but this is only the case during the transitional period of Conway era and only for staking
-- credential registration certificates without a deposit. Future eras will require a witness for
-- registration certificates, because the one without a deposit will be removed.
mkTxCertificates
  :: Applicative (BuildTxWith build)
  => ShelleyBasedEra era
  -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
  -> TxCertificates build era
mkTxCertificates :: forall build era.
Applicative (BuildTxWith build) =>
ShelleyBasedEra era
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> TxCertificates build era
mkTxCertificates ShelleyBasedEra era
_ [] = TxCertificates build era
forall build era. TxCertificates build era
TxCertificatesNone
mkTxCertificates ShelleyBasedEra era
sbe [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certs = ShelleyBasedEra era
-> OMap
     (Certificate era)
     (BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> TxCertificates build era
forall era build.
ShelleyBasedEra era
-> OMap
     (Certificate era)
     (BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> TxCertificates build era
TxCertificates ShelleyBasedEra era
sbe (OMap
   (Certificate era)
   (BuildTxWith
      build (Maybe (StakeCredential, Witness WitCtxStake era)))
 -> TxCertificates build era)
-> ([(Certificate era,
      BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))]
    -> OMap
         (Certificate era)
         (BuildTxWith
            build (Maybe (StakeCredential, Witness WitCtxStake era))))
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> TxCertificates build era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Certificate era,
  BuildTxWith
    build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> OMap
     (Certificate era)
     (BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))
[Item
   (OMap
      (Certificate era)
      (BuildTxWith
         build (Maybe (StakeCredential, Witness WitCtxStake era))))]
-> OMap
     (Certificate era)
     (BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))
forall l. IsList l => [Item l] -> l
fromList ([(Certificate era,
   BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))]
 -> TxCertificates build era)
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> TxCertificates build era
forall a b. (a -> b) -> a -> b
$ ((Certificate era, Maybe (ScriptWitness WitCtxStake era))
 -> (Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era))))
-> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
forall a b. (a -> b) -> [a] -> [b]
map (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> (Certificate era,
    BuildTxWith
      build (Maybe (StakeCredential, Witness WitCtxStake era)))
forall {f :: * -> *} {era} {era}.
Applicative f =>
(Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> (Certificate era,
    f (Maybe (StakeCredential, Witness WitCtxStake era)))
getStakeCred [(Certificate era, Maybe (ScriptWitness WitCtxStake era))]
certs
 where
  getStakeCred :: (Certificate era, Maybe (ScriptWitness WitCtxStake era))
-> (Certificate era,
    f (Maybe (StakeCredential, Witness WitCtxStake era)))
getStakeCred (Certificate era
cert, Maybe (ScriptWitness WitCtxStake era)
mWit) = do
    let wit :: Witness WitCtxStake era
wit =
          Witness WitCtxStake era
-> (ScriptWitness WitCtxStake era -> Witness WitCtxStake era)
-> Maybe (ScriptWitness WitCtxStake era)
-> Witness WitCtxStake era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
            (KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr)
            (ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr)
            Maybe (ScriptWitness WitCtxStake era)
mWit
    ( Certificate era
cert
      , Maybe (StakeCredential, Witness WitCtxStake era)
-> f (Maybe (StakeCredential, Witness WitCtxStake era))
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (StakeCredential, Witness WitCtxStake era)
 -> f (Maybe (StakeCredential, Witness WitCtxStake era)))
-> Maybe (StakeCredential, Witness WitCtxStake era)
-> f (Maybe (StakeCredential, Witness WitCtxStake era))
forall a b. (a -> b) -> a -> b
$
          (,Witness WitCtxStake era
wit) (StakeCredential -> (StakeCredential, Witness WitCtxStake era))
-> Maybe StakeCredential
-> Maybe (StakeCredential, Witness WitCtxStake era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Certificate era -> Maybe StakeCredential
forall era. Certificate era -> Maybe StakeCredential
selectStakeCredentialWitness Certificate era
cert
      )

-- | Index certificates with witnesses by the order they appear in the list (in the transaction).
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
indexTxCertificates
  :: TxCertificates BuildTx era
  -> [(ScriptWitnessIndex, Certificate era, StakeCredential, Witness WitCtxStake era)]
indexTxCertificates :: forall era.
TxCertificates BuildTx era
-> [(ScriptWitnessIndex, Certificate era, StakeCredential,
     Witness WitCtxStake era)]
indexTxCertificates TxCertificates BuildTx era
TxCertificatesNone = []
indexTxCertificates (TxCertificates ShelleyBasedEra era
_ OMap
  (Certificate era)
  (BuildTxWith
     BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))
certsWits) =
  [ (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexCertificate Word32
ix, Certificate era
cert, StakeCredential
stakeCred, Witness WitCtxStake era
witness)
  | (Word32
ix, (Certificate era
cert, BuildTxWith (Just (StakeCredential
stakeCred, Witness WitCtxStake era
witness)))) <- [Word32]
-> [(Certificate era,
     BuildTxWith
       BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> [(Word32,
     (Certificate era,
      BuildTxWith
        BuildTx (Maybe (StakeCredential, Witness WitCtxStake era))))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word32
0 ..] ([(Certificate era,
   BuildTxWith
     BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
 -> [(Word32,
      (Certificate era,
       BuildTxWith
         BuildTx (Maybe (StakeCredential, Witness WitCtxStake era))))])
-> [(Certificate era,
     BuildTxWith
       BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> [(Word32,
     (Certificate era,
      BuildTxWith
        BuildTx (Maybe (StakeCredential, Witness WitCtxStake era))))]
forall a b. (a -> b) -> a -> b
$ OMap
  (Certificate era)
  (BuildTxWith
     BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))
-> [Item
      (OMap
         (Certificate era)
         (BuildTxWith
            BuildTx (Maybe (StakeCredential, Witness WitCtxStake era))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (Certificate era)
  (BuildTxWith
     BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))
certsWits
  ]

data TxUpdateProposal era where
  TxUpdateProposalNone :: TxUpdateProposal era
  TxUpdateProposal :: ShelleyToBabbageEra 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
    :: MaryEraOnwards era
    -> Map
         PolicyId
         ( PolicyAssets
         , BuildTxWith build (ScriptWitness WitCtxMint era)
         )
    -> TxMintValue build era

deriving instance Eq (TxMintValue build era)

deriving instance Show (TxMintValue build era)

instance Semigroup (TxMintValue build era) where
  TxMintValue build era
TxMintNone <> :: TxMintValue build era
-> TxMintValue build era -> TxMintValue build era
<> TxMintValue build era
b = TxMintValue build era
b
  TxMintValue build era
a <> TxMintValue build era
TxMintNone = TxMintValue build era
a
  TxMintValue MaryEraOnwards era
w Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
a <> TxMintValue MaryEraOnwards era
_ Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
b = MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
w (Map
   PolicyId
   (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> TxMintValue build era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall a b. (a -> b) -> a -> b
$ ((PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> (PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era)))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall {a} {b} {b}. Semigroup a => (a, b) -> (a, b) -> (a, b)
mergeElements Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
a Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
b
   where
    mergeElements :: (a, b) -> (a, b) -> (a, b)
mergeElements (a
a1, b
w1) (a
a2, b
_w2) = (a
a1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a2, b
w1)

instance Monoid (TxMintValue build era) where
  mempty :: TxMintValue build era
mempty = TxMintValue build era
forall build era. TxMintValue build era
TxMintNone
  mappend :: TxMintValue build era
-> TxMintValue build era -> TxMintValue build era
mappend = TxMintValue build era
-> TxMintValue build era -> TxMintValue build era
forall a. Semigroup a => a -> a -> a
(<>)

-- | A helper function for building 'TxMintValue' with present witnesses. Only the first witness
-- in the argument will be used for each policy id.
mkTxMintValue
  :: MaryEraOnwards era
  -> [(PolicyId, PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))]
  -> TxMintValue build era
mkTxMintValue :: forall era build.
MaryEraOnwards era
-> [(PolicyId, PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era))]
-> TxMintValue build era
mkTxMintValue MaryEraOnwards era
_ [] = TxMintValue build era
forall build era. TxMintValue build era
TxMintNone
mkTxMintValue MaryEraOnwards era
w [(PolicyId, PolicyAssets,
  BuildTxWith build (ScriptWitness WitCtxMint era))]
vs =
  [TxMintValue build era] -> TxMintValue build era
forall a. Monoid a => [a] -> a
mconcat ([TxMintValue build era] -> TxMintValue build era)
-> [TxMintValue build era] -> TxMintValue build era
forall a b. (a -> b) -> a -> b
$
    [ MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
w ([Item
   (Map
      PolicyId
      (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall l. IsList l => [Item l] -> l
fromList [(PolicyId
policyId, (PolicyAssets
assets, BuildTxWith build (ScriptWitness WitCtxMint era)
bWit))])
    | (PolicyId
policyId, PolicyAssets
assets, BuildTxWith build (ScriptWitness WitCtxMint era)
bWit) <- [(PolicyId, PolicyAssets,
  BuildTxWith build (ScriptWitness WitCtxMint era))]
vs
    ]

-- | Convert 'TxMintValue' to a more handy 'Value'.
txMintValueToValue :: TxMintValue build era -> Value
txMintValueToValue :: forall build era. TxMintValue build era -> Value
txMintValueToValue TxMintValue build era
TxMintNone = Value
forall a. Monoid a => a
mempty
txMintValueToValue (TxMintValue MaryEraOnwards era
_ Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
policiesWithAssets) =
  [Value] -> Value
forall a. Monoid a => [a] -> a
mconcat
    [ PolicyId -> PolicyAssets -> Value
policyAssetsToValue PolicyId
policyId PolicyAssets
assets
    | (PolicyId
policyId, (PolicyAssets
assets, BuildTxWith build (ScriptWitness WitCtxMint era)
_witness)) <- Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> [Item
      (Map
         PolicyId
         (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
forall l. IsList l => l -> [Item l]
toList Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
policiesWithAssets
    ]

-- | Index the assets with witnesses in the order of policy ids.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
indexTxMintValue
  :: TxMintValue build era
  -> [ ( ScriptWitnessIndex
       , PolicyId
       , PolicyAssets
       , BuildTxWith build (ScriptWitness WitCtxMint era)
       )
     ]
indexTxMintValue :: forall build era.
TxMintValue build era
-> [(ScriptWitnessIndex, PolicyId, PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era))]
indexTxMintValue TxMintValue build era
TxMintNone = []
indexTxMintValue (TxMintValue MaryEraOnwards era
_ Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
policiesWithAssets) =
  [ (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexMint Word32
ix, PolicyId
policyId, PolicyAssets
assets, BuildTxWith build (ScriptWitness WitCtxMint era)
witness)
  | (Word32
ix, (PolicyId
policyId, (PolicyAssets
assets, BuildTxWith build (ScriptWitness WitCtxMint era)
witness))) <- [Word32]
-> [(PolicyId,
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
-> [(Word32,
     (PolicyId,
      (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word32
0 ..] ([(PolicyId,
   (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
 -> [(Word32,
      (PolicyId,
       (PolicyAssets,
        BuildTxWith build (ScriptWitness WitCtxMint era))))])
-> [(PolicyId,
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
-> [(Word32,
     (PolicyId,
      (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))))]
forall a b. (a -> b) -> a -> b
$ Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> [Item
      (Map
         PolicyId
         (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
forall l. IsList l => l -> [Item l]
toList Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
policiesWithAssets
  ]

-- ----------------------------------------------------------------------------
-- Votes within transactions (era-dependent)
--

data TxVotingProcedures build era where
  TxVotingProceduresNone :: TxVotingProcedures build era
  TxVotingProcedures
    :: L.VotingProcedures (ShelleyLedgerEra era)
    -> BuildTxWith
         build
         (Map Ledger.Voter (ScriptWitness WitCtxStake era))
    -> TxVotingProcedures build era

deriving instance Eq (TxVotingProcedures build era)

deriving instance Show (TxVotingProcedures build era)

-- | Create voting procedures from map of voting procedures and optional witnesses.
-- Validates the function argument, to make sure the list of votes is legal.
-- See 'mergeVotingProcedures' for validation rules.
mkTxVotingProcedures
  :: Applicative (BuildTxWith build)
  => [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
  -> Either (VotesMergingConflict era) (TxVotingProcedures build era)
mkTxVotingProcedures :: forall build era.
Applicative (BuildTxWith build) =>
[(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
mkTxVotingProcedures [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures = do
  VotingProcedures VotingProcedures (ShelleyLedgerEra era)
procedure <-
    (VotingProcedures era
 -> (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
 -> Either (VotesMergingConflict era) (VotingProcedures era))
-> VotingProcedures era
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Either (VotesMergingConflict era) (VotingProcedures era)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM VotingProcedures era
-> (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
-> Either (VotesMergingConflict era) (VotingProcedures era)
forall {era} {b}.
VotingProcedures era
-> (VotingProcedures era, b)
-> Either (VotesMergingConflict era) (VotingProcedures era)
f VotingProcedures era
forall era. VotingProcedures era
emptyVotingProcedures [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
  TxVotingProcedures build era
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
forall a. a -> Either (VotesMergingConflict era) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TxVotingProcedures build era
 -> Either
      (VotesMergingConflict era) (TxVotingProcedures build era))
-> TxVotingProcedures build era
-> Either (VotesMergingConflict era) (TxVotingProcedures build era)
forall a b. (a -> b) -> a -> b
$ VotingProcedures (ShelleyLedgerEra era)
-> BuildTxWith build (Map Voter (ScriptWitness WitCtxStake era))
-> TxVotingProcedures build era
forall era build.
VotingProcedures (ShelleyLedgerEra era)
-> BuildTxWith build (Map Voter (ScriptWitness WitCtxStake era))
-> TxVotingProcedures build era
TxVotingProcedures VotingProcedures (ShelleyLedgerEra era)
procedure (Map Voter (ScriptWitness WitCtxStake era)
-> BuildTxWith build (Map Voter (ScriptWitness WitCtxStake era))
forall a. a -> BuildTxWith build a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map Voter (ScriptWitness WitCtxStake era)
votingScriptWitnessMap)
 where
  votingScriptWitnessMap :: Map Voter (ScriptWitness WitCtxStake era)
votingScriptWitnessMap =
    (Map Voter (ScriptWitness WitCtxStake era)
 -> (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
 -> Map Voter (ScriptWitness WitCtxStake era))
-> Map Voter (ScriptWitness WitCtxStake era)
-> [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
-> Map Voter (ScriptWitness WitCtxStake era)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl
      (\Map Voter (ScriptWitness WitCtxStake era)
acc (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
next -> Map Voter (ScriptWitness WitCtxStake era)
acc Map Voter (ScriptWitness WitCtxStake era)
-> Map Voter (ScriptWitness WitCtxStake era)
-> Map Voter (ScriptWitness WitCtxStake era)
forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` (VotingProcedures era
 -> Maybe (ScriptWitness WitCtxStake era)
 -> Map Voter (ScriptWitness WitCtxStake era))
-> (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
-> Map Voter (ScriptWitness WitCtxStake era)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry VotingProcedures era
-> Maybe (ScriptWitness WitCtxStake era)
-> Map Voter (ScriptWitness WitCtxStake era)
forall era.
VotingProcedures era
-> Maybe (ScriptWitness WitCtxStake era)
-> Map Voter (ScriptWitness WitCtxStake era)
votingScriptWitnessSingleton (VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))
next)
      Map Voter (ScriptWitness WitCtxStake era)
forall k a. Map k a
Map.empty
      [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))]
votingProcedures
  f :: VotingProcedures era
-> (VotingProcedures era, b)
-> Either (VotesMergingConflict era) (VotingProcedures era)
f VotingProcedures era
acc (VotingProcedures era
procedure, b
_witness) = VotingProcedures era
-> VotingProcedures era
-> Either (VotesMergingConflict era) (VotingProcedures era)
forall era.
VotingProcedures era
-> VotingProcedures era
-> Either (VotesMergingConflict era) (VotingProcedures era)
mergeVotingProcedures VotingProcedures era
acc VotingProcedures era
procedure

  votingScriptWitnessSingleton
    :: VotingProcedures era
    -> Maybe (ScriptWitness WitCtxStake era)
    -> Map L.Voter (ScriptWitness WitCtxStake era)
  votingScriptWitnessSingleton :: forall era.
VotingProcedures era
-> Maybe (ScriptWitness WitCtxStake era)
-> Map Voter (ScriptWitness WitCtxStake era)
votingScriptWitnessSingleton VotingProcedures era
_ Maybe (ScriptWitness WitCtxStake era)
Nothing = Map Voter (ScriptWitness WitCtxStake era)
forall k a. Map k a
Map.empty
  votingScriptWitnessSingleton VotingProcedures era
votingProcedures' (Just ScriptWitness WitCtxStake era
scriptWitness) = do
    let voter :: Voter
voter = Maybe Voter -> Voter
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Voter -> Voter) -> Maybe Voter -> Voter
forall a b. (a -> b) -> a -> b
$ VotingProcedures era -> Maybe Voter
forall era. VotingProcedures era -> Maybe Voter
getVotingScriptCredentials VotingProcedures era
votingProcedures'
    Voter
-> ScriptWitness WitCtxStake era
-> Map Voter (ScriptWitness WitCtxStake era)
forall k a. k -> a -> Map k a
Map.singleton Voter
voter ScriptWitness WitCtxStake era
scriptWitness

  getVotingScriptCredentials
    :: VotingProcedures era
    -> Maybe L.Voter
  getVotingScriptCredentials :: forall era. VotingProcedures era -> Maybe Voter
getVotingScriptCredentials (VotingProcedures (L.VotingProcedures Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
m)) =
    [Voter] -> Maybe Voter
forall a. [a] -> Maybe a
listToMaybe ([Voter] -> Maybe Voter) -> [Voter] -> Maybe Voter
forall a b. (a -> b) -> a -> b
$ Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
-> [Voter]
forall k a. Map k a -> [k]
Map.keys Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
m

-- | Index voting procedures by the order of the votes ('Ord').
indexTxVotingProcedures
  :: TxVotingProcedures BuildTx era
  -> [ ( ScriptWitnessIndex
       , L.Voter
       , ScriptWitness WitCtxStake era
       )
     ]
indexTxVotingProcedures :: forall era.
TxVotingProcedures BuildTx era
-> [(ScriptWitnessIndex, Voter, ScriptWitness WitCtxStake era)]
indexTxVotingProcedures TxVotingProcedures BuildTx era
TxVotingProceduresNone = []
indexTxVotingProcedures (TxVotingProcedures VotingProcedures (ShelleyLedgerEra era)
vProcedures (BuildTxWith Map Voter (ScriptWitness WitCtxStake era)
sWitMap)) =
  [ (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexVoting (Word32 -> ScriptWitnessIndex) -> Word32 -> ScriptWitnessIndex
forall a b. (a -> b) -> a -> b
$ Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
index, Voter
vote, ScriptWitness WitCtxStake era
scriptWitness)
  | let allVoteMap :: Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
allVoteMap = VotingProcedures (ShelleyLedgerEra era)
-> Map
     Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
forall era.
VotingProcedures era
-> Map Voter (Map GovActionId (VotingProcedure era))
L.unVotingProcedures VotingProcedures (ShelleyLedgerEra era)
vProcedures
  , (Voter
vote, ScriptWitness WitCtxStake era
scriptWitness) <- Map Voter (ScriptWitness WitCtxStake era)
-> [Item (Map Voter (ScriptWitness WitCtxStake era))]
forall l. IsList l => l -> [Item l]
toList Map Voter (ScriptWitness WitCtxStake era)
sWitMap
  , Int
index <- Maybe Int -> [Int]
forall a. Maybe a -> [a]
maybeToList (Maybe Int -> [Int]) -> Maybe Int -> [Int]
forall a b. (a -> b) -> a -> b
$ Voter
-> Map
     Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
-> Maybe Int
forall k a. Ord k => k -> Map k a -> Maybe Int
Map.lookupIndex Voter
vote Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
allVoteMap
  ]

-- ----------------------------------------------------------------------------
-- Proposals within transactions (era-dependent)
--
-- A proposal procedure houses a governance action that is required to be voted into acceptance when submitted.
data TxProposalProcedures build era where
  -- | No proposals in transaction..
  TxProposalProceduresNone :: TxProposalProcedures build era
  -- | Represents proposal procedures present in transaction.
  TxProposalProcedures
    :: Ledger.EraPParams (ShelleyLedgerEra era)
    => OMap
         (L.ProposalProcedure (ShelleyLedgerEra era))
         ( BuildTxWith
             build
             (Maybe (ScriptWitness WitCtxStake era))
         )
    -> TxProposalProcedures build era

deriving instance Eq (TxProposalProcedures build era)

deriving instance Show (TxProposalProcedures build era)

-- | A smart constructor for 'TxProposalProcedures'. It makes sure that the value produced is consistent - the
-- witnessed proposals are also present in the first constructor parameter.
mkTxProposalProcedures
  :: forall era build
   . Applicative (BuildTxWith build)
  => IsShelleyBasedEra era
  => [(L.ProposalProcedure (ShelleyLedgerEra era), Maybe (ScriptWitness WitCtxStake era))]
  -> TxProposalProcedures build era
mkTxProposalProcedures :: forall era build.
(Applicative (BuildTxWith build), IsShelleyBasedEra era) =>
[(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures build era
mkTxProposalProcedures [(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
proposals = do
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    TxProposalProcedures build era)
-> TxProposalProcedures build era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints (forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @era) ((ShelleyBasedEraConstraints era => TxProposalProcedures build era)
 -> TxProposalProcedures build era)
-> (ShelleyBasedEraConstraints era =>
    TxProposalProcedures build era)
-> TxProposalProcedures build era
forall a b. (a -> b) -> a -> b
$
    OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> TxProposalProcedures build era
forall era build.
EraPParams (ShelleyLedgerEra era) =>
OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> TxProposalProcedures build era
TxProposalProcedures (OMap
   (ProposalProcedure (ShelleyLedgerEra era))
   (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
 -> TxProposalProcedures build era)
-> OMap
     (ProposalProcedure (ShelleyLedgerEra era))
     (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> TxProposalProcedures build era
forall a b. (a -> b) -> a -> b
$
      [Item
   (OMap
      (ProposalProcedure (ShelleyLedgerEra era))
      (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))]
-> OMap
     (ProposalProcedure (ShelleyLedgerEra era))
     (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
forall l. IsList l => [Item l] -> l
fromList ([Item
    (OMap
       (ProposalProcedure (ShelleyLedgerEra era))
       (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))]
 -> OMap
      (ProposalProcedure (ShelleyLedgerEra era))
      (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))
-> [Item
      (OMap
         (ProposalProcedure (ShelleyLedgerEra era))
         (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))]
-> OMap
     (ProposalProcedure (ShelleyLedgerEra era))
     (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
forall a b. (a -> b) -> a -> b
$
        ((ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))
 -> (ProposalProcedure (ShelleyLedgerEra era),
     BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
-> [(ProposalProcedure (ShelleyLedgerEra era),
     BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))]
forall a b. (a -> b) -> [a] -> [b]
map ((Maybe (ScriptWitness WitCtxStake era)
 -> BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> (ProposalProcedure (ShelleyLedgerEra era),
    Maybe (ScriptWitness WitCtxStake era))
-> (ProposalProcedure (ShelleyLedgerEra era),
    BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Maybe (ScriptWitness WitCtxStake era)
-> BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))
forall a. a -> BuildTxWith build a
forall (f :: * -> *) a. Applicative f => a -> f a
pure) [(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
proposals

-- | Index proposal procedures by their order ('Ord').
-- | and filter out the ones that do not have a witness.
indexTxProposalProcedures
  :: TxProposalProcedures BuildTx era
  -> [(ScriptWitnessIndex, L.ProposalProcedure (ShelleyLedgerEra era), ScriptWitness WitCtxStake era)]
indexTxProposalProcedures :: forall era.
TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, ProposalProcedure (ShelleyLedgerEra era),
     ScriptWitness WitCtxStake era)]
indexTxProposalProcedures TxProposalProcedures BuildTx era
proposals =
  [ (ScriptWitnessIndex
ix, ProposalProcedure (ShelleyLedgerEra era)
proposal, ScriptWitness WitCtxStake era
scriptWitness)
  | (ProposalProcedure (ShelleyLedgerEra era)
proposal, Just (ScriptWitnessIndex
ix, ScriptWitness WitCtxStake era
scriptWitness)) <- TxProposalProcedures BuildTx era
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitnessIndex, ScriptWitness WitCtxStake era))]
forall era.
TxProposalProcedures BuildTx era
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitnessIndex, ScriptWitness WitCtxStake era))]
indexWitnessedTxProposalProcedures TxProposalProcedures BuildTx era
proposals
  ]

-- | Index proposal procedures by their order ('Ord').
indexWitnessedTxProposalProcedures
  :: TxProposalProcedures BuildTx era
  -> [ ( L.ProposalProcedure (ShelleyLedgerEra era)
       , Maybe (ScriptWitnessIndex, ScriptWitness WitCtxStake era)
       )
     ]
indexWitnessedTxProposalProcedures :: forall era.
TxProposalProcedures BuildTx era
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitnessIndex, ScriptWitness WitCtxStake era))]
indexWitnessedTxProposalProcedures TxProposalProcedures BuildTx era
TxProposalProceduresNone = []
indexWitnessedTxProposalProcedures (TxProposalProcedures OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))
proposals) = do
  let allProposalsList :: [(Word32,
  (ProposalProcedure (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))]
allProposalsList = [Word32]
-> [(ProposalProcedure (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))]
-> [(Word32,
     (ProposalProcedure (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Word32
0 ..] ([(ProposalProcedure (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))]
 -> [(Word32,
      (ProposalProcedure (ShelleyLedgerEra era),
       BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))])
-> [(ProposalProcedure (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))]
-> [(Word32,
     (ProposalProcedure (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))]
forall a b. (a -> b) -> a -> b
$ OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))
-> [Item
      (OMap
         (ProposalProcedure (ShelleyLedgerEra era))
         (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))
proposals
  [ (ProposalProcedure (ShelleyLedgerEra era)
proposal, (ScriptWitness WitCtxStake era
 -> (ScriptWitnessIndex, ScriptWitness WitCtxStake era))
-> Maybe (ScriptWitness WitCtxStake era)
-> Maybe (ScriptWitnessIndex, ScriptWitness WitCtxStake era)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word32 -> ScriptWitnessIndex
ScriptWitnessIndexProposing Word32
ix,) Maybe (ScriptWitness WitCtxStake era)
mScriptWitness)
    | (Word32
ix, (ProposalProcedure (ShelleyLedgerEra era)
proposal, BuildTxWith Maybe (ScriptWitness WitCtxStake era)
mScriptWitness)) <- [(Word32,
  (ProposalProcedure (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era))))]
allProposalsList
    ]

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

-- If you extend this type, consider updating:
-- - the 'makeShelleyTransactionBody' function of the relevant era below, and
-- - the @friendly*@ family of functions in cardano-cli.
data TxBodyContent build era
  = TxBodyContent
  { forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns build era
  , forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral :: TxInsCollateral era
  , forall build era. TxBodyContent build era -> TxInsReference era
txInsReference :: TxInsReference era
  , forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
  , forall build era. TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
  , forall build era.
TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
  , forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
  , forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
  , forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
  , forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
  , forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
  , forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
  , forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams :: BuildTxWith build (Maybe (LedgerProtocolParameters era))
  , forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals build era
  , forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates build era
  , forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
  , forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue build era
  , forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity :: TxScriptValidity era
  , forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures build era))
txProposalProcedures :: Maybe (Featured ConwayEraOnwards era (TxProposalProcedures build era))
  , forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures build era))
txVotingProcedures :: Maybe (Featured ConwayEraOnwards era (TxVotingProcedures build era))
  , forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue :: Maybe (Featured ConwayEraOnwards era (Maybe L.Coin))
  -- ^ Current treasury value
  , forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation :: Maybe (Featured ConwayEraOnwards era L.Coin)
  -- ^ Treasury donation to perform
  }
  deriving (TxBodyContent build era -> TxBodyContent build era -> Bool
(TxBodyContent build era -> TxBodyContent build era -> Bool)
-> (TxBodyContent build era -> TxBodyContent build era -> Bool)
-> Eq (TxBodyContent build era)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall build era.
IsShelleyBasedEra era =>
TxBodyContent build era -> TxBodyContent build era -> Bool
$c== :: forall build era.
IsShelleyBasedEra era =>
TxBodyContent build era -> TxBodyContent build era -> Bool
== :: TxBodyContent build era -> TxBodyContent build era -> Bool
$c/= :: forall build era.
IsShelleyBasedEra era =>
TxBodyContent build era -> TxBodyContent build era -> Bool
/= :: TxBodyContent build era -> TxBodyContent build era -> Bool
Eq, Int -> TxBodyContent build era -> ShowS
[TxBodyContent build era] -> ShowS
TxBodyContent build era -> String
(Int -> TxBodyContent build era -> ShowS)
-> (TxBodyContent build era -> String)
-> ([TxBodyContent build era] -> ShowS)
-> Show (TxBodyContent build era)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall build era.
IsShelleyBasedEra era =>
Int -> TxBodyContent build era -> ShowS
forall build era.
IsShelleyBasedEra era =>
[TxBodyContent build era] -> ShowS
forall build era.
IsShelleyBasedEra era =>
TxBodyContent build era -> String
$cshowsPrec :: forall build era.
IsShelleyBasedEra era =>
Int -> TxBodyContent build era -> ShowS
showsPrec :: Int -> TxBodyContent build era -> ShowS
$cshow :: forall build era.
IsShelleyBasedEra era =>
TxBodyContent build era -> String
show :: TxBodyContent build era -> String
$cshowList :: forall build era.
IsShelleyBasedEra era =>
[TxBodyContent build era] -> ShowS
showList :: [TxBodyContent build era] -> ShowS
Show)

defaultTxBodyContent
  :: ()
  => ShelleyBasedEra era
  -> TxBodyContent BuildTx era
defaultTxBodyContent :: forall era. ShelleyBasedEra era -> TxBodyContent BuildTx era
defaultTxBodyContent ShelleyBasedEra era
era =
  TxBodyContent
    { txIns :: TxIns BuildTx era
txIns = []
    , txInsCollateral :: TxInsCollateral era
txInsCollateral = TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone
    , txInsReference :: TxInsReference era
txInsReference = TxInsReference era
forall era. TxInsReference era
TxInsReferenceNone
    , txOuts :: [TxOut CtxTx era]
txOuts = []
    , txTotalCollateral :: TxTotalCollateral era
txTotalCollateral = TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
    , txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral = TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
    , txFee :: TxFee era
txFee = ShelleyBasedEra era -> TxFee era
forall era. ShelleyBasedEra era -> TxFee era
defaultTxFee ShelleyBasedEra era
era
    , txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound = TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
    , txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound = ShelleyBasedEra era -> TxValidityUpperBound era
forall era. ShelleyBasedEra era -> TxValidityUpperBound era
defaultTxValidityUpperBound ShelleyBasedEra era
era
    , txMetadata :: TxMetadataInEra era
txMetadata = TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone
    , txAuxScripts :: TxAuxScripts era
txAuxScripts = TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
    , txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits = TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
    , txProtocolParams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams = Maybe (LedgerProtocolParameters era)
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Maybe (LedgerProtocolParameters era)
forall a. Maybe a
Nothing
    , txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals = TxWithdrawals BuildTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
    , txCertificates :: TxCertificates BuildTx era
txCertificates = TxCertificates BuildTx era
forall build era. TxCertificates build era
TxCertificatesNone
    , txUpdateProposal :: TxUpdateProposal era
txUpdateProposal = TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
    , txMintValue :: TxMintValue BuildTx era
txMintValue = TxMintValue BuildTx era
forall build era. TxMintValue build era
TxMintNone
    , txScriptValidity :: TxScriptValidity era
txScriptValidity = TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
    , txProposalProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures = Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
forall a. Maybe a
Nothing
    , txVotingProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures = Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
forall a. Maybe a
Nothing
    , txCurrentTreasuryValue :: Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue = Maybe (Featured ConwayEraOnwards era (Maybe Coin))
forall a. Maybe a
Nothing
    , txTreasuryDonation :: Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation = Maybe (Featured ConwayEraOnwards era Coin)
forall a. Maybe a
Nothing
    }

setTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era
setTxIns :: forall build era.
TxIns build era
-> TxBodyContent build era -> TxBodyContent build era
setTxIns TxIns build era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txIns = v}

modTxIns
  :: (TxIns build era -> TxIns build era) -> TxBodyContent build era -> TxBodyContent build era
modTxIns :: forall build era.
(TxIns build era -> TxIns build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxIns TxIns build era -> TxIns build era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txIns = f (txIns txBodyContent)}

addTxIn
  :: (TxIn, BuildTxWith build (Witness WitCtxTxIn era))
  -> TxBodyContent build era
  -> TxBodyContent build era
addTxIn :: forall build era.
(TxIn, BuildTxWith build (Witness WitCtxTxIn era))
-> TxBodyContent build era -> TxBodyContent build era
addTxIn (TxIn, BuildTxWith build (Witness WitCtxTxIn era))
txIn = (TxIns build era -> TxIns build era)
-> TxBodyContent build era -> TxBodyContent build era
forall build era.
(TxIns build era -> TxIns build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxIns ((TxIn, BuildTxWith build (Witness WitCtxTxIn era))
txIn (TxIn, BuildTxWith build (Witness WitCtxTxIn era))
-> TxIns build era -> TxIns build era
forall a. a -> [a] -> [a]
:)

addTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era
addTxIns :: forall build era.
TxIns build era
-> TxBodyContent build era -> TxBodyContent build era
addTxIns TxIns build era
txIns = (TxIns build era -> TxIns build era)
-> TxBodyContent build era -> TxBodyContent build era
forall build era.
(TxIns build era -> TxIns build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxIns (TxIns build era -> TxIns build era -> TxIns build era
forall a. Semigroup a => a -> a -> a
<> TxIns build era
txIns)

setTxInsCollateral :: TxInsCollateral era -> TxBodyContent build era -> TxBodyContent build era
setTxInsCollateral :: forall era build.
TxInsCollateral era
-> TxBodyContent build era -> TxBodyContent build era
setTxInsCollateral TxInsCollateral era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txInsCollateral = v}

modTxInsCollateral
  :: (TxInsCollateral era -> TxInsCollateral era) -> TxBodyContent build era -> TxBodyContent build era
modTxInsCollateral :: forall era build.
(TxInsCollateral era -> TxInsCollateral era)
-> TxBodyContent build era -> TxBodyContent build era
modTxInsCollateral TxInsCollateral era -> TxInsCollateral era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txInsCollateral = f (txInsCollateral txBodyContent)}

addTxInsCollateral
  :: IsAlonzoBasedEra era => [TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsCollateral :: forall era build.
IsAlonzoBasedEra era =>
[TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsCollateral [TxIn]
txInsCollateral =
  (TxInsCollateral era -> TxInsCollateral era)
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
(TxInsCollateral era -> TxInsCollateral era)
-> TxBodyContent build era -> TxBodyContent build era
modTxInsCollateral
    ( \case
        TxInsCollateral era
TxInsCollateralNone -> AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
forall era. AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
TxInsCollateral AlonzoEraOnwards era
forall era. IsAlonzoBasedEra era => AlonzoEraOnwards era
alonzoBasedEra [TxIn]
txInsCollateral
        TxInsCollateral AlonzoEraOnwards era
era [TxIn]
xs -> AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
forall era. AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
TxInsCollateral AlonzoEraOnwards era
era ([TxIn]
xs [TxIn] -> [TxIn] -> [TxIn]
forall a. Semigroup a => a -> a -> a
<> [TxIn]
txInsCollateral)
    )

addTxInCollateral
  :: IsAlonzoBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInCollateral :: forall era build.
IsAlonzoBasedEra era =>
TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInCollateral TxIn
txInCollateral = [TxIn] -> TxBodyContent build era -> TxBodyContent build era
forall era build.
IsAlonzoBasedEra era =>
[TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsCollateral [TxIn
txInCollateral]

setTxInsReference :: TxInsReference era -> TxBodyContent build era -> TxBodyContent build era
setTxInsReference :: forall era build.
TxInsReference era
-> TxBodyContent build era -> TxBodyContent build era
setTxInsReference TxInsReference era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txInsReference = v}

modTxInsReference
  :: (TxInsReference era -> TxInsReference era) -> TxBodyContent build era -> TxBodyContent build era
modTxInsReference :: forall era build.
(TxInsReference era -> TxInsReference era)
-> TxBodyContent build era -> TxBodyContent build era
modTxInsReference TxInsReference era -> TxInsReference era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txInsReference = f (txInsReference txBodyContent)}

addTxInsReference
  :: IsBabbageBasedEra era => [TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsReference :: forall era build.
IsBabbageBasedEra era =>
[TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsReference [TxIn]
txInsReference =
  (TxInsReference era -> TxInsReference era)
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
(TxInsReference era -> TxInsReference era)
-> TxBodyContent build era -> TxBodyContent build era
modTxInsReference
    ( \case
        TxInsReference era
TxInsReferenceNone -> BabbageEraOnwards era -> [TxIn] -> TxInsReference era
forall era. BabbageEraOnwards era -> [TxIn] -> TxInsReference era
TxInsReference BabbageEraOnwards era
forall era. IsBabbageBasedEra era => BabbageEraOnwards era
babbageBasedEra [TxIn]
txInsReference
        TxInsReference BabbageEraOnwards era
era [TxIn]
xs -> BabbageEraOnwards era -> [TxIn] -> TxInsReference era
forall era. BabbageEraOnwards era -> [TxIn] -> TxInsReference era
TxInsReference BabbageEraOnwards era
era ([TxIn]
xs [TxIn] -> [TxIn] -> [TxIn]
forall a. Semigroup a => a -> a -> a
<> [TxIn]
txInsReference)
    )

addTxInReference
  :: IsBabbageBasedEra era => TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInReference :: forall era build.
IsBabbageBasedEra era =>
TxIn -> TxBodyContent build era -> TxBodyContent build era
addTxInReference TxIn
txInReference = [TxIn] -> TxBodyContent build era -> TxBodyContent build era
forall era build.
IsBabbageBasedEra era =>
[TxIn] -> TxBodyContent build era -> TxBodyContent build era
addTxInsReference [TxIn
txInReference]

setTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era
setTxOuts :: forall era build.
[TxOut CtxTx era]
-> TxBodyContent build era -> TxBodyContent build era
setTxOuts [TxOut CtxTx era]
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txOuts = v}

modTxOuts
  :: ([TxOut CtxTx era] -> [TxOut CtxTx era]) -> TxBodyContent build era -> TxBodyContent build era
modTxOuts :: forall era build.
([TxOut CtxTx era] -> [TxOut CtxTx era])
-> TxBodyContent build era -> TxBodyContent build era
modTxOuts [TxOut CtxTx era] -> [TxOut CtxTx era]
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txOuts = f (txOuts txBodyContent)}

addTxOut :: TxOut CtxTx era -> TxBodyContent build era -> TxBodyContent build era
addTxOut :: forall era build.
TxOut CtxTx era
-> TxBodyContent build era -> TxBodyContent build era
addTxOut TxOut CtxTx era
txOut = ([TxOut CtxTx era] -> [TxOut CtxTx era])
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
([TxOut CtxTx era] -> [TxOut CtxTx era])
-> TxBodyContent build era -> TxBodyContent build era
modTxOuts (TxOut CtxTx era
txOut TxOut CtxTx era -> [TxOut CtxTx era] -> [TxOut CtxTx era]
forall a. a -> [a] -> [a]
:)

addTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era
addTxOuts :: forall era build.
[TxOut CtxTx era]
-> TxBodyContent build era -> TxBodyContent build era
addTxOuts [TxOut CtxTx era]
txOuts = ([TxOut CtxTx era] -> [TxOut CtxTx era])
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
([TxOut CtxTx era] -> [TxOut CtxTx era])
-> TxBodyContent build era -> TxBodyContent build era
modTxOuts ([TxOut CtxTx era] -> [TxOut CtxTx era] -> [TxOut CtxTx era]
forall a. Semigroup a => a -> a -> a
<> [TxOut CtxTx era]
txOuts)

setTxTotalCollateral :: TxTotalCollateral era -> TxBodyContent build era -> TxBodyContent build era
setTxTotalCollateral :: forall era build.
TxTotalCollateral era
-> TxBodyContent build era -> TxBodyContent build era
setTxTotalCollateral TxTotalCollateral era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txTotalCollateral = v}

modTxTotalCollateral
  :: (TxTotalCollateral era -> TxTotalCollateral era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxTotalCollateral :: forall era build.
(TxTotalCollateral era -> TxTotalCollateral era)
-> TxBodyContent build era -> TxBodyContent build era
modTxTotalCollateral TxTotalCollateral era -> TxTotalCollateral era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txTotalCollateral = f (txTotalCollateral txBodyContent)}

setTxReturnCollateral
  :: TxReturnCollateral CtxTx era -> TxBodyContent build era -> TxBodyContent build era
setTxReturnCollateral :: forall era build.
TxReturnCollateral CtxTx era
-> TxBodyContent build era -> TxBodyContent build era
setTxReturnCollateral TxReturnCollateral CtxTx era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txReturnCollateral = v}

modTxReturnCollateral
  :: (TxReturnCollateral CtxTx era -> TxReturnCollateral CtxTx era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxReturnCollateral :: forall era build.
(TxReturnCollateral CtxTx era -> TxReturnCollateral CtxTx era)
-> TxBodyContent build era -> TxBodyContent build era
modTxReturnCollateral TxReturnCollateral CtxTx era -> TxReturnCollateral CtxTx era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txReturnCollateral = f (txReturnCollateral txBodyContent)}

setTxFee :: TxFee era -> TxBodyContent build era -> TxBodyContent build era
setTxFee :: forall era build.
TxFee era -> TxBodyContent build era -> TxBodyContent build era
setTxFee TxFee era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txFee = v}

modTxFee
  :: (TxFee era -> TxFee era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxFee :: forall era build.
(TxFee era -> TxFee era)
-> TxBodyContent build era -> TxBodyContent build era
modTxFee TxFee era -> TxFee era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txFee = f (txFee txBodyContent)}

setTxValidityLowerBound
  :: TxValidityLowerBound era -> TxBodyContent build era -> TxBodyContent build era
setTxValidityLowerBound :: forall era build.
TxValidityLowerBound era
-> TxBodyContent build era -> TxBodyContent build era
setTxValidityLowerBound TxValidityLowerBound era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txValidityLowerBound = v}

modTxValidityLowerBound
  :: (TxValidityLowerBound era -> TxValidityLowerBound era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxValidityLowerBound :: forall era build.
(TxValidityLowerBound era -> TxValidityLowerBound era)
-> TxBodyContent build era -> TxBodyContent build era
modTxValidityLowerBound TxValidityLowerBound era -> TxValidityLowerBound era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txValidityLowerBound = f (txValidityLowerBound txBodyContent)}

setTxValidityUpperBound
  :: TxValidityUpperBound era -> TxBodyContent build era -> TxBodyContent build era
setTxValidityUpperBound :: forall era build.
TxValidityUpperBound era
-> TxBodyContent build era -> TxBodyContent build era
setTxValidityUpperBound TxValidityUpperBound era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txValidityUpperBound = v}

modTxValidityUpperBound
  :: (TxValidityUpperBound era -> TxValidityUpperBound era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxValidityUpperBound :: forall era build.
(TxValidityUpperBound era -> TxValidityUpperBound era)
-> TxBodyContent build era -> TxBodyContent build era
modTxValidityUpperBound TxValidityUpperBound era -> TxValidityUpperBound era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txValidityUpperBound = f (txValidityUpperBound txBodyContent)}

setTxMetadata :: TxMetadataInEra era -> TxBodyContent build era -> TxBodyContent build era
setTxMetadata :: forall era build.
TxMetadataInEra era
-> TxBodyContent build era -> TxBodyContent build era
setTxMetadata TxMetadataInEra era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txMetadata = v}

modTxMetadata
  :: (TxMetadataInEra era -> TxMetadataInEra era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxMetadata :: forall era build.
(TxMetadataInEra era -> TxMetadataInEra era)
-> TxBodyContent build era -> TxBodyContent build era
modTxMetadata TxMetadataInEra era -> TxMetadataInEra era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txMetadata = f (txMetadata txBodyContent)}

setTxAuxScripts :: TxAuxScripts era -> TxBodyContent build era -> TxBodyContent build era
setTxAuxScripts :: forall era build.
TxAuxScripts era
-> TxBodyContent build era -> TxBodyContent build era
setTxAuxScripts TxAuxScripts era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txAuxScripts = v}

modTxAuxScripts
  :: (TxAuxScripts era -> TxAuxScripts era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxAuxScripts :: forall era build.
(TxAuxScripts era -> TxAuxScripts era)
-> TxBodyContent build era -> TxBodyContent build era
modTxAuxScripts TxAuxScripts era -> TxAuxScripts era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txAuxScripts = f (txAuxScripts txBodyContent)}

setTxExtraKeyWits :: TxExtraKeyWitnesses era -> TxBodyContent build era -> TxBodyContent build era
setTxExtraKeyWits :: forall era build.
TxExtraKeyWitnesses era
-> TxBodyContent build era -> TxBodyContent build era
setTxExtraKeyWits TxExtraKeyWitnesses era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txExtraKeyWits = v}

modTxExtraKeyWits
  :: (TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxExtraKeyWits :: forall era build.
(TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era)
-> TxBodyContent build era -> TxBodyContent build era
modTxExtraKeyWits TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txExtraKeyWits = f (txExtraKeyWits txBodyContent)}

addTxExtraKeyWits
  :: IsAlonzoBasedEra era => [Hash PaymentKey] -> TxBodyContent build era -> TxBodyContent build era
addTxExtraKeyWits :: forall era build.
IsAlonzoBasedEra era =>
[Hash PaymentKey]
-> TxBodyContent build era -> TxBodyContent build era
addTxExtraKeyWits [Hash PaymentKey]
vks =
  (TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era)
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
(TxExtraKeyWitnesses era -> TxExtraKeyWitnesses era)
-> TxBodyContent build era -> TxBodyContent build era
modTxExtraKeyWits
    ( \case
        TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone ->
          AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
forall era.
AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses AlonzoEraOnwards era
forall era. IsAlonzoBasedEra era => AlonzoEraOnwards era
alonzoBasedEra [Hash PaymentKey]
vks
        TxExtraKeyWitnesses AlonzoEraOnwards era
era [Hash PaymentKey]
vks' ->
          AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
forall era.
AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses AlonzoEraOnwards era
era ([Hash PaymentKey]
vks' [Hash PaymentKey] -> [Hash PaymentKey] -> [Hash PaymentKey]
forall a. Semigroup a => a -> a -> a
<> [Hash PaymentKey]
vks)
    )

setTxProtocolParams
  :: BuildTxWith build (Maybe (LedgerProtocolParameters era))
  -> TxBodyContent build era
  -> TxBodyContent build era
setTxProtocolParams :: forall build era.
BuildTxWith build (Maybe (LedgerProtocolParameters era))
-> TxBodyContent build era -> TxBodyContent build era
setTxProtocolParams BuildTxWith build (Maybe (LedgerProtocolParameters era))
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txProtocolParams = v}

setTxWithdrawals :: TxWithdrawals build era -> TxBodyContent build era -> TxBodyContent build era
setTxWithdrawals :: forall build era.
TxWithdrawals build era
-> TxBodyContent build era -> TxBodyContent build era
setTxWithdrawals TxWithdrawals build era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txWithdrawals = v}

modTxWithdrawals
  :: (TxWithdrawals build era -> TxWithdrawals build era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxWithdrawals :: forall build era.
(TxWithdrawals build era -> TxWithdrawals build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxWithdrawals TxWithdrawals build era -> TxWithdrawals build era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txWithdrawals = f (txWithdrawals txBodyContent)}

setTxCertificates :: TxCertificates build era -> TxBodyContent build era -> TxBodyContent build era
setTxCertificates :: forall build era.
TxCertificates build era
-> TxBodyContent build era -> TxBodyContent build era
setTxCertificates TxCertificates build era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txCertificates = v}

modTxCertificates
  :: (TxCertificates build era -> TxCertificates build era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxCertificates :: forall build era.
(TxCertificates build era -> TxCertificates build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxCertificates TxCertificates build era -> TxCertificates build era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txCertificates = f (txCertificates txBodyContent)}

setTxUpdateProposal :: TxUpdateProposal era -> TxBodyContent build era -> TxBodyContent build era
setTxUpdateProposal :: forall era build.
TxUpdateProposal era
-> TxBodyContent build era -> TxBodyContent build era
setTxUpdateProposal TxUpdateProposal era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txUpdateProposal = v}

modTxUpdateProposal
  :: (TxUpdateProposal era -> TxUpdateProposal era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxUpdateProposal :: forall era build.
(TxUpdateProposal era -> TxUpdateProposal era)
-> TxBodyContent build era -> TxBodyContent build era
modTxUpdateProposal TxUpdateProposal era -> TxUpdateProposal era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txUpdateProposal = f (txUpdateProposal txBodyContent)}

setTxMintValue :: TxMintValue build era -> TxBodyContent build era -> TxBodyContent build era
setTxMintValue :: forall build era.
TxMintValue build era
-> TxBodyContent build era -> TxBodyContent build era
setTxMintValue TxMintValue build era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txMintValue = v}

modTxMintValue
  :: (TxMintValue build era -> TxMintValue build era)
  -> TxBodyContent build era
  -> TxBodyContent build era
modTxMintValue :: forall build era.
(TxMintValue build era -> TxMintValue build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxMintValue TxMintValue build era -> TxMintValue build era
f TxBodyContent build era
tx = TxBodyContent build era
tx{txMintValue = f (txMintValue tx)}

addTxMintValue
  :: IsMaryBasedEra era
  => Map PolicyId (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
  -> TxBodyContent build era
  -> TxBodyContent build era
addTxMintValue :: forall era build.
IsMaryBasedEra era =>
Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxBodyContent build era -> TxBodyContent build era
addTxMintValue Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
assets =
  (TxMintValue build era -> TxMintValue build era)
-> TxBodyContent build era -> TxBodyContent build era
forall build era.
(TxMintValue build era -> TxMintValue build era)
-> TxBodyContent build era -> TxBodyContent build era
modTxMintValue
    ( \case
        TxMintValue build era
TxMintNone -> MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
forall era. IsMaryBasedEra era => MaryEraOnwards era
maryBasedEra Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
assets
        TxMintValue MaryEraOnwards era
era Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
t -> MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
era (Map
   PolicyId
   (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> TxMintValue build era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
forall a b. (a -> b) -> a -> b
$ ((PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> (PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era)))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\(PolicyAssets
v1, BuildTxWith build (ScriptWitness WitCtxMint era)
w1) (PolicyAssets
v2, BuildTxWith build (ScriptWitness WitCtxMint era)
_w2) -> (PolicyAssets
v1 PolicyAssets -> PolicyAssets -> PolicyAssets
forall a. Semigroup a => a -> a -> a
<> PolicyAssets
v2, BuildTxWith build (ScriptWitness WitCtxMint era)
w1)) Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
assets Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
t -- w1 == w2
    )

-- | Adds the negation of the provided assets and quantities to the txMintValue field of the `TxBodyContent`.
subtractTxMintValue
  :: IsMaryBasedEra era
  => Map PolicyId (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
  -> TxBodyContent build era
  -> TxBodyContent build era
subtractTxMintValue :: forall era build.
IsMaryBasedEra era =>
Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxBodyContent build era -> TxBodyContent build era
subtractTxMintValue Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
assets = Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxBodyContent build era -> TxBodyContent build era
forall era build.
IsMaryBasedEra era =>
Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxBodyContent build era -> TxBodyContent build era
addTxMintValue (Map
   PolicyId
   (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> TxBodyContent build era -> TxBodyContent build era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxBodyContent build era
-> TxBodyContent build era
forall a b. (a -> b) -> a -> b
$ (PolicyAssets -> PolicyAssets)
-> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((Element PolicyAssets -> Element PolicyAssets)
-> PolicyAssets -> PolicyAssets
forall mono.
MonoFunctor mono =>
(Element mono -> Element mono) -> mono -> mono
omap Element PolicyAssets -> Element PolicyAssets
Quantity -> Quantity
forall a. Num a => a -> a
negate) ((PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
 -> (PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era)))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
assets

setTxScriptValidity :: TxScriptValidity era -> TxBodyContent build era -> TxBodyContent build era
setTxScriptValidity :: forall era build.
TxScriptValidity era
-> TxBodyContent build era -> TxBodyContent build era
setTxScriptValidity TxScriptValidity era
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txScriptValidity = v}

modTxScriptValidity
  :: (TxScriptValidity era -> TxScriptValidity era) -> TxBodyContent build era -> TxBodyContent build era
modTxScriptValidity :: forall era build.
(TxScriptValidity era -> TxScriptValidity era)
-> TxBodyContent build era -> TxBodyContent build era
modTxScriptValidity TxScriptValidity era -> TxScriptValidity era
f TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txScriptValidity = f (txScriptValidity txBodyContent)}

setTxProposalProcedures
  :: Maybe (Featured ConwayEraOnwards era (TxProposalProcedures build era))
  -> TxBodyContent build era
  -> TxBodyContent build era
setTxProposalProcedures :: forall era build.
Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures build era))
-> TxBodyContent build era -> TxBodyContent build era
setTxProposalProcedures Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures build era))
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txProposalProcedures = v}

setTxVotingProcedures
  :: Maybe (Featured ConwayEraOnwards era (TxVotingProcedures build era))
  -> TxBodyContent build era
  -> TxBodyContent build era
setTxVotingProcedures :: forall era build.
Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures build era))
-> TxBodyContent build era -> TxBodyContent build era
setTxVotingProcedures Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures build era))
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txVotingProcedures = v}

setTxCurrentTreasuryValue
  :: Maybe (Featured ConwayEraOnwards era (Maybe L.Coin))
  -> TxBodyContent build era
  -> TxBodyContent build era
setTxCurrentTreasuryValue :: forall era build.
Maybe (Featured ConwayEraOnwards era (Maybe Coin))
-> TxBodyContent build era -> TxBodyContent build era
setTxCurrentTreasuryValue Maybe (Featured ConwayEraOnwards era (Maybe Coin))
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txCurrentTreasuryValue = v}

setTxTreasuryDonation
  :: Maybe (Featured ConwayEraOnwards era L.Coin) -> TxBodyContent build era -> TxBodyContent build era
setTxTreasuryDonation :: forall era build.
Maybe (Featured ConwayEraOnwards era Coin)
-> TxBodyContent build era -> TxBodyContent build era
setTxTreasuryDonation Maybe (Featured ConwayEraOnwards era Coin)
v TxBodyContent build era
txBodyContent = TxBodyContent build era
txBodyContent{txTreasuryDonation = v}

getTxIdByron :: Byron.ATxAux ByteString -> TxId
getTxIdByron :: ATxAux ByteString -> TxId
getTxIdByron (Byron.ATxAux{aTaTx :: forall a. ATxAux a -> Annotated Tx a
Byron.aTaTx = Annotated Tx ByteString
txbody}) =
  Hash HASH EraIndependentTxBody -> TxId
TxId
    (Hash HASH EraIndependentTxBody -> TxId)
-> (Annotated Tx ByteString -> Hash HASH EraIndependentTxBody)
-> Annotated Tx ByteString
-> TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash HASH EraIndependentTxBody
-> Maybe (Hash HASH EraIndependentTxBody)
-> Hash HASH EraIndependentTxBody
forall a. a -> Maybe a -> a
fromMaybe Hash HASH EraIndependentTxBody
forall {a}. a
impossible
    (Maybe (Hash HASH EraIndependentTxBody)
 -> Hash HASH EraIndependentTxBody)
-> (Annotated Tx ByteString
    -> Maybe (Hash HASH EraIndependentTxBody))
-> Annotated Tx ByteString
-> Hash HASH EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Maybe (Hash HASH EraIndependentTxBody)
forall h a. HashAlgorithm h => ShortByteString -> Maybe (Hash h a)
Crypto.hashFromBytesShort
    (ShortByteString -> Maybe (Hash HASH EraIndependentTxBody))
-> (Annotated Tx ByteString -> ShortByteString)
-> Annotated Tx ByteString
-> Maybe (Hash HASH EraIndependentTxBody)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AbstractHash Blake2b_256 Tx -> ShortByteString
forall algo a. AbstractHash algo a -> ShortByteString
Byron.abstractHashToShort
    (AbstractHash Blake2b_256 Tx -> ShortByteString)
-> (Annotated Tx ByteString -> AbstractHash Blake2b_256 Tx)
-> Annotated Tx ByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotated Tx ByteString
-> Hash (BaseType (Annotated Tx ByteString))
Annotated Tx ByteString -> AbstractHash Blake2b_256 Tx
forall t. Decoded t => t -> Hash (BaseType t)
Byron.hashDecoded
    (Annotated Tx ByteString -> TxId)
-> Annotated Tx ByteString -> TxId
forall a b. (a -> b) -> a -> b
$ Annotated Tx ByteString
txbody
 where
  impossible :: a
impossible =
    String -> a
forall a. HasCallStack => String -> a
error String
"getTxIdByron: byron and shelley hash sizes do not match"

-- | Calculate the transaction identifier for a 'TxBody'.
getTxId :: TxBody era -> TxId
getTxId :: forall era. TxBody era -> TxId
getTxId (ShelleyTxBody ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
tx [Script (ShelleyLedgerEra era)]
_ TxBodyScriptData era
_ Maybe (TxAuxData (ShelleyLedgerEra era))
_ TxScriptValidity era
_) =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxId) -> TxId
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxId) -> TxId)
-> (ShelleyBasedEraConstraints era => TxId) -> TxId
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
forall era.
EraTxBody (ShelleyLedgerEra era) =>
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
tx

getTxIdShelley
  :: Ledger.EraTxBody (ShelleyLedgerEra era)
  => ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxId
getTxIdShelley :: forall era.
EraTxBody (ShelleyLedgerEra era) =>
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley ShelleyBasedEra era
_ TxBody (ShelleyLedgerEra era)
tx =
  Hash HASH EraIndependentTxBody -> TxId
TxId
    (Hash HASH EraIndependentTxBody -> TxId)
-> (TxId -> Hash HASH EraIndependentTxBody) -> TxId -> TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash HASH EraIndependentTxBody -> Hash HASH EraIndependentTxBody
forall h a b. Hash h a -> Hash h b
Crypto.castHash
    (Hash HASH EraIndependentTxBody -> Hash HASH EraIndependentTxBody)
-> (TxId -> Hash HASH EraIndependentTxBody)
-> TxId
-> Hash HASH EraIndependentTxBody
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(Ledger.TxId SafeHash EraIndependentTxBody
txhash) -> SafeHash EraIndependentTxBody -> Hash HASH EraIndependentTxBody
forall i. SafeHash i -> Hash HASH i
SafeHash.extractHash SafeHash EraIndependentTxBody
txhash)
    (TxId -> TxId) -> TxId -> TxId
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era) -> TxId
forall era. EraTxBody era => TxBody era -> TxId
Ledger.txIdTxBody TxBody (ShelleyLedgerEra era)
tx

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

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

renderBuildable :: Buildable a => a -> Text
renderBuildable :: forall a. Buildable a => a -> Text
renderBuildable a
e = LazyText -> Text
LText.toStrict (LazyText -> Text) -> (Builder -> LazyText) -> Builder -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> LazyText
LText.toLazyText (Builder -> Text) -> Builder -> Text
forall a b. (a -> b) -> a -> b
$ a -> Builder
forall p. Buildable p => p -> Builder
Build.build a
e

instance Error TxBodyError where
  prettyError :: forall ann. TxBodyError -> Doc ann
prettyError = \case
    TxBodyPlutusScriptDecodeError DecoderError
err ->
      Doc ann
"Error decoding Plutus script: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (DecoderError -> Text
forall a. Buildable a => a -> Text
renderBuildable DecoderError
err)
    TxBodyError
TxBodyEmptyTxIns ->
      Doc ann
"Transaction body has no inputs"
    TxBodyError
TxBodyEmptyTxInsCollateral ->
      Doc ann
"Transaction body has no collateral inputs, but uses Plutus scripts"
    TxBodyError
TxBodyEmptyTxOuts ->
      Doc ann
"Transaction body has no outputs"
    TxBodyOutputNegative (Quantity Integer
q) TxOutInAnyEra
txout ->
      Doc ann
"Negative quantity ("
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Integer -> Doc ann
forall ann. Integer -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Integer
q
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
") in transaction output: "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TxOutInAnyEra -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. TxOutInAnyEra -> Doc ann
pretty TxOutInAnyEra
txout
    TxBodyOutputOverflow (Quantity Integer
q) TxOutInAnyEra
txout ->
      Doc ann
"Quantity too large ("
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Integer -> Doc ann
forall ann. Integer -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Integer
q
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" >= 2^64) in transaction output: "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TxOutInAnyEra -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. TxOutInAnyEra -> Doc ann
pretty TxOutInAnyEra
txout
    TxBodyMetadataError [(Word64
k, TxMetadataRangeError
err)] ->
      Doc ann
"Error in metadata entry " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Word64 -> Doc ann
forall ann. Word64 -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Word64
k Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
": " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TxMetadataRangeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. TxMetadataRangeError -> Doc ann
prettyError TxMetadataRangeError
err
    TxBodyMetadataError [(Word64, TxMetadataRangeError)]
errs ->
      [Doc ann] -> Doc ann
forall a. Monoid a => [a] -> a
mconcat
        [ Doc ann
"Error in metadata entries: "
        , [Doc ann] -> Doc ann
forall a. Monoid a => [a] -> a
mconcat ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$
            Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
List.intersperse
              Doc ann
"; "
              [ Word64 -> Doc ann
forall ann. Word64 -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Word64
k Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
": " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TxMetadataRangeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. TxMetadataRangeError -> Doc ann
prettyError TxMetadataRangeError
err
              | (Word64
k, TxMetadataRangeError
err) <- [(Word64, TxMetadataRangeError)]
errs
              ]
        ]
    TxBodyError
TxBodyMissingProtocolParams ->
      Doc ann
"Transaction uses Plutus scripts but does not provide the protocol "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"parameters to hash"
    TxBodyInIxOverflow TxIn
txin ->
      Doc ann
"Transaction input index is too big, "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"acceptable value is up to 2^32-1, "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"in input "
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TxIn -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. TxIn -> Doc ann
pretty TxIn
txin
    TxBodyProtocolParamsConversionError ProtocolParametersConversionError
ppces ->
      Doc ann
"Errors in protocol parameters conversion: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> ProtocolParametersConversionError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. ProtocolParametersConversionError -> Doc ann
prettyError ProtocolParametersConversionError
ppces

createTransactionBody
  :: forall era
   . HasCallStack
  => ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> Either TxBodyError (TxBody era)
createTransactionBody :: forall era.
HasCallStack =>
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
createTransactionBody ShelleyBasedEra era
sbe TxBodyContent BuildTx era
bc =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era =>
    Either TxBodyError (TxBody era))
-> Either TxBodyError (TxBody era)
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era =>
  Either TxBodyError (TxBody era))
 -> Either TxBodyError (TxBody era))
-> (ShelleyBasedEraConstraints era =>
    Either TxBodyError (TxBody era))
-> Either TxBodyError (TxBody era)
forall a b. (a -> b) -> a -> b
$ do
    (TxBodyScriptData era
sData, StrictMaybe ScriptIntegrityHash
mScriptIntegrityHash, [Script (ShelleyLedgerEra era)]
scripts) <-
      (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era
 -> Either
      TxBodyError
      (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
       [Script (ShelleyLedgerEra era)]))
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era
    -> Either
         TxBodyError
         (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
          [Script (ShelleyLedgerEra era)]))
-> ShelleyBasedEra era
-> Either
     TxBodyError
     (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
      [Script (ShelleyLedgerEra era)])
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
        ( \ShelleyToMaryEra era
eon -> do
            let scripts :: [Script (ShelleyLedgerEra era)]
scripts =
                  [Maybe (Script (ShelleyLedgerEra era))]
-> [Script (ShelleyLedgerEra era)]
forall a. [Maybe a] -> [a]
catMaybes
                    [ ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Script (ShelleyLedgerEra era))
-> Maybe (ScriptInEra era) -> Maybe (Script (ShelleyLedgerEra era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
getScriptWitnessScript ScriptWitness witctx era
scriptwitness
                    | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness) <-
                        ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses (ShelleyToMaryEra era -> ShelleyBasedEra era
forall era. ShelleyToMaryEra era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert ShelleyToMaryEra era
eon) TxBodyContent BuildTx era
bc
                    ]
            (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
 [Script (ShelleyLedgerEra era)])
-> Either
     TxBodyError
     (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
      [Script (ShelleyLedgerEra era)])
forall a. a -> Either TxBodyError a
forall (m :: * -> *) a. Monad m => a -> m a
return (TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData, StrictMaybe ScriptIntegrityHash
forall a. StrictMaybe a
SNothing, [Script (ShelleyLedgerEra era)]
scripts)
        )
        ( \AlonzoEraOnwards era
aeon -> do
            TxScriptWitnessRequirements Set Language
languages [Script (ShelleyLedgerEra era)]
scripts TxDats (ShelleyLedgerEra era)
dats Redeemers (ShelleyLedgerEra era)
redeemers <-
              AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era.
IsShelleyBasedEra era =>
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
collectTxBodyScriptWitnessRequirements AlonzoEraOnwards era
aeon TxBodyContent BuildTx era
bc

            let pparams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
pparams = TxBodyContent BuildTx era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams TxBodyContent BuildTx era
bc
                sData :: TxBodyScriptData era
sData = AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
AlonzoEraOnwardsConstraints era =>
AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData AlonzoEraOnwards era
aeon TxDats (ShelleyLedgerEra era)
dats Redeemers (ShelleyLedgerEra era)
redeemers
                mScriptIntegrityHash :: StrictMaybe ScriptIntegrityHash
mScriptIntegrityHash = BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language
-> TxBodyScriptData era
-> StrictMaybe ScriptIntegrityHash
forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language
-> TxBodyScriptData era
-> StrictMaybe ScriptIntegrityHash
getScriptIntegrityHash BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
pparams Set Language
languages TxBodyScriptData era
sData
            (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
 [Script (ShelleyLedgerEra era)])
-> Either
     TxBodyError
     (TxBodyScriptData era, StrictMaybe ScriptIntegrityHash,
      [Script (ShelleyLedgerEra era)])
forall a. a -> Either TxBodyError a
forall (m :: * -> *) a. Monad m => a -> m a
return
              ( TxBodyScriptData era
sData
              , StrictMaybe ScriptIntegrityHash
mScriptIntegrityHash
              , [Script (ShelleyLedgerEra era)]
[AlonzoScript (ShelleyLedgerEra era)]
scripts
              )
        )
        ShelleyBasedEra era
sbe
    let era :: CardanoEra era
era = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe

        apiScriptValidity :: TxScriptValidity era
apiScriptValidity = TxBodyContent BuildTx era -> TxScriptValidity era
forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity TxBodyContent BuildTx era
bc
        apiMintValue :: TxMintValue BuildTx era
apiMintValue = TxBodyContent BuildTx era -> TxMintValue BuildTx era
forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue TxBodyContent BuildTx era
bc
        apiCollateralTxIns :: TxInsCollateral era
apiCollateralTxIns = TxBodyContent BuildTx era -> TxInsCollateral era
forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral TxBodyContent BuildTx era
bc
        apiReferenceInputs :: TxInsReference era
apiReferenceInputs = TxBodyContent BuildTx era -> TxInsReference era
forall build era. TxBodyContent build era -> TxInsReference era
txInsReference TxBodyContent BuildTx era
bc
        apiExtraKeyWitnesses :: TxExtraKeyWitnesses era
apiExtraKeyWitnesses = TxBodyContent BuildTx era -> TxExtraKeyWitnesses era
forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits TxBodyContent BuildTx era
bc
        apiReturnCollateral :: TxReturnCollateral CtxTx era
apiReturnCollateral = TxBodyContent BuildTx era -> TxReturnCollateral CtxTx era
forall build era.
TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral TxBodyContent BuildTx era
bc
        apiTotalCollateral :: TxTotalCollateral era
apiTotalCollateral = TxBodyContent BuildTx era -> TxTotalCollateral era
forall build era. TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral TxBodyContent BuildTx era
bc

        -- Ledger types
        collTxIns :: Set TxIn
collTxIns = TxInsCollateral era -> Set TxIn
forall era. TxInsCollateral era -> Set TxIn
convCollateralTxIns TxInsCollateral era
apiCollateralTxIns
        refTxIns :: Set TxIn
refTxIns = TxInsReference era -> Set TxIn
forall era. TxInsReference era -> Set TxIn
convReferenceInputs TxInsReference era
apiReferenceInputs
        returnCollateral :: StrictMaybe (TxOut (ShelleyLedgerEra era))
returnCollateral = ShelleyBasedEra era
-> TxReturnCollateral CtxTx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall era ctx.
ShelleyBasedEra era
-> TxReturnCollateral ctx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
convReturnCollateral ShelleyBasedEra era
sbe TxReturnCollateral CtxTx era
apiReturnCollateral
        totalCollateral :: StrictMaybe Coin
totalCollateral = TxTotalCollateral era -> StrictMaybe Coin
forall era. TxTotalCollateral era -> StrictMaybe Coin
convTotalCollateral TxTotalCollateral era
apiTotalCollateral
        certs :: StrictSeq (TxCert (ShelleyLedgerEra era))
certs = ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe (TxCertificates BuildTx era
 -> StrictSeq (TxCert (ShelleyLedgerEra era)))
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ TxBodyContent BuildTx era -> TxCertificates BuildTx era
forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates TxBodyContent BuildTx era
bc
        txAuxData :: Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe (TxBodyContent BuildTx era -> TxMetadataInEra era
forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata TxBodyContent BuildTx era
bc) (TxBodyContent BuildTx era -> TxAuxScripts era
forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts TxBodyContent BuildTx era
bc)

        proposalProcedures :: OSet (ProposalProcedure (ShelleyLedgerEra era))
proposalProcedures = TxProposalProcedures BuildTx era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall build era.
TxProposalProcedures build era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures (TxProposalProcedures BuildTx era
 -> OSet (ProposalProcedure (ShelleyLedgerEra era)))
-> TxProposalProcedures BuildTx era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ TxProposalProcedures BuildTx era
-> (Featured
      ConwayEraOnwards era (TxProposalProcedures BuildTx era)
    -> TxProposalProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> TxProposalProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxProposalProcedures BuildTx era
forall build era. TxProposalProcedures build era
TxProposalProceduresNone Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (TxBodyContent BuildTx era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures build era))
txProposalProcedures TxBodyContent BuildTx era
bc)
        votingProcedures :: VotingProcedures (ShelleyLedgerEra era)
votingProcedures = TxVotingProcedures BuildTx era
-> VotingProcedures (ShelleyLedgerEra era)
forall build era.
TxVotingProcedures build era
-> VotingProcedures (ShelleyLedgerEra era)
convVotingProcedures (TxVotingProcedures BuildTx era
 -> VotingProcedures (ShelleyLedgerEra era))
-> TxVotingProcedures BuildTx era
-> VotingProcedures (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$ TxVotingProcedures BuildTx era
-> (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
    -> TxVotingProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
-> TxVotingProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxVotingProcedures BuildTx era
forall build era. TxVotingProcedures build era
TxVotingProceduresNone Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
-> TxVotingProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (TxBodyContent BuildTx era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures build era))
txVotingProcedures TxBodyContent BuildTx era
bc)
        currentTreasuryValue :: StrictMaybe Coin
currentTreasuryValue = Maybe Coin -> StrictMaybe Coin
forall a. Maybe a -> StrictMaybe a
Ledger.maybeToStrictMaybe (Maybe Coin -> StrictMaybe Coin) -> Maybe Coin -> StrictMaybe Coin
forall a b. (a -> b) -> a -> b
$ Featured ConwayEraOnwards era (Maybe Coin) -> Maybe Coin
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (Featured ConwayEraOnwards era (Maybe Coin) -> Maybe Coin)
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin)) -> Maybe Coin
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TxBodyContent BuildTx era
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue TxBodyContent BuildTx era
bc
        treasuryDonation :: Coin
treasuryDonation = Coin
-> (Featured ConwayEraOnwards era Coin -> Coin)
-> Maybe (Featured ConwayEraOnwards era Coin)
-> Coin
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Coin
0 Featured ConwayEraOnwards era Coin -> Coin
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (Maybe (Featured ConwayEraOnwards era Coin) -> Coin)
-> Maybe (Featured ConwayEraOnwards era Coin) -> Coin
forall a b. (a -> b) -> a -> b
$ TxBodyContent BuildTx era
-> Maybe (Featured ConwayEraOnwards era Coin)
forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation TxBodyContent BuildTx era
bc

    Endo (TxBody era)
setUpdateProposal <- CardanoEra era
-> (ShelleyToBabbageEra era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((ShelleyToBabbageEra era
  -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (ShelleyToBabbageEra era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \ShelleyToBabbageEra era
w ->
      (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (StrictMaybe (Update (ShelleyLedgerEra era))
    -> TxBody era -> TxBody era)
-> StrictMaybe (Update (ShelleyLedgerEra era))
-> Endo (TxBody era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
w ((StrictMaybe (Update (ShelleyLedgerEra era))
  -> Identity (StrictMaybe (Update (ShelleyLedgerEra era))))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update (ShelleyLedgerEra era))
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~) (StrictMaybe (Update (ShelleyLedgerEra era)) -> Endo (TxBody era))
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
-> Either TxBodyError (Endo (TxBody era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe (TxBodyContent BuildTx era -> TxUpdateProposal era
forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal TxBodyContent BuildTx era
bc)

    Endo (TxBody era)
setInvalidBefore <- CardanoEra era
-> (AllegraEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((AllegraEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (AllegraEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \AllegraEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
w ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound (TxBodyContent BuildTx era -> TxValidityLowerBound era
forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound TxBodyContent BuildTx era
bc)

    Endo (TxBody era)
setMint <- CardanoEra era
-> (MaryEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((MaryEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (MaryEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \MaryEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
forall era. MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
A.mintTxBodyL MaryEraOnwards era
w ((MultiAsset -> Identity MultiAsset)
 -> TxBody era -> Identity (TxBody era))
-> MultiAsset -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxMintValue BuildTx era -> MultiAsset
forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue BuildTx era
apiMintValue

    Endo (TxBody era)
setScriptIntegrityHash <- CardanoEra era
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \AlonzoEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$
        (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$
          AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
forall era.
AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
A.scriptIntegrityHashTxBodyL AlonzoEraOnwards era
w ((StrictMaybe ScriptIntegrityHash
  -> Identity (StrictMaybe ScriptIntegrityHash))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe ScriptIntegrityHash -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe ScriptIntegrityHash
mScriptIntegrityHash

    Endo (TxBody era)
setCollateralInputs <- CardanoEra era
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \AlonzoEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.collateralInputsTxBodyL AlonzoEraOnwards era
w ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Set TxIn
collTxIns

    Endo (TxBody era)
setReqSignerHashes <- CardanoEra era
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (AlonzoEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \AlonzoEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
forall era.
AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
A.reqSignerHashesTxBodyL AlonzoEraOnwards era
w ((Set (KeyHash 'Witness) -> Identity (Set (KeyHash 'Witness)))
 -> TxBody era -> Identity (TxBody era))
-> Set (KeyHash 'Witness) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
forall era. TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
convExtraKeyWitnesses TxExtraKeyWitnesses era
apiExtraKeyWitnesses

    Endo (TxBody era)
setReferenceInputs <- CardanoEra era
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((BabbageEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \BabbageEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.referenceInputsTxBodyL BabbageEraOnwards era
w ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Set TxIn
refTxIns

    Endo (TxBody era)
setCollateralReturn <- CardanoEra era
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((BabbageEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \BabbageEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
forall era.
BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
A.collateralReturnTxBodyL BabbageEraOnwards era
w ((StrictMaybe (TxOut (ShelleyLedgerEra era))
  -> Identity (StrictMaybe (TxOut (ShelleyLedgerEra era))))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (TxOut (ShelleyLedgerEra era))
returnCollateral

    Endo (TxBody era)
setTotalCollateral <- CardanoEra era
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((BabbageEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (BabbageEraOnwards era
    -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \BabbageEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
forall era.
BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
A.totalCollateralTxBodyL BabbageEraOnwards era
w ((StrictMaybe Coin -> Identity (StrictMaybe Coin))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe Coin
totalCollateral

    Endo (TxBody era)
setProposalProcedures <- CardanoEra era
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ ConwayEraOnwards era
-> Lens'
     (TxBody era) (OSet (ProposalProcedure (ShelleyLedgerEra era)))
forall era.
ConwayEraOnwards era
-> Lens'
     (TxBody era) (OSet (ProposalProcedure (ShelleyLedgerEra era)))
A.proposalProceduresTxBodyL ConwayEraOnwards era
w ((OSet (ProposalProcedure (ShelleyLedgerEra era))
  -> Identity (OSet (ProposalProcedure (ShelleyLedgerEra era))))
 -> TxBody era -> Identity (TxBody era))
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ OSet (ProposalProcedure (ShelleyLedgerEra era))
proposalProcedures

    Endo (TxBody era)
setVotingProcedures <- CardanoEra era
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ ConwayEraOnwards era
-> Lens' (TxBody era) (VotingProcedures (ShelleyLedgerEra era))
forall era.
ConwayEraOnwards era
-> Lens' (TxBody era) (VotingProcedures (ShelleyLedgerEra era))
A.votingProceduresTxBodyL ConwayEraOnwards era
w ((VotingProcedures (ShelleyLedgerEra era)
  -> Identity (VotingProcedures (ShelleyLedgerEra era)))
 -> TxBody era -> Identity (TxBody era))
-> VotingProcedures (ShelleyLedgerEra era)
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ VotingProcedures (ShelleyLedgerEra era)
votingProcedures

    Endo (TxBody era)
setCurrentTreasuryValue <- CardanoEra era
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ ConwayEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
forall era.
ConwayEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
A.currentTreasuryValueTxBodyL ConwayEraOnwards era
w ((StrictMaybe Coin -> Identity (StrictMaybe Coin))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe Coin
currentTreasuryValue

    Endo (TxBody era)
setTreasuryDonation <- CardanoEra era
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall (eon :: * -> *) (f :: * -> *) a era.
(Eon eon, Applicative f, Monoid a) =>
CardanoEra era -> (eon era -> f a) -> f a
monoidForEraInEonA CardanoEra era
era ((ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
 -> Either TxBodyError (Endo (TxBody era)))
-> (ConwayEraOnwards era -> Either TxBodyError (Endo (TxBody era)))
-> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
      Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era)))
-> Endo (TxBody era) -> Either TxBodyError (Endo (TxBody era))
forall a b. (a -> b) -> a -> b
$ (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a. (a -> a) -> Endo a
Endo ((TxBody era -> TxBody era) -> Endo (TxBody era))
-> (TxBody era -> TxBody era) -> Endo (TxBody era)
forall a b. (a -> b) -> a -> b
$ ConwayEraOnwards era -> Lens' (TxBody era) Coin
forall era. ConwayEraOnwards era -> Lens' (TxBody era) Coin
A.treasuryDonationTxBodyL ConwayEraOnwards era
w ((Coin -> Identity Coin) -> TxBody era -> Identity (TxBody era))
-> Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin
treasuryDonation

    let ledgerTxBody :: TxBody era
ledgerTxBody =
          ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe (TxBodyContent BuildTx era -> TxIns BuildTx era
forall build era. TxBodyContent build era -> TxIns build era
txIns TxBodyContent BuildTx era
bc) (TxBodyContent BuildTx era -> [TxOut CtxTx era]
forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts TxBodyContent BuildTx era
bc) (TxBodyContent BuildTx era -> TxFee era
forall build era. TxBodyContent build era -> TxFee era
txFee TxBodyContent BuildTx era
bc) (TxBodyContent BuildTx era -> TxWithdrawals BuildTx era
forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals TxBodyContent BuildTx era
bc) Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
            TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (TxCert (ShelleyLedgerEra era))
  -> Identity (StrictSeq (TxCert (ShelleyLedgerEra era))))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (TxCert (ShelleyLedgerEra era))
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictSeq (TxCert (ShelleyLedgerEra era))
certs
            TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe (TxBodyContent BuildTx era -> TxValidityUpperBound era
forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound TxBodyContent BuildTx era
bc)
            TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& Endo (TxBody era) -> TxBody era -> TxBody era
forall a. Endo a -> a -> a
appEndo
              ( [Endo (TxBody era)] -> Endo (TxBody era)
forall a. Monoid a => [a] -> a
mconcat
                  [ Endo (TxBody era)
setUpdateProposal
                  , Endo (TxBody era)
setInvalidBefore
                  , Endo (TxBody era)
setMint
                  , Endo (TxBody era)
setScriptIntegrityHash
                  , Endo (TxBody era)
setCollateralInputs
                  , Endo (TxBody era)
setReqSignerHashes
                  , Endo (TxBody era)
setReferenceInputs
                  , Endo (TxBody era)
setCollateralReturn
                  , Endo (TxBody era)
setTotalCollateral
                  , Endo (TxBody era)
setProposalProcedures
                  , Endo (TxBody era)
setVotingProcedures
                  , Endo (TxBody era)
setCurrentTreasuryValue
                  , Endo (TxBody era)
setTreasuryDonation
                  ]
              )

    -- TODO: NetworkId for hardware wallets. We don't always want this
    -- & L.networkIdTxBodyL .~ ...

    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody ShelleyBasedEra era
sbe (TxBody era
ledgerTxBody TxBody era
-> Getting
     (TxBody (ShelleyLedgerEra era))
     (TxBody era)
     (TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall s a. s -> Getting a s a -> a
^. Getting
  (TxBody (ShelleyLedgerEra era))
  (TxBody era)
  (TxBody (ShelleyLedgerEra era))
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL) [Script (ShelleyLedgerEra era)]
scripts TxBodyScriptData era
sData Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData TxScriptValidity era
apiScriptValidity

getScriptIntegrityHash
  :: ()
  => BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
  -> Set Plutus.Language
  -> TxBodyScriptData era
  -> StrictMaybe L.ScriptIntegrityHash
getScriptIntegrityHash :: forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language
-> TxBodyScriptData era
-> StrictMaybe ScriptIntegrityHash
getScriptIntegrityHash BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
apiProtocolParameters Set Language
languages = \case
  TxBodyScriptData era
TxBodyNoScriptData -> StrictMaybe ScriptIntegrityHash
forall a. StrictMaybe a
SNothing
  TxBodyScriptData AlonzoEraOnwards era
w TxDats (ShelleyLedgerEra era)
datums Redeemers (ShelleyLedgerEra era)
redeemers ->
    AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
forall era.
AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
convPParamsToScriptIntegrityHash AlonzoEraOnwards era
w BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
apiProtocolParameters Redeemers (ShelleyLedgerEra era)
redeemers TxDats (ShelleyLedgerEra era)
datums Set Language
languages

validateTxBodyContent
  :: ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> Either TxBodyError ()
validateTxBodyContent :: forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent
  ShelleyBasedEra era
sbe
  txBodContent :: TxBodyContent BuildTx era
txBodContent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    } =
    let witnesses :: [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses = ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txBodContent
        languages :: Set Language
languages =
          [Item (Set Language)] -> Set Language
forall l. IsList l => [Item l] -> l
fromList
            [ AnyPlutusScriptVersion -> Language
toAlonzoLanguage (PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v)
            | (ScriptWitnessIndex
_, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses
            ]
            :: Set Plutus.Language
     in case ShelleyBasedEra era
sbe of
          ShelleyBasedEra era
ShelleyBasedEraShelley -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx era
txIns)
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
          ShelleyBasedEra era
ShelleyBasedEraAllegra -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx era
txIns)
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
          ShelleyBasedEra era
ShelleyBasedEraMary -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx era
txIns)
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
          ShelleyBasedEra era
ShelleyBasedEraAlonzo -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx era
txIns)
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
            TxInsCollateral era -> Set Language -> Either TxBodyError ()
forall era.
TxInsCollateral era -> Set Language -> Either TxBodyError ()
validateTxInsCollateral TxInsCollateral era
txInsCollateral Set Language
languages
            BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
validateProtocolParameters BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams Set Language
languages
          ShelleyBasedEra era
ShelleyBasedEraBabbage -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn
forall a b. (a, b) -> a
fst TxIns BuildTx era
txIns)
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
            TxInsCollateral era -> Set Language -> Either TxBodyError ()
forall era.
TxInsCollateral era -> Set Language -> Either TxBodyError ()
validateTxInsCollateral TxInsCollateral era
txInsCollateral Set Language
languages
            BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
validateProtocolParameters BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams Set Language
languages
          ShelleyBasedEra era
ShelleyBasedEraConway -> do
            TxIns BuildTx era -> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns TxIns BuildTx era
txIns
            ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts
            TxMetadataInEra era -> Either TxBodyError ()
forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata
            TxInsCollateral era -> Set Language -> Either TxBodyError ()
forall era.
TxInsCollateral era -> Set Language -> Either TxBodyError ()
validateTxInsCollateral TxInsCollateral era
txInsCollateral Set Language
languages
            BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
validateProtocolParameters BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams Set Language
languages

validateMetadata :: TxMetadataInEra era -> Either TxBodyError ()
validateMetadata :: forall era. TxMetadataInEra era -> Either TxBodyError ()
validateMetadata TxMetadataInEra era
txMetadata =
  case TxMetadataInEra era
txMetadata of
    TxMetadataInEra era
TxMetadataNone -> () -> Either TxBodyError ()
forall a. a -> Either TxBodyError a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    TxMetadataInEra ShelleyBasedEra era
_ TxMetadata
m -> ([(Word64, TxMetadataRangeError)] -> TxBodyError)
-> Either [(Word64, TxMetadataRangeError)] ()
-> Either TxBodyError ()
forall a b c. (a -> b) -> Either a c -> Either b c
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)

validateProtocolParameters
  :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
  -> Set Plutus.Language
  -> Either TxBodyError ()
validateProtocolParameters :: forall era.
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Set Language -> Either TxBodyError ()
validateProtocolParameters BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams Set Language
languages =
  case BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams of
    BuildTxWith Maybe (LedgerProtocolParameters era)
Nothing
      | Bool -> Bool
not (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages) ->
          TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyMissingProtocolParams
    BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
_ -> () -> Either TxBodyError ()
forall a. a -> Either TxBodyError a
forall (m :: * -> *) a. Monad m => a -> m a
return () -- TODO alonzo: validate protocol params for the Alonzo era.
    --             All the necessary params must be provided.

validateTxIns :: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))] -> Either TxBodyError ()
validateTxIns :: forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
validateTxIns [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns =
  [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
    [ [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
forall a. [(TxIn, a)] -> Either TxBodyError ()
inputIndexDoesNotExceedMax [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns
    , [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
txBodyContentHasTxIns [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
txIns
    ]

validateTxInsCollateral
  :: TxInsCollateral era -> Set Plutus.Language -> Either TxBodyError ()
validateTxInsCollateral :: forall era.
TxInsCollateral era -> Set Language -> Either TxBodyError ()
validateTxInsCollateral TxInsCollateral era
txInsCollateral Set Language
languages =
  case TxInsCollateral era
txInsCollateral of
    TxInsCollateral era
TxInsCollateralNone ->
      Bool -> Either TxBodyError () -> Either TxBodyError ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set Language -> Bool
forall a. Set a -> Bool
Set.null Set Language
languages) (TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left TxBodyError
TxBodyEmptyTxInsCollateral)
    TxInsCollateral AlonzoEraOnwards era
_ [TxIn]
collateralTxIns ->
      [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow [TxIn]
collateralTxIns

validateTxOuts :: ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts :: forall era.
ShelleyBasedEra era -> [TxOut CtxTx era] -> Either TxBodyError ()
validateTxOuts ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts = do
  let era :: CardanoEra era
era = ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe
  CardanoEra era
-> (CardanoEraConstraints era => Either TxBodyError ())
-> Either TxBodyError ()
forall era a.
CardanoEra era -> (CardanoEraConstraints era => a) -> a
cardanoEraConstraints CardanoEra era
era ((CardanoEraConstraints era => Either TxBodyError ())
 -> Either TxBodyError ())
-> (CardanoEraConstraints era => Either TxBodyError ())
-> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$
    [Either TxBodyError ()] -> Either TxBodyError ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
      [ do
          CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
forall era.
CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
positiveOutput CardanoEra era
era (TxOutValue era -> Value
forall era. TxOutValue era -> Value
txOutValueToValue TxOutValue era
v) TxOut CtxTx era
txout
          CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
forall era.
CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
outputDoesNotExceedMax CardanoEra era
era (TxOutValue era -> Value
forall era. TxOutValue era -> Value
txOutValueToValue TxOutValue era
v) TxOut CtxTx era
txout
      | txout :: TxOut CtxTx era
txout@(TxOut AddressInEra era
_ TxOutValue era
v TxOutDatum CtxTx era
_ ReferenceScript era
_) <- [TxOut CtxTx era]
txOuts
      ]

inputIndexDoesNotExceedMax :: [(TxIn, a)] -> Either TxBodyError ()
inputIndexDoesNotExceedMax :: forall a. [(TxIn, a)] -> Either TxBodyError ()
inputIndexDoesNotExceedMax [(TxIn, a)]
txIns =
  [(TxIn, a)]
-> ((TxIn, a) -> Either TxBodyError ()) -> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [(TxIn, a)]
txIns (((TxIn, a) -> Either TxBodyError ()) -> Either TxBodyError ())
-> ((TxIn, a) -> Either TxBodyError ()) -> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \(txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)), a
_) ->
    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin

outputDoesNotExceedMax
  :: ()
  => CardanoEra era
  -> Value
  -> TxOut CtxTx era
  -> Either TxBodyError ()
outputDoesNotExceedMax :: forall era.
CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
outputDoesNotExceedMax CardanoEra era
era Value
v TxOut CtxTx era
txout =
  case [Quantity
q | (AssetId
_, Quantity
q) <- Value -> [Item Value]
forall l. IsList l => l -> [Item l]
toList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
> Quantity
maxTxOut] of
    [] -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
    Quantity
q : [Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow Quantity
q (CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
forall era. CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra CardanoEra era
era TxOut CtxTx era
txout))

positiveOutput
  :: ()
  => CardanoEra era
  -> Value
  -> TxOut CtxTx era
  -> Either TxBodyError ()
positiveOutput :: forall era.
CardanoEra era -> Value -> TxOut CtxTx era -> Either TxBodyError ()
positiveOutput CardanoEra era
era Value
v TxOut CtxTx era
txout =
  case [Quantity
q | (AssetId
_, Quantity
q) <- Value -> [Item Value]
forall l. IsList l => l -> [Item l]
toList Value
v, Quantity
q Quantity -> Quantity -> Bool
forall a. Ord a => a -> a -> Bool
< Quantity
0] of
    [] -> () -> Either TxBodyError ()
forall a b. b -> Either a b
Right ()
    Quantity
q : [Quantity]
_ -> TxBodyError -> Either TxBodyError ()
forall a b. a -> Either a b
Left (Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative Quantity
q (CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
forall era. CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra CardanoEra era
era TxOut CtxTx era
txout))

txBodyContentHasTxIns :: TxIns BuildTx era -> Either TxBodyError ()
txBodyContentHasTxIns :: forall era.
[(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either TxBodyError ()
txBodyContentHasTxIns TxIns BuildTx era
txIns = Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (TxIns BuildTx era -> Bool
forall a. [a] -> 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

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

maxTxOut :: Quantity
maxTxOut :: Quantity
maxTxOut = Word64 -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64)

{-# DEPRECATED createAndValidateTransactionBody "Use createTransactionBody instead" #-}
createAndValidateTransactionBody
  :: ()
  => ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> Either TxBodyError (TxBody era)
createAndValidateTransactionBody :: forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
createAndValidateTransactionBody = ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody

{-# DEPRECATED TxBody "Use getTxBodyContent $ getTxBody instead" #-}
pattern TxBody :: TxBodyContent ViewTx era -> TxBody era
pattern $mTxBody :: forall {r} {era}.
TxBody era -> (TxBodyContent ViewTx era -> r) -> ((# #) -> r) -> r
TxBody txbodycontent <- (getTxBodyContent -> txbodycontent)

{-# COMPLETE TxBody #-}

getTxBodyContent :: TxBody era -> TxBodyContent ViewTx era
getTxBodyContent :: forall era. TxBody era -> TxBodyContent ViewTx era
getTxBodyContent = \case
  ShelleyTxBody ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body [Script (ShelleyLedgerEra era)]
_scripts TxBodyScriptData era
scriptdata Maybe (TxAuxData (ShelleyLedgerEra era))
mAux TxScriptValidity era
scriptValidity ->
    ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
forall era.
ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
sbe TxScriptValidity era
scriptValidity TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata Maybe (TxAuxData (ShelleyLedgerEra era))
mAux

fromLedgerTxBody
  :: ShelleyBasedEra era
  -> TxScriptValidity era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxBodyScriptData era
  -> Maybe (L.TxAuxData (ShelleyLedgerEra era))
  -> TxBodyContent ViewTx era
fromLedgerTxBody :: forall era.
ShelleyBasedEra era
-> TxScriptValidity era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBodyContent ViewTx era
fromLedgerTxBody ShelleyBasedEra era
sbe TxScriptValidity era
scriptValidity TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata Maybe (TxAuxData (ShelleyLedgerEra era))
mAux =
  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
sbe 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
sbe TxBody (ShelleyLedgerEra era)
body
    , txInsReference :: TxInsReference era
txInsReference = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference era
fromLedgerTxInsReference ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    , txOuts :: [TxOut CtxTx era]
txOuts = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
fromLedgerTxOuts ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata
    , txTotalCollateral :: TxTotalCollateral era
txTotalCollateral = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
fromLedgerTxTotalCollateral ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    , txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral ShelleyBasedEra era
sbe 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
sbe TxBody (ShelleyLedgerEra era)
body
    , txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound = ShelleyBasedEra era -> TxBody era -> TxValidityLowerBound era
forall era.
ShelleyBasedEra era -> TxBody era -> TxValidityLowerBound era
fromLedgerTxValidityLowerBound ShelleyBasedEra era
sbe (TxBody (ShelleyLedgerEra era) -> TxBody era
forall era. TxBody (ShelleyLedgerEra era) -> TxBody era
A.TxBody TxBody (ShelleyLedgerEra era)
body)
    , txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound = ShelleyBasedEra era -> TxBody era -> TxValidityUpperBound era
forall era.
ShelleyBasedEra era -> TxBody era -> TxValidityUpperBound era
fromLedgerTxValidityUpperBound ShelleyBasedEra era
sbe (TxBody (ShelleyLedgerEra era) -> TxBody era
forall era. TxBody (ShelleyLedgerEra era) -> TxBody era
A.TxBody 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
sbe 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
sbe TxBody (ShelleyLedgerEra era)
body
    , txUpdateProposal :: TxUpdateProposal era
txUpdateProposal = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
maybeFromLedgerTxUpdateProposal ShelleyBasedEra era
sbe 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
sbe 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
sbe TxBody (ShelleyLedgerEra era)
body
    , txProtocolParams :: BuildTxWith ViewTx (Maybe (LedgerProtocolParameters era))
txProtocolParams = BuildTxWith ViewTx (Maybe (LedgerProtocolParameters era))
forall a. BuildTxWith ViewTx a
ViewTx
    , TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , txScriptValidity :: TxScriptValidity era
txScriptValidity = TxScriptValidity era
scriptValidity
    , txProposalProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
txProposalProcedures = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
fromLedgerProposalProcedures ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    , txVotingProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
txVotingProcedures = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
fromLedgerVotingProcedures ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    , txCurrentTreasuryValue :: Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
fromLedgerCurrentTreasuryValue ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    , txTreasuryDonation :: Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation = ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era Coin)
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era Coin)
fromLedgerTreasuryDonation ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body
    }
 where
  (TxMetadataInEra era
txMetadata, TxAuxScripts era
txAuxScripts) = ShelleyBasedEra era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
forall era.
ShelleyBasedEra era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
sbe Maybe (TxAuxData (ShelleyLedgerEra era))
mAux

fromLedgerProposalProcedures
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> Maybe (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
fromLedgerProposalProcedures :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
fromLedgerProposalProcedures ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
sbe ((ConwayEraOnwards era
  -> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
 -> Maybe
      (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era)))
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
    ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era)
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
 -> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era)
forall a b. (a -> b) -> a -> b
$
      ConwayEraOnwards era
-> TxProposalProcedures ViewTx era
-> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era)
forall (eon :: * -> *) era a. eon era -> a -> Featured eon era a
Featured ConwayEraOnwards era
w (TxProposalProcedures ViewTx era
 -> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era))
-> TxProposalProcedures ViewTx era
-> Featured ConwayEraOnwards era (TxProposalProcedures ViewTx era)
forall a b. (a -> b) -> a -> b
$
        [(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures ViewTx era
forall era build.
(Applicative (BuildTxWith build), IsShelleyBasedEra era) =>
[(ProposalProcedure (ShelleyLedgerEra era),
  Maybe (ScriptWitness WitCtxStake era))]
-> TxProposalProcedures build era
mkTxProposalProcedures
          ((ProposalProcedure (ShelleyLedgerEra era)
 -> (ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era)))
-> [ProposalProcedure (ShelleyLedgerEra era)]
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (,Maybe (ScriptWitness WitCtxStake era)
forall a. Maybe a
Nothing) ([ProposalProcedure (ShelleyLedgerEra era)]
 -> [(ProposalProcedure (ShelleyLedgerEra era),
      Maybe (ScriptWitness WitCtxStake era))])
-> (OSet (ProposalProcedure (ShelleyLedgerEra era))
    -> [ProposalProcedure (ShelleyLedgerEra era)])
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OSet (ProposalProcedure (ShelleyLedgerEra era))
-> [Item (OSet (ProposalProcedure (ShelleyLedgerEra era)))]
OSet (ProposalProcedure (ShelleyLedgerEra era))
-> [ProposalProcedure (ShelleyLedgerEra era)]
forall l. IsList l => l -> [Item l]
toList (OSet (ProposalProcedure (ShelleyLedgerEra era))
 -> [(ProposalProcedure (ShelleyLedgerEra era),
      Maybe (ScriptWitness WitCtxStake era))])
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
-> [(ProposalProcedure (ShelleyLedgerEra era),
     Maybe (ScriptWitness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (OSet (ProposalProcedure (ShelleyLedgerEra era)))
     (TxBody (ShelleyLedgerEra era))
     (OSet (ProposalProcedure (ShelleyLedgerEra era)))
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall s a. s -> Getting a s a -> a
^. Getting
  (OSet (ProposalProcedure (ShelleyLedgerEra era)))
  (TxBody (ShelleyLedgerEra era))
  (OSet (ProposalProcedure (ShelleyLedgerEra era)))
forall era.
ConwayEraTxBody era =>
Lens' (TxBody era) (OSet (ProposalProcedure era))
Lens'
  (TxBody (ShelleyLedgerEra era))
  (OSet (ProposalProcedure (ShelleyLedgerEra era)))
L.proposalProceduresTxBodyL)

fromLedgerVotingProcedures
  :: ()
  => ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> Maybe (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
fromLedgerVotingProcedures :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
fromLedgerVotingProcedures ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
sbe ((ConwayEraOnwards era
  -> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
 -> Maybe
      (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era)))
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
    ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era)
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
 -> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era)
forall a b. (a -> b) -> a -> b
$
      ConwayEraOnwards era
-> TxVotingProcedures ViewTx era
-> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era)
forall (eon :: * -> *) era a. eon era -> a -> Featured eon era a
Featured ConwayEraOnwards era
w (TxVotingProcedures ViewTx era
 -> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era))
-> TxVotingProcedures ViewTx era
-> Featured ConwayEraOnwards era (TxVotingProcedures ViewTx era)
forall a b. (a -> b) -> a -> b
$
        VotingProcedures (ShelleyLedgerEra era)
-> BuildTxWith ViewTx (Map Voter (ScriptWitness WitCtxStake era))
-> TxVotingProcedures ViewTx era
forall era build.
VotingProcedures (ShelleyLedgerEra era)
-> BuildTxWith build (Map Voter (ScriptWitness WitCtxStake era))
-> TxVotingProcedures build era
TxVotingProcedures
          (TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (VotingProcedures (ShelleyLedgerEra era))
     (TxBody (ShelleyLedgerEra era))
     (VotingProcedures (ShelleyLedgerEra era))
-> VotingProcedures (ShelleyLedgerEra era)
forall s a. s -> Getting a s a -> a
^. Getting
  (VotingProcedures (ShelleyLedgerEra era))
  (TxBody (ShelleyLedgerEra era))
  (VotingProcedures (ShelleyLedgerEra era))
forall era.
ConwayEraTxBody era =>
Lens' (TxBody era) (VotingProcedures era)
Lens'
  (TxBody (ShelleyLedgerEra era))
  (VotingProcedures (ShelleyLedgerEra era))
L.votingProceduresTxBodyL)
          BuildTxWith ViewTx (Map Voter (ScriptWitness WitCtxStake era))
forall a. BuildTxWith ViewTx a
ViewTx

fromLedgerCurrentTreasuryValue
  :: ()
  => ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
fromLedgerCurrentTreasuryValue :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
fromLedgerCurrentTreasuryValue ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body = CardanoEra era
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (Maybe Coin))
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
forall (eon :: * -> *) era a.
Eon eon =>
CardanoEra era -> (eon era -> a) -> Maybe a
forEraInEonMaybe (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe) ((ConwayEraOnwards era
  -> Featured ConwayEraOnwards era (Maybe Coin))
 -> Maybe (Featured ConwayEraOnwards era (Maybe Coin)))
-> (ConwayEraOnwards era
    -> Featured ConwayEraOnwards era (Maybe Coin))
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
ceo ->
  ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (Maybe Coin))
-> Featured ConwayEraOnwards era (Maybe Coin)
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
ceo ((ConwayEraOnwardsConstraints era =>
  Featured ConwayEraOnwards era (Maybe Coin))
 -> Featured ConwayEraOnwards era (Maybe Coin))
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era (Maybe Coin))
-> Featured ConwayEraOnwards era (Maybe Coin)
forall a b. (a -> b) -> a -> b
$
    ConwayEraOnwards era
-> Maybe Coin -> Featured ConwayEraOnwards era (Maybe Coin)
forall (eon :: * -> *) era a. eon era -> a -> Featured eon era a
Featured ConwayEraOnwards era
ceo (Maybe Coin -> Featured ConwayEraOnwards era (Maybe Coin))
-> (StrictMaybe Coin -> Maybe Coin)
-> StrictMaybe Coin
-> Featured ConwayEraOnwards era (Maybe Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictMaybe Coin -> Maybe Coin
forall a. StrictMaybe a -> Maybe a
Ledger.strictMaybeToMaybe (StrictMaybe Coin -> Featured ConwayEraOnwards era (Maybe Coin))
-> StrictMaybe Coin -> Featured ConwayEraOnwards era (Maybe Coin)
forall a b. (a -> b) -> a -> b
$
      TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe Coin)
     (TxBody (ShelleyLedgerEra era))
     (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe Coin)
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe Coin)
forall era.
ConwayEraTxBody era =>
Lens' (TxBody era) (StrictMaybe Coin)
Lens' (TxBody (ShelleyLedgerEra era)) (StrictMaybe Coin)
L.currentTreasuryValueTxBodyL

fromLedgerTreasuryDonation
  :: ()
  => ShelleyBasedEra era
  -> L.TxBody (ShelleyLedgerEra era)
  -> Maybe (Featured ConwayEraOnwards era Coin)
fromLedgerTreasuryDonation :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> Maybe (Featured ConwayEraOnwards era Coin)
fromLedgerTreasuryDonation ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ConwayEraOnwards era -> Featured ConwayEraOnwards era Coin)
-> Maybe (Featured ConwayEraOnwards era Coin)
forall (eon :: * -> *) era a.
Eon eon =>
ShelleyBasedEra era -> (eon era -> a) -> Maybe a
forShelleyBasedEraInEonMaybe ShelleyBasedEra era
sbe ((ConwayEraOnwards era -> Featured ConwayEraOnwards era Coin)
 -> Maybe (Featured ConwayEraOnwards era Coin))
-> (ConwayEraOnwards era -> Featured ConwayEraOnwards era Coin)
-> Maybe (Featured ConwayEraOnwards era Coin)
forall a b. (a -> b) -> a -> b
$ \ConwayEraOnwards era
w ->
    ConwayEraOnwards era
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era Coin)
-> Featured ConwayEraOnwards era Coin
forall era a.
ConwayEraOnwards era -> (ConwayEraOnwardsConstraints era => a) -> a
conwayEraOnwardsConstraints ConwayEraOnwards era
w ((ConwayEraOnwardsConstraints era =>
  Featured ConwayEraOnwards era Coin)
 -> Featured ConwayEraOnwards era Coin)
-> (ConwayEraOnwardsConstraints era =>
    Featured ConwayEraOnwards era Coin)
-> Featured ConwayEraOnwards era Coin
forall a b. (a -> b) -> a -> b
$
      ConwayEraOnwards era -> Coin -> Featured ConwayEraOnwards era Coin
forall (eon :: * -> *) era a. eon era -> a -> Featured eon era a
Featured ConwayEraOnwards era
w (TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting Coin (TxBody (ShelleyLedgerEra era)) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. Getting Coin (TxBody (ShelleyLedgerEra era)) Coin
forall era. ConwayEraTxBody era => Lens' (TxBody era) Coin
Lens' (TxBody (ShelleyLedgerEra era)) Coin
L.treasuryDonationTxBodyL)

fromLedgerTxIns
  :: forall era
   . ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> [(TxIn, BuildTxWith ViewTx (Witness WitCtxTxIn era))]
fromLedgerTxIns :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [(TxIn, BuildTxWith ViewTx (Witness WitCtxTxIn era))]
fromLedgerTxIns ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  [ (TxIn -> TxIn
fromShelleyTxIn TxIn
input, BuildTxWith ViewTx (Witness WitCtxTxIn era)
forall a. BuildTxWith ViewTx a
ViewTx)
  | TxIn
input <- Set TxIn -> [Item (Set TxIn)]
forall l. IsList l => l -> [Item l]
toList (ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> Set TxIn
inputs_ ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body)
  ]
 where
  inputs_
    :: ShelleyBasedEra era
    -> Ledger.TxBody (ShelleyLedgerEra era)
    -> Set Ledger.TxIn
  inputs_ :: ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> Set TxIn
inputs_ ShelleyBasedEra era
ShelleyBasedEraShelley = Getting (Set TxIn) (ShelleyTxBody ShelleyEra) (Set TxIn)
-> ShelleyTxBody ShelleyEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody ShelleyEra -> Const (Set TxIn) (TxBody ShelleyEra)
Getting (Set TxIn) (ShelleyTxBody ShelleyEra) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody ShelleyEra) (Set TxIn)
L.inputsTxBodyL
  inputs_ ShelleyBasedEra era
ShelleyBasedEraAllegra = Getting (Set TxIn) (AllegraTxBody AllegraEra) (Set TxIn)
-> AllegraTxBody AllegraEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view Getting (Set TxIn) (AllegraTxBody AllegraEra) (Set TxIn)
(Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody AllegraEra -> Const (Set TxIn) (TxBody AllegraEra)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody AllegraEra) (Set TxIn)
L.inputsTxBodyL
  inputs_ ShelleyBasedEra era
ShelleyBasedEraMary = Getting (Set TxIn) (MaryTxBody MaryEra) (Set TxIn)
-> MaryTxBody MaryEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody MaryEra -> Const (Set TxIn) (TxBody MaryEra)
Getting (Set TxIn) (MaryTxBody MaryEra) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody MaryEra) (Set TxIn)
L.inputsTxBodyL
  inputs_ ShelleyBasedEra era
ShelleyBasedEraAlonzo = Getting (Set TxIn) (AlonzoTxBody AlonzoEra) (Set TxIn)
-> AlonzoTxBody AlonzoEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody AlonzoEra -> Const (Set TxIn) (TxBody AlonzoEra)
Getting (Set TxIn) (AlonzoTxBody AlonzoEra) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody AlonzoEra) (Set TxIn)
L.inputsTxBodyL
  inputs_ ShelleyBasedEra era
ShelleyBasedEraBabbage = Getting (Set TxIn) (BabbageTxBody BabbageEra) (Set TxIn)
-> BabbageTxBody BabbageEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody BabbageEra -> Const (Set TxIn) (TxBody BabbageEra)
Getting (Set TxIn) (BabbageTxBody BabbageEra) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody BabbageEra) (Set TxIn)
L.inputsTxBodyL
  inputs_ ShelleyBasedEra era
ShelleyBasedEraConway = Getting (Set TxIn) (ConwayTxBody ConwayEra) (Set TxIn)
-> ConwayTxBody ConwayEra -> Set TxIn
forall a s. Getting a s a -> s -> a
view (Set TxIn -> Const (Set TxIn) (Set TxIn))
-> TxBody ConwayEra -> Const (Set TxIn) (TxBody ConwayEra)
Getting (Set TxIn) (ConwayTxBody ConwayEra) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody ConwayEra) (Set TxIn)
L.inputsTxBodyL

fromLedgerTxInsCollateral
  :: forall era
   . ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxInsCollateral era
fromLedgerTxInsCollateral :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsCollateral era
fromLedgerTxInsCollateral ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era -> TxInsCollateral era)
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era -> TxInsCollateral era)
-> ShelleyBasedEra era
-> TxInsCollateral era
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
    (TxInsCollateral era -> ShelleyToMaryEra era -> TxInsCollateral era
forall a b. a -> b -> a
const TxInsCollateral era
forall era. TxInsCollateral era
TxInsCollateralNone)
    (\AlonzoEraOnwards era
w -> AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
forall era. AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era
TxInsCollateral AlonzoEraOnwards era
w ([TxIn] -> TxInsCollateral era) -> [TxIn] -> TxInsCollateral era
forall a b. (a -> b) -> a -> b
$ (TxIn -> TxIn) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn
fromShelleyTxIn ([TxIn] -> [TxIn]) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> a -> b
$ Set TxIn -> [Item (Set TxIn)]
forall l. IsList l => l -> [Item l]
toList (Set TxIn -> [Item (Set TxIn)]) -> Set TxIn -> [Item (Set TxIn)]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting (Set TxIn) (TxBody (ShelleyLedgerEra era)) (Set TxIn)
-> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody (ShelleyLedgerEra era)) (Set TxIn)
forall era. AlonzoEraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody (ShelleyLedgerEra era)) (Set TxIn)
L.collateralInputsTxBodyL)
    ShelleyBasedEra era
sbe

fromLedgerTxInsReference
  :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxInsReference era
fromLedgerTxInsReference :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxInsReference era
fromLedgerTxInsReference ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
txBody =
  (ShelleyToAlonzoEraConstraints era =>
 ShelleyToAlonzoEra era -> TxInsReference era)
-> (BabbageEraOnwardsConstraints era =>
    BabbageEraOnwards era -> TxInsReference era)
-> ShelleyBasedEra era
-> TxInsReference era
forall era a.
(ShelleyToAlonzoEraConstraints era => ShelleyToAlonzoEra era -> a)
-> (BabbageEraOnwardsConstraints era => BabbageEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAlonzoOrBabbageEraOnwards
    (TxInsReference era -> ShelleyToAlonzoEra era -> TxInsReference era
forall a b. a -> b -> a
const TxInsReference era
forall era. TxInsReference era
TxInsReferenceNone)
    (\BabbageEraOnwards era
w -> BabbageEraOnwards era -> [TxIn] -> TxInsReference era
forall era. BabbageEraOnwards era -> [TxIn] -> TxInsReference era
TxInsReference BabbageEraOnwards era
w ([TxIn] -> TxInsReference era) -> [TxIn] -> TxInsReference era
forall a b. (a -> b) -> a -> b
$ (TxIn -> TxIn) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn
fromShelleyTxIn ([TxIn] -> [TxIn]) -> (Set TxIn -> [TxIn]) -> Set TxIn -> [TxIn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set TxIn -> [Item (Set TxIn)]
Set TxIn -> [TxIn]
forall l. IsList l => l -> [Item l]
toList (Set TxIn -> [TxIn]) -> Set TxIn -> [TxIn]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era)
txBody TxBody (ShelleyLedgerEra era)
-> Getting (Set TxIn) (TxBody (ShelleyLedgerEra era)) (Set TxIn)
-> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody (ShelleyLedgerEra era)) (Set TxIn)
forall era. BabbageEraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody (ShelleyLedgerEra era)) (Set TxIn)
L.referenceInputsTxBodyL)
    ShelleyBasedEra era
sbe

fromLedgerTxOuts
  :: forall era
   . ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxBodyScriptData era
  -> [TxOut CtxTx era]
fromLedgerTxOuts :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> TxBodyScriptData era
-> [TxOut CtxTx era]
fromLedgerTxOuts ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body TxBodyScriptData era
scriptdata =
  case ShelleyBasedEra era
sbe of
    ShelleyBasedEra era
ShelleyBasedEraShelley ->
      [ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era
forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
sbe Item (StrictSeq (TxOut ShelleyEra))
TxOut (ShelleyLedgerEra era)
txout | Item (StrictSeq (TxOut ShelleyEra))
txout <- StrictSeq (TxOut ShelleyEra)
-> [Item (StrictSeq (TxOut ShelleyEra))]
forall l. IsList l => l -> [Item l]
toList (TxBody (ShelleyLedgerEra era)
ShelleyTxBody ShelleyEra
body ShelleyTxBody ShelleyEra
-> Getting
     (StrictSeq (TxOut ShelleyEra))
     (ShelleyTxBody ShelleyEra)
     (StrictSeq (TxOut ShelleyEra))
-> StrictSeq (TxOut ShelleyEra)
forall s a. s -> Getting a s a -> a
^. (StrictSeq (TxOut ShelleyEra)
 -> Const
      (StrictSeq (TxOut ShelleyEra)) (StrictSeq (TxOut ShelleyEra)))
-> TxBody ShelleyEra
-> Const (StrictSeq (TxOut ShelleyEra)) (TxBody ShelleyEra)
Getting
  (StrictSeq (TxOut ShelleyEra))
  (ShelleyTxBody ShelleyEra)
  (StrictSeq (TxOut ShelleyEra))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody ShelleyEra) (StrictSeq (TxOut ShelleyEra))
L.outputsTxBodyL)]
    ShelleyBasedEra era
ShelleyBasedEraAllegra ->
      [ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era
forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
sbe Item (StrictSeq (TxOut AllegraEra))
TxOut (ShelleyLedgerEra era)
txout | Item (StrictSeq (TxOut AllegraEra))
txout <- StrictSeq (TxOut AllegraEra)
-> [Item (StrictSeq (TxOut AllegraEra))]
forall l. IsList l => l -> [Item l]
toList (AllegraTxBody AllegraEra
TxBody (ShelleyLedgerEra era)
body AllegraTxBody AllegraEra
-> Getting
     (StrictSeq (TxOut AllegraEra))
     (AllegraTxBody AllegraEra)
     (StrictSeq (TxOut AllegraEra))
-> StrictSeq (TxOut AllegraEra)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictSeq (TxOut AllegraEra))
  (AllegraTxBody AllegraEra)
  (StrictSeq (TxOut AllegraEra))
(StrictSeq (TxOut AllegraEra)
 -> Const
      (StrictSeq (TxOut AllegraEra)) (StrictSeq (TxOut AllegraEra)))
-> TxBody AllegraEra
-> Const (StrictSeq (TxOut AllegraEra)) (TxBody AllegraEra)
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody AllegraEra) (StrictSeq (TxOut AllegraEra))
L.outputsTxBodyL)]
    ShelleyBasedEra era
ShelleyBasedEraMary ->
      [ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era
forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
sbe Item (StrictSeq (TxOut MaryEra))
TxOut (ShelleyLedgerEra era)
txout | Item (StrictSeq (TxOut MaryEra))
txout <- StrictSeq (TxOut MaryEra) -> [Item (StrictSeq (TxOut MaryEra))]
forall l. IsList l => l -> [Item l]
toList (TxBody (ShelleyLedgerEra era)
MaryTxBody MaryEra
body MaryTxBody MaryEra
-> Getting
     (StrictSeq (TxOut MaryEra))
     (MaryTxBody MaryEra)
     (StrictSeq (TxOut MaryEra))
-> StrictSeq (TxOut MaryEra)
forall s a. s -> Getting a s a -> a
^. (StrictSeq (TxOut MaryEra)
 -> Const (StrictSeq (TxOut MaryEra)) (StrictSeq (TxOut MaryEra)))
-> TxBody MaryEra
-> Const (StrictSeq (TxOut MaryEra)) (TxBody MaryEra)
Getting
  (StrictSeq (TxOut MaryEra))
  (MaryTxBody MaryEra)
  (StrictSeq (TxOut MaryEra))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody MaryEra) (StrictSeq (TxOut MaryEra))
L.outputsTxBodyL)]
    ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
      [ AlonzoEraOnwards era
-> Map DataHash (Data AlonzoEra)
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
forall era ledgerera.
AlonzoEraOnwards era
-> Map DataHash (Data ledgerera)
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
fromAlonzoTxOut
          AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
AlonzoEraOnwardsAlonzo
          Map DataHash (Data AlonzoEra)
Map DataHash (Data (ShelleyLedgerEra era))
txdatums
          Item (StrictSeq (TxOut AlonzoEra))
TxOut (ShelleyLedgerEra era)
txout
      | let txdatums :: Map DataHash (Data (ShelleyLedgerEra era))
txdatums = TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
forall era.
TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
scriptdata
      , Item (StrictSeq (TxOut AlonzoEra))
txout <- StrictSeq (TxOut AlonzoEra) -> [Item (StrictSeq (TxOut AlonzoEra))]
forall l. IsList l => l -> [Item l]
toList (TxBody (ShelleyLedgerEra era)
AlonzoTxBody AlonzoEra
body AlonzoTxBody AlonzoEra
-> Getting
     (StrictSeq (TxOut AlonzoEra))
     (AlonzoTxBody AlonzoEra)
     (StrictSeq (TxOut AlonzoEra))
-> StrictSeq (TxOut AlonzoEra)
forall s a. s -> Getting a s a -> a
^. (StrictSeq (TxOut AlonzoEra)
 -> Const
      (StrictSeq (TxOut AlonzoEra)) (StrictSeq (TxOut AlonzoEra)))
-> TxBody AlonzoEra
-> Const (StrictSeq (TxOut AlonzoEra)) (TxBody AlonzoEra)
Getting
  (StrictSeq (TxOut AlonzoEra))
  (AlonzoTxBody AlonzoEra)
  (StrictSeq (TxOut AlonzoEra))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody AlonzoEra) (StrictSeq (TxOut AlonzoEra))
L.outputsTxBodyL)
      ]
    ShelleyBasedEra era
ShelleyBasedEraBabbage ->
      [ BabbageEraOnwards era
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
forall era.
BabbageEraOnwards era
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
fromBabbageTxOut
          BabbageEraOnwards era
BabbageEraOnwards BabbageEra
BabbageEraOnwardsBabbage
          Map DataHash (Data (ShelleyLedgerEra era))
txdatums
          Item (StrictSeq (TxOut BabbageEra))
TxOut (ShelleyLedgerEra era)
txouts
      | let txdatums :: Map DataHash (Data (ShelleyLedgerEra era))
txdatums = TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
forall era.
TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
scriptdata
      , Item (StrictSeq (TxOut BabbageEra))
txouts <- StrictSeq (TxOut BabbageEra)
-> [Item (StrictSeq (TxOut BabbageEra))]
forall l. IsList l => l -> [Item l]
toList (TxBody (ShelleyLedgerEra era)
BabbageTxBody BabbageEra
body BabbageTxBody BabbageEra
-> Getting
     (StrictSeq (TxOut BabbageEra))
     (BabbageTxBody BabbageEra)
     (StrictSeq (TxOut BabbageEra))
-> StrictSeq (TxOut BabbageEra)
forall s a. s -> Getting a s a -> a
^. (StrictSeq (TxOut BabbageEra)
 -> Const
      (StrictSeq (TxOut BabbageEra)) (StrictSeq (TxOut BabbageEra)))
-> TxBody BabbageEra
-> Const (StrictSeq (TxOut BabbageEra)) (TxBody BabbageEra)
Getting
  (StrictSeq (TxOut BabbageEra))
  (BabbageTxBody BabbageEra)
  (StrictSeq (TxOut BabbageEra))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody BabbageEra) (StrictSeq (TxOut BabbageEra))
L.outputsTxBodyL)
      ]
    ShelleyBasedEra era
ShelleyBasedEraConway ->
      [ BabbageEraOnwards era
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
forall era.
BabbageEraOnwards era
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
fromBabbageTxOut
          BabbageEraOnwards era
BabbageEraOnwards ConwayEra
BabbageEraOnwardsConway
          Map DataHash (Data (ShelleyLedgerEra era))
txdatums
          Item (StrictSeq (TxOut ConwayEra))
TxOut (ShelleyLedgerEra era)
txouts
      | let txdatums :: Map DataHash (Data (ShelleyLedgerEra era))
txdatums = TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
forall era.
TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
scriptdata
      , Item (StrictSeq (TxOut ConwayEra))
txouts <- StrictSeq (TxOut ConwayEra) -> [Item (StrictSeq (TxOut ConwayEra))]
forall l. IsList l => l -> [Item l]
toList (TxBody (ShelleyLedgerEra era)
ConwayTxBody ConwayEra
body ConwayTxBody ConwayEra
-> Getting
     (StrictSeq (TxOut ConwayEra))
     (ConwayTxBody ConwayEra)
     (StrictSeq (TxOut ConwayEra))
-> StrictSeq (TxOut ConwayEra)
forall s a. s -> Getting a s a -> a
^. (StrictSeq (TxOut ConwayEra)
 -> Const
      (StrictSeq (TxOut ConwayEra)) (StrictSeq (TxOut ConwayEra)))
-> TxBody ConwayEra
-> Const (StrictSeq (TxOut ConwayEra)) (TxBody ConwayEra)
Getting
  (StrictSeq (TxOut ConwayEra))
  (ConwayTxBody ConwayEra)
  (StrictSeq (TxOut ConwayEra))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody ConwayEra) (StrictSeq (TxOut ConwayEra))
L.outputsTxBodyL)
      ]

selectTxDatums
  :: TxBodyScriptData era
  -> Map L.DataHash (L.Data (ShelleyLedgerEra era))
selectTxDatums :: forall era.
TxBodyScriptData era -> Map DataHash (Data (ShelleyLedgerEra era))
selectTxDatums TxBodyScriptData era
TxBodyNoScriptData = Map DataHash (Data (ShelleyLedgerEra era))
forall k a. Map k a
Map.empty
selectTxDatums (TxBodyScriptData AlonzoEraOnwards era
_ (Alonzo.TxDats' Map DataHash (Data (ShelleyLedgerEra era))
datums) Redeemers (ShelleyLedgerEra era)
_) = Map DataHash (Data (ShelleyLedgerEra era))
datums

fromAlonzoTxOut
  :: forall era ledgerera
   . AlonzoEraOnwards era
  -> Map L.DataHash (L.Data ledgerera)
  -> L.TxOut (ShelleyLedgerEra era)
  -> TxOut CtxTx era
fromAlonzoTxOut :: forall era ledgerera.
AlonzoEraOnwards era
-> Map DataHash (Data ledgerera)
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
fromAlonzoTxOut AlonzoEraOnwards era
w Map DataHash (Data ledgerera)
txdatums TxOut (ShelleyLedgerEra era)
txOut =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era => TxOut CtxTx era)
-> TxOut CtxTx era
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
w ((AlonzoEraOnwardsConstraints era => TxOut CtxTx era)
 -> TxOut CtxTx era)
-> (AlonzoEraOnwardsConstraints era => TxOut CtxTx era)
-> TxOut CtxTx era
forall a b. (a -> b) -> a -> b
$
    AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
      (ShelleyBasedEra era -> Addr -> AddressInEra era
forall era. ShelleyBasedEra era -> Addr -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra (TxOut (ShelleyLedgerEra era)
txOut TxOut (ShelleyLedgerEra era)
-> Getting Addr (TxOut (ShelleyLedgerEra era)) Addr -> Addr
forall s a. s -> Getting a s a -> a
^. Getting Addr (TxOut (ShelleyLedgerEra era)) Addr
forall era. EraTxOut era => Lens' (TxOut era) Addr
Lens' (TxOut (ShelleyLedgerEra era)) Addr
L.addrTxOutL))
      (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (TxOut (ShelleyLedgerEra era)
txOut TxOut (ShelleyLedgerEra era)
-> Getting MaryValue (TxOut (ShelleyLedgerEra era)) MaryValue
-> MaryValue
forall s a. s -> Getting a s a -> a
^. (Value (ShelleyLedgerEra era)
 -> Const MaryValue (Value (ShelleyLedgerEra era)))
-> TxOut (ShelleyLedgerEra era)
-> Const MaryValue (TxOut (ShelleyLedgerEra era))
Getting MaryValue (TxOut (ShelleyLedgerEra era)) MaryValue
forall era. EraTxOut era => Lens' (TxOut era) (Value era)
Lens' (TxOut (ShelleyLedgerEra era)) (Value (ShelleyLedgerEra era))
L.valueTxOutL))
      (AlonzoEraOnwards era
-> Map DataHash (Data ledgerera)
-> StrictMaybe DataHash
-> TxOutDatum CtxTx era
forall era ledgerera.
AlonzoEraOnwards era
-> Map DataHash (Data ledgerera)
-> StrictMaybe DataHash
-> TxOutDatum CtxTx era
fromAlonzoTxOutDatum AlonzoEraOnwards era
w Map DataHash (Data ledgerera)
txdatums (TxOut (ShelleyLedgerEra era)
txOut TxOut (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe DataHash)
     (TxOut (ShelleyLedgerEra era))
     (StrictMaybe DataHash)
-> StrictMaybe DataHash
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe DataHash)
  (TxOut (ShelleyLedgerEra era))
  (StrictMaybe DataHash)
forall era.
AlonzoEraTxOut era =>
Lens' (TxOut era) (StrictMaybe DataHash)
Lens' (TxOut (ShelleyLedgerEra era)) (StrictMaybe DataHash)
L.dataHashTxOutL))
      ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
 where
  ShelleyBasedEra era
sbe :: ShelleyBasedEra era = AlonzoEraOnwards era -> ShelleyBasedEra era
forall era. AlonzoEraOnwards era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert AlonzoEraOnwards era
w

fromAlonzoTxOutDatum
  :: ()
  => AlonzoEraOnwards era
  -> Map L.DataHash (L.Data ledgerera)
  -> StrictMaybe L.DataHash
  -> TxOutDatum CtxTx era
fromAlonzoTxOutDatum :: forall era ledgerera.
AlonzoEraOnwards era
-> Map DataHash (Data ledgerera)
-> StrictMaybe DataHash
-> TxOutDatum CtxTx era
fromAlonzoTxOutDatum AlonzoEraOnwards era
w Map DataHash (Data ledgerera)
txdatums = \case
  StrictMaybe DataHash
SNothing -> TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
  SJust DataHash
dh
    | Just Data ledgerera
d <- DataHash -> Map DataHash (Data ledgerera) -> Maybe (Data ledgerera)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup DataHash
dh Map DataHash (Data ledgerera)
txdatums ->
        AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
forall era.
AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
TxOutSupplementalDatum AlonzoEraOnwards era
w (Data ledgerera -> HashableScriptData
forall ledgerera. Data ledgerera -> HashableScriptData
fromAlonzoData Data ledgerera
d)
    | Bool
otherwise -> AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash AlonzoEraOnwards era
w (DataHash -> Hash ScriptData
ScriptDataHash DataHash
dh)

fromBabbageTxOut
  :: forall era
   . BabbageEraOnwards era
  -> Map L.DataHash (L.Data (ShelleyLedgerEra era))
  -> L.TxOut (ShelleyLedgerEra era)
  -> TxOut CtxTx era
fromBabbageTxOut :: forall era.
BabbageEraOnwards era
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxOut (ShelleyLedgerEra era)
-> TxOut CtxTx era
fromBabbageTxOut BabbageEraOnwards era
w Map DataHash (Data (ShelleyLedgerEra era))
txdatums TxOut (ShelleyLedgerEra era)
txout =
  BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => TxOut CtxTx era)
-> TxOut CtxTx era
forall era a.
BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => a) -> a
babbageEraOnwardsConstraints BabbageEraOnwards era
w ((BabbageEraOnwardsConstraints era => TxOut CtxTx era)
 -> TxOut CtxTx era)
-> (BabbageEraOnwardsConstraints era => TxOut CtxTx era)
-> TxOut CtxTx era
forall a b. (a -> b) -> a -> b
$
    AddressInEra era
-> TxOutValue era
-> TxOutDatum CtxTx era
-> ReferenceScript era
-> TxOut CtxTx era
forall ctx era.
AddressInEra era
-> TxOutValue era
-> TxOutDatum ctx era
-> ReferenceScript era
-> TxOut ctx era
TxOut
      (ShelleyBasedEra era -> Addr -> AddressInEra era
forall era. ShelleyBasedEra era -> Addr -> AddressInEra era
fromShelleyAddr ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra (TxOut (ShelleyLedgerEra era)
BabbageTxOut (ShelleyLedgerEra era)
txout BabbageTxOut (ShelleyLedgerEra era)
-> Getting Addr (BabbageTxOut (ShelleyLedgerEra era)) Addr -> Addr
forall s a. s -> Getting a s a -> a
^. (Addr -> Const Addr Addr)
-> TxOut (ShelleyLedgerEra era)
-> Const Addr (TxOut (ShelleyLedgerEra era))
Getting Addr (BabbageTxOut (ShelleyLedgerEra era)) Addr
forall era. EraTxOut era => Lens' (TxOut era) Addr
Lens' (TxOut (ShelleyLedgerEra era)) Addr
L.addrTxOutL))
      (ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
forall era.
(Eq (Value (ShelleyLedgerEra era)),
 Show (Value (ShelleyLedgerEra era))) =>
ShelleyBasedEra era
-> Value (ShelleyLedgerEra era) -> TxOutValue era
TxOutValueShelleyBased ShelleyBasedEra era
sbe (TxOut (ShelleyLedgerEra era)
BabbageTxOut (ShelleyLedgerEra era)
txout BabbageTxOut (ShelleyLedgerEra era)
-> Getting
     MaryValue (BabbageTxOut (ShelleyLedgerEra era)) MaryValue
-> MaryValue
forall s a. s -> Getting a s a -> a
^. (Value (ShelleyLedgerEra era)
 -> Const MaryValue (Value (ShelleyLedgerEra era)))
-> TxOut (ShelleyLedgerEra era)
-> Const MaryValue (TxOut (ShelleyLedgerEra era))
Getting MaryValue (BabbageTxOut (ShelleyLedgerEra era)) MaryValue
forall era. EraTxOut era => Lens' (TxOut era) (Value era)
Lens' (TxOut (ShelleyLedgerEra era)) (Value (ShelleyLedgerEra era))
L.valueTxOutL))
      TxOutDatum CtxTx era
babbageTxOutDatum
      ( case TxOut (ShelleyLedgerEra era)
BabbageTxOut (ShelleyLedgerEra era)
txout BabbageTxOut (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe (Script (ShelleyLedgerEra era)))
     (BabbageTxOut (ShelleyLedgerEra era))
     (StrictMaybe (Script (ShelleyLedgerEra era)))
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall s a. s -> Getting a s a -> a
^. (StrictMaybe (Script (ShelleyLedgerEra era))
 -> Const
      (StrictMaybe (Script (ShelleyLedgerEra era)))
      (StrictMaybe (Script (ShelleyLedgerEra era))))
-> TxOut (ShelleyLedgerEra era)
-> Const
     (StrictMaybe (Script (ShelleyLedgerEra era)))
     (TxOut (ShelleyLedgerEra era))
Getting
  (StrictMaybe (Script (ShelleyLedgerEra era)))
  (BabbageTxOut (ShelleyLedgerEra era))
  (StrictMaybe (Script (ShelleyLedgerEra era)))
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens'
  (TxOut (ShelleyLedgerEra era))
  (StrictMaybe (Script (ShelleyLedgerEra era)))
L.referenceScriptTxOutL of
          StrictMaybe (Script (ShelleyLedgerEra era))
SNothing -> ReferenceScript era
forall era. ReferenceScript era
ReferenceScriptNone
          SJust Script (ShelleyLedgerEra era)
rScript -> ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ReferenceScript era
fromShelleyScriptToReferenceScript ShelleyBasedEra era
forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra Script (ShelleyLedgerEra era)
rScript
      )
 where
  ShelleyBasedEra era
sbe :: ShelleyBasedEra era = BabbageEraOnwards era -> ShelleyBasedEra era
forall era. BabbageEraOnwards era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert BabbageEraOnwards era
w

  -- NOTE: This is different to 'fromBabbageTxOutDatum' as it may resolve
  -- 'DatumHash' values using the datums included in the transaction.
  babbageTxOutDatum :: TxOutDatum CtxTx era
  babbageTxOutDatum :: TxOutDatum CtxTx era
babbageTxOutDatum =
    BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => TxOutDatum CtxTx era)
-> TxOutDatum CtxTx era
forall era a.
BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => a) -> a
babbageEraOnwardsConstraints BabbageEraOnwards era
w ((BabbageEraOnwardsConstraints era => TxOutDatum CtxTx era)
 -> TxOutDatum CtxTx era)
-> (BabbageEraOnwardsConstraints era => TxOutDatum CtxTx era)
-> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$
      case TxOut (ShelleyLedgerEra era)
BabbageTxOut (ShelleyLedgerEra era)
txout BabbageTxOut (ShelleyLedgerEra era)
-> Getting
     (Datum (ShelleyLedgerEra era))
     (BabbageTxOut (ShelleyLedgerEra era))
     (Datum (ShelleyLedgerEra era))
-> Datum (ShelleyLedgerEra era)
forall s a. s -> Getting a s a -> a
^. (Datum (ShelleyLedgerEra era)
 -> Const
      (Datum (ShelleyLedgerEra era)) (Datum (ShelleyLedgerEra era)))
-> TxOut (ShelleyLedgerEra era)
-> Const
     (Datum (ShelleyLedgerEra era)) (TxOut (ShelleyLedgerEra era))
Getting
  (Datum (ShelleyLedgerEra era))
  (BabbageTxOut (ShelleyLedgerEra era))
  (Datum (ShelleyLedgerEra era))
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut (ShelleyLedgerEra era)) (Datum (ShelleyLedgerEra era))
L.datumTxOutL of
        Datum (ShelleyLedgerEra era)
L.NoDatum -> TxOutDatum CtxTx era
forall ctx era. TxOutDatum ctx era
TxOutDatumNone
        L.DatumHash DataHash
dh -> DataHash -> TxOutDatum CtxTx era
resolveDatumInTx DataHash
dh
        L.Datum BinaryData (ShelleyLedgerEra era)
d -> BabbageEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
forall era ctx.
BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx era
TxOutDatumInline BabbageEraOnwards era
w (HashableScriptData -> TxOutDatum CtxTx era)
-> HashableScriptData -> TxOutDatum CtxTx era
forall a b. (a -> b) -> a -> b
$ BabbageEraOnwards era
-> BinaryData (ShelleyLedgerEra era) -> HashableScriptData
forall ledgerera era.
Era ledgerera =>
BabbageEraOnwards era -> BinaryData ledgerera -> HashableScriptData
binaryDataToScriptData BabbageEraOnwards era
w BinaryData (ShelleyLedgerEra era)
d

  resolveDatumInTx :: L.DataHash -> TxOutDatum CtxTx era
  resolveDatumInTx :: DataHash -> TxOutDatum CtxTx era
resolveDatumInTx DataHash
dh
    | Just Data (ShelleyLedgerEra era)
d <- DataHash
-> Map DataHash (Data (ShelleyLedgerEra era))
-> Maybe (Data (ShelleyLedgerEra era))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup DataHash
dh Map DataHash (Data (ShelleyLedgerEra era))
txdatums =
        AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
forall era.
AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx era
TxOutSupplementalDatum
          (BabbageEraOnwards era -> AlonzoEraOnwards era
forall era. BabbageEraOnwards era -> AlonzoEraOnwards era
babbageEraOnwardsToAlonzoEraOnwards BabbageEraOnwards era
w)
          (Data (ShelleyLedgerEra era) -> HashableScriptData
forall ledgerera. Data ledgerera -> HashableScriptData
fromAlonzoData Data (ShelleyLedgerEra era)
d)
    | Bool
otherwise = AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum CtxTx era
forall era ctx.
AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era
TxOutDatumHash (BabbageEraOnwards era -> AlonzoEraOnwards era
forall era. BabbageEraOnwards era -> AlonzoEraOnwards era
babbageEraOnwardsToAlonzoEraOnwards BabbageEraOnwards era
w) (DataHash -> Hash ScriptData
ScriptDataHash DataHash
dh)

fromLedgerTxTotalCollateral
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxTotalCollateral era
fromLedgerTxTotalCollateral :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxTotalCollateral era
fromLedgerTxTotalCollateral ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
txbody =
  (ShelleyToAlonzoEraConstraints era =>
 ShelleyToAlonzoEra era -> TxTotalCollateral era)
-> (BabbageEraOnwardsConstraints era =>
    BabbageEraOnwards era -> TxTotalCollateral era)
-> ShelleyBasedEra era
-> TxTotalCollateral era
forall era a.
(ShelleyToAlonzoEraConstraints era => ShelleyToAlonzoEra era -> a)
-> (BabbageEraOnwardsConstraints era => BabbageEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAlonzoOrBabbageEraOnwards
    (TxTotalCollateral era
-> ShelleyToAlonzoEra era -> TxTotalCollateral era
forall a b. a -> b -> a
const TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone)
    ( \BabbageEraOnwards era
w ->
        case TxBody (ShelleyLedgerEra era)
txbody TxBody (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe Coin)
     (TxBody (ShelleyLedgerEra era))
     (StrictMaybe Coin)
-> StrictMaybe Coin
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe Coin)
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe Coin)
forall era.
BabbageEraTxBody era =>
Lens' (TxBody era) (StrictMaybe Coin)
Lens' (TxBody (ShelleyLedgerEra era)) (StrictMaybe Coin)
L.totalCollateralTxBodyL of
          StrictMaybe Coin
SNothing -> TxTotalCollateral era
forall era. TxTotalCollateral era
TxTotalCollateralNone
          SJust Coin
totColl -> BabbageEraOnwards era -> Coin -> TxTotalCollateral era
forall era. BabbageEraOnwards era -> Coin -> TxTotalCollateral era
TxTotalCollateral BabbageEraOnwards era
w Coin
totColl
    )
    ShelleyBasedEra era
sbe

fromLedgerTxReturnCollateral
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxReturnCollateral CtxTx era
fromLedgerTxReturnCollateral ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
txbody =
  (ShelleyToAlonzoEraConstraints era =>
 ShelleyToAlonzoEra era -> TxReturnCollateral CtxTx era)
-> (BabbageEraOnwardsConstraints era =>
    BabbageEraOnwards era -> TxReturnCollateral CtxTx era)
-> ShelleyBasedEra era
-> TxReturnCollateral CtxTx era
forall era a.
(ShelleyToAlonzoEraConstraints era => ShelleyToAlonzoEra era -> a)
-> (BabbageEraOnwardsConstraints era => BabbageEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToAlonzoOrBabbageEraOnwards
    (TxReturnCollateral CtxTx era
-> ShelleyToAlonzoEra era -> TxReturnCollateral CtxTx era
forall a b. a -> b -> a
const TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone)
    ( \BabbageEraOnwards era
w ->
        case TxBody (ShelleyLedgerEra era)
txbody TxBody (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe (TxOut (ShelleyLedgerEra era)))
     (TxBody (ShelleyLedgerEra era))
     (StrictMaybe (TxOut (ShelleyLedgerEra era)))
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (TxOut (ShelleyLedgerEra era)))
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (TxOut (ShelleyLedgerEra era)))
forall era.
BabbageEraTxBody era =>
Lens' (TxBody era) (StrictMaybe (TxOut era))
Lens'
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (TxOut (ShelleyLedgerEra era)))
L.collateralReturnTxBodyL of
          StrictMaybe (TxOut (ShelleyLedgerEra era))
SNothing -> TxReturnCollateral CtxTx era
forall ctx era. TxReturnCollateral ctx era
TxReturnCollateralNone
          SJust TxOut (ShelleyLedgerEra era)
collReturnOut -> BabbageEraOnwards era
-> TxOut CtxTx era -> TxReturnCollateral CtxTx era
forall era ctx.
BabbageEraOnwards era
-> TxOut ctx era -> TxReturnCollateral ctx era
TxReturnCollateral BabbageEraOnwards era
w (TxOut CtxTx era -> TxReturnCollateral CtxTx era)
-> TxOut CtxTx era -> TxReturnCollateral CtxTx era
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut CtxTx era
forall era ctx.
ShelleyBasedEra era
-> TxOut (ShelleyLedgerEra era) -> TxOut ctx era
fromShelleyTxOut ShelleyBasedEra era
sbe TxOut (ShelleyLedgerEra era)
collReturnOut
    )
    ShelleyBasedEra era
sbe

fromLedgerTxFee
  :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee :: forall era.
ShelleyBasedEra era -> TxBody (ShelleyLedgerEra era) -> TxFee era
fromLedgerTxFee ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxFee era) -> TxFee era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxFee era) -> TxFee era)
-> (ShelleyBasedEraConstraints era => TxFee era) -> TxFee era
forall a b. (a -> b) -> a -> b
$
    ShelleyBasedEra era -> Coin -> TxFee era
forall era. ShelleyBasedEra era -> Coin -> TxFee era
TxFeeExplicit ShelleyBasedEra era
sbe (Coin -> TxFee era) -> Coin -> TxFee era
forall a b. (a -> b) -> a -> b
$
      TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting Coin (TxBody (ShelleyLedgerEra era)) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. Getting Coin (TxBody (ShelleyLedgerEra era)) Coin
forall era. EraTxBody era => Lens' (TxBody era) Coin
Lens' (TxBody (ShelleyLedgerEra era)) Coin
L.feeTxBodyL

fromLedgerTxValidityLowerBound
  :: ShelleyBasedEra era
  -> A.TxBody era
  -> TxValidityLowerBound era
fromLedgerTxValidityLowerBound :: forall era.
ShelleyBasedEra era -> TxBody era -> TxValidityLowerBound era
fromLedgerTxValidityLowerBound ShelleyBasedEra era
sbe TxBody era
body =
  (ShelleyEraOnlyConstraints era =>
 ShelleyEraOnly era -> TxValidityLowerBound era)
-> (AllegraEraOnwardsConstraints era =>
    AllegraEraOnwards era -> TxValidityLowerBound era)
-> ShelleyBasedEra era
-> TxValidityLowerBound era
forall era a.
(ShelleyEraOnlyConstraints era => ShelleyEraOnly era -> a)
-> (AllegraEraOnwardsConstraints era => AllegraEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyEraOnlyOrAllegraEraOnwards
    (TxValidityLowerBound era
-> ShelleyEraOnly era -> TxValidityLowerBound era
forall a b. a -> b -> a
const TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound)
    ( \AllegraEraOnwards era
w ->
        let mInvalidBefore :: Maybe SlotNo
mInvalidBefore = TxBody era
body TxBody era
-> Getting (Maybe SlotNo) (TxBody era) (Maybe SlotNo)
-> Maybe SlotNo
forall s a. s -> Getting a s a -> a
^. AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
w
         in case Maybe SlotNo
mInvalidBefore of
              Maybe SlotNo
Nothing -> TxValidityLowerBound era
forall era. TxValidityLowerBound era
TxValidityNoLowerBound
              Just SlotNo
s -> AllegraEraOnwards era -> SlotNo -> TxValidityLowerBound era
forall era.
AllegraEraOnwards era -> SlotNo -> TxValidityLowerBound era
TxValidityLowerBound AllegraEraOnwards era
w SlotNo
s
    )
    ShelleyBasedEra era
sbe

fromLedgerTxValidityUpperBound
  :: ShelleyBasedEra era
  -> A.TxBody era
  -> TxValidityUpperBound era
fromLedgerTxValidityUpperBound :: forall era.
ShelleyBasedEra era -> TxBody era -> TxValidityUpperBound era
fromLedgerTxValidityUpperBound ShelleyBasedEra era
sbe TxBody era
body =
  ShelleyBasedEra era -> Maybe SlotNo -> TxValidityUpperBound era
forall era.
ShelleyBasedEra era -> Maybe SlotNo -> TxValidityUpperBound era
TxValidityUpperBound ShelleyBasedEra era
sbe (Maybe SlotNo -> TxValidityUpperBound era)
-> Maybe SlotNo -> TxValidityUpperBound era
forall a b. (a -> b) -> a -> b
$ TxBody era
body TxBody era
-> Getting (Maybe SlotNo) (TxBody era) (Maybe SlotNo)
-> Maybe SlotNo
forall s a. s -> Getting a s a -> a
^. ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe

fromLedgerAuxiliaryData
  :: ShelleyBasedEra era
  -> L.TxAuxData (ShelleyLedgerEra era)
  -> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData :: forall era.
ShelleyBasedEra era
-> TxAuxData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraShelley (L.ShelleyTxAuxData Map Word64 Metadatum
metadata) =
  (Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
metadata, [])
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraAllegra (L.AllegraTxAuxData Map Word64 Metadatum
ms StrictSeq (Timelock AllegraEra)
ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra era
ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra (Timelock AllegraEra -> ScriptInEra era)
-> [Timelock AllegraEra] -> [ScriptInEra era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock AllegraEra)
-> [Item (StrictSeq (Timelock AllegraEra))]
forall l. IsList l => l -> [Item l]
toList StrictSeq (Timelock AllegraEra)
ss
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraMary (L.AllegraTxAuxData Map Word64 Metadatum
ms StrictSeq (Timelock MaryEra)
ss) =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata Map Word64 Metadatum
ms
  , ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra era
ShelleyBasedEra MaryEra
ShelleyBasedEraMary (Timelock MaryEra -> ScriptInEra era)
-> [Timelock MaryEra] -> [ScriptInEra era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (Timelock MaryEra)
-> [Item (StrictSeq (Timelock MaryEra))]
forall l. IsList l => l -> [Item l]
toList StrictSeq (Timelock MaryEra)
ss
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraAlonzo TxAuxData (ShelleyLedgerEra era)
txAuxData =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata (AlonzoTxAuxData AlonzoEra -> Map Word64 Metadatum
forall era.
(HasCallStack, AlonzoEraScript era) =>
AlonzoTxAuxData era -> Map Word64 Metadatum
L.atadMetadata TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData AlonzoEra
txAuxData)
  , ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra era
ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo
      (AlonzoScript AlonzoEra -> ScriptInEra era)
-> [AlonzoScript AlonzoEra] -> [ScriptInEra era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (AlonzoScript AlonzoEra)
-> [Item (StrictSeq (AlonzoScript AlonzoEra))]
forall l. IsList l => l -> [Item l]
toList (AlonzoTxAuxData AlonzoEra -> StrictSeq (AlonzoScript AlonzoEra)
forall era.
AlonzoEraScript era =>
AlonzoTxAuxData era -> StrictSeq (AlonzoScript era)
L.getAlonzoTxAuxDataScripts TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData AlonzoEra
txAuxData)
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraBabbage TxAuxData (ShelleyLedgerEra era)
txAuxData =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata (AlonzoTxAuxData BabbageEra -> Map Word64 Metadatum
forall era.
(HasCallStack, AlonzoEraScript era) =>
AlonzoTxAuxData era -> Map Word64 Metadatum
L.atadMetadata TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData BabbageEra
txAuxData)
  , ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra era
ShelleyBasedEra BabbageEra
ShelleyBasedEraBabbage
      (AlonzoScript BabbageEra -> ScriptInEra era)
-> [AlonzoScript BabbageEra] -> [ScriptInEra era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (AlonzoScript BabbageEra)
-> [Item (StrictSeq (AlonzoScript BabbageEra))]
forall l. IsList l => l -> [Item l]
toList (AlonzoTxAuxData BabbageEra -> StrictSeq (AlonzoScript BabbageEra)
forall era.
AlonzoEraScript era =>
AlonzoTxAuxData era -> StrictSeq (AlonzoScript era)
L.getAlonzoTxAuxDataScripts TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData BabbageEra
txAuxData)
  )
fromLedgerAuxiliaryData ShelleyBasedEra era
ShelleyBasedEraConway TxAuxData (ShelleyLedgerEra era)
txAuxData =
  ( Map Word64 Metadatum -> Map Word64 TxMetadataValue
fromShelleyMetadata (AlonzoTxAuxData ConwayEra -> Map Word64 Metadatum
forall era.
(HasCallStack, AlonzoEraScript era) =>
AlonzoTxAuxData era -> Map Word64 Metadatum
L.atadMetadata TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData ConwayEra
txAuxData)
  , ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
forall era.
ShelleyBasedEra era
-> Script (ShelleyLedgerEra era) -> ScriptInEra era
fromShelleyBasedScript ShelleyBasedEra era
ShelleyBasedEra ConwayEra
ShelleyBasedEraConway
      (AlonzoScript ConwayEra -> ScriptInEra era)
-> [AlonzoScript ConwayEra] -> [ScriptInEra era]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictSeq (AlonzoScript ConwayEra)
-> [Item (StrictSeq (AlonzoScript ConwayEra))]
forall l. IsList l => l -> [Item l]
toList (AlonzoTxAuxData ConwayEra -> StrictSeq (AlonzoScript ConwayEra)
forall era.
AlonzoEraScript era =>
AlonzoTxAuxData era -> StrictSeq (AlonzoScript era)
L.getAlonzoTxAuxDataScripts TxAuxData (ShelleyLedgerEra era)
AlonzoTxAuxData ConwayEra
txAuxData)
  )

fromLedgerTxAuxiliaryData
  :: ShelleyBasedEra era
  -> Maybe (L.TxAuxData (ShelleyLedgerEra era))
  -> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData :: forall era.
ShelleyBasedEra era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> (TxMetadataInEra era, TxAuxScripts era)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
_ Maybe (TxAuxData (ShelleyLedgerEra era))
Nothing = (TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone, TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone)
fromLedgerTxAuxiliaryData ShelleyBasedEra era
sbe (Just TxAuxData (ShelleyLedgerEra era)
auxData) =
  (TxMetadataInEra era
metadata, TxAuxScripts era
auxdata)
 where
  metadata :: TxMetadataInEra era
metadata = if Map Word64 TxMetadataValue -> Bool
forall a. Map Word64 a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Word64 TxMetadataValue
ms then TxMetadataInEra era
forall era. TxMetadataInEra era
TxMetadataNone else ShelleyBasedEra era -> TxMetadata -> TxMetadataInEra era
forall era.
ShelleyBasedEra era -> TxMetadata -> TxMetadataInEra era
TxMetadataInEra ShelleyBasedEra era
sbe (TxMetadata -> TxMetadataInEra era)
-> TxMetadata -> TxMetadataInEra era
forall a b. (a -> b) -> a -> b
$ Map Word64 TxMetadataValue -> TxMetadata
TxMetadata Map Word64 TxMetadataValue
ms

  auxdata :: TxAuxScripts era
auxdata =
    (ShelleyEraOnlyConstraints era =>
 ShelleyEraOnly era -> TxAuxScripts era)
-> (AllegraEraOnwardsConstraints era =>
    AllegraEraOnwards era -> TxAuxScripts era)
-> ShelleyBasedEra era
-> TxAuxScripts era
forall era a.
(ShelleyEraOnlyConstraints era => ShelleyEraOnly era -> a)
-> (AllegraEraOnwardsConstraints era => AllegraEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyEraOnlyOrAllegraEraOnwards
      (TxAuxScripts era -> ShelleyEraOnly era -> TxAuxScripts era
forall a b. a -> b -> a
const TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone)
      ( \AllegraEraOnwards era
w ->
          case [ScriptInEra era]
ss of
            [] -> TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
            [ScriptInEra era]
_ -> AllegraEraOnwards era -> [ScriptInEra era] -> TxAuxScripts era
forall era.
AllegraEraOnwards era -> [ScriptInEra era] -> TxAuxScripts era
TxAuxScripts AllegraEraOnwards era
w [ScriptInEra era]
ss
      )
      ShelleyBasedEra era
sbe

  (Map Word64 TxMetadataValue
ms, [ScriptInEra era]
ss) = ShelleyBasedEra era
-> TxAuxData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
forall era.
ShelleyBasedEra era
-> TxAuxData (ShelleyLedgerEra era)
-> (Map Word64 TxMetadataValue, [ScriptInEra era])
fromLedgerAuxiliaryData ShelleyBasedEra era
sbe TxAuxData (ShelleyLedgerEra era)
auxData

fromLedgerTxExtraKeyWitnesses
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxExtraKeyWitnesses era
fromLedgerTxExtraKeyWitnesses ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era -> TxExtraKeyWitnesses era)
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era -> TxExtraKeyWitnesses era)
-> ShelleyBasedEra era
-> TxExtraKeyWitnesses era
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
    (TxExtraKeyWitnesses era
-> ShelleyToMaryEra era -> TxExtraKeyWitnesses era
forall a b. a -> b -> a
const TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone)
    ( \AlonzoEraOnwards era
w ->
        let keyhashes :: Set (KeyHash 'Witness)
keyhashes = TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (Set (KeyHash 'Witness))
     (TxBody (ShelleyLedgerEra era))
     (Set (KeyHash 'Witness))
-> Set (KeyHash 'Witness)
forall s a. s -> Getting a s a -> a
^. Getting
  (Set (KeyHash 'Witness))
  (TxBody (ShelleyLedgerEra era))
  (Set (KeyHash 'Witness))
forall era.
AlonzoEraTxBody era =>
Lens' (TxBody era) (Set (KeyHash 'Witness))
Lens' (TxBody (ShelleyLedgerEra era)) (Set (KeyHash 'Witness))
L.reqSignerHashesTxBodyL
         in if Set (KeyHash 'Witness) -> Bool
forall a. Set a -> Bool
Set.null Set (KeyHash 'Witness)
keyhashes
              then TxExtraKeyWitnesses era
forall era. TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone
              else
                AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
forall era.
AlonzoEraOnwards era
-> [Hash PaymentKey] -> TxExtraKeyWitnesses era
TxExtraKeyWitnesses
                  AlonzoEraOnwards era
w
                  [ KeyHash 'Payment -> Hash PaymentKey
PaymentKeyHash (KeyHash 'Witness -> KeyHash 'Payment
forall (r :: KeyRole) (r' :: KeyRole). KeyHash r -> KeyHash r'
forall (a :: KeyRole -> *) (r :: KeyRole) (r' :: KeyRole).
HasKeyRole a =>
a r -> a r'
Shelley.coerceKeyRole KeyHash 'Witness
keyhash)
                  | KeyHash 'Witness
keyhash <- Set (KeyHash 'Witness) -> [Item (Set (KeyHash 'Witness))]
forall l. IsList l => l -> [Item l]
toList (Set (KeyHash 'Witness) -> [Item (Set (KeyHash 'Witness))])
-> Set (KeyHash 'Witness) -> [Item (Set (KeyHash 'Witness))]
forall a b. (a -> b) -> a -> b
$ TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (Set (KeyHash 'Witness))
     (TxBody (ShelleyLedgerEra era))
     (Set (KeyHash 'Witness))
-> Set (KeyHash 'Witness)
forall s a. s -> Getting a s a -> a
^. Getting
  (Set (KeyHash 'Witness))
  (TxBody (ShelleyLedgerEra era))
  (Set (KeyHash 'Witness))
forall era.
AlonzoEraTxBody era =>
Lens' (TxBody era) (Set (KeyHash 'Witness))
Lens' (TxBody (ShelleyLedgerEra era)) (Set (KeyHash 'Witness))
L.reqSignerHashesTxBodyL
                  ]
    )
    ShelleyBasedEra era
sbe

fromLedgerTxWithdrawals
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxWithdrawals ViewTx era
fromLedgerTxWithdrawals :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxWithdrawals ViewTx era
fromLedgerTxWithdrawals ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxWithdrawals ViewTx era)
-> TxWithdrawals ViewTx era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxWithdrawals ViewTx era)
 -> TxWithdrawals ViewTx era)
-> (ShelleyBasedEraConstraints era => TxWithdrawals ViewTx era)
-> TxWithdrawals ViewTx era
forall a b. (a -> b) -> a -> b
$
    let withdrawals :: Withdrawals
withdrawals = TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting Withdrawals (TxBody (ShelleyLedgerEra era)) Withdrawals
-> Withdrawals
forall s a. s -> Getting a s a -> a
^. Getting Withdrawals (TxBody (ShelleyLedgerEra era)) Withdrawals
forall era. EraTxBody era => Lens' (TxBody era) Withdrawals
Lens' (TxBody (ShelleyLedgerEra era)) Withdrawals
L.withdrawalsTxBodyL
     in if Map RewardAccount Coin -> Bool
forall a. Map RewardAccount a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Withdrawals -> Map RewardAccount Coin
L.unWithdrawals Withdrawals
withdrawals)
          then TxWithdrawals ViewTx era
forall build era. TxWithdrawals build era
TxWithdrawalsNone
          else ShelleyBasedEra era
-> [(StakeAddress, Coin,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
-> TxWithdrawals ViewTx era
forall era build.
ShelleyBasedEra era
-> [(StakeAddress, Coin,
     BuildTxWith build (Witness WitCtxStake era))]
-> TxWithdrawals build era
TxWithdrawals ShelleyBasedEra era
sbe ([(StakeAddress, Coin,
   BuildTxWith ViewTx (Witness WitCtxStake era))]
 -> TxWithdrawals ViewTx era)
-> [(StakeAddress, Coin,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
-> TxWithdrawals ViewTx era
forall a b. (a -> b) -> a -> b
$ Withdrawals
-> [(StakeAddress, Coin,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
forall era.
Withdrawals
-> [(StakeAddress, Coin,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal Withdrawals
withdrawals

fromLedgerTxCertificates
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxCertificates ViewTx era
fromLedgerTxCertificates :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxCertificates ViewTx era
fromLedgerTxCertificates ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxCertificates ViewTx era)
-> TxCertificates ViewTx era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxCertificates ViewTx era)
 -> TxCertificates ViewTx era)
-> (ShelleyBasedEraConstraints era => TxCertificates ViewTx era)
-> TxCertificates ViewTx era
forall a b. (a -> b) -> a -> b
$
    let certificates :: StrictSeq (TxCert (ShelleyLedgerEra era))
certificates = TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (StrictSeq (TxCert (ShelleyLedgerEra era)))
     (TxBody (ShelleyLedgerEra era))
     (StrictSeq (TxCert (ShelleyLedgerEra era)))
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictSeq (TxCert (ShelleyLedgerEra era)))
  (TxBody (ShelleyLedgerEra era))
  (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxCert era))
Lens'
  (TxBody (ShelleyLedgerEra era))
  (StrictSeq (TxCert (ShelleyLedgerEra era)))
L.certsTxBodyL
     in if StrictSeq (TxCert (ShelleyLedgerEra era)) -> Bool
forall a. StrictSeq a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null StrictSeq (TxCert (ShelleyLedgerEra era))
certificates
          then TxCertificates ViewTx era
forall build era. TxCertificates build era
TxCertificatesNone
          else
            ShelleyBasedEra era
-> OMap
     (Certificate era)
     (BuildTxWith
        ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))
-> TxCertificates ViewTx era
forall era build.
ShelleyBasedEra era
-> OMap
     (Certificate era)
     (BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> TxCertificates build era
TxCertificates ShelleyBasedEra era
sbe (OMap
   (Certificate era)
   (BuildTxWith
      ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))
 -> TxCertificates ViewTx era)
-> ([(Certificate era,
      BuildTxWith
        ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
    -> OMap
         (Certificate era)
         (BuildTxWith
            ViewTx (Maybe (StakeCredential, Witness WitCtxStake era))))
-> [(Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> TxCertificates ViewTx era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Certificate era,
  BuildTxWith
    ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> OMap
     (Certificate era)
     (BuildTxWith
        ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))
[Item
   (OMap
      (Certificate era)
      (BuildTxWith
         ViewTx (Maybe (StakeCredential, Witness WitCtxStake era))))]
-> OMap
     (Certificate era)
     (BuildTxWith
        ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))
forall l. IsList l => [Item l] -> l
fromList ([(Certificate era,
   BuildTxWith
     ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
 -> TxCertificates ViewTx era)
-> [(Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> TxCertificates ViewTx era
forall a b. (a -> b) -> a -> b
$ (TxCert (ShelleyLedgerEra era)
 -> (Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era))))
-> [TxCert (ShelleyLedgerEra era)]
-> [(Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
forall a b. (a -> b) -> [a] -> [b]
map ((,BuildTxWith
  ViewTx (Maybe (StakeCredential, Witness WitCtxStake era))
forall a. BuildTxWith ViewTx a
ViewTx) (Certificate era
 -> (Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era))))
-> (TxCert (ShelleyLedgerEra era) -> Certificate era)
-> TxCert (ShelleyLedgerEra era)
-> (Certificate era,
    BuildTxWith
      ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyBasedEra era
-> TxCert (ShelleyLedgerEra era) -> Certificate era
forall era.
ShelleyBasedEra era
-> TxCert (ShelleyLedgerEra era) -> Certificate era
fromShelleyCertificate ShelleyBasedEra era
sbe) ([TxCert (ShelleyLedgerEra era)]
 -> [(Certificate era,
      BuildTxWith
        ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))])
-> [TxCert (ShelleyLedgerEra era)]
-> [(Certificate era,
     BuildTxWith
       ViewTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
forall a b. (a -> b) -> a -> b
$ StrictSeq (TxCert (ShelleyLedgerEra era))
-> [Item (StrictSeq (TxCert (ShelleyLedgerEra era)))]
forall l. IsList l => l -> [Item l]
toList StrictSeq (TxCert (ShelleyLedgerEra era))
certificates

maybeFromLedgerTxUpdateProposal
  :: ()
  => ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxUpdateProposal era
maybeFromLedgerTxUpdateProposal :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxUpdateProposal era
maybeFromLedgerTxUpdateProposal ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body =
  (ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era -> TxUpdateProposal era)
-> (ConwayEraOnwardsConstraints era =>
    ConwayEraOnwards era -> TxUpdateProposal era)
-> ShelleyBasedEra era
-> TxUpdateProposal era
forall era a.
(ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era -> a)
-> (ConwayEraOnwardsConstraints era => ConwayEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToBabbageOrConwayEraOnwards
    ( \ShelleyToBabbageEra era
w ->
        case TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting
     (StrictMaybe (Update (ShelleyLedgerEra era)))
     (TxBody (ShelleyLedgerEra era))
     (StrictMaybe (Update (ShelleyLedgerEra era)))
-> StrictMaybe (Update (ShelleyLedgerEra era))
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Update (ShelleyLedgerEra era)))
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyEraTxBody era =>
Lens' (TxBody era) (StrictMaybe (Update era))
Lens'
  (TxBody (ShelleyLedgerEra era))
  (StrictMaybe (Update (ShelleyLedgerEra era)))
L.updateTxBodyL of
          StrictMaybe (Update (ShelleyLedgerEra era))
SNothing -> TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone
          SJust Update (ShelleyLedgerEra era)
p -> ShelleyToBabbageEra era -> UpdateProposal -> TxUpdateProposal era
forall era.
ShelleyToBabbageEra era -> UpdateProposal -> TxUpdateProposal era
TxUpdateProposal ShelleyToBabbageEra era
w (ShelleyBasedEra era
-> Update (ShelleyLedgerEra era) -> UpdateProposal
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> Update ledgerera -> UpdateProposal
fromLedgerUpdate ShelleyBasedEra era
sbe Update (ShelleyLedgerEra era)
p)
    )
    (TxUpdateProposal era
-> ConwayEraOnwards era -> TxUpdateProposal era
forall a b. a -> b -> a
const TxUpdateProposal era
forall era. TxUpdateProposal era
TxUpdateProposalNone)
    ShelleyBasedEra era
sbe

fromLedgerTxMintValue
  :: ShelleyBasedEra era
  -> Ledger.TxBody (ShelleyLedgerEra era)
  -> TxMintValue ViewTx era
fromLedgerTxMintValue :: forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era) -> TxMintValue ViewTx era
fromLedgerTxMintValue ShelleyBasedEra era
sbe TxBody (ShelleyLedgerEra era)
body = CardanoEra era
-> TxMintValue ViewTx era
-> (MaryEraOnwards era -> TxMintValue ViewTx era)
-> TxMintValue ViewTx era
forall (eon :: * -> *) era a.
Eon eon =>
CardanoEra era -> a -> (eon era -> a) -> a
forEraInEon (ShelleyBasedEra era -> CardanoEra era
forall era. ShelleyBasedEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra ShelleyBasedEra era
sbe) TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone ((MaryEraOnwards era -> TxMintValue ViewTx era)
 -> TxMintValue ViewTx era)
-> (MaryEraOnwards era -> TxMintValue ViewTx era)
-> TxMintValue ViewTx era
forall a b. (a -> b) -> a -> b
$ \MaryEraOnwards era
w ->
  MaryEraOnwards era
-> (MaryEraOnwardsConstraints era => TxMintValue ViewTx era)
-> TxMintValue ViewTx era
forall era a.
MaryEraOnwards era -> (MaryEraOnwardsConstraints era => a) -> a
maryEraOnwardsConstraints MaryEraOnwards era
w ((MaryEraOnwardsConstraints era => TxMintValue ViewTx era)
 -> TxMintValue ViewTx era)
-> (MaryEraOnwardsConstraints era => TxMintValue ViewTx era)
-> TxMintValue ViewTx era
forall a b. (a -> b) -> a -> b
$ do
    let multiAsset :: MultiAsset
multiAsset = TxBody (ShelleyLedgerEra era)
body TxBody (ShelleyLedgerEra era)
-> Getting MultiAsset (TxBody (ShelleyLedgerEra era)) MultiAsset
-> MultiAsset
forall s a. s -> Getting a s a -> a
^. Getting MultiAsset (TxBody (ShelleyLedgerEra era)) MultiAsset
forall era. MaryEraTxBody era => Lens' (TxBody era) MultiAsset
Lens' (TxBody (ShelleyLedgerEra era)) MultiAsset
L.mintTxBodyL
    if MaryValue -> Bool
forall t. Val t => t -> Bool
L.isZero (MaryValue -> Bool) -> MaryValue -> Bool
forall a b. (a -> b) -> a -> b
$ Coin -> MultiAsset -> MaryValue
MaryValue (Integer -> Coin
Ledger.Coin Integer
0) MultiAsset
multiAsset
      then TxMintValue ViewTx era
forall build era. TxMintValue build era
TxMintNone
      else
        MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith ViewTx (ScriptWitness WitCtxMint era))
-> TxMintValue ViewTx era
forall era build.
MaryEraOnwards era
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> TxMintValue build era
TxMintValue MaryEraOnwards era
w (Map
   PolicyId
   (PolicyAssets, BuildTxWith ViewTx (ScriptWitness WitCtxMint era))
 -> TxMintValue ViewTx era)
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith ViewTx (ScriptWitness WitCtxMint era))
-> TxMintValue ViewTx era
forall a b. (a -> b) -> a -> b
$ (,BuildTxWith ViewTx (ScriptWitness WitCtxMint era)
forall a. BuildTxWith ViewTx a
ViewTx) (PolicyAssets
 -> (PolicyAssets,
     BuildTxWith ViewTx (ScriptWitness WitCtxMint era)))
-> Map PolicyId PolicyAssets
-> Map
     PolicyId
     (PolicyAssets, BuildTxWith ViewTx (ScriptWitness WitCtxMint era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MultiAsset -> Map PolicyId PolicyAssets
multiAssetToPolicyAssets MultiAsset
multiAsset

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

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

classifyRangeError :: TxOut CtxTx ByronEra -> TxBodyError
classifyRangeError :: TxOut CtxTx ByronEra -> TxBodyError
classifyRangeError TxOut CtxTx ByronEra
txout =
  case TxOut CtxTx ByronEra
txout of
    TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra ByronAddress{}) (TxOutValueByron Coin
value) TxOutDatum CtxTx ByronEra
_ ReferenceScript ByronEra
_
      | Coin
value Coin -> Coin -> Bool
forall a. Ord a => a -> a -> Bool
< Coin
0 -> Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputNegative (Coin -> Quantity
lovelaceToQuantity Coin
value) (CardanoEra ByronEra -> TxOut CtxTx ByronEra -> TxOutInAnyEra
forall era. CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra CardanoEra ByronEra
ByronEra TxOut CtxTx ByronEra
txout)
      | Bool
otherwise -> Quantity -> TxOutInAnyEra -> TxBodyError
TxBodyOutputOverflow (Coin -> Quantity
lovelaceToQuantity Coin
value) (CardanoEra ByronEra -> TxOut CtxTx ByronEra -> TxOutInAnyEra
forall era. CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra
txOutInAnyEra CardanoEra ByronEra
ByronEra TxOut CtxTx ByronEra
txout)
    TxOut (AddressInEra AddressTypeInEra addrtype ByronEra
ByronAddressInAnyEra (ByronAddress Address
_)) (TxOutValueShelleyBased ShelleyBasedEra ByronEra
w Value (ShelleyLedgerEra ByronEra)
_) TxOutDatum CtxTx ByronEra
_ ReferenceScript ByronEra
_ -> case ShelleyBasedEra ByronEra
w of {}
    TxOut (AddressInEra (ShelleyAddressInEra ShelleyBasedEra ByronEra
sbe) ShelleyAddress{}) TxOutValue ByronEra
_ TxOutDatum CtxTx ByronEra
_ ReferenceScript ByronEra
_ -> case ShelleyBasedEra ByronEra
sbe of {}

convTxIns :: TxIns BuildTx era -> Set L.TxIn
convTxIns :: forall era. TxIns BuildTx era -> Set TxIn
convTxIns TxIns BuildTx era
txIns = [Item (Set TxIn)] -> Set TxIn
forall l. IsList l => [Item l] -> l
fromList (((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> TxIns BuildTx era -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map (TxIn -> TxIn
toShelleyTxIn (TxIn -> TxIn)
-> ((TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era)) -> TxIn)
-> (TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))
-> TxIn
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)

convCollateralTxIns :: TxInsCollateral era -> Set Ledger.TxIn
convCollateralTxIns :: forall era. TxInsCollateral era -> Set TxIn
convCollateralTxIns TxInsCollateral era
txInsCollateral =
  case TxInsCollateral era
txInsCollateral of
    TxInsCollateral era
TxInsCollateralNone -> Set TxIn
forall a. Set a
Set.empty
    TxInsCollateral AlonzoEraOnwards era
_ [TxIn]
txins -> [Item (Set TxIn)] -> Set TxIn
forall l. IsList l => [Item l] -> l
fromList ((TxIn -> TxIn) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn
toShelleyTxIn [TxIn]
txins)

convReturnCollateral
  :: ShelleyBasedEra era
  -> TxReturnCollateral ctx era
  -> StrictMaybe (Ledger.TxOut (ShelleyLedgerEra era))
convReturnCollateral :: forall era ctx.
ShelleyBasedEra era
-> TxReturnCollateral ctx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
convReturnCollateral ShelleyBasedEra era
sbe TxReturnCollateral ctx era
txReturnCollateral =
  case TxReturnCollateral ctx era
txReturnCollateral of
    TxReturnCollateral ctx era
TxReturnCollateralNone -> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall a. StrictMaybe a
SNothing
    TxReturnCollateral BabbageEraOnwards era
_ TxOut ctx era
colTxOut -> TxOut (ShelleyLedgerEra era)
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall a. a -> StrictMaybe a
SJust (TxOut (ShelleyLedgerEra era)
 -> StrictMaybe (TxOut (ShelleyLedgerEra era)))
-> TxOut (ShelleyLedgerEra era)
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> TxOut ctx era -> TxOut (ShelleyLedgerEra era)
forall ctx era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
sbe TxOut ctx era
colTxOut

convTotalCollateral :: TxTotalCollateral era -> StrictMaybe Ledger.Coin
convTotalCollateral :: forall era. TxTotalCollateral era -> StrictMaybe Coin
convTotalCollateral TxTotalCollateral era
txTotalCollateral =
  case TxTotalCollateral era
txTotalCollateral of
    TxTotalCollateral era
TxTotalCollateralNone -> StrictMaybe Coin
forall a. StrictMaybe a
SNothing
    TxTotalCollateral BabbageEraOnwards era
_ Coin
totCollLovelace -> Coin -> StrictMaybe Coin
forall a. a -> StrictMaybe a
SJust Coin
totCollLovelace

convTxOuts
  :: forall ctx era ledgerera
   . HasCallStack
  => ShelleyLedgerEra era ~ ledgerera
  => ShelleyBasedEra era
  -> [TxOut ctx era]
  -> Seq.StrictSeq (Ledger.TxOut ledgerera)
convTxOuts :: forall ctx era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era
-> [TxOut ctx era] -> StrictSeq (TxOut ledgerera)
convTxOuts ShelleyBasedEra era
sbe [TxOut ctx era]
txOuts = [Item (StrictSeq (TxOut ledgerera))] -> StrictSeq (TxOut ledgerera)
forall l. IsList l => [Item l] -> l
fromList ([Item (StrictSeq (TxOut ledgerera))]
 -> StrictSeq (TxOut ledgerera))
-> [Item (StrictSeq (TxOut ledgerera))]
-> StrictSeq (TxOut ledgerera)
forall a b. (a -> b) -> a -> b
$ (TxOut ctx era -> TxOut ledgerera)
-> [TxOut ctx era] -> [TxOut ledgerera]
forall a b. (a -> b) -> [a] -> [b]
map (ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
forall ctx era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
sbe) [TxOut ctx era]
txOuts

convCertificates
  :: ShelleyBasedEra era
  -> TxCertificates build era
  -> Seq.StrictSeq (Shelley.TxCert (ShelleyLedgerEra era))
convCertificates :: forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
_ = \case
  TxCertificates build era
TxCertificatesNone -> StrictSeq (TxCert (ShelleyLedgerEra era))
forall a. StrictSeq a
Seq.empty
  TxCertificates ShelleyBasedEra era
_ OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
cs -> [Item (StrictSeq (TxCert (ShelleyLedgerEra era)))]
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall l. IsList l => [Item l] -> l
fromList ([Item (StrictSeq (TxCert (ShelleyLedgerEra era)))]
 -> StrictSeq (TxCert (ShelleyLedgerEra era)))
-> ([(Certificate era,
      BuildTxWith
        build (Maybe (StakeCredential, Witness WitCtxStake era)))]
    -> [Item (StrictSeq (TxCert (ShelleyLedgerEra era)))])
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Certificate era,
  BuildTxWith
    build (Maybe (StakeCredential, Witness WitCtxStake era)))
 -> Item (StrictSeq (TxCert (ShelleyLedgerEra era))))
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> [Item (StrictSeq (TxCert (ShelleyLedgerEra era)))]
forall a b. (a -> b) -> [a] -> [b]
map (Certificate era -> Item (StrictSeq (TxCert (ShelleyLedgerEra era)))
Certificate era -> TxCert (ShelleyLedgerEra era)
forall era. Certificate era -> TxCert (ShelleyLedgerEra era)
toShelleyCertificate (Certificate era
 -> Item (StrictSeq (TxCert (ShelleyLedgerEra era))))
-> ((Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))
    -> Certificate era)
-> (Certificate era,
    BuildTxWith
      build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> Item (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Certificate era,
 BuildTxWith
   build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> Certificate era
forall a b. (a, b) -> a
fst) ([(Certificate era,
   BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))]
 -> StrictSeq (TxCert (ShelleyLedgerEra era)))
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> [Item
      (OMap
         (Certificate era)
         (BuildTxWith
            build (Maybe (StakeCredential, Witness WitCtxStake era))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
cs

convWithdrawals :: TxWithdrawals build era -> L.Withdrawals
convWithdrawals :: forall build era. TxWithdrawals build era -> Withdrawals
convWithdrawals TxWithdrawals build era
txWithdrawals =
  case TxWithdrawals build era
txWithdrawals of
    TxWithdrawals build era
TxWithdrawalsNone -> Map RewardAccount Coin -> Withdrawals
L.Withdrawals Map RewardAccount Coin
forall k a. Map k a
Map.empty
    TxWithdrawals ShelleyBasedEra era
_ [(StakeAddress, Coin, BuildTxWith build (Witness WitCtxStake era))]
ws -> [(StakeAddress, Coin, BuildTxWith build (Witness WitCtxStake era))]
-> Withdrawals
forall a. [(StakeAddress, Coin, a)] -> Withdrawals
toShelleyWithdrawal [(StakeAddress, Coin, BuildTxWith build (Witness WitCtxStake era))]
ws

convTransactionFee :: ShelleyBasedEra era -> TxFee era -> Ledger.Coin
convTransactionFee :: forall era. ShelleyBasedEra era -> TxFee era -> Coin
convTransactionFee ShelleyBasedEra era
_ (TxFeeExplicit ShelleyBasedEra era
_ Coin
fee) = Coin
fee

convValidityLowerBound
  :: ()
  => TxValidityLowerBound era
  -> Maybe SlotNo
convValidityLowerBound :: forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound = \case
  TxValidityLowerBound era
TxValidityNoLowerBound -> Maybe SlotNo
forall a. Maybe a
Nothing
  TxValidityLowerBound AllegraEraOnwards era
_ SlotNo
s -> SlotNo -> Maybe SlotNo
forall a. a -> Maybe a
Just SlotNo
s

convValidityUpperBound
  :: ()
  => ShelleyBasedEra era
  -> TxValidityUpperBound era
  -> Maybe SlotNo
convValidityUpperBound :: forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
_ = \case
  TxValidityUpperBound ShelleyBasedEra era
_ Maybe SlotNo
ms -> Maybe SlotNo
ms

-- | Convert transaction update proposal into ledger update proposal
convTxUpdateProposal
  :: ()
  => ShelleyBasedEra era
  -> TxUpdateProposal era
  -> Either TxBodyError (StrictMaybe (Ledger.Update (ShelleyLedgerEra era)))
  -- ^ 'Left' when there's protocol params conversion error, 'Right' otherwise, 'Right SNothing' means that
  -- there's no update proposal
convTxUpdateProposal :: forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe = \case
  TxUpdateProposal era
TxUpdateProposalNone -> StrictMaybe (Update (ShelleyLedgerEra era))
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall a b. b -> Either a b
Right StrictMaybe (Update (ShelleyLedgerEra era))
forall a. StrictMaybe a
SNothing
  TxUpdateProposal ShelleyToBabbageEra era
_ UpdateProposal
p -> (ProtocolParametersConversionError -> TxBodyError)
-> (Update (ShelleyLedgerEra era)
    -> StrictMaybe (Update (ShelleyLedgerEra era)))
-> Either
     ProtocolParametersConversionError (Update (ShelleyLedgerEra era))
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ProtocolParametersConversionError -> TxBodyError
TxBodyProtocolParamsConversionError Update (ShelleyLedgerEra era)
-> StrictMaybe (Update (ShelleyLedgerEra era))
forall a. a -> StrictMaybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either
   ProtocolParametersConversionError (Update (ShelleyLedgerEra era))
 -> Either
      TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era))))
-> Either
     ProtocolParametersConversionError (Update (ShelleyLedgerEra era))
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall a b. (a -> b) -> a -> b
$ ShelleyBasedEra era
-> UpdateProposal
-> Either
     ProtocolParametersConversionError (Update (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> UpdateProposal
-> Either
     ProtocolParametersConversionError (Update (ShelleyLedgerEra era))
toLedgerUpdate ShelleyBasedEra era
sbe UpdateProposal
p

convMintValue :: TxMintValue build era -> MultiAsset
convMintValue :: forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue build era
txMintValue = do
  let L.MaryValue Coin
_coin MultiAsset
multiAsset = Value -> MaryValue
toMaryValue (Value -> MaryValue) -> Value -> MaryValue
forall a b. (a -> b) -> a -> b
$ TxMintValue build era -> Value
forall build era. TxMintValue build era -> Value
txMintValueToValue TxMintValue build era
txMintValue
  MultiAsset
multiAsset

convExtraKeyWitnesses
  :: TxExtraKeyWitnesses era -> Set (Shelley.KeyHash Shelley.Witness)
convExtraKeyWitnesses :: forall era. TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
convExtraKeyWitnesses TxExtraKeyWitnesses era
txExtraKeyWits =
  case TxExtraKeyWitnesses era
txExtraKeyWits of
    TxExtraKeyWitnesses era
TxExtraKeyWitnessesNone -> Set (KeyHash 'Witness)
forall a. Set a
Set.empty
    TxExtraKeyWitnesses AlonzoEraOnwards era
_ [Hash PaymentKey]
khs ->
      [Item (Set (KeyHash 'Witness))] -> Set (KeyHash 'Witness)
forall l. IsList l => [Item l] -> l
fromList
        [ KeyHash 'Payment -> KeyHash 'Witness
forall (a :: KeyRole -> *) (r :: KeyRole).
HasKeyRole a =>
a r -> a 'Witness
Shelley.asWitness KeyHash 'Payment
kh
        | PaymentKeyHash KeyHash 'Payment
kh <- [Hash PaymentKey]
khs
        ]

convScripts
  :: ShelleyLedgerEra era ~ ledgerera
  => [(ScriptWitnessIndex, AnyScriptWitness era)]
  -> [Ledger.Script ledgerera]
convScripts :: forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
[(ScriptWitnessIndex, AnyScriptWitness era)] -> [Script ledgerera]
convScripts [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnesses =
  [Maybe (Script ledgerera)] -> [Script ledgerera]
forall a. [Maybe a] -> [a]
catMaybes
    [ ScriptInEra era -> Script ledgerera
ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Script ledgerera)
-> Maybe (ScriptInEra era) -> Maybe (Script ledgerera)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
getScriptWitnessScript ScriptWitness witctx era
scriptwitness
    | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness) <- [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnesses
    ]

-- ScriptData collectively refers to datums and/or redeemers
convScriptData
  :: ()
  => ShelleyBasedEra era
  -> [TxOut CtxTx era]
  -> [(ScriptWitnessIndex, AnyScriptWitness era)]
  -> TxBodyScriptData era
convScriptData :: forall era.
ShelleyBasedEra era
-> [TxOut CtxTx era]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> TxBodyScriptData era
convScriptData ShelleyBasedEra era
sbe [TxOut CtxTx era]
txOuts [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnesses =
  (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era -> TxBodyScriptData era)
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era -> TxBodyScriptData era)
-> ShelleyBasedEra era
-> TxBodyScriptData era
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
    (TxBodyScriptData era
-> ShelleyToMaryEra era -> TxBodyScriptData era
forall a b. a -> b -> a
const TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData)
    ( \AlonzoEraOnwards era
w ->
        let redeemers :: Redeemers (ShelleyLedgerEra era)
redeemers =
              Map
  (PlutusPurpose AsIx (ShelleyLedgerEra era))
  (Data (ShelleyLedgerEra era), ExUnits)
-> Redeemers (ShelleyLedgerEra era)
forall era.
AlonzoEraScript era =>
Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map
   (PlutusPurpose AsIx (ShelleyLedgerEra era))
   (Data (ShelleyLedgerEra era), ExUnits)
 -> Redeemers (ShelleyLedgerEra era))
-> Map
     (PlutusPurpose AsIx (ShelleyLedgerEra era))
     (Data (ShelleyLedgerEra era), ExUnits)
-> Redeemers (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
                [Item
   (Map
      (PlutusPurpose AsIx (ShelleyLedgerEra era))
      (Data (ShelleyLedgerEra era), ExUnits))]
-> Map
     (PlutusPurpose AsIx (ShelleyLedgerEra era))
     (Data (ShelleyLedgerEra era), ExUnits)
forall l. IsList l => [Item l] -> l
fromList
                  [ (PlutusPurpose AsIx (ShelleyLedgerEra era)
i, (HashableScriptData -> Data (ShelleyLedgerEra era)
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
                  | ( ScriptWitnessIndex
idx
                      , AnyScriptWitness
                          (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
d ExecutionUnits
e)
                      ) <-
                      [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnesses
                  , Just PlutusPurpose AsIx (ShelleyLedgerEra era)
i <- [AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
forall era.
AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex AlonzoEraOnwards era
w ScriptWitnessIndex
idx]
                  ]

            datums :: TxDats (ShelleyLedgerEra era)
datums =
              Map DataHash (Data (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall era. Era era => Map DataHash (Data era) -> TxDats era
Alonzo.TxDats (Map DataHash (Data (ShelleyLedgerEra era))
 -> TxDats (ShelleyLedgerEra era))
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
                [Item (Map DataHash (Data (ShelleyLedgerEra era)))]
-> Map DataHash (Data (ShelleyLedgerEra era))
forall l. IsList l => [Item l] -> l
fromList
                  [ (Data (ShelleyLedgerEra era) -> DataHash
forall era. Data era -> DataHash
L.hashData Data (ShelleyLedgerEra era)
d', Data (ShelleyLedgerEra era)
d')
                  | HashableScriptData
d <- [HashableScriptData]
scriptdata
                  , let d' :: Data (ShelleyLedgerEra era)
d' = HashableScriptData -> Data (ShelleyLedgerEra era)
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d
                  ]

            scriptdata :: [HashableScriptData]
            scriptdata :: [HashableScriptData]
scriptdata =
              [HashableScriptData
d | TxOut AddressInEra era
_ TxOutValue era
_ (TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
d) ReferenceScript era
_ <- [TxOut CtxTx era]
txOuts]
                [HashableScriptData]
-> [HashableScriptData] -> [HashableScriptData]
forall a. [a] -> [a] -> [a]
++ [ HashableScriptData
d
                   | ( ScriptWitnessIndex
_
                       , AnyScriptWitness
                           ( PlutusScriptWitness
                               ScriptLanguageInEra lang era
_
                               PlutusScriptVersion lang
_
                               PlutusScriptOrReferenceInput lang
_
                               (ScriptDatumForTxIn (Just HashableScriptData
d))
                               HashableScriptData
_
                               ExecutionUnits
_
                             )
                       ) <-
                       [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnesses
                   ]
         in AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
AlonzoEraOnwardsConstraints era =>
AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData AlonzoEraOnwards era
w TxDats (ShelleyLedgerEra era)
datums Redeemers (ShelleyLedgerEra era)
redeemers
    )
    ShelleyBasedEra era
sbe

convPParamsToScriptIntegrityHash
  :: ()
  => AlonzoEraOnwards era
  -> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
  -> Alonzo.Redeemers (ShelleyLedgerEra era)
  -> Alonzo.TxDats (ShelleyLedgerEra era)
  -> Set Plutus.Language
  -> StrictMaybe L.ScriptIntegrityHash
convPParamsToScriptIntegrityHash :: forall era.
AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
convPParamsToScriptIntegrityHash AlonzoEraOnwards era
w BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams Redeemers (ShelleyLedgerEra era)
redeemers TxDats (ShelleyLedgerEra era)
datums Set Language
languages =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    StrictMaybe ScriptIntegrityHash)
-> StrictMaybe ScriptIntegrityHash
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
w ((AlonzoEraOnwardsConstraints era =>
  StrictMaybe ScriptIntegrityHash)
 -> StrictMaybe ScriptIntegrityHash)
-> (AlonzoEraOnwardsConstraints era =>
    StrictMaybe ScriptIntegrityHash)
-> StrictMaybe ScriptIntegrityHash
forall a b. (a -> b) -> a -> b
$
    case BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams of
      BuildTxWith Maybe (LedgerProtocolParameters era)
Nothing -> StrictMaybe ScriptIntegrityHash
forall a. StrictMaybe a
SNothing
      BuildTxWith (Just (LedgerProtocolParameters PParams (ShelleyLedgerEra era)
pp)) ->
        Set LangDepView
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> StrictMaybe ScriptIntegrityHash
forall era.
AlonzoEraScript era =>
Set LangDepView
-> Redeemers era -> TxDats era -> StrictMaybe ScriptIntegrityHash
Alonzo.hashScriptIntegrity ((Language -> LangDepView) -> Set Language -> Set LangDepView
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map (PParams (ShelleyLedgerEra era) -> Language -> LangDepView
forall era.
AlonzoEraPParams era =>
PParams era -> Language -> LangDepView
L.getLanguageView PParams (ShelleyLedgerEra era)
pp) Set Language
languages) Redeemers (ShelleyLedgerEra era)
redeemers TxDats (ShelleyLedgerEra era)
datums

convLanguages :: [(ScriptWitnessIndex, AnyScriptWitness era)] -> Set Plutus.Language
convLanguages :: forall era.
[(ScriptWitnessIndex, AnyScriptWitness era)] -> Set Language
convLanguages [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses =
  [Item (Set Language)] -> Set Language
forall l. IsList l => [Item l] -> l
fromList
    [ AnyPlutusScriptVersion -> Language
toAlonzoLanguage (PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v)
    | (ScriptWitnessIndex
_, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang era
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness era)]
witnesses
    ]

convReferenceInputs :: TxInsReference era -> Set Ledger.TxIn
convReferenceInputs :: forall era. TxInsReference era -> Set TxIn
convReferenceInputs TxInsReference era
txInsReference =
  case TxInsReference era
txInsReference of
    TxInsReference era
TxInsReferenceNone -> Set TxIn
forall a. Monoid a => a
mempty
    TxInsReference BabbageEraOnwards era
_ [TxIn]
refTxins -> [Item (Set TxIn)] -> Set TxIn
forall l. IsList l => [Item l] -> l
fromList ([Item (Set TxIn)] -> Set TxIn) -> [Item (Set TxIn)] -> Set TxIn
forall a b. (a -> b) -> a -> b
$ (TxIn -> TxIn) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn
toShelleyTxIn [TxIn]
refTxins

-- | Returns an OSet of proposals from 'TxProposalProcedures'.
convProposalProcedures
  :: TxProposalProcedures build era -> OSet (L.ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures :: forall build era.
TxProposalProcedures build era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures TxProposalProcedures build era
TxProposalProceduresNone = OSet (ProposalProcedure (ShelleyLedgerEra era))
forall a. OSet a
OSet.empty
convProposalProcedures (TxProposalProcedures OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
proposals) = [Item (OSet (ProposalProcedure (ShelleyLedgerEra era)))]
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall l. IsList l => [Item l] -> l
fromList ([Item (OSet (ProposalProcedure (ShelleyLedgerEra era)))]
 -> OSet (ProposalProcedure (ShelleyLedgerEra era)))
-> [Item (OSet (ProposalProcedure (ShelleyLedgerEra era)))]
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ (ProposalProcedure (ShelleyLedgerEra era),
 BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> ProposalProcedure (ShelleyLedgerEra era)
forall a b. (a, b) -> a
fst ((ProposalProcedure (ShelleyLedgerEra era),
  BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
 -> ProposalProcedure (ShelleyLedgerEra era))
-> [(ProposalProcedure (ShelleyLedgerEra era),
     BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))]
-> [ProposalProcedure (ShelleyLedgerEra era)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
-> [Item
      (OMap
         (ProposalProcedure (ShelleyLedgerEra era))
         (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era)))
proposals

convVotingProcedures :: TxVotingProcedures build era -> L.VotingProcedures (ShelleyLedgerEra era)
convVotingProcedures :: forall build era.
TxVotingProcedures build era
-> VotingProcedures (ShelleyLedgerEra era)
convVotingProcedures TxVotingProcedures build era
txVotingProcedures =
  case TxVotingProcedures build era
txVotingProcedures of
    TxVotingProcedures build era
TxVotingProceduresNone -> Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
-> VotingProcedures (ShelleyLedgerEra era)
forall era.
Map Voter (Map GovActionId (VotingProcedure era))
-> VotingProcedures era
L.VotingProcedures Map
  Voter (Map GovActionId (VotingProcedure (ShelleyLedgerEra era)))
forall k a. Map k a
Map.empty
    TxVotingProcedures VotingProcedures (ShelleyLedgerEra era)
vps BuildTxWith build (Map Voter (ScriptWitness WitCtxStake era))
_ -> VotingProcedures (ShelleyLedgerEra era)
vps

guardShelleyTxInsOverflow :: [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow :: [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow [TxIn]
txIns = do
  [TxIn] -> (TxIn -> Either TxBodyError ()) -> Either TxBodyError ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [TxIn]
txIns ((TxIn -> Either TxBodyError ()) -> Either TxBodyError ())
-> (TxIn -> Either TxBodyError ()) -> Either TxBodyError ()
forall a b. (a -> b) -> a -> b
$ \txin :: TxIn
txin@(TxIn TxId
_ (TxIx Word
txix)) ->
    Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Word
txix Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
maxShelleyTxInIx) Maybe () -> TxBodyError -> Either TxBodyError ()
forall a e. Maybe a -> e -> Either e a
?! TxIn -> TxBodyError
TxBodyInIxOverflow TxIn
txin

-- | A helper function that constructs a TxBody with all of the fields that are common for
-- all eras
mkCommonTxBody
  :: ()
  => HasCallStack
  => ShelleyBasedEra era
  -> TxIns BuildTx era
  -> [TxOut ctx era]
  -> TxFee era
  -> TxWithdrawals build era
  -> Maybe (L.TxAuxData (ShelleyLedgerEra era))
  -> A.TxBody era
mkCommonTxBody :: forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut ctx era]
txOuts TxFee era
txFee TxWithdrawals build era
txWithdrawals Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData =
  ShelleyBasedEra era
-> (ShelleyBasedEraConstraints era => TxBody era) -> TxBody era
forall era a.
ShelleyBasedEra era -> (ShelleyBasedEraConstraints era => a) -> a
shelleyBasedEraConstraints ShelleyBasedEra era
sbe ((ShelleyBasedEraConstraints era => TxBody era) -> TxBody era)
-> (ShelleyBasedEraConstraints era => TxBody era) -> TxBody era
forall a b. (a -> b) -> a -> b
$
    TxBody (ShelleyLedgerEra era) -> TxBody era
forall era. TxBody (ShelleyLedgerEra era) -> TxBody era
A.TxBody (TxBody (ShelleyLedgerEra era) -> TxBody era)
-> TxBody (ShelleyLedgerEra era) -> TxBody era
forall a b. (a -> b) -> a -> b
$
      TxBody (ShelleyLedgerEra era)
forall era. EraTxBody era => TxBody era
L.mkBasicTxBody
        TxBody (ShelleyLedgerEra era)
-> (TxBody (ShelleyLedgerEra era) -> TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall a b. a -> (a -> b) -> b
& (Set TxIn -> Identity (Set TxIn))
-> TxBody (ShelleyLedgerEra era)
-> Identity (TxBody (ShelleyLedgerEra era))
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody (ShelleyLedgerEra era)) (Set TxIn)
L.inputsTxBodyL ((Set TxIn -> Identity (Set TxIn))
 -> TxBody (ShelleyLedgerEra era)
 -> Identity (TxBody (ShelleyLedgerEra era)))
-> Set TxIn
-> TxBody (ShelleyLedgerEra era)
-> TxBody (ShelleyLedgerEra era)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxIns BuildTx era -> Set TxIn
forall era. TxIns BuildTx era -> Set TxIn
convTxIns TxIns BuildTx era
txIns
        TxBody (ShelleyLedgerEra era)
-> (TxBody (ShelleyLedgerEra era) -> TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall a b. a -> (a -> b) -> b
& (StrictSeq (TxOut (ShelleyLedgerEra era))
 -> Identity (StrictSeq (TxOut (ShelleyLedgerEra era))))
-> TxBody (ShelleyLedgerEra era)
-> Identity (TxBody (ShelleyLedgerEra era))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens'
  (TxBody (ShelleyLedgerEra era))
  (StrictSeq (TxOut (ShelleyLedgerEra era)))
L.outputsTxBodyL ((StrictSeq (TxOut (ShelleyLedgerEra era))
  -> Identity (StrictSeq (TxOut (ShelleyLedgerEra era))))
 -> TxBody (ShelleyLedgerEra era)
 -> Identity (TxBody (ShelleyLedgerEra era)))
-> StrictSeq (TxOut (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
-> TxBody (ShelleyLedgerEra era)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> [TxOut ctx era] -> StrictSeq (TxOut (ShelleyLedgerEra era))
forall ctx era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era
-> [TxOut ctx era] -> StrictSeq (TxOut ledgerera)
convTxOuts ShelleyBasedEra era
sbe [TxOut ctx era]
txOuts
        TxBody (ShelleyLedgerEra era)
-> (TxBody (ShelleyLedgerEra era) -> TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall a b. a -> (a -> b) -> b
& (Coin -> Identity Coin)
-> TxBody (ShelleyLedgerEra era)
-> Identity (TxBody (ShelleyLedgerEra era))
forall era. EraTxBody era => Lens' (TxBody era) Coin
Lens' (TxBody (ShelleyLedgerEra era)) Coin
L.feeTxBodyL ((Coin -> Identity Coin)
 -> TxBody (ShelleyLedgerEra era)
 -> Identity (TxBody (ShelleyLedgerEra era)))
-> Coin
-> TxBody (ShelleyLedgerEra era)
-> TxBody (ShelleyLedgerEra era)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxFee era -> Coin
forall era. ShelleyBasedEra era -> TxFee era -> Coin
convTransactionFee ShelleyBasedEra era
sbe TxFee era
txFee
        TxBody (ShelleyLedgerEra era)
-> (TxBody (ShelleyLedgerEra era) -> TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall a b. a -> (a -> b) -> b
& (Withdrawals -> Identity Withdrawals)
-> TxBody (ShelleyLedgerEra era)
-> Identity (TxBody (ShelleyLedgerEra era))
forall era. EraTxBody era => Lens' (TxBody era) Withdrawals
Lens' (TxBody (ShelleyLedgerEra era)) Withdrawals
L.withdrawalsTxBodyL ((Withdrawals -> Identity Withdrawals)
 -> TxBody (ShelleyLedgerEra era)
 -> Identity (TxBody (ShelleyLedgerEra era)))
-> Withdrawals
-> TxBody (ShelleyLedgerEra era)
-> TxBody (ShelleyLedgerEra era)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxWithdrawals build era -> Withdrawals
forall build era. TxWithdrawals build era -> Withdrawals
convWithdrawals TxWithdrawals build era
txWithdrawals
        TxBody (ShelleyLedgerEra era)
-> (TxBody (ShelleyLedgerEra era) -> TxBody (ShelleyLedgerEra era))
-> TxBody (ShelleyLedgerEra era)
forall a b. a -> (a -> b) -> b
& (StrictMaybe TxAuxDataHash -> Identity (StrictMaybe TxAuxDataHash))
-> TxBody (ShelleyLedgerEra era)
-> Identity (TxBody (ShelleyLedgerEra era))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictMaybe TxAuxDataHash)
Lens' (TxBody (ShelleyLedgerEra era)) (StrictMaybe TxAuxDataHash)
L.auxDataHashTxBodyL ((StrictMaybe TxAuxDataHash
  -> Identity (StrictMaybe TxAuxDataHash))
 -> TxBody (ShelleyLedgerEra era)
 -> Identity (TxBody (ShelleyLedgerEra era)))
-> StrictMaybe TxAuxDataHash
-> TxBody (ShelleyLedgerEra era)
-> TxBody (ShelleyLedgerEra era)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe TxAuxDataHash
-> (TxAuxData (ShelleyLedgerEra era) -> StrictMaybe TxAuxDataHash)
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> StrictMaybe TxAuxDataHash
forall b a. b -> (a -> b) -> Maybe a -> b
maybe StrictMaybe TxAuxDataHash
forall a. StrictMaybe a
SNothing (TxAuxDataHash -> StrictMaybe TxAuxDataHash
forall a. a -> StrictMaybe a
SJust (TxAuxDataHash -> StrictMaybe TxAuxDataHash)
-> (TxAuxData (ShelleyLedgerEra era) -> TxAuxDataHash)
-> TxAuxData (ShelleyLedgerEra era)
-> StrictMaybe TxAuxDataHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxAuxData (ShelleyLedgerEra era) -> TxAuxDataHash
forall era. EraTxAuxData era => TxAuxData era -> TxAuxDataHash
Ledger.hashTxAuxData) Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData

makeShelleyTransactionBody
  :: forall era
   . ()
  => ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody :: forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era)
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraShelley
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal
    } = do
    let s2b :: ShelleyToBabbageEra ShelleyEra
s2b = ShelleyToBabbageEra ShelleyEra
ShelleyToBabbageEraShelley
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    StrictMaybe (Update ShelleyEra)
update <- ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe TxUpdateProposal era
txUpdateProposal
    let txbody :: ShelleyTxBody ShelleyEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData ShelleyEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ShelleyTxCert ShelleyEra)
  -> Identity (StrictSeq (ShelleyTxCert ShelleyEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ShelleyTxCert ShelleyEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
ShelleyToBabbageEra ShelleyEra
s2b ((StrictMaybe (Update ShelleyEra)
  -> Identity (StrictMaybe (Update ShelleyEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update ShelleyEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (Update ShelleyEra)
update
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
          )
            TxBody era
-> Getting
     (ShelleyTxBody ShelleyEra) (TxBody era) (ShelleyTxBody ShelleyEra)
-> ShelleyTxBody ShelleyEra
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const
      (ShelleyTxBody ShelleyEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (ShelleyTxBody ShelleyEra) (TxBody era)
Getting
  (ShelleyTxBody ShelleyEra) (TxBody era) (ShelleyTxBody ShelleyEra)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        TxBody (ShelleyLedgerEra era)
ShelleyTxBody ShelleyEra
txbody
        [Script ShelleyEra]
[Script (ShelleyLedgerEra era)]
scripts_
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (TxAuxData ShelleyEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
   where
    scripts_ :: [Ledger.Script E.ShelleyEra]
    scripts_ :: [Script ShelleyEra]
scripts_ =
      [Maybe (MultiSig ShelleyEra)] -> [MultiSig ShelleyEra]
forall a. [Maybe a] -> [a]
catMaybes
        [ ScriptInEra era -> Script (ShelleyLedgerEra era)
ScriptInEra era -> MultiSig ShelleyEra
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> MultiSig ShelleyEra)
-> Maybe (ScriptInEra era) -> Maybe (MultiSig ShelleyEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
getScriptWitnessScript ScriptWitness witctx era
scriptwitness
        | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness) <-
            ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
        ]

    txAuxData :: Maybe (L.TxAuxData E.ShelleyEra)
    txAuxData :: Maybe (TxAuxData ShelleyEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
forall era. TxAuxScripts era
TxAuxScriptsNone
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraAllegra
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityLowerBound era
txValidityLowerBound :: forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal
    } = do
    let aOn :: AllegraEraOnwards AllegraEra
aOn = AllegraEraOnwards AllegraEra
AllegraEraOnwardsAllegra
    let s2b :: ShelleyToBabbageEra AllegraEra
s2b = ShelleyToBabbageEra AllegraEra
ShelleyToBabbageEraAllegra
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    StrictMaybe (Update AllegraEra)
update <- ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe TxUpdateProposal era
txUpdateProposal
    let txbody :: AllegraTxBody AllegraEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData AllegraEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ShelleyTxCert AllegraEra)
  -> Identity (StrictSeq (ShelleyTxCert AllegraEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ShelleyTxCert AllegraEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
AllegraEraOnwards AllegraEra
aOn ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound TxValidityLowerBound era
txValidityLowerBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
ShelleyToBabbageEra AllegraEra
s2b ((StrictMaybe (Update AllegraEra)
  -> Identity (StrictMaybe (Update AllegraEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update AllegraEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (Update AllegraEra)
update
          )
            TxBody era
-> Getting
     (AllegraTxBody AllegraEra) (TxBody era) (AllegraTxBody AllegraEra)
-> AllegraTxBody AllegraEra
forall s a. s -> Getting a s a -> a
^. Getting
  (AllegraTxBody AllegraEra) (TxBody era) (AllegraTxBody AllegraEra)
(TxBody (ShelleyLedgerEra era)
 -> Const
      (AllegraTxBody AllegraEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (AllegraTxBody AllegraEra) (TxBody era)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        AllegraTxBody AllegraEra
TxBody (ShelleyLedgerEra era)
txbody
        [Script AllegraEra]
[Script (ShelleyLedgerEra era)]
scripts_
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (TxAuxData AllegraEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
   where
    scripts_ :: [Ledger.Script E.AllegraEra]
    scripts_ :: [Script AllegraEra]
scripts_ =
      [Maybe (Timelock AllegraEra)] -> [Timelock AllegraEra]
forall a. [Maybe a] -> [a]
catMaybes
        [ ScriptInEra era -> Timelock AllegraEra
ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Timelock AllegraEra)
-> Maybe (ScriptInEra era) -> Maybe (Timelock AllegraEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
getScriptWitnessScript ScriptWitness witctx era
scriptwitness
        | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness) <-
            ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
        ]

    txAuxData :: Maybe (L.TxAuxData E.AllegraEra)
    txAuxData :: Maybe (TxAuxData AllegraEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraMary
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityLowerBound era
txValidityLowerBound :: forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal
    , TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue
    } = do
    let aOn :: AllegraEraOnwards MaryEra
aOn = AllegraEraOnwards MaryEra
AllegraEraOnwardsMary
    let s2b :: ShelleyToBabbageEra MaryEra
s2b = ShelleyToBabbageEra MaryEra
ShelleyToBabbageEraMary
    let mOn :: MaryEraOnwards MaryEra
mOn = MaryEraOnwards MaryEra
MaryEraOnwardsMary
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    StrictMaybe (Update MaryEra)
update <- ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe TxUpdateProposal era
txUpdateProposal
    let txbody :: MaryTxBody MaryEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData MaryEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ShelleyTxCert MaryEra)
  -> Identity (StrictSeq (ShelleyTxCert MaryEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ShelleyTxCert MaryEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
AllegraEraOnwards MaryEra
aOn ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound TxValidityLowerBound era
txValidityLowerBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
ShelleyToBabbageEra MaryEra
s2b ((StrictMaybe (Update MaryEra)
  -> Identity (StrictMaybe (Update MaryEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update MaryEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (Update MaryEra)
update
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
forall era. MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
A.mintTxBodyL MaryEraOnwards era
MaryEraOnwards MaryEra
mOn ((MultiAsset -> Identity MultiAsset)
 -> TxBody era -> Identity (TxBody era))
-> MultiAsset -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxMintValue BuildTx era -> MultiAsset
forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue BuildTx era
txMintValue
          )
            TxBody era
-> Getting (MaryTxBody MaryEra) (TxBody era) (MaryTxBody MaryEra)
-> MaryTxBody MaryEra
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const (MaryTxBody MaryEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (MaryTxBody MaryEra) (TxBody era)
Getting (MaryTxBody MaryEra) (TxBody era) (MaryTxBody MaryEra)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        TxBody (ShelleyLedgerEra era)
MaryTxBody MaryEra
txbody
        [Script MaryEra]
[Script (ShelleyLedgerEra era)]
scripts
        TxBodyScriptData era
forall era. TxBodyScriptData era
TxBodyNoScriptData
        Maybe (TxAuxData MaryEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
forall era. TxScriptValidity era
TxScriptValidityNone
   where
    scripts :: [Ledger.Script E.MaryEra]
    scripts :: [Script MaryEra]
scripts =
      [Script MaryEra] -> [Script MaryEra]
forall a. Eq a => [a] -> [a]
List.nub ([Script MaryEra] -> [Script MaryEra])
-> [Script MaryEra] -> [Script MaryEra]
forall a b. (a -> b) -> a -> b
$
        [Maybe (Timelock MaryEra)] -> [Timelock MaryEra]
forall a. [Maybe a] -> [a]
catMaybes
          [ ScriptInEra era -> Timelock MaryEra
ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript (ScriptInEra era -> Timelock MaryEra)
-> Maybe (ScriptInEra era) -> Maybe (Timelock MaryEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScriptWitness witctx era -> Maybe (ScriptInEra era)
forall witctx era.
ScriptWitness witctx era -> Maybe (ScriptInEra era)
getScriptWitnessScript ScriptWitness witctx era
scriptwitness
          | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx era
scriptwitness) <-
              ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
          ]

    txAuxData :: Maybe (L.TxAuxData E.MaryEra)
    txAuxData :: Maybe (TxAuxData MaryEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraAlonzo
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityLowerBound era
txValidityLowerBound :: forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , TxExtraKeyWitnesses era
txExtraKeyWits :: forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits
    , BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal
    , TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue
    , TxScriptValidity era
txScriptValidity :: forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity
    } = do
    let aOn :: AllegraEraOnwards AlonzoEra
aOn = AllegraEraOnwards AlonzoEra
AllegraEraOnwardsAlonzo
    let s2b :: ShelleyToBabbageEra AlonzoEra
s2b = ShelleyToBabbageEra AlonzoEra
ShelleyToBabbageEraAlonzo
    let mOn :: MaryEraOnwards AlonzoEra
mOn = MaryEraOnwards AlonzoEra
MaryEraOnwardsAlonzo
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    StrictMaybe (Update AlonzoEra)
update <- ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe TxUpdateProposal era
txUpdateProposal
    let scriptIntegrityHash :: StrictMaybe ScriptIntegrityHash
scriptIntegrityHash =
          AlonzoEraOnwards AlonzoEra
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters AlonzoEra))
-> Redeemers (ShelleyLedgerEra AlonzoEra)
-> TxDats (ShelleyLedgerEra AlonzoEra)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
forall era.
AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
convPParamsToScriptIntegrityHash AlonzoEraOnwards AlonzoEra
AlonzoEraOnwardsAlonzo BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters AlonzoEra))
txProtocolParams Redeemers AlonzoEra
Redeemers (ShelleyLedgerEra AlonzoEra)
redeemers TxDats AlonzoEra
TxDats (ShelleyLedgerEra AlonzoEra)
datums Set Language
languages
    let txbody :: AlonzoTxBody AlonzoEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData AlonzoEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.collateralInputsTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
azOn ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxInsCollateral era -> Set TxIn
forall era. TxInsCollateral era -> Set TxIn
convCollateralTxIns TxInsCollateral era
txInsCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ShelleyTxCert AlonzoEra)
  -> Identity (StrictSeq (ShelleyTxCert AlonzoEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ShelleyTxCert AlonzoEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
AllegraEraOnwards AlonzoEra
aOn ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound TxValidityLowerBound era
txValidityLowerBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
ShelleyToBabbageEra AlonzoEra
s2b ((StrictMaybe (Update AlonzoEra)
  -> Identity (StrictMaybe (Update AlonzoEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update AlonzoEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (Update AlonzoEra)
update
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
forall era.
AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
A.reqSignerHashesTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
azOn ((Set (KeyHash 'Witness) -> Identity (Set (KeyHash 'Witness)))
 -> TxBody era -> Identity (TxBody era))
-> Set (KeyHash 'Witness) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
forall era. TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
convExtraKeyWitnesses TxExtraKeyWitnesses era
txExtraKeyWits
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
forall era. MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
A.mintTxBodyL MaryEraOnwards era
MaryEraOnwards AlonzoEra
mOn ((MultiAsset -> Identity MultiAsset)
 -> TxBody era -> Identity (TxBody era))
-> MultiAsset -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxMintValue BuildTx era -> MultiAsset
forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue BuildTx era
txMintValue
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
forall era.
AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
A.scriptIntegrityHashTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
azOn ((StrictMaybe ScriptIntegrityHash
  -> Identity (StrictMaybe ScriptIntegrityHash))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe ScriptIntegrityHash -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe ScriptIntegrityHash
scriptIntegrityHash
              -- TODO Alonzo: support optional network id in TxBodyContent
              -- & L.networkIdTxBodyL .~ SNothing
          )
            TxBody era
-> Getting
     (AlonzoTxBody AlonzoEra) (TxBody era) (AlonzoTxBody AlonzoEra)
-> AlonzoTxBody AlonzoEra
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const (AlonzoTxBody AlonzoEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (AlonzoTxBody AlonzoEra) (TxBody era)
Getting
  (AlonzoTxBody AlonzoEra) (TxBody era) (AlonzoTxBody AlonzoEra)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        TxBody (ShelleyLedgerEra era)
AlonzoTxBody AlonzoEra
txbody
        [Script AlonzoEra]
[Script (ShelleyLedgerEra era)]
scripts
        (AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
AlonzoEraOnwardsConstraints era =>
AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData AlonzoEraOnwards era
AlonzoEraOnwards AlonzoEra
AlonzoEraOnwardsAlonzo TxDats AlonzoEra
TxDats (ShelleyLedgerEra era)
datums Redeemers AlonzoEra
Redeemers (ShelleyLedgerEra era)
redeemers)
        Maybe (TxAuxData AlonzoEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
txScriptValidity
   where
    azOn :: AlonzoEraOnwards AlonzoEra
azOn = AlonzoEraOnwards AlonzoEra
AlonzoEraOnwardsAlonzo

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

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

    datums :: Alonzo.TxDats E.AlonzoEra
    datums :: TxDats AlonzoEra
datums =
      Map DataHash (Data AlonzoEra) -> TxDats AlonzoEra
forall era. Era era => Map DataHash (Data era) -> TxDats era
Alonzo.TxDats (Map DataHash (Data AlonzoEra) -> TxDats AlonzoEra)
-> Map DataHash (Data AlonzoEra) -> TxDats AlonzoEra
forall a b. (a -> b) -> a -> b
$
        [Item (Map DataHash (Data AlonzoEra))]
-> Map DataHash (Data AlonzoEra)
forall l. IsList l => [Item l] -> l
fromList
          [ (Data AlonzoEra -> DataHash
forall era. Data era -> DataHash
L.hashData Data AlonzoEra
d, Data AlonzoEra
d)
          | Data AlonzoEra
d <- HashableScriptData -> Data AlonzoEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData (HashableScriptData -> Data AlonzoEra)
-> [HashableScriptData] -> [Data AlonzoEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HashableScriptData]
scriptdata
          ]

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

    redeemers :: Alonzo.Redeemers E.AlonzoEra
    redeemers :: Redeemers AlonzoEra
redeemers =
      Map (PlutusPurpose AsIx AlonzoEra) (Data AlonzoEra, ExUnits)
-> Redeemers AlonzoEra
forall era.
AlonzoEraScript era =>
Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map (PlutusPurpose AsIx AlonzoEra) (Data AlonzoEra, ExUnits)
 -> Redeemers AlonzoEra)
-> Map (PlutusPurpose AsIx AlonzoEra) (Data AlonzoEra, ExUnits)
-> Redeemers AlonzoEra
forall a b. (a -> b) -> a -> b
$
        [Item
   (Map
      (AlonzoPlutusPurpose AsIx AlonzoEra) (Data AlonzoEra, ExUnits))]
-> Map
     (AlonzoPlutusPurpose AsIx AlonzoEra) (Data AlonzoEra, ExUnits)
forall l. IsList l => [Item l] -> l
fromList
          [ (AlonzoPlutusPurpose AsIx AlonzoEra
i, (HashableScriptData -> Data AlonzoEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
          | ( ScriptWitnessIndex
idx
              , AnyScriptWitness
                  (PlutusScriptWitness ScriptLanguageInEra lang AlonzoEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
d ExecutionUnits
e)
              ) <-
              [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
          , Just AlonzoPlutusPurpose AsIx AlonzoEra
i <- [AlonzoEraOnwards AlonzoEra
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall era.
AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex AlonzoEraOnwards AlonzoEra
azOn ScriptWitnessIndex
idx]
          ]

    languages :: Set Plutus.Language
    languages :: Set Language
languages =
      [Item (Set Language)] -> Set Language
forall l. IsList l => [Item l] -> l
fromList
        [ AnyPlutusScriptVersion -> Language
toAlonzoLanguage (PlutusScriptVersion lang -> AnyPlutusScriptVersion
forall lang.
IsPlutusScriptLanguage lang =>
PlutusScriptVersion lang -> AnyPlutusScriptVersion
AnyPlutusScriptVersion PlutusScriptVersion lang
v)
        | (ScriptWitnessIndex
_, AnyScriptWitness (PlutusScriptWitness ScriptLanguageInEra lang AlonzoEra
_ PlutusScriptVersion lang
v PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
_ ExecutionUnits
_)) <- [(ScriptWitnessIndex, AnyScriptWitness AlonzoEra)]
witnesses
        ]

    txAuxData :: Maybe (L.TxAuxData E.AlonzoEra)
    txAuxData :: Maybe (TxAuxData AlonzoEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraBabbage
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral
    , TxInsReference era
txInsReference :: forall build era. TxBodyContent build era -> TxInsReference era
txInsReference :: TxInsReference era
txInsReference
    , TxReturnCollateral CtxTx era
txReturnCollateral :: forall build era.
TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral
    , TxTotalCollateral era
txTotalCollateral :: forall build era. TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
txTotalCollateral
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityLowerBound era
txValidityLowerBound :: forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , TxExtraKeyWitnesses era
txExtraKeyWits :: forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits
    , BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxUpdateProposal era
txUpdateProposal :: forall build era. TxBodyContent build era -> TxUpdateProposal era
txUpdateProposal :: TxUpdateProposal era
txUpdateProposal
    , TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue
    , TxScriptValidity era
txScriptValidity :: forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity
    } = do
    let aOn :: AllegraEraOnwards BabbageEra
aOn = AllegraEraOnwards BabbageEra
AllegraEraOnwardsBabbage
    let mOn :: MaryEraOnwards BabbageEra
mOn = MaryEraOnwards BabbageEra
MaryEraOnwardsBabbage
    let bOn :: BabbageEraOnwards BabbageEra
bOn = BabbageEraOnwards BabbageEra
BabbageEraOnwardsBabbage
    let s2b :: ShelleyToBabbageEra BabbageEra
s2b = ShelleyToBabbageEra BabbageEra
ShelleyToBabbageEraBabbage
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    StrictMaybe (Update BabbageEra)
update <- ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> TxUpdateProposal era
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))
convTxUpdateProposal ShelleyBasedEra era
sbe TxUpdateProposal era
txUpdateProposal
    let scriptIntegrityHash :: StrictMaybe ScriptIntegrityHash
scriptIntegrityHash =
          AlonzoEraOnwards BabbageEra
-> BuildTxWith
     BuildTx (Maybe (LedgerProtocolParameters BabbageEra))
-> Redeemers (ShelleyLedgerEra BabbageEra)
-> TxDats (ShelleyLedgerEra BabbageEra)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
forall era.
AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
convPParamsToScriptIntegrityHash AlonzoEraOnwards BabbageEra
AlonzoEraOnwardsBabbage BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters BabbageEra))
txProtocolParams Redeemers BabbageEra
Redeemers (ShelleyLedgerEra BabbageEra)
redeemers TxDats BabbageEra
TxDats (ShelleyLedgerEra BabbageEra)
datums Set Language
languages
    let txbody :: BabbageTxBody BabbageEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData BabbageEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.collateralInputsTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards BabbageEra
azOn ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxInsCollateral era -> Set TxIn
forall era. TxInsCollateral era -> Set TxIn
convCollateralTxIns TxInsCollateral era
txInsCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.referenceInputsTxBodyL BabbageEraOnwards era
BabbageEraOnwards BabbageEra
bOn ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxInsReference era -> Set TxIn
forall era. TxInsReference era -> Set TxIn
convReferenceInputs TxInsReference era
txInsReference
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
forall era.
BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
A.collateralReturnTxBodyL BabbageEraOnwards era
BabbageEraOnwards BabbageEra
bOn ((StrictMaybe (BabbageTxOut BabbageEra)
  -> Identity (StrictMaybe (BabbageTxOut BabbageEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (BabbageTxOut BabbageEra)
-> TxBody era
-> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxReturnCollateral CtxTx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall era ctx.
ShelleyBasedEra era
-> TxReturnCollateral ctx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
convReturnCollateral ShelleyBasedEra era
sbe TxReturnCollateral CtxTx era
txReturnCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
forall era.
BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
A.totalCollateralTxBodyL BabbageEraOnwards era
BabbageEraOnwards BabbageEra
bOn ((StrictMaybe Coin -> Identity (StrictMaybe Coin))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxTotalCollateral era -> StrictMaybe Coin
forall era. TxTotalCollateral era -> StrictMaybe Coin
convTotalCollateral TxTotalCollateral era
txTotalCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ShelleyTxCert BabbageEra)
  -> Identity (StrictSeq (ShelleyTxCert BabbageEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ShelleyTxCert BabbageEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
AllegraEraOnwards BabbageEra
aOn ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound TxValidityLowerBound era
txValidityLowerBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
forall era.
ShelleyToBabbageEra era
-> Lens' (TxBody era) (StrictMaybe (Update (ShelleyLedgerEra era)))
A.updateTxBodyL ShelleyToBabbageEra era
ShelleyToBabbageEra BabbageEra
s2b ((StrictMaybe (Update BabbageEra)
  -> Identity (StrictMaybe (Update BabbageEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (Update BabbageEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe (Update BabbageEra)
update
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
forall era.
AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
A.reqSignerHashesTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards BabbageEra
azOn ((Set (KeyHash 'Witness) -> Identity (Set (KeyHash 'Witness)))
 -> TxBody era -> Identity (TxBody era))
-> Set (KeyHash 'Witness) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
forall era. TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
convExtraKeyWitnesses TxExtraKeyWitnesses era
txExtraKeyWits
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
forall era. MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
A.mintTxBodyL MaryEraOnwards era
MaryEraOnwards BabbageEra
mOn ((MultiAsset -> Identity MultiAsset)
 -> TxBody era -> Identity (TxBody era))
-> MultiAsset -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxMintValue BuildTx era -> MultiAsset
forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue BuildTx era
txMintValue
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
forall era.
AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
A.scriptIntegrityHashTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards BabbageEra
azOn ((StrictMaybe ScriptIntegrityHash
  -> Identity (StrictMaybe ScriptIntegrityHash))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe ScriptIntegrityHash -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe ScriptIntegrityHash
scriptIntegrityHash
              -- TODO Babbage: support optional network id in TxBodyContent
              -- & L.networkIdTxBodyL .~ SNothing
          )
            TxBody era
-> Getting
     (BabbageTxBody BabbageEra) (TxBody era) (BabbageTxBody BabbageEra)
-> BabbageTxBody BabbageEra
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const
      (BabbageTxBody BabbageEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (BabbageTxBody BabbageEra) (TxBody era)
Getting
  (BabbageTxBody BabbageEra) (TxBody era) (BabbageTxBody BabbageEra)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        TxBody (ShelleyLedgerEra era)
BabbageTxBody BabbageEra
txbody
        [Script BabbageEra]
[Script (ShelleyLedgerEra era)]
scripts
        ( AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
AlonzoEraOnwardsConstraints era =>
AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData
            AlonzoEraOnwards era
AlonzoEraOnwards BabbageEra
AlonzoEraOnwardsBabbage
            TxDats BabbageEra
TxDats (ShelleyLedgerEra era)
datums
            Redeemers BabbageEra
Redeemers (ShelleyLedgerEra era)
redeemers
        )
        Maybe (TxAuxData BabbageEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
txScriptValidity
   where
    azOn :: AlonzoEraOnwards BabbageEra
azOn = AlonzoEraOnwards BabbageEra
AlonzoEraOnwardsBabbage

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

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

    -- Note these do not include inline datums!
    datums :: Alonzo.TxDats E.BabbageEra
    datums :: TxDats BabbageEra
datums =
      Map DataHash (Data BabbageEra) -> TxDats BabbageEra
forall era. Era era => Map DataHash (Data era) -> TxDats era
Alonzo.TxDats (Map DataHash (Data BabbageEra) -> TxDats BabbageEra)
-> Map DataHash (Data BabbageEra) -> TxDats BabbageEra
forall a b. (a -> b) -> a -> b
$
        [Item (Map DataHash (Data BabbageEra))]
-> Map DataHash (Data BabbageEra)
forall l. IsList l => [Item l] -> l
fromList
          [ (Data BabbageEra -> DataHash
forall era. Data era -> DataHash
L.hashData Data BabbageEra
d', Data BabbageEra
d')
          | HashableScriptData
d <- [HashableScriptData]
scriptdata
          , let d' :: Data BabbageEra
d' = HashableScriptData -> Data BabbageEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d
          ]

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

    redeemers :: Alonzo.Redeemers E.BabbageEra
    redeemers :: Redeemers BabbageEra
redeemers =
      Map (PlutusPurpose AsIx BabbageEra) (Data BabbageEra, ExUnits)
-> Redeemers BabbageEra
forall era.
AlonzoEraScript era =>
Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map (PlutusPurpose AsIx BabbageEra) (Data BabbageEra, ExUnits)
 -> Redeemers BabbageEra)
-> Map (PlutusPurpose AsIx BabbageEra) (Data BabbageEra, ExUnits)
-> Redeemers BabbageEra
forall a b. (a -> b) -> a -> b
$
        [Item
   (Map
      (AlonzoPlutusPurpose AsIx BabbageEra) (Data BabbageEra, ExUnits))]
-> Map
     (AlonzoPlutusPurpose AsIx BabbageEra) (Data BabbageEra, ExUnits)
forall l. IsList l => [Item l] -> l
fromList
          [ (AlonzoPlutusPurpose AsIx BabbageEra
i, (HashableScriptData -> Data BabbageEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
          | ( ScriptWitnessIndex
idx
              , AnyScriptWitness
                  (PlutusScriptWitness ScriptLanguageInEra lang BabbageEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
d ExecutionUnits
e)
              ) <-
              [(ScriptWitnessIndex, AnyScriptWitness BabbageEra)]
witnesses
          , Just AlonzoPlutusPurpose AsIx BabbageEra
i <- [AlonzoEraOnwards BabbageEra
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall era.
AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex AlonzoEraOnwards BabbageEra
azOn ScriptWitnessIndex
idx]
          ]

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

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

    txAuxData :: Maybe (L.TxAuxData E.BabbageEra)
    txAuxData :: Maybe (TxAuxData BabbageEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts
makeShelleyTransactionBody
  sbe :: ShelleyBasedEra era
sbe@ShelleyBasedEra era
ShelleyBasedEraConway
  txbodycontent :: TxBodyContent BuildTx era
txbodycontent@TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , TxInsCollateral era
txInsCollateral :: forall build era. TxBodyContent build era -> TxInsCollateral era
txInsCollateral :: TxInsCollateral era
txInsCollateral
    , TxInsReference era
txInsReference :: forall build era. TxBodyContent build era -> TxInsReference era
txInsReference :: TxInsReference era
txInsReference
    , TxReturnCollateral CtxTx era
txReturnCollateral :: forall build era.
TxBodyContent build era -> TxReturnCollateral CtxTx era
txReturnCollateral :: TxReturnCollateral CtxTx era
txReturnCollateral
    , TxTotalCollateral era
txTotalCollateral :: forall build era. TxBodyContent build era -> TxTotalCollateral era
txTotalCollateral :: TxTotalCollateral era
txTotalCollateral
    , [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    , TxFee era
txFee :: forall build era. TxBodyContent build era -> TxFee era
txFee :: TxFee era
txFee
    , TxValidityLowerBound era
txValidityLowerBound :: forall build era.
TxBodyContent build era -> TxValidityLowerBound era
txValidityLowerBound :: TxValidityLowerBound era
txValidityLowerBound
    , TxValidityUpperBound era
txValidityUpperBound :: forall build era.
TxBodyContent build era -> TxValidityUpperBound era
txValidityUpperBound :: TxValidityUpperBound era
txValidityUpperBound
    , TxMetadataInEra era
txMetadata :: forall build era. TxBodyContent build era -> TxMetadataInEra era
txMetadata :: TxMetadataInEra era
txMetadata
    , TxAuxScripts era
txAuxScripts :: forall build era. TxBodyContent build era -> TxAuxScripts era
txAuxScripts :: TxAuxScripts era
txAuxScripts
    , TxExtraKeyWitnesses era
txExtraKeyWits :: forall build era.
TxBodyContent build era -> TxExtraKeyWitnesses era
txExtraKeyWits :: TxExtraKeyWitnesses era
txExtraKeyWits
    , BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams :: forall build era.
TxBodyContent build era
-> BuildTxWith build (Maybe (LedgerProtocolParameters era))
txProtocolParams :: BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
txProtocolParams
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue
    , TxScriptValidity era
txScriptValidity :: forall build era. TxBodyContent build era -> TxScriptValidity era
txScriptValidity :: TxScriptValidity era
txScriptValidity
    , Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures build era))
txProposalProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures
    , Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures build era))
txVotingProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures
    , Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue :: forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue :: Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue
    , Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation :: forall build era.
TxBodyContent build era
-> Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation :: Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation
    } = do
    let aOn :: AllegraEraOnwards ConwayEra
aOn = AllegraEraOnwards ConwayEra
AllegraEraOnwardsConway
    let cOn :: ConwayEraOnwards ConwayEra
cOn = ConwayEraOnwards ConwayEra
ConwayEraOnwardsConway
    let mOn :: MaryEraOnwards ConwayEra
mOn = MaryEraOnwards ConwayEra
MaryEraOnwardsConway
    let bOn :: BabbageEraOnwards ConwayEra
bOn = BabbageEraOnwards ConwayEra
BabbageEraOnwardsConway
    ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era -> Either TxBodyError ()
validateTxBodyContent ShelleyBasedEra era
sbe TxBodyContent BuildTx era
txbodycontent
    let scriptIntegrityHash :: StrictMaybe ScriptIntegrityHash
scriptIntegrityHash =
          AlonzoEraOnwards ConwayEra
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters ConwayEra))
-> Redeemers (ShelleyLedgerEra ConwayEra)
-> TxDats (ShelleyLedgerEra ConwayEra)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
forall era.
AlonzoEraOnwards era
-> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Redeemers (ShelleyLedgerEra era)
-> TxDats (ShelleyLedgerEra era)
-> Set Language
-> StrictMaybe ScriptIntegrityHash
convPParamsToScriptIntegrityHash AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
BuildTxWith BuildTx (Maybe (LedgerProtocolParameters ConwayEra))
txProtocolParams Redeemers ConwayEra
Redeemers (ShelleyLedgerEra ConwayEra)
redeemers TxDats ConwayEra
TxDats (ShelleyLedgerEra ConwayEra)
datums Set Language
languages
    let txbody :: ConwayTxBody ConwayEra
txbody =
          ( ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut CtxTx era]
-> TxFee era
-> TxWithdrawals BuildTx era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
forall era ctx build.
HasCallStack =>
ShelleyBasedEra era
-> TxIns BuildTx era
-> [TxOut ctx era]
-> TxFee era
-> TxWithdrawals build era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxBody era
mkCommonTxBody ShelleyBasedEra era
sbe TxIns BuildTx era
txIns [TxOut CtxTx era]
txOuts TxFee era
txFee TxWithdrawals BuildTx era
txWithdrawals Maybe (TxAuxData ConwayEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. AlonzoEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.collateralInputsTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
azOn
                ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ case TxInsCollateral era
txInsCollateral of
                  TxInsCollateral era
TxInsCollateralNone -> Set TxIn
forall a. Set a
Set.empty
                  TxInsCollateral AlonzoEraOnwards era
_ [TxIn]
txins -> [Item (Set TxIn)] -> Set TxIn
forall l. IsList l => [Item l] -> l
fromList ((TxIn -> TxIn) -> [TxIn] -> [TxIn]
forall a b. (a -> b) -> [a] -> [b]
map TxIn -> TxIn
toShelleyTxIn [TxIn]
txins)
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
forall era. BabbageEraOnwards era -> Lens' (TxBody era) (Set TxIn)
A.referenceInputsTxBodyL BabbageEraOnwards era
BabbageEraOnwards ConwayEra
bOn ((Set TxIn -> Identity (Set TxIn))
 -> TxBody era -> Identity (TxBody era))
-> Set TxIn -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxInsReference era -> Set TxIn
forall era. TxInsReference era -> Set TxIn
convReferenceInputs TxInsReference era
txInsReference
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
forall era.
BabbageEraOnwards era
-> Lens' (TxBody era) (StrictMaybe (TxOut (ShelleyLedgerEra era)))
A.collateralReturnTxBodyL BabbageEraOnwards era
BabbageEraOnwards ConwayEra
bOn ((StrictMaybe (BabbageTxOut ConwayEra)
  -> Identity (StrictMaybe (BabbageTxOut ConwayEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe (BabbageTxOut ConwayEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxReturnCollateral CtxTx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
forall era ctx.
ShelleyBasedEra era
-> TxReturnCollateral ctx era
-> StrictMaybe (TxOut (ShelleyLedgerEra era))
convReturnCollateral ShelleyBasedEra era
sbe TxReturnCollateral CtxTx era
txReturnCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
forall era.
BabbageEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
A.totalCollateralTxBodyL BabbageEraOnwards era
BabbageEraOnwards ConwayEra
bOn ((StrictMaybe Coin -> Identity (StrictMaybe Coin))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxTotalCollateral era -> StrictMaybe Coin
forall era. TxTotalCollateral era -> StrictMaybe Coin
convTotalCollateral TxTotalCollateral era
txTotalCollateral
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
forall era.
ShelleyBasedEra era
-> Lens' (TxBody era) (StrictSeq (TxCert (ShelleyLedgerEra era)))
A.certsTxBodyL ShelleyBasedEra era
sbe ((StrictSeq (ConwayTxCert ConwayEra)
  -> Identity (StrictSeq (ConwayTxCert ConwayEra)))
 -> TxBody era -> Identity (TxBody era))
-> StrictSeq (ConwayTxCert ConwayEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> TxCertificates BuildTx era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
forall era build.
ShelleyBasedEra era
-> TxCertificates build era
-> StrictSeq (TxCert (ShelleyLedgerEra era))
convCertificates ShelleyBasedEra era
sbe TxCertificates BuildTx era
txCertificates
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
AllegraEraOnwards era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidBeforeTxBodyL AllegraEraOnwards era
AllegraEraOnwards ConwayEra
aOn ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxValidityLowerBound era -> Maybe SlotNo
forall era. TxValidityLowerBound era -> Maybe SlotNo
convValidityLowerBound TxValidityLowerBound era
txValidityLowerBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
forall era.
ShelleyBasedEra era -> Lens' (TxBody era) (Maybe SlotNo)
A.invalidHereAfterTxBodyL ShelleyBasedEra era
sbe ((Maybe SlotNo -> Identity (Maybe SlotNo))
 -> TxBody era -> Identity (TxBody era))
-> Maybe SlotNo -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
forall era.
ShelleyBasedEra era -> TxValidityUpperBound era -> Maybe SlotNo
convValidityUpperBound ShelleyBasedEra era
sbe TxValidityUpperBound era
txValidityUpperBound
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
forall era.
AlonzoEraOnwards era -> Lens' (TxBody era) (Set (KeyHash 'Witness))
A.reqSignerHashesTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
azOn ((Set (KeyHash 'Witness) -> Identity (Set (KeyHash 'Witness)))
 -> TxBody era -> Identity (TxBody era))
-> Set (KeyHash 'Witness) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
forall era. TxExtraKeyWitnesses era -> Set (KeyHash 'Witness)
convExtraKeyWitnesses TxExtraKeyWitnesses era
txExtraKeyWits
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
forall era. MaryEraOnwards era -> Lens' (TxBody era) MultiAsset
A.mintTxBodyL MaryEraOnwards era
MaryEraOnwards ConwayEra
mOn ((MultiAsset -> Identity MultiAsset)
 -> TxBody era -> Identity (TxBody era))
-> MultiAsset -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxMintValue BuildTx era -> MultiAsset
forall build era. TxMintValue build era -> MultiAsset
convMintValue TxMintValue BuildTx era
txMintValue
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
forall era.
AlonzoEraOnwards era
-> Lens' (TxBody era) (StrictMaybe ScriptIntegrityHash)
A.scriptIntegrityHashTxBodyL AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
azOn ((StrictMaybe ScriptIntegrityHash
  -> Identity (StrictMaybe ScriptIntegrityHash))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe ScriptIntegrityHash -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ StrictMaybe ScriptIntegrityHash
scriptIntegrityHash
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ConwayEraOnwards era
-> Lens' (TxBody era) (VotingProcedures (ShelleyLedgerEra era))
forall era.
ConwayEraOnwards era
-> Lens' (TxBody era) (VotingProcedures (ShelleyLedgerEra era))
A.votingProceduresTxBodyL ConwayEraOnwards era
ConwayEraOnwards ConwayEra
cOn
                ((VotingProcedures ConwayEra
  -> Identity (VotingProcedures ConwayEra))
 -> TxBody era -> Identity (TxBody era))
-> VotingProcedures ConwayEra -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxVotingProcedures BuildTx era
-> VotingProcedures (ShelleyLedgerEra era)
forall build era.
TxVotingProcedures build era
-> VotingProcedures (ShelleyLedgerEra era)
convVotingProcedures (TxVotingProcedures BuildTx era
-> (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
    -> TxVotingProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
-> TxVotingProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxVotingProcedures BuildTx era
forall build era. TxVotingProcedures build era
TxVotingProceduresNone Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
-> TxVotingProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures)
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ConwayEraOnwards era
-> Lens'
     (TxBody era) (OSet (ProposalProcedure (ShelleyLedgerEra era)))
forall era.
ConwayEraOnwards era
-> Lens'
     (TxBody era) (OSet (ProposalProcedure (ShelleyLedgerEra era)))
A.proposalProceduresTxBodyL ConwayEraOnwards era
ConwayEraOnwards ConwayEra
cOn
                ((OSet (ProposalProcedure ConwayEra)
  -> Identity (OSet (ProposalProcedure ConwayEra)))
 -> TxBody era -> Identity (TxBody era))
-> OSet (ProposalProcedure ConwayEra) -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxProposalProcedures BuildTx era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
forall build era.
TxProposalProcedures build era
-> OSet (ProposalProcedure (ShelleyLedgerEra era))
convProposalProcedures (TxProposalProcedures BuildTx era
-> (Featured
      ConwayEraOnwards era (TxProposalProcedures BuildTx era)
    -> TxProposalProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> TxProposalProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxProposalProcedures BuildTx era
forall build era. TxProposalProcedures build era
TxProposalProceduresNone Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures)
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ConwayEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
forall era.
ConwayEraOnwards era -> Lens' (TxBody era) (StrictMaybe Coin)
A.currentTreasuryValueTxBodyL ConwayEraOnwards era
ConwayEraOnwards ConwayEra
cOn
                ((StrictMaybe Coin -> Identity (StrictMaybe Coin))
 -> TxBody era -> Identity (TxBody era))
-> StrictMaybe Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe Coin -> StrictMaybe Coin
forall a. Maybe a -> StrictMaybe a
Ledger.maybeToStrictMaybe (Featured ConwayEraOnwards era (Maybe Coin) -> Maybe Coin
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured (Featured ConwayEraOnwards era (Maybe Coin) -> Maybe Coin)
-> Maybe (Featured ConwayEraOnwards era (Maybe Coin)) -> Maybe Coin
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe (Featured ConwayEraOnwards era (Maybe Coin))
txCurrentTreasuryValue)
              TxBody era -> (TxBody era -> TxBody era) -> TxBody era
forall a b. a -> (a -> b) -> b
& ConwayEraOnwards era -> Lens' (TxBody era) Coin
forall era. ConwayEraOnwards era -> Lens' (TxBody era) Coin
A.treasuryDonationTxBodyL ConwayEraOnwards era
ConwayEraOnwards ConwayEra
cOn ((Coin -> Identity Coin) -> TxBody era -> Identity (TxBody era))
-> Coin -> TxBody era -> TxBody era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Coin
-> (Featured ConwayEraOnwards era Coin -> Coin)
-> Maybe (Featured ConwayEraOnwards era Coin)
-> Coin
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Integer -> Coin
L.Coin Integer
0) Featured ConwayEraOnwards era Coin -> Coin
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe (Featured ConwayEraOnwards era Coin)
txTreasuryDonation
              -- TODO Conway: support optional network id in TxBodyContent
              -- & L.networkIdTxBodyL .~ SNothing
          )
            TxBody era
-> Getting
     (ConwayTxBody ConwayEra) (TxBody era) (ConwayTxBody ConwayEra)
-> ConwayTxBody ConwayEra
forall s a. s -> Getting a s a -> a
^. (TxBody (ShelleyLedgerEra era)
 -> Const (ConwayTxBody ConwayEra) (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> Const (ConwayTxBody ConwayEra) (TxBody era)
Getting
  (ConwayTxBody ConwayEra) (TxBody era) (ConwayTxBody ConwayEra)
forall era (f :: * -> *).
Functor f =>
(TxBody (ShelleyLedgerEra era)
 -> f (TxBody (ShelleyLedgerEra era)))
-> TxBody era -> f (TxBody era)
A.txBodyL
    TxBody era -> Either TxBodyError (TxBody era)
forall a. a -> Either TxBodyError a
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 (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
forall era.
ShelleyBasedEra era
-> TxBody (ShelleyLedgerEra era)
-> [Script (ShelleyLedgerEra era)]
-> TxBodyScriptData era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
-> TxScriptValidity era
-> TxBody era
ShelleyTxBody
        ShelleyBasedEra era
sbe
        TxBody (ShelleyLedgerEra era)
ConwayTxBody ConwayEra
txbody
        [Script ConwayEra]
[Script (ShelleyLedgerEra era)]
scripts
        ( AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
forall era.
AlonzoEraOnwardsConstraints era =>
AlonzoEraOnwards era
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxBodyScriptData era
TxBodyScriptData
            AlonzoEraOnwards era
AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway
            TxDats ConwayEra
TxDats (ShelleyLedgerEra era)
datums
            Redeemers ConwayEra
Redeemers (ShelleyLedgerEra era)
redeemers
        )
        Maybe (TxAuxData ConwayEra)
Maybe (TxAuxData (ShelleyLedgerEra era))
txAuxData
        TxScriptValidity era
txScriptValidity
   where
    azOn :: AlonzoEraOnwards ConwayEra
azOn = AlonzoEraOnwards ConwayEra
AlonzoEraOnwardsConway

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

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

    -- Note these do not include inline datums!
    datums :: Alonzo.TxDats E.ConwayEra
    datums :: TxDats ConwayEra
datums =
      Map DataHash (Data ConwayEra) -> TxDats ConwayEra
forall era. Era era => Map DataHash (Data era) -> TxDats era
Alonzo.TxDats (Map DataHash (Data ConwayEra) -> TxDats ConwayEra)
-> Map DataHash (Data ConwayEra) -> TxDats ConwayEra
forall a b. (a -> b) -> a -> b
$
        [Item (Map DataHash (Data ConwayEra))]
-> Map DataHash (Data ConwayEra)
forall l. IsList l => [Item l] -> l
fromList
          [ (Data ConwayEra -> DataHash
forall era. Data era -> DataHash
L.hashData Data ConwayEra
d, Data ConwayEra
d)
          | Data ConwayEra
d <- HashableScriptData -> Data ConwayEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData (HashableScriptData -> Data ConwayEra)
-> [HashableScriptData] -> [Data ConwayEra]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HashableScriptData]
scriptdata
          ]

    scriptdata :: [HashableScriptData]
    scriptdata :: [HashableScriptData]
scriptdata =
      [HashableScriptData
d | TxOut AddressInEra era
_ TxOutValue era
_ (TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
d) ReferenceScript era
_ <- [TxOut CtxTx era]
txOuts]
        [HashableScriptData]
-> [HashableScriptData] -> [HashableScriptData]
forall a. [a] -> [a] -> [a]
++ [ HashableScriptData
d
           | ( ScriptWitnessIndex
_
               , AnyScriptWitness
                   ( PlutusScriptWitness
                       ScriptLanguageInEra lang ConwayEra
_
                       PlutusScriptVersion lang
_
                       PlutusScriptOrReferenceInput lang
_
                       (ScriptDatumForTxIn (Just HashableScriptData
d))
                       HashableScriptData
_
                       ExecutionUnits
_
                     )
               ) <-
               [(ScriptWitnessIndex, AnyScriptWitness ConwayEra)]
witnesses
           ]

    redeemers :: Alonzo.Redeemers E.ConwayEra
    redeemers :: Redeemers ConwayEra
redeemers =
      Map (PlutusPurpose AsIx ConwayEra) (Data ConwayEra, ExUnits)
-> Redeemers ConwayEra
forall era.
AlonzoEraScript era =>
Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Redeemers era
Alonzo.Redeemers (Map (PlutusPurpose AsIx ConwayEra) (Data ConwayEra, ExUnits)
 -> Redeemers ConwayEra)
-> Map (PlutusPurpose AsIx ConwayEra) (Data ConwayEra, ExUnits)
-> Redeemers ConwayEra
forall a b. (a -> b) -> a -> b
$
        [Item
   (Map
      (ConwayPlutusPurpose AsIx ConwayEra) (Data ConwayEra, ExUnits))]
-> Map
     (ConwayPlutusPurpose AsIx ConwayEra) (Data ConwayEra, ExUnits)
forall l. IsList l => [Item l] -> l
fromList
          [ (ConwayPlutusPurpose AsIx ConwayEra
i, (HashableScriptData -> Data ConwayEra
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d, ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
e))
          | ( ScriptWitnessIndex
idx
              , AnyScriptWitness
                  (PlutusScriptWitness ScriptLanguageInEra lang ConwayEra
_ PlutusScriptVersion lang
_ PlutusScriptOrReferenceInput lang
_ ScriptDatum witctx
_ HashableScriptData
d ExecutionUnits
e)
              ) <-
              [(ScriptWitnessIndex, AnyScriptWitness ConwayEra)]
witnesses
          , Just ConwayPlutusPurpose AsIx ConwayEra
i <- [AlonzoEraOnwards ConwayEra
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall era.
AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex AlonzoEraOnwards ConwayEra
azOn ScriptWitnessIndex
idx]
          ]

    languages :: Set Plutus.Language
    languages :: Set Language
languages =
      [Item (Set Language)] -> Set Language
forall l. IsList l => [Item l] -> l
fromList ([Item (Set Language)] -> Set Language)
-> [Item (Set Language)] -> Set Language
forall a b. (a -> b) -> a -> b
$
        [Maybe Language] -> [Language]
forall a. [Maybe a] -> [a]
catMaybes
          [ ScriptWitness witctx era -> Maybe Language
forall witctx. ScriptWitness witctx era -> Maybe Language
getScriptLanguage ScriptWitness witctx era
ScriptWitness witctx ConwayEra
sw
          | (ScriptWitnessIndex
_, AnyScriptWitness ScriptWitness witctx ConwayEra
sw) <- [(ScriptWitnessIndex, AnyScriptWitness ConwayEra)]
witnesses
          ]

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

    txAuxData :: Maybe (L.TxAuxData E.ConwayEra)
    txAuxData :: Maybe (TxAuxData ConwayEra)
txAuxData = ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts

-- | A variant of 'toShelleyTxOutAny that is used only internally to this module
-- that works with a 'TxOut' in any context (including CtxTx) by ignoring
-- embedded datums (taking only their hash).
toShelleyTxOutAny
  :: forall ctx era ledgerera
   . HasCallStack
  => ShelleyLedgerEra era ~ ledgerera
  => ShelleyBasedEra era
  -> TxOut ctx era
  -> Ledger.TxOut ledgerera
toShelleyTxOutAny :: forall ctx era ledgerera.
(HasCallStack, ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera
toShelleyTxOutAny ShelleyBasedEra era
_ = \case
  TxOut AddressInEra era
_ (TxOutValueByron Coin
_) TxOutDatum ctx era
_ ReferenceScript era
_ ->
    -- TODO: Temporary until we have basic tx
    -- construction functionality
    String -> TxOut ledgerera
forall a. HasCallStack => String -> a
error String
"toShelleyTxOutAny: Expected a Shelley value"
  TxOut AddressInEra era
addr (TxOutValueShelleyBased ShelleyBasedEra era
sbe Value (ShelleyLedgerEra era)
value) TxOutDatum ctx era
txoutdata ReferenceScript era
refScript ->
    (ShelleyToMaryEraConstraints era =>
 ShelleyToMaryEra era -> TxOut ledgerera)
-> (AlonzoEraOnwardsConstraints era =>
    AlonzoEraOnwards era -> TxOut ledgerera)
-> ShelleyBasedEra era
-> TxOut ledgerera
forall era a.
(ShelleyToMaryEraConstraints era => ShelleyToMaryEra era -> a)
-> (AlonzoEraOnwardsConstraints era => AlonzoEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToMaryOrAlonzoEraOnwards
      (TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera
forall a b. a -> b -> a
const (TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera)
-> TxOut ledgerera -> ShelleyToMaryEra era -> TxOut ledgerera
forall a b. (a -> b) -> a -> b
$ Addr -> Value ledgerera -> TxOut ledgerera
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value ledgerera
Value (ShelleyLedgerEra era)
value)
      ( \case
          AlonzoEraOnwards era
AlonzoEraOnwardsAlonzo ->
            Addr -> Value AlonzoEra -> TxOut AlonzoEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value AlonzoEra
Value (ShelleyLedgerEra era)
value
              TxOut AlonzoEra
-> (TxOut AlonzoEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
-> TxOut AlonzoEra -> Identity (TxOut ledgerera)
(StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
-> TxOut AlonzoEra -> Identity (TxOut AlonzoEra)
forall era.
AlonzoEraTxOut era =>
Lens' (TxOut era) (StrictMaybe DataHash)
Lens' (TxOut AlonzoEra) (StrictMaybe DataHash)
L.dataHashTxOutL ((StrictMaybe DataHash -> Identity (StrictMaybe DataHash))
 -> TxOut AlonzoEra -> Identity (TxOut ledgerera))
-> StrictMaybe DataHash -> TxOut AlonzoEra -> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum ctx era -> StrictMaybe DataHash
forall ctx era. TxOutDatum ctx era -> StrictMaybe DataHash
toAlonzoTxOutDatumHash TxOutDatum ctx era
txoutdata
          AlonzoEraOnwards era
AlonzoEraOnwardsBabbage ->
            Addr -> Value BabbageEra -> TxOut BabbageEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value BabbageEra
Value (ShelleyLedgerEra era)
value
              TxOut BabbageEra
-> (TxOut BabbageEra -> TxOut BabbageEra) -> TxOut BabbageEra
forall a b. a -> (a -> b) -> b
& (Datum BabbageEra -> Identity (Datum BabbageEra))
-> TxOut BabbageEra -> Identity (TxOut BabbageEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut BabbageEra) (Datum BabbageEra)
L.datumTxOutL ((Datum BabbageEra -> Identity (Datum BabbageEra))
 -> TxOut BabbageEra -> Identity (TxOut BabbageEra))
-> Datum BabbageEra -> TxOut BabbageEra -> TxOut BabbageEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
forall era ctx.
Era (ShelleyLedgerEra era) =>
TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum TxOutDatum ctx era
txoutdata
              TxOut BabbageEra
-> (TxOut BabbageEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe (Script BabbageEra)
 -> Identity (StrictMaybe (Script BabbageEra)))
-> TxOut BabbageEra -> Identity (TxOut ledgerera)
(StrictMaybe (Script BabbageEra)
 -> Identity (StrictMaybe (Script BabbageEra)))
-> TxOut BabbageEra -> Identity (TxOut BabbageEra)
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut BabbageEra) (StrictMaybe (Script BabbageEra))
L.referenceScriptTxOutL ((StrictMaybe (Script BabbageEra)
  -> Identity (StrictMaybe (Script BabbageEra)))
 -> TxOut BabbageEra -> Identity (TxOut ledgerera))
-> StrictMaybe (Script BabbageEra)
-> TxOut BabbageEra
-> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
refScriptToShelleyScript ShelleyBasedEra era
sbe ReferenceScript era
refScript
          AlonzoEraOnwards era
AlonzoEraOnwardsConway ->
            Addr -> Value ConwayEra -> TxOut ConwayEra
forall era.
(EraTxOut era, HasCallStack) =>
Addr -> Value era -> TxOut era
L.mkBasicTxOut (AddressInEra era -> Addr
forall era. AddressInEra era -> Addr
toShelleyAddr AddressInEra era
addr) Value ConwayEra
Value (ShelleyLedgerEra era)
value
              TxOut ConwayEra
-> (TxOut ConwayEra -> TxOut ConwayEra) -> TxOut ConwayEra
forall a b. a -> (a -> b) -> b
& (Datum ConwayEra -> Identity (Datum ConwayEra))
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
forall era. BabbageEraTxOut era => Lens' (TxOut era) (Datum era)
Lens' (TxOut ConwayEra) (Datum ConwayEra)
L.datumTxOutL ((Datum ConwayEra -> Identity (Datum ConwayEra))
 -> TxOut ConwayEra -> Identity (TxOut ConwayEra))
-> Datum ConwayEra -> TxOut ConwayEra -> TxOut ConwayEra
forall s t a b. ASetter s t a b -> b -> s -> t
.~ TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
forall era ctx.
Era (ShelleyLedgerEra era) =>
TxOutDatum ctx era -> Datum (ShelleyLedgerEra era)
toBabbageTxOutDatum TxOutDatum ctx era
txoutdata
              TxOut ConwayEra
-> (TxOut ConwayEra -> TxOut ledgerera) -> TxOut ledgerera
forall a b. a -> (a -> b) -> b
& (StrictMaybe (Script ConwayEra)
 -> Identity (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra -> Identity (TxOut ledgerera)
(StrictMaybe (Script ConwayEra)
 -> Identity (StrictMaybe (Script ConwayEra)))
-> TxOut ConwayEra -> Identity (TxOut ConwayEra)
forall era.
BabbageEraTxOut era =>
Lens' (TxOut era) (StrictMaybe (Script era))
Lens' (TxOut ConwayEra) (StrictMaybe (Script ConwayEra))
L.referenceScriptTxOutL ((StrictMaybe (Script ConwayEra)
  -> Identity (StrictMaybe (Script ConwayEra)))
 -> TxOut ConwayEra -> Identity (TxOut ledgerera))
-> StrictMaybe (Script ConwayEra)
-> TxOut ConwayEra
-> TxOut ledgerera
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
forall era.
ShelleyBasedEra era
-> ReferenceScript era
-> StrictMaybe (Script (ShelleyLedgerEra era))
refScriptToShelleyScript ShelleyBasedEra era
sbe ReferenceScript era
refScript
      )
      ShelleyBasedEra era
sbe

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

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

deriving instance Show (AnyScriptWitness era)

instance Eq (AnyScriptWitness era) where
  AnyScriptWitness ScriptWitness witctx era
sw1 == :: AnyScriptWitness era -> AnyScriptWitness era -> Bool
== AnyScriptWitness ScriptWitness witctx era
sw2 =
    case ScriptWitness witctx era
-> ScriptWitness witctx era -> Maybe (witctx :~: witctx)
forall w1 w2.
(Typeable w1, Typeable w2) =>
ScriptWitness w1 era -> ScriptWitness w2 era -> Maybe (w1 :~: w2)
eqsw ScriptWitness witctx era
sw1 ScriptWitness witctx era
sw2 of
      Just witctx :~: witctx
Refl -> ScriptWitness witctx era
sw1 ScriptWitness witctx era -> ScriptWitness witctx era -> Bool
forall a. Eq a => a -> a -> Bool
== ScriptWitness witctx era
ScriptWitness witctx era
sw2
      Maybe (witctx :~: witctx)
Nothing -> Bool
False
   where
    eqsw
      :: (Typeable w1, Typeable w2)
      => ScriptWitness w1 era
      -> ScriptWitness w2 era
      -> Maybe (w1 :~: w2)
    eqsw :: forall w1 w2.
(Typeable w1, Typeable w2) =>
ScriptWitness w1 era -> ScriptWitness w2 era -> Maybe (w1 :~: w2)
eqsw ScriptWitness w1 era
_ ScriptWitness w2 era
_ = Maybe (w1 :~: w2)
forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT

-- | Identify the location of a 'ScriptWitness' within the context of a
-- 'TxBody'. These are indexes of the objects within the transaction that
-- need or can use script witnesses: inputs, minted assets, withdrawals and
-- certificates. These are simple numeric indices, enumerated from zero.
-- Thus the indices are not stable if the transaction body is modified.
data ScriptWitnessIndex
  = -- | The n'th transaction input, in the order of the 'TxId's.
    ScriptWitnessIndexTxIn !Word32
  | -- | The n'th minting 'PolicyId', in the order of the 'PolicyId's.
    ScriptWitnessIndexMint !Word32
  | -- | The n'th certificate, in the list order of the certificates.
    ScriptWitnessIndexCertificate !Word32
  | -- | The n'th withdrawal, in the order of the 'StakeAddress's.
    ScriptWitnessIndexWithdrawal !Word32
  | -- | The n'th vote, in the order of the votes.
    ScriptWitnessIndexVoting !Word32
  | -- | The n'th proposal, in the order of the proposals.
    ScriptWitnessIndexProposing !Word32
  deriving (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
(ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> Eq ScriptWitnessIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
== :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c/= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
/= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
Eq, Eq ScriptWitnessIndex
Eq ScriptWitnessIndex =>
(ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> Bool)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex)
-> (ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex)
-> Ord ScriptWitnessIndex
ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
compare :: ScriptWitnessIndex -> ScriptWitnessIndex -> Ordering
$c< :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
< :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c<= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
<= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c> :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
> :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$c>= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
>= :: ScriptWitnessIndex -> ScriptWitnessIndex -> Bool
$cmax :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
max :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
$cmin :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
min :: ScriptWitnessIndex -> ScriptWitnessIndex -> ScriptWitnessIndex
Ord, Int -> ScriptWitnessIndex -> ShowS
[ScriptWitnessIndex] -> ShowS
ScriptWitnessIndex -> String
(Int -> ScriptWitnessIndex -> ShowS)
-> (ScriptWitnessIndex -> String)
-> ([ScriptWitnessIndex] -> ShowS)
-> Show ScriptWitnessIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScriptWitnessIndex -> ShowS
showsPrec :: Int -> ScriptWitnessIndex -> ShowS
$cshow :: ScriptWitnessIndex -> String
show :: ScriptWitnessIndex -> String
$cshowList :: [ScriptWitnessIndex] -> ShowS
showList :: [ScriptWitnessIndex] -> ShowS
Show)

instance ToJSON ScriptWitnessIndex where
  toJSON :: ScriptWitnessIndex -> Value
toJSON = \case
    ScriptWitnessIndexTxIn Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexTxIn"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]
    ScriptWitnessIndexMint Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexMint"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]
    ScriptWitnessIndexCertificate Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexCertificate"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]
    ScriptWitnessIndexWithdrawal Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexWithdrawal"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]
    ScriptWitnessIndexVoting Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexVoting"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]
    ScriptWitnessIndexProposing Word32
n ->
      [Pair] -> Value
object
        [ Key
"kind" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
Aeson.String Text
"ScriptWitnessIndexProposing"
        , Key
"value" Key -> Word32 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Word32
n
        ]

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

fromScriptWitnessIndex
  :: AlonzoEraOnwards era
  -> ScriptWitnessIndex
  -> Maybe (L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex :: forall era.
AlonzoEraOnwards era
-> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra era))
fromScriptWitnessIndex AlonzoEraOnwards era
aOnwards ScriptWitnessIndex
widx =
  case AlonzoEraOnwards era
aOnwards of
    AlonzoEraOnwards era
AlonzoEraOnwardsAlonzo -> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
fromScriptWitnessIndexAlonzo ScriptWitnessIndex
widx
    AlonzoEraOnwards era
AlonzoEraOnwardsBabbage -> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
fromScriptWitnessIndexBabbage ScriptWitnessIndex
widx
    AlonzoEraOnwards era
AlonzoEraOnwardsConway -> ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
fromScriptWitnessIndexConway ScriptWitnessIndex
widx

fromScriptWitnessIndexAlonzo
  :: ScriptWitnessIndex -> Maybe (L.PlutusPurpose L.AsIx (ShelleyLedgerEra AlonzoEra))
fromScriptWitnessIndexAlonzo :: ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
fromScriptWitnessIndexAlonzo ScriptWitnessIndex
i =
  case ScriptWitnessIndex
i of
    ScriptWitnessIndexTxIn Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 TxIn -> AlonzoPlutusPurpose AsIx AlonzoEra
forall (f :: * -> * -> *) era.
f Word32 TxIn -> AlonzoPlutusPurpose f era
L.AlonzoSpending (Word32 -> AsIx Word32 TxIn
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexMint Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 PolicyID -> AlonzoPlutusPurpose AsIx AlonzoEra
forall (f :: * -> * -> *) era.
f Word32 PolicyID -> AlonzoPlutusPurpose f era
L.AlonzoMinting (Word32 -> AsIx Word32 PolicyID
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexCertificate Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 (TxCert AlonzoEra)
-> AlonzoPlutusPurpose AsIx AlonzoEra
forall (f :: * -> * -> *) era.
f Word32 (TxCert era) -> AlonzoPlutusPurpose f era
L.AlonzoCertifying (Word32 -> AsIx Word32 (ShelleyTxCert AlonzoEra)
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexWithdrawal Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 RewardAccount -> AlonzoPlutusPurpose AsIx AlonzoEra
forall (f :: * -> * -> *) era.
f Word32 RewardAccount -> AlonzoPlutusPurpose f era
L.AlonzoRewarding (Word32 -> AsIx Word32 RewardAccount
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndex
_ -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra))
Maybe (AlonzoPlutusPurpose AsIx AlonzoEra)
forall a. Maybe a
Nothing

fromScriptWitnessIndexBabbage
  :: ScriptWitnessIndex -> Maybe (L.PlutusPurpose L.AsIx (ShelleyLedgerEra BabbageEra))
fromScriptWitnessIndexBabbage :: ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
fromScriptWitnessIndexBabbage ScriptWitnessIndex
i =
  case ScriptWitnessIndex
i of
    ScriptWitnessIndexTxIn Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 TxIn -> AlonzoPlutusPurpose AsIx BabbageEra
forall (f :: * -> * -> *) era.
f Word32 TxIn -> AlonzoPlutusPurpose f era
L.AlonzoSpending (Word32 -> AsIx Word32 TxIn
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexMint Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 PolicyID -> AlonzoPlutusPurpose AsIx BabbageEra
forall (f :: * -> * -> *) era.
f Word32 PolicyID -> AlonzoPlutusPurpose f era
L.AlonzoMinting (Word32 -> AsIx Word32 PolicyID
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexCertificate Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 (TxCert BabbageEra)
-> AlonzoPlutusPurpose AsIx BabbageEra
forall (f :: * -> * -> *) era.
f Word32 (TxCert era) -> AlonzoPlutusPurpose f era
L.AlonzoCertifying (Word32 -> AsIx Word32 (ShelleyTxCert BabbageEra)
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexWithdrawal Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 RewardAccount -> AlonzoPlutusPurpose AsIx BabbageEra
forall (f :: * -> * -> *) era.
f Word32 RewardAccount -> AlonzoPlutusPurpose f era
L.AlonzoRewarding (Word32 -> AsIx Word32 RewardAccount
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndex
_ -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra BabbageEra))
Maybe (AlonzoPlutusPurpose AsIx BabbageEra)
forall a. Maybe a
Nothing

fromScriptWitnessIndexConway
  :: ScriptWitnessIndex -> Maybe (L.PlutusPurpose L.AsIx (ShelleyLedgerEra ConwayEra))
fromScriptWitnessIndexConway :: ScriptWitnessIndex
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
fromScriptWitnessIndexConway ScriptWitnessIndex
i =
  case ScriptWitnessIndex
i of
    ScriptWitnessIndexTxIn Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 TxIn -> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 TxIn -> ConwayPlutusPurpose f era
L.ConwaySpending (Word32 -> AsIx Word32 TxIn
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexMint Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 PolicyID -> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 PolicyID -> ConwayPlutusPurpose f era
L.ConwayMinting (Word32 -> AsIx Word32 PolicyID
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexCertificate Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 (TxCert ConwayEra)
-> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 (TxCert era) -> ConwayPlutusPurpose f era
L.ConwayCertifying (Word32 -> AsIx Word32 (ConwayTxCert ConwayEra)
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexWithdrawal Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 RewardAccount -> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 RewardAccount -> ConwayPlutusPurpose f era
L.ConwayRewarding (Word32 -> AsIx Word32 RewardAccount
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexVoting Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 Voter -> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 Voter -> ConwayPlutusPurpose f era
L.ConwayVoting (Word32 -> AsIx Word32 Voter
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)
    ScriptWitnessIndexProposing Word32
n -> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a. a -> Maybe a
Just (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
 -> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)))
-> PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> Maybe (PlutusPurpose AsIx (ShelleyLedgerEra ConwayEra))
forall a b. (a -> b) -> a -> b
$ AsIx Word32 (ProposalProcedure ConwayEra)
-> ConwayPlutusPurpose AsIx ConwayEra
forall (f :: * -> * -> *) era.
f Word32 (ProposalProcedure era) -> ConwayPlutusPurpose f era
L.ConwayProposing (Word32 -> AsIx Word32 (ProposalProcedure ConwayEra)
forall ix it. ix -> AsIx ix it
L.AsIx Word32
n)

toScriptIndex
  :: AlonzoEraOnwards era
  -> L.PlutusPurpose L.AsIx (ShelleyLedgerEra era)
  -> ScriptWitnessIndex
toScriptIndex :: forall era.
AlonzoEraOnwards era
-> PlutusPurpose AsIx (ShelleyLedgerEra era) -> ScriptWitnessIndex
toScriptIndex AlonzoEraOnwards era
sbe PlutusPurpose AsIx (ShelleyLedgerEra era)
scriptPurposeIndex =
  case AlonzoEraOnwards era
sbe of
    AlonzoEraOnwards era
AlonzoEraOnwardsAlonzo -> AlonzoPlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
-> ScriptWitnessIndex
forall era.
AlonzoPlutusPurpose AsIx (ShelleyLedgerEra era)
-> ScriptWitnessIndex
toScriptIndexAlonzo PlutusPurpose AsIx (ShelleyLedgerEra era)
AlonzoPlutusPurpose AsIx (ShelleyLedgerEra AlonzoEra)
scriptPurposeIndex
    AlonzoEraOnwards era
AlonzoEraOnwardsBabbage -> AlonzoPlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
-> ScriptWitnessIndex
forall era.
AlonzoPlutusPurpose AsIx (ShelleyLedgerEra era)
-> ScriptWitnessIndex
toScriptIndexAlonzo PlutusPurpose AsIx (ShelleyLedgerEra era)
AlonzoPlutusPurpose AsIx (ShelleyLedgerEra BabbageEra)
scriptPurposeIndex
    AlonzoEraOnwards era
AlonzoEraOnwardsConway -> ConwayPlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
-> ScriptWitnessIndex
forall era.
ConwayPlutusPurpose AsIx (ShelleyLedgerEra era)
-> ScriptWitnessIndex
toScriptIndexConway PlutusPurpose AsIx (ShelleyLedgerEra era)
ConwayPlutusPurpose AsIx (ShelleyLedgerEra ConwayEra)
scriptPurposeIndex

toScriptIndexAlonzo
  :: L.AlonzoPlutusPurpose L.AsIx (ShelleyLedgerEra era)
  -> ScriptWitnessIndex
toScriptIndexAlonzo :: forall era.
AlonzoPlutusPurpose AsIx (ShelleyLedgerEra era)
-> ScriptWitnessIndex
toScriptIndexAlonzo AlonzoPlutusPurpose AsIx (ShelleyLedgerEra era)
scriptPurposeIndex =
  case AlonzoPlutusPurpose AsIx (ShelleyLedgerEra era)
scriptPurposeIndex of
    L.AlonzoSpending (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexTxIn Word32
i
    L.AlonzoMinting (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexMint Word32
i
    L.AlonzoCertifying (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexCertificate Word32
i
    L.AlonzoRewarding (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexWithdrawal Word32
i

toScriptIndexConway
  :: L.ConwayPlutusPurpose L.AsIx (ShelleyLedgerEra era)
  -> ScriptWitnessIndex
toScriptIndexConway :: forall era.
ConwayPlutusPurpose AsIx (ShelleyLedgerEra era)
-> ScriptWitnessIndex
toScriptIndexConway ConwayPlutusPurpose AsIx (ShelleyLedgerEra era)
scriptPurposeIndex =
  case ConwayPlutusPurpose AsIx (ShelleyLedgerEra era)
scriptPurposeIndex of
    L.ConwaySpending (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexTxIn Word32
i
    L.ConwayMinting (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexMint Word32
i
    L.ConwayCertifying (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexCertificate Word32
i
    L.ConwayRewarding (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexWithdrawal Word32
i
    L.ConwayVoting (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexVoting Word32
i
    L.ConwayProposing (L.AsIx Word32
i) -> Word32 -> ScriptWitnessIndex
ScriptWitnessIndexProposing Word32
i

collectTxBodyScriptWitnesses
  :: forall era
   . ShelleyBasedEra era
  -> TxBodyContent BuildTx era
  -> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses :: forall era.
ShelleyBasedEra era
-> TxBodyContent BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
collectTxBodyScriptWitnesses
  ShelleyBasedEra era
_
  TxBodyContent
    { TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns
    , TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals
    , TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates
    , TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue
    , Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures build era))
txVotingProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures
    , Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures build era))
txProposalProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures
    } =
    [[(ScriptWitnessIndex, AnyScriptWitness era)]]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
      [ TxIns BuildTx era -> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesTxIns TxIns BuildTx era
txIns
      , TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesWithdrawals TxWithdrawals BuildTx era
txWithdrawals
      , TxCertificates BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesCertificates TxCertificates BuildTx era
txCertificates
      , TxMintValue BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesMinting TxMintValue BuildTx era
txMintValue
      , TxVotingProcedures BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesVoting (TxVotingProcedures BuildTx era
-> (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
    -> TxVotingProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
-> TxVotingProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxVotingProcedures BuildTx era
forall build era. TxVotingProcedures build era
TxVotingProceduresNone Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
-> TxVotingProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures)
      , TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesProposing (TxProposalProcedures BuildTx era
-> (Featured
      ConwayEraOnwards era (TxProposalProcedures BuildTx era)
    -> TxProposalProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> TxProposalProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxProposalProcedures BuildTx era
forall build era. TxProposalProcedures build era
TxProposalProceduresNone Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures)
      ]
   where
    scriptWitnessesTxIns
      :: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesTxIns :: TxIns BuildTx era -> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesTxIns TxIns BuildTx era
txIns' =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxTxIn era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxTxIn era
witness)
        | (ScriptWitnessIndex
ix, TxIn
_, ScriptWitness ScriptWitnessInCtx WitCtxTxIn
_ ScriptWitness WitCtxTxIn era
witness) <- TxIns BuildTx era
-> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)]
forall era.
TxIns BuildTx era
-> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)]
indexTxIns TxIns BuildTx era
txIns'
        ]

    scriptWitnessesWithdrawals
      :: TxWithdrawals BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesWithdrawals :: TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesWithdrawals TxWithdrawals BuildTx era
TxWithdrawalsNone = []
    scriptWitnessesWithdrawals TxWithdrawals BuildTx era
txw =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
        | (ScriptWitnessIndex
ix, StakeAddress
_, Coin
_, ScriptWitness ScriptWitnessInCtx WitCtxStake
_ ScriptWitness WitCtxStake era
witness) <- TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, StakeAddress, Coin,
     Witness WitCtxStake era)]
forall era.
TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, StakeAddress, Coin,
     Witness WitCtxStake era)]
indexTxWithdrawals TxWithdrawals BuildTx era
txw
        ]

    scriptWitnessesCertificates
      :: TxCertificates BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesCertificates :: TxCertificates BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesCertificates TxCertificates BuildTx era
TxCertificatesNone = []
    scriptWitnessesCertificates TxCertificates BuildTx era
txc =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
        | (ScriptWitnessIndex
ix, Certificate era
_, StakeCredential
_, ScriptWitness ScriptWitnessInCtx WitCtxStake
_ ScriptWitness WitCtxStake era
witness) <- TxCertificates BuildTx era
-> [(ScriptWitnessIndex, Certificate era, StakeCredential,
     Witness WitCtxStake era)]
forall era.
TxCertificates BuildTx era
-> [(ScriptWitnessIndex, Certificate era, StakeCredential,
     Witness WitCtxStake era)]
indexTxCertificates TxCertificates BuildTx era
txc
        ]

    scriptWitnessesMinting
      :: TxMintValue BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesMinting :: TxMintValue BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesMinting TxMintValue BuildTx era
TxMintNone = []
    scriptWitnessesMinting TxMintValue BuildTx era
txMintValue' =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxMint era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxMint era
witness)
        | (ScriptWitnessIndex
ix, PolicyId
_, PolicyAssets
_, BuildTxWith ScriptWitness WitCtxMint era
witness) <- TxMintValue BuildTx era
-> [(ScriptWitnessIndex, PolicyId, PolicyAssets,
     BuildTxWith BuildTx (ScriptWitness WitCtxMint era))]
forall build era.
TxMintValue build era
-> [(ScriptWitnessIndex, PolicyId, PolicyAssets,
     BuildTxWith build (ScriptWitness WitCtxMint era))]
indexTxMintValue TxMintValue BuildTx era
txMintValue'
        ]

    scriptWitnessesVoting
      :: TxVotingProcedures BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesVoting :: TxVotingProcedures BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesVoting TxVotingProcedures BuildTx era
TxVotingProceduresNone = []
    scriptWitnessesVoting TxVotingProcedures BuildTx era
txv =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
        | (ScriptWitnessIndex
ix, Voter
_, ScriptWitness WitCtxStake era
witness) <- TxVotingProcedures BuildTx era
-> [(ScriptWitnessIndex, Voter, ScriptWitness WitCtxStake era)]
forall era.
TxVotingProcedures BuildTx era
-> [(ScriptWitnessIndex, Voter, ScriptWitness WitCtxStake era)]
indexTxVotingProcedures TxVotingProcedures BuildTx era
txv
        ]

    scriptWitnessesProposing
      :: TxProposalProcedures BuildTx era
      -> [(ScriptWitnessIndex, AnyScriptWitness era)]
    scriptWitnessesProposing :: TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesProposing TxProposalProcedures BuildTx era
TxProposalProceduresNone = []
    scriptWitnessesProposing TxProposalProcedures BuildTx era
txp =
      [(ScriptWitnessIndex, AnyScriptWitness era)]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
forall a. Eq a => [a] -> [a]
List.nub
        [ (ScriptWitnessIndex
ix, ScriptWitness WitCtxStake era -> AnyScriptWitness era
forall witctx era.
Typeable witctx =>
ScriptWitness witctx era -> AnyScriptWitness era
AnyScriptWitness ScriptWitness WitCtxStake era
witness)
        | (ScriptWitnessIndex
ix, ProposalProcedure (ShelleyLedgerEra era)
_, ScriptWitness WitCtxStake era
witness) <- TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, ProposalProcedure (ShelleyLedgerEra era),
     ScriptWitness WitCtxStake era)]
forall era.
TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, ProposalProcedure (ShelleyLedgerEra era),
     ScriptWitness WitCtxStake era)]
indexTxProposalProcedures TxProposalProcedures BuildTx era
txp
        ]

getSupplementalDatums
  :: AlonzoEraOnwards era -> [TxOut CtxTx era] -> L.TxDats (ShelleyLedgerEra era)
getSupplementalDatums :: forall era.
AlonzoEraOnwards era
-> [TxOut CtxTx era] -> TxDats (ShelleyLedgerEra era)
getSupplementalDatums AlonzoEraOnwards era
eon [] = AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    TxDats (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
eon TxDats (ShelleyLedgerEra era)
AlonzoEraOnwardsConstraints era => TxDats (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty
getSupplementalDatums AlonzoEraOnwards era
eon [TxOut CtxTx era]
txouts =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    TxDats (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
eon ((AlonzoEraOnwardsConstraints era => TxDats (ShelleyLedgerEra era))
 -> TxDats (ShelleyLedgerEra era))
-> (AlonzoEraOnwardsConstraints era =>
    TxDats (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
    Map DataHash (Data (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall era. Era era => Map DataHash (Data era) -> TxDats era
L.TxDats (Map DataHash (Data (ShelleyLedgerEra era))
 -> TxDats (ShelleyLedgerEra era))
-> Map DataHash (Data (ShelleyLedgerEra era))
-> TxDats (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
      [Item (Map DataHash (Data (ShelleyLedgerEra era)))]
-> Map DataHash (Data (ShelleyLedgerEra era))
forall l. IsList l => [Item l] -> l
fromList
        [ (Data (ShelleyLedgerEra era) -> DataHash
forall era. Data era -> DataHash
L.hashData Data (ShelleyLedgerEra era)
ledgerData, Data (ShelleyLedgerEra era)
ledgerData)
        | TxOut AddressInEra era
_ TxOutValue era
_ (TxOutSupplementalDatum AlonzoEraOnwards era
_ HashableScriptData
d) ReferenceScript era
_ <- [TxOut CtxTx era]
txouts
        , let ledgerData :: Data (ShelleyLedgerEra era)
ledgerData = HashableScriptData -> Data (ShelleyLedgerEra era)
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d
        ]

collectTxBodyScriptWitnessRequirements
  :: forall era
   . IsShelleyBasedEra era
  => AlonzoEraOnwards era
  -> TxBodyContent BuildTx era
  -> Either
       TxBodyError
       (TxScriptWitnessRequirements (ShelleyLedgerEra era))
collectTxBodyScriptWitnessRequirements :: forall era.
IsShelleyBasedEra era =>
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
collectTxBodyScriptWitnessRequirements
  AlonzoEraOnwards era
aEon
  bc :: TxBodyContent BuildTx era
bc@TxBodyContent
    { [TxOut CtxTx era]
txOuts :: forall build era. TxBodyContent build era -> [TxOut CtxTx era]
txOuts :: [TxOut CtxTx era]
txOuts
    } =
    AlonzoEraOnwards era
-> ((GetPlutusScriptPurpose era,
     AlonzoEraScript (ShelleyLedgerEra era)) =>
    Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era a.
AlonzoEraOnwards era
-> ((GetPlutusScriptPurpose era,
     AlonzoEraScript (ShelleyLedgerEra era)) =>
    a)
-> a
obtainAlonzoScriptPurposeConstraints AlonzoEraOnwards era
aEon (((GetPlutusScriptPurpose era,
   AlonzoEraScript (ShelleyLedgerEra era)) =>
  Either
    TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> ((GetPlutusScriptPurpose era,
     AlonzoEraScript (ShelleyLedgerEra era)) =>
    Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ do
      let sbe :: ShelleyBasedEra era
sbe = forall era. IsShelleyBasedEra era => ShelleyBasedEra era
shelleyBasedEra @era
          supplementaldatums :: TxScriptWitnessRequirements (ShelleyLedgerEra era)
supplementaldatums = Set Language
-> [Script (ShelleyLedgerEra era)]
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall era.
Set Language
-> [Script era]
-> TxDats era
-> Redeemers era
-> TxScriptWitnessRequirements era
TxScriptWitnessRequirements Set Language
forall a. Monoid a => a
mempty [Script (ShelleyLedgerEra era)]
forall a. Monoid a => a
mempty (AlonzoEraOnwards era
-> [TxOut CtxTx era] -> TxDats (ShelleyLedgerEra era)
forall era.
AlonzoEraOnwards era
-> [TxOut CtxTx era] -> TxDats (ShelleyLedgerEra era)
getSupplementalDatums AlonzoEraOnwards era
aEon [TxOut CtxTx era]
txOuts) Redeemers (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty
      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txInWits <-
        (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
          AlonzoEraOnwards era
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'TxInItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxTxIn era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
            AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
extractWitnessableTxIns AlonzoEraOnwards era
aEon TxBodyContent BuildTx era
bc

      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txWithdrawalWits <-
        (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
          AlonzoEraOnwards era
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
            AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableWithdrawals AlonzoEraOnwards era
aEon TxBodyContent BuildTx era
bc

      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txCertWits <-
        (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
          AlonzoEraOnwards era
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'CertItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
            AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableCertificates AlonzoEraOnwards era
aEon TxBodyContent BuildTx era
bc

      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txMintWits <-
        (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
          AlonzoEraOnwards era
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'MintItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxMint era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
            AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
extractWitnessableMints AlonzoEraOnwards era
aEon TxBodyContent BuildTx era
bc

      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txVotingWits <-
        (ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> (ConwayEraOnwardsConstraints era =>
    ConwayEraOnwards era
    -> Either
         TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> ShelleyBasedEra era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era a.
(ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era -> a)
-> (ConwayEraOnwardsConstraints era => ConwayEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToBabbageOrConwayEraOnwards
          ( \ShelleyToBabbageEra era
w ->
              ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era =>
    Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era a.
ShelleyToBabbageEra era
-> (ShelleyToBabbageEraConstraints era => a) -> a
shelleyToBabbageEraConstraints ShelleyToBabbageEra era
w ((ShelleyToBabbageEraConstraints era =>
  Either
    TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> (ShelleyToBabbageEraConstraints era =>
    Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. b -> Either a b
Right (TxScriptWitnessRequirements (ShelleyLedgerEra era)
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ Set Language
-> [Script (ShelleyLedgerEra era)]
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall era.
Set Language
-> [Script era]
-> TxDats era
-> Redeemers era
-> TxScriptWitnessRequirements era
TxScriptWitnessRequirements Set Language
forall a. Monoid a => a
mempty [Script (ShelleyLedgerEra era)]
forall a. Monoid a => a
mempty TxDats (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty Redeemers (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty
          )
          ( \ConwayEraOnwards era
eon ->
              (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
                AlonzoEraOnwards era
-> [(Witnessable 'VoterItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'VoterItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'VoterItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
                  ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'VoterItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era.
ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'VoterItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableVotes ConwayEraOnwards era
eon TxBodyContent BuildTx era
bc
          )
          ShelleyBasedEra era
sbe
      TxScriptWitnessRequirements (ShelleyLedgerEra era)
txProposalWits <-
        (ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> (ConwayEraOnwardsConstraints era =>
    ConwayEraOnwards era
    -> Either
         TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> ShelleyBasedEra era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era a.
(ShelleyToBabbageEraConstraints era =>
 ShelleyToBabbageEra era -> a)
-> (ConwayEraOnwardsConstraints era => ConwayEraOnwards era -> a)
-> ShelleyBasedEra era
-> a
caseShelleyToBabbageOrConwayEraOnwards
          (Either
  TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> ShelleyToBabbageEra era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. a -> b -> a
const (Either
   TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> ShelleyToBabbageEra era
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> ShelleyToBabbageEra era
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. b -> Either a b
Right (TxScriptWitnessRequirements (ShelleyLedgerEra era)
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$ Set Language
-> [Script (ShelleyLedgerEra era)]
-> TxDats (ShelleyLedgerEra era)
-> Redeemers (ShelleyLedgerEra era)
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall era.
Set Language
-> [Script era]
-> TxDats era
-> Redeemers era
-> TxScriptWitnessRequirements era
TxScriptWitnessRequirements Set Language
forall a. Monoid a => a
mempty [Script (ShelleyLedgerEra era)]
forall a. Monoid a => a
mempty TxDats (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty Redeemers (ShelleyLedgerEra era)
forall a. Monoid a => a
mempty)
          ( \ConwayEraOnwards era
eon ->
              (DecoderError -> TxBodyError)
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first DecoderError -> TxBodyError
TxBodyPlutusScriptDecodeError (Either
   DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
                AlonzoEraOnwards era
-> [(Witnessable 'ProposalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall era (witnessable :: WitnessableItem) ctx.
AlonzoEraOnwards era
-> [(Witnessable witnessable (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness ctx era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
legacyWitnessToScriptRequirements AlonzoEraOnwards era
aEon ([(Witnessable 'ProposalItem (ShelleyLedgerEra era),
   BuildTxWith BuildTx (Witness WitCtxStake era))]
 -> Either
      DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> [(Witnessable 'ProposalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
-> Either
     DecoderError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
                  ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'ProposalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era.
ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'ProposalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableProposals ConwayEraOnwards era
eon TxBodyContent BuildTx era
bc
          )
          ShelleyBasedEra era
sbe

      TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a. a -> Either TxBodyError a
forall (m :: * -> *) a. Monad m => a -> m a
return (TxScriptWitnessRequirements (ShelleyLedgerEra era)
 -> Either
      TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era)))
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
-> Either
     TxBodyError (TxScriptWitnessRequirements (ShelleyLedgerEra era))
forall a b. (a -> b) -> a -> b
$
        AlonzoEraOnwards era
-> (Monoid (TxScriptWitnessRequirements (ShelleyLedgerEra era)) =>
    TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall era a.
AlonzoEraOnwards era
-> (Monoid (TxScriptWitnessRequirements (ShelleyLedgerEra era)) =>
    a)
-> a
obtainMonoidConstraint AlonzoEraOnwards era
aEon ((Monoid (TxScriptWitnessRequirements (ShelleyLedgerEra era)) =>
  TxScriptWitnessRequirements (ShelleyLedgerEra era))
 -> TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> (Monoid (TxScriptWitnessRequirements (ShelleyLedgerEra era)) =>
    TxScriptWitnessRequirements (ShelleyLedgerEra era))
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall a b. (a -> b) -> a -> b
$
          [TxScriptWitnessRequirements (ShelleyLedgerEra era)]
-> TxScriptWitnessRequirements (ShelleyLedgerEra era)
forall a. Monoid a => [a] -> a
mconcat
            [ TxScriptWitnessRequirements (ShelleyLedgerEra era)
supplementaldatums
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txInWits
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txWithdrawalWits
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txCertWits
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txMintWits
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txVotingWits
            , TxScriptWitnessRequirements (ShelleyLedgerEra era)
txProposalWits
            ]

extractWitnessableTxIns
  :: AlonzoEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable TxInItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxTxIn era))]
extractWitnessableTxIns :: forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
extractWitnessableTxIns AlonzoEraOnwards era
aeon TxBodyContent{TxIns BuildTx era
txIns :: forall build era. TxBodyContent build era -> TxIns build era
txIns :: TxIns BuildTx era
txIns} =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'TxInItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxTxIn era))])
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
aeon ((AlonzoEraOnwardsConstraints era =>
  [(Witnessable 'TxInItem (ShelleyLedgerEra era),
    BuildTxWith BuildTx (Witness WitCtxTxIn era))])
 -> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxTxIn era))])
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'TxInItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxTxIn era))])
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a b. (a -> b) -> a -> b
$
    [(Witnessable 'TxInItem (ShelleyLedgerEra era),
  BuildTxWith BuildTx (Witness WitCtxTxIn era))]
-> [(Witnessable 'TxInItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxTxIn era))]
forall a. Eq a => [a] -> [a]
List.nub [(TxIn -> Witnessable 'TxInItem (ShelleyLedgerEra era)
forall era.
AlonzoEraScript era =>
TxIn -> Witnessable 'TxInItem era
WitTxIn TxIn
txin, BuildTxWith BuildTx (Witness WitCtxTxIn era)
wit) | (TxIn
txin, BuildTxWith BuildTx (Witness WitCtxTxIn era)
wit) <- TxIns BuildTx era
txIns]

extractWitnessableWithdrawals
  :: AlonzoEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable WithdrawalItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableWithdrawals :: forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableWithdrawals AlonzoEraOnwards era
aeon TxBodyContent{TxWithdrawals BuildTx era
txWithdrawals :: forall build era.
TxBodyContent build era -> TxWithdrawals build era
txWithdrawals :: TxWithdrawals BuildTx era
txWithdrawals} =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
aeon ((AlonzoEraOnwardsConstraints era =>
  [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
    BuildTxWith BuildTx (Witness WitCtxStake era))])
 -> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
    [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(Witnessable 'WithdrawalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a. Eq a => [a] -> [a]
List.nub
      [ (StakeAddress
-> Coin -> Witnessable 'WithdrawalItem (ShelleyLedgerEra era)
forall era.
AlonzoEraScript era =>
StakeAddress -> Coin -> Witnessable 'WithdrawalItem era
WitWithdrawal StakeAddress
addr Coin
withAmt, BuildTxWith BuildTx (Witness WitCtxStake era)
wit)
      | (StakeAddress
addr, Coin
withAmt, BuildTxWith BuildTx (Witness WitCtxStake era)
wit) <- TxWithdrawals BuildTx era
-> [(StakeAddress, Coin,
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall {build} {era}.
TxWithdrawals build era
-> [(StakeAddress, Coin,
     BuildTxWith build (Witness WitCtxStake era))]
getWithdrawals TxWithdrawals BuildTx era
txWithdrawals
      ]
 where
  getWithdrawals :: TxWithdrawals build era
-> [(StakeAddress, Coin,
     BuildTxWith build (Witness WitCtxStake era))]
getWithdrawals TxWithdrawals build era
TxWithdrawalsNone = []
  getWithdrawals (TxWithdrawals ShelleyBasedEra era
_ [(StakeAddress, Coin, BuildTxWith build (Witness WitCtxStake era))]
txws) = [(StakeAddress, Coin, BuildTxWith build (Witness WitCtxStake era))]
txws

extractWitnessableCertificates
  :: AlonzoEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable CertItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableCertificates :: forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableCertificates AlonzoEraOnwards era
aeon TxBodyContent{TxCertificates BuildTx era
txCertificates :: forall build era.
TxBodyContent build era -> TxCertificates build era
txCertificates :: TxCertificates BuildTx era
txCertificates} =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'CertItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
aeon ((AlonzoEraOnwardsConstraints era =>
  [(Witnessable 'CertItem (ShelleyLedgerEra era),
    BuildTxWith BuildTx (Witness WitCtxStake era))])
 -> [(Witnessable 'CertItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'CertItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxStake era))])
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a b. (a -> b) -> a -> b
$
    [(Witnessable 'CertItem (ShelleyLedgerEra era),
  BuildTxWith BuildTx (Witness WitCtxStake era))]
-> [(Witnessable 'CertItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
forall a. Eq a => [a] -> [a]
List.nub
      [ ( TxCert (ShelleyLedgerEra era)
-> StakeCredential -> Witnessable 'CertItem (ShelleyLedgerEra era)
forall era.
(EraTxCert era, AlonzoEraScript era) =>
TxCert era -> StakeCredential -> Witnessable 'CertItem era
WitTxCert (Certificate era -> TxCert (ShelleyLedgerEra era)
forall era. Certificate era -> TxCert (ShelleyLedgerEra era)
certificateToTxCert Certificate era
cert) StakeCredential
stakeCred
        , Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Witness WitCtxStake era
wit
        )
      | (Certificate era
cert, BuildTxWith (Just (StakeCredential
stakeCred, Witness WitCtxStake era
wit))) <- TxCertificates BuildTx era
-> [(Certificate era,
     BuildTxWith
       BuildTx (Maybe (StakeCredential, Witness WitCtxStake era)))]
forall {build} {era}.
TxCertificates build era
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
getCertificates TxCertificates BuildTx era
txCertificates
      ]
 where
  getCertificates :: TxCertificates build era
-> [(Certificate era,
     BuildTxWith
       build (Maybe (StakeCredential, Witness WitCtxStake era)))]
getCertificates TxCertificates build era
TxCertificatesNone = []
  getCertificates (TxCertificates ShelleyBasedEra era
_ OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
txcs) = OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
-> [Item
      (OMap
         (Certificate era)
         (BuildTxWith
            build (Maybe (StakeCredential, Witness WitCtxStake era))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (Certificate era)
  (BuildTxWith
     build (Maybe (StakeCredential, Witness WitCtxStake era)))
txcs

extractWitnessableMints
  :: AlonzoEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable MintItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxMint era))]
extractWitnessableMints :: forall era.
AlonzoEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
extractWitnessableMints AlonzoEraOnwards era
aeon TxBodyContent{TxMintValue BuildTx era
txMintValue :: forall build era. TxBodyContent build era -> TxMintValue build era
txMintValue :: TxMintValue BuildTx era
txMintValue} =
  AlonzoEraOnwards era
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'MintItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxMint era))])
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
forall era a.
AlonzoEraOnwards era -> (AlonzoEraOnwardsConstraints era => a) -> a
alonzoEraOnwardsConstraints AlonzoEraOnwards era
aeon ((AlonzoEraOnwardsConstraints era =>
  [(Witnessable 'MintItem (ShelleyLedgerEra era),
    BuildTxWith BuildTx (Witness WitCtxMint era))])
 -> [(Witnessable 'MintItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxMint era))])
-> (AlonzoEraOnwardsConstraints era =>
    [(Witnessable 'MintItem (ShelleyLedgerEra era),
      BuildTxWith BuildTx (Witness WitCtxMint era))])
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
forall a b. (a -> b) -> a -> b
$
    [(Witnessable 'MintItem (ShelleyLedgerEra era),
  BuildTxWith BuildTx (Witness WitCtxMint era))]
-> [(Witnessable 'MintItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxMint era))]
forall a. Eq a => [a] -> [a]
List.nub
      [ (PolicyId
-> PolicyAssets -> Witnessable 'MintItem (ShelleyLedgerEra era)
forall era.
AlonzoEraScript era =>
PolicyId -> PolicyAssets -> Witnessable 'MintItem era
WitMint PolicyId
policyId PolicyAssets
policyAssets, Witness WitCtxMint era
-> BuildTxWith BuildTx (Witness WitCtxMint era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith (Witness WitCtxMint era
 -> BuildTxWith BuildTx (Witness WitCtxMint era))
-> Witness WitCtxMint era
-> BuildTxWith BuildTx (Witness WitCtxMint era)
forall a b. (a -> b) -> a -> b
$ ScriptWitnessInCtx WitCtxMint
-> ScriptWitness WitCtxMint era -> Witness WitCtxMint era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxMint
ScriptWitnessForMinting ScriptWitness WitCtxMint era
wit)
      | (PolicyId
policyId, (PolicyAssets
policyAssets, BuildTxWith ScriptWitness WitCtxMint era
wit)) <- TxMintValue BuildTx era
-> [(PolicyId,
     (PolicyAssets,
      BuildTxWith BuildTx (ScriptWitness WitCtxMint era)))]
forall {build} {era}.
TxMintValue build era
-> [(PolicyId,
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
getMints TxMintValue BuildTx era
txMintValue
      ]
 where
  getMints :: TxMintValue build era
-> [(PolicyId,
     (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
getMints TxMintValue build era
TxMintNone = []
  getMints (TxMintValue MaryEraOnwards era
_ Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
txms) = Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
-> [Item
      (Map
         PolicyId
         (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era)))]
forall l. IsList l => l -> [Item l]
toList Map
  PolicyId
  (PolicyAssets, BuildTxWith build (ScriptWitness WitCtxMint era))
txms

extractWitnessableVotes
  :: ConwayEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable VoterItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableVotes :: forall era.
ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'VoterItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableVotes e :: ConwayEraOnwards era
e@ConwayEraOnwards era
ConwayEraOnwardsConway TxBodyContent{Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures build era))
txVotingProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures} =
  [(Witnessable 'VoterItem ConwayEra,
  BuildTxWith BuildTx (Witness WitCtxStake ConwayEra))]
-> [(Witnessable 'VoterItem ConwayEra,
     BuildTxWith BuildTx (Witness WitCtxStake ConwayEra))]
forall a. Eq a => [a] -> [a]
List.nub
    [ (Voter -> Witnessable 'VoterItem ConwayEra
forall era.
ConwayEraScript era =>
Voter -> Witnessable 'VoterItem era
WitVote Voter
vote, Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Witness WitCtxStake era
wit)
    | (Voter Voter
vote, Witness WitCtxStake era
wit) <- ConwayEraOnwards era
-> TxVotingProcedures BuildTx era
-> [(Voter era, Witness WitCtxStake era)]
forall era.
ConwayEraOnwards era
-> TxVotingProcedures BuildTx era
-> [(Voter era, Witness WitCtxStake era)]
getVotes ConwayEraOnwards era
e (TxVotingProcedures BuildTx era
 -> [(Voter era, Witness WitCtxStake era)])
-> TxVotingProcedures BuildTx era
-> [(Voter era, Witness WitCtxStake era)]
forall a b. (a -> b) -> a -> b
$ TxVotingProcedures BuildTx era
-> (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
    -> TxVotingProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
-> TxVotingProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxVotingProcedures BuildTx era
forall build era. TxVotingProcedures build era
TxVotingProceduresNone Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era)
-> TxVotingProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxVotingProcedures BuildTx era))
txVotingProcedures
    ]
 where
  getVotes
    :: ConwayEraOnwards era
    -> TxVotingProcedures BuildTx era
    -> [(Voter era, Witness WitCtxStake era)]
  getVotes :: forall era.
ConwayEraOnwards era
-> TxVotingProcedures BuildTx era
-> [(Voter era, Witness WitCtxStake era)]
getVotes ConwayEraOnwards era
ConwayEraOnwardsConway TxVotingProcedures BuildTx era
TxVotingProceduresNone = []
  getVotes ConwayEraOnwards era
ConwayEraOnwardsConway (TxVotingProcedures VotingProcedures (ShelleyLedgerEra era)
allVotingProcedures (BuildTxWith Map Voter (ScriptWitness WitCtxStake era)
scriptWitnessedVotes)) =
    [ (Voter -> Voter era
forall era. Typeable era => Voter -> Voter era
Voter Voter
singleVoter, Witness WitCtxStake era
wit)
    | (Voter
singleVoter, Map GovActionId (VotingProcedure ConwayEra)
_) <- Map Voter (Map GovActionId (VotingProcedure ConwayEra))
-> [Item (Map Voter (Map GovActionId (VotingProcedure ConwayEra)))]
forall l. IsList l => l -> [Item l]
toList (Map Voter (Map GovActionId (VotingProcedure ConwayEra))
 -> [Item
       (Map Voter (Map GovActionId (VotingProcedure ConwayEra)))])
-> Map Voter (Map GovActionId (VotingProcedure ConwayEra))
-> [Item (Map Voter (Map GovActionId (VotingProcedure ConwayEra)))]
forall a b. (a -> b) -> a -> b
$ VotingProcedures ConwayEra
-> Map Voter (Map GovActionId (VotingProcedure ConwayEra))
forall era.
VotingProcedures era
-> Map Voter (Map GovActionId (VotingProcedure era))
L.unVotingProcedures VotingProcedures ConwayEra
VotingProcedures (ShelleyLedgerEra era)
allVotingProcedures
    , let wit :: Witness WitCtxStake era
wit = case Voter
-> Map Voter (ScriptWitness WitCtxStake era)
-> Maybe (ScriptWitness WitCtxStake era)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Voter
singleVoter Map Voter (ScriptWitness WitCtxStake era)
scriptWitnessedVotes of
            Just ScriptWitness WitCtxStake era
sWit -> ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit
            Maybe (ScriptWitness WitCtxStake era)
Nothing -> KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr
    ]

extractWitnessableProposals
  :: ConwayEraOnwards era
  -> TxBodyContent BuildTx era
  -> [(Witnessable ProposalItem (ShelleyLedgerEra era), BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableProposals :: forall era.
ConwayEraOnwards era
-> TxBodyContent BuildTx era
-> [(Witnessable 'ProposalItem (ShelleyLedgerEra era),
     BuildTxWith BuildTx (Witness WitCtxStake era))]
extractWitnessableProposals e :: ConwayEraOnwards era
e@ConwayEraOnwards era
ConwayEraOnwardsConway TxBodyContent{Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures :: forall build era.
TxBodyContent build era
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures build era))
txProposalProcedures :: Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures} =
  [(Witnessable 'ProposalItem ConwayEra,
  BuildTxWith BuildTx (Witness WitCtxStake ConwayEra))]
-> [(Witnessable 'ProposalItem ConwayEra,
     BuildTxWith BuildTx (Witness WitCtxStake ConwayEra))]
forall a. Eq a => [a] -> [a]
List.nub
    [ (ProposalProcedure ConwayEra -> Witnessable 'ProposalItem ConwayEra
forall era.
(ConwayEraScript era, EraPParams era) =>
ProposalProcedure era -> Witnessable 'ProposalItem era
WitProposal ProposalProcedure ConwayEra
ProposalProcedure (ShelleyLedgerEra era)
prop, Witness WitCtxStake era
-> BuildTxWith BuildTx (Witness WitCtxStake era)
forall a. a -> BuildTxWith BuildTx a
BuildTxWith Witness WitCtxStake era
wit)
    | (Proposal ProposalProcedure (ShelleyLedgerEra era)
prop, Witness WitCtxStake era
wit) <-
        ConwayEraOnwards era
-> TxProposalProcedures BuildTx era
-> [(Proposal era, Witness WitCtxStake era)]
forall era.
ConwayEraOnwards era
-> TxProposalProcedures BuildTx era
-> [(Proposal era, Witness WitCtxStake era)]
getProposals ConwayEraOnwards era
e (TxProposalProcedures BuildTx era
 -> [(Proposal era, Witness WitCtxStake era)])
-> TxProposalProcedures BuildTx era
-> [(Proposal era, Witness WitCtxStake era)]
forall a b. (a -> b) -> a -> b
$ TxProposalProcedures BuildTx era
-> (Featured
      ConwayEraOnwards era (TxProposalProcedures BuildTx era)
    -> TxProposalProcedures BuildTx era)
-> Maybe
     (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
-> TxProposalProcedures BuildTx era
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TxProposalProcedures BuildTx era
forall build era. TxProposalProcedures build era
TxProposalProceduresNone Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era)
-> TxProposalProcedures BuildTx era
forall (eon :: * -> *) era a. Featured eon era a -> a
unFeatured Maybe
  (Featured ConwayEraOnwards era (TxProposalProcedures BuildTx era))
txProposalProcedures
    ]
 where
  getProposals
    :: ConwayEraOnwards era
    -> TxProposalProcedures BuildTx era
    -> [(Proposal era, Witness WitCtxStake era)]
  getProposals :: forall era.
ConwayEraOnwards era
-> TxProposalProcedures BuildTx era
-> [(Proposal era, Witness WitCtxStake era)]
getProposals ConwayEraOnwards era
ConwayEraOnwardsConway TxProposalProcedures BuildTx era
TxProposalProceduresNone = []
  getProposals ConwayEraOnwards era
ConwayEraOnwardsConway (TxProposalProcedures OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))
txps) =
    [ (ProposalProcedure (ShelleyLedgerEra era) -> Proposal era
forall era.
Typeable era =>
ProposalProcedure (ShelleyLedgerEra era) -> Proposal era
Proposal ProposalProcedure ConwayEra
ProposalProcedure (ShelleyLedgerEra era)
p, Witness WitCtxStake era
wit)
    | (ProposalProcedure ConwayEra
p, BuildTxWith Maybe (ScriptWitness WitCtxStake ConwayEra)
mScriptWit) <- OMap
  (ProposalProcedure ConwayEra)
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake ConwayEra)))
-> [Item
      (OMap
         (ProposalProcedure ConwayEra)
         (BuildTxWith
            BuildTx (Maybe (ScriptWitness WitCtxStake ConwayEra))))]
forall l. IsList l => l -> [Item l]
toList OMap
  (ProposalProcedure ConwayEra)
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake ConwayEra)))
OMap
  (ProposalProcedure (ShelleyLedgerEra era))
  (BuildTxWith BuildTx (Maybe (ScriptWitness WitCtxStake era)))
txps
    , let wit :: Witness WitCtxStake era
wit = case Maybe (ScriptWitness WitCtxStake ConwayEra)
mScriptWit of
            Just ScriptWitness WitCtxStake era
sWit -> ScriptWitnessInCtx WitCtxStake
-> ScriptWitness WitCtxStake era -> Witness WitCtxStake era
forall witctx era.
ScriptWitnessInCtx witctx
-> ScriptWitness witctx era -> Witness witctx era
ScriptWitness ScriptWitnessInCtx WitCtxStake
ScriptWitnessForStakeAddr ScriptWitness WitCtxStake era
sWit
            Maybe (ScriptWitness WitCtxStake ConwayEra)
Nothing -> KeyWitnessInCtx WitCtxStake -> Witness WitCtxStake era
forall witctx era. KeyWitnessInCtx witctx -> Witness witctx era
KeyWitness KeyWitnessInCtx WitCtxStake
KeyWitnessForStakeAddr
    ]

toShelleyWithdrawal :: [(StakeAddress, L.Coin, a)] -> L.Withdrawals
toShelleyWithdrawal :: forall a. [(StakeAddress, Coin, a)] -> Withdrawals
toShelleyWithdrawal [(StakeAddress, Coin, a)]
withdrawals =
  Map RewardAccount Coin -> Withdrawals
L.Withdrawals (Map RewardAccount Coin -> Withdrawals)
-> Map RewardAccount Coin -> Withdrawals
forall a b. (a -> b) -> a -> b
$
    [Item (Map RewardAccount Coin)] -> Map RewardAccount Coin
forall l. IsList l => [Item l] -> l
fromList
      [ (StakeAddress -> RewardAccount
toShelleyStakeAddr StakeAddress
stakeAddr, Coin
value)
      | (StakeAddress
stakeAddr, Coin
value, a
_) <- [(StakeAddress, Coin, a)]
withdrawals
      ]

fromShelleyWithdrawal
  :: L.Withdrawals
  -> [(StakeAddress, L.Coin, BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal :: forall era.
Withdrawals
-> [(StakeAddress, Coin,
     BuildTxWith ViewTx (Witness WitCtxStake era))]
fromShelleyWithdrawal (L.Withdrawals Map RewardAccount Coin
withdrawals) =
  [ (RewardAccount -> StakeAddress
fromShelleyStakeAddr RewardAccount
stakeAddr, Coin
value, BuildTxWith ViewTx (Witness WitCtxStake era)
forall a. BuildTxWith ViewTx a
ViewTx)
  | (RewardAccount
stakeAddr, Coin
value) <- Map RewardAccount Coin -> [(RewardAccount, Coin)]
forall k a. Map k a -> [(k, a)]
Map.assocs Map RewardAccount Coin
withdrawals
  ]

-- | In the Allegra and Mary eras the auxiliary data consists of the tx metadata
-- and the axiliary scripts. In the Alonzo and later eras the auxiliary data consists of the tx metadata
-- and the axiliary scripts, and the axiliary script data.
toAuxiliaryData
  :: ShelleyBasedEra era
  -> TxMetadataInEra era
  -> TxAuxScripts era
  -> Maybe (L.TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData :: forall era.
ShelleyBasedEra era
-> TxMetadataInEra era
-> TxAuxScripts era
-> Maybe (TxAuxData (ShelleyLedgerEra era))
toAuxiliaryData ShelleyBasedEra era
sbe TxMetadataInEra era
txMetadata TxAuxScripts era
txAuxScripts =
  let ms :: Map Word64 Metadatum
ms = case TxMetadataInEra era
txMetadata of
        TxMetadataInEra era
TxMetadataNone -> Map Word64 Metadatum
forall k a. Map k a
Map.empty
        TxMetadataInEra ShelleyBasedEra era
_ (TxMetadata Map Word64 TxMetadataValue
ms') -> Map Word64 TxMetadataValue -> Map Word64 Metadatum
toShelleyMetadata Map Word64 TxMetadataValue
ms'
      ss :: [Script (ShelleyLedgerEra era)]
ss = case TxAuxScripts era
txAuxScripts of
        TxAuxScripts era
TxAuxScriptsNone -> []
        TxAuxScripts AllegraEraOnwards era
_ [ScriptInEra era]
ss' -> (ScriptInEra era -> Script (ShelleyLedgerEra era))
-> [ScriptInEra era] -> [Script (ShelleyLedgerEra era)]
forall a b. (a -> b) -> [a] -> [b]
map ScriptInEra era -> Script (ShelleyLedgerEra era)
forall era. ScriptInEra era -> Script (ShelleyLedgerEra era)
toShelleyScript [ScriptInEra era]
ss'
   in case ShelleyBasedEra era
sbe of
        ShelleyBasedEra era
ShelleyBasedEraShelley ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms)) Maybe ()
-> ShelleyTxAuxData ShelleyEra
-> Maybe (ShelleyTxAuxData ShelleyEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum -> ShelleyTxAuxData ShelleyEra
forall era. Era era => Map Word64 Metadatum -> ShelleyTxAuxData era
L.ShelleyTxAuxData Map Word64 Metadatum
ms
        ShelleyBasedEra era
ShelleyBasedEraAllegra ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Script (ShelleyLedgerEra era)]
ss)) Maybe ()
-> AllegraTxAuxData AllegraEra
-> Maybe (AllegraTxAuxData AllegraEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum
-> StrictSeq (Timelock AllegraEra) -> AllegraTxAuxData AllegraEra
forall era.
Era era =>
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxData era
L.AllegraTxAuxData Map Word64 Metadatum
ms ([Item (StrictSeq (Timelock AllegraEra))]
-> StrictSeq (Timelock AllegraEra)
forall l. IsList l => [Item l] -> l
fromList [Item (StrictSeq (Timelock AllegraEra))]
[Script (ShelleyLedgerEra era)]
ss)
        ShelleyBasedEra era
ShelleyBasedEraMary ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Script (ShelleyLedgerEra era)]
ss)) Maybe ()
-> AllegraTxAuxData MaryEra -> Maybe (AllegraTxAuxData MaryEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum
-> StrictSeq (Timelock MaryEra) -> AllegraTxAuxData MaryEra
forall era.
Era era =>
Map Word64 Metadatum
-> StrictSeq (Timelock era) -> AllegraTxAuxData era
L.AllegraTxAuxData Map Word64 Metadatum
ms ([Item (StrictSeq (Timelock MaryEra))]
-> StrictSeq (Timelock MaryEra)
forall l. IsList l => [Item l] -> l
fromList [Item (StrictSeq (Timelock MaryEra))]
[Script (ShelleyLedgerEra era)]
ss)
        ShelleyBasedEra era
ShelleyBasedEraAlonzo ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Script (ShelleyLedgerEra era)]
ss)) Maybe ()
-> AlonzoTxAuxData AlonzoEra -> Maybe (AlonzoTxAuxData AlonzoEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum
-> [AlonzoScript AlonzoEra] -> AlonzoTxAuxData AlonzoEra
forall (f :: * -> *) era.
(Foldable f, AlonzoEraScript era) =>
Map Word64 Metadatum -> f (AlonzoScript era) -> AlonzoTxAuxData era
L.mkAlonzoTxAuxData Map Word64 Metadatum
ms [Script (ShelleyLedgerEra era)]
[AlonzoScript AlonzoEra]
ss
        ShelleyBasedEra era
ShelleyBasedEraBabbage ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Script (ShelleyLedgerEra era)]
ss)) Maybe ()
-> AlonzoTxAuxData BabbageEra -> Maybe (AlonzoTxAuxData BabbageEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum
-> [AlonzoScript BabbageEra] -> AlonzoTxAuxData BabbageEra
forall (f :: * -> *) era.
(Foldable f, AlonzoEraScript era) =>
Map Word64 Metadatum -> f (AlonzoScript era) -> AlonzoTxAuxData era
L.mkAlonzoTxAuxData Map Word64 Metadatum
ms [Script (ShelleyLedgerEra era)]
[AlonzoScript BabbageEra]
ss
        ShelleyBasedEra era
ShelleyBasedEraConway ->
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Map Word64 Metadatum -> Bool
forall k a. Map k a -> Bool
Map.null Map Word64 Metadatum
ms Bool -> Bool -> Bool
&& [Script (ShelleyLedgerEra era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Script (ShelleyLedgerEra era)]
ss)) Maybe ()
-> AlonzoTxAuxData ConwayEra -> Maybe (AlonzoTxAuxData ConwayEra)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Map Word64 Metadatum
-> [AlonzoScript ConwayEra] -> AlonzoTxAuxData ConwayEra
forall (f :: * -> *) era.
(Foldable f, AlonzoEraScript era) =>
Map Word64 Metadatum -> f (AlonzoScript era) -> AlonzoTxAuxData era
L.mkAlonzoTxAuxData Map Word64 Metadatum
ms [Script (ShelleyLedgerEra era)]
[AlonzoScript ConwayEra]
ss

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

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

-- | Calculate the reference inputs size in bytes for provided set of transaction IDs and UTXOs.
getReferenceInputsSizeForTxIds
  :: ShelleyLedgerEra era ~ ledgerera
  => BabbageEraOnwards era
  -> Ledger.UTxO ledgerera
  -> Set TxIn
  -> Int
getReferenceInputsSizeForTxIds :: forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
BabbageEraOnwards era -> UTxO ledgerera -> Set TxIn -> Int
getReferenceInputsSizeForTxIds BabbageEraOnwards era
beo UTxO ledgerera
utxo Set TxIn
txIds = BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => Int) -> Int
forall era a.
BabbageEraOnwards era
-> (BabbageEraOnwardsConstraints era => a) -> a
babbageEraOnwardsConstraints BabbageEraOnwards era
beo ((BabbageEraOnwardsConstraints era => Int) -> Int)
-> (BabbageEraOnwardsConstraints era => Int) -> Int
forall a b. (a -> b) -> a -> b
$ do
  let refScripts :: [(ScriptHash, Script ledgerera)]
refScripts = UTxO ledgerera -> Set TxIn -> [(ScriptHash, Script ledgerera)]
forall era.
BabbageEraTxOut era =>
UTxO era -> Set TxIn -> [(ScriptHash, Script era)]
L.getReferenceScriptsNonDistinct UTxO ledgerera
utxo ((TxIn -> TxIn) -> Set TxIn -> Set TxIn
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map TxIn -> TxIn
toShelleyTxIn Set TxIn
txIds)
  Sum Int -> Int
forall a. Sum a -> a
getSum (Sum Int -> Int) -> Sum Int -> Int
forall a b. (a -> b) -> a -> b
$ ((ScriptHash, AlonzoScript ledgerera) -> Sum Int)
-> [(ScriptHash, AlonzoScript ledgerera)] -> Sum Int
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Int -> Sum Int
forall a. a -> Sum a
Sum (Int -> Sum Int)
-> ((ScriptHash, AlonzoScript ledgerera) -> Int)
-> (ScriptHash, AlonzoScript ledgerera)
-> Sum Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AlonzoScript ledgerera -> Int
forall t. SafeToHash t => t -> Int
SafeHash.originalBytesSize (AlonzoScript ledgerera -> Int)
-> ((ScriptHash, AlonzoScript ledgerera) -> AlonzoScript ledgerera)
-> (ScriptHash, AlonzoScript ledgerera)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScriptHash, AlonzoScript ledgerera) -> AlonzoScript ledgerera
forall a b. (a, b) -> b
snd) [(ScriptHash, Script ledgerera)]
[(ScriptHash, AlonzoScript ledgerera)]
refScripts

calculateExecutionUnitsLovelace :: Ledger.Prices -> ExecutionUnits -> Maybe L.Coin
calculateExecutionUnitsLovelace :: Prices -> ExecutionUnits -> Maybe Coin
calculateExecutionUnitsLovelace Prices
prices ExecutionUnits
eUnits =
  Coin -> Maybe Coin
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Coin -> Maybe Coin) -> Coin -> Maybe Coin
forall a b. (a -> b) -> a -> b
$ Prices -> ExUnits -> Coin
Alonzo.txscriptfee Prices
prices (ExecutionUnits -> ExUnits
toAlonzoExUnits ExecutionUnits
eUnits)

-- ----------------------------------------------------------------------------
-- Inline data
--

-- | Conversion of ScriptData to binary data which allows for the storage of data
-- onchain within a transaction output.
scriptDataToInlineDatum :: L.Era ledgerera => HashableScriptData -> L.Datum ledgerera
scriptDataToInlineDatum :: forall ledgerera.
Era ledgerera =>
HashableScriptData -> Datum ledgerera
scriptDataToInlineDatum HashableScriptData
d =
  BinaryData ledgerera -> Datum ledgerera
forall era. BinaryData era -> Datum era
L.Datum (BinaryData ledgerera -> Datum ledgerera)
-> (Data ledgerera -> BinaryData ledgerera)
-> Data ledgerera
-> Datum ledgerera
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Data ledgerera -> BinaryData ledgerera
forall era. Data era -> BinaryData era
L.dataToBinaryData (Data ledgerera -> Datum ledgerera)
-> Data ledgerera -> Datum ledgerera
forall a b. (a -> b) -> a -> b
$ HashableScriptData -> Data ledgerera
forall ledgerera.
Era ledgerera =>
HashableScriptData -> Data ledgerera
toAlonzoData HashableScriptData
d

binaryDataToScriptData
  :: L.Era ledgerera
  => BabbageEraOnwards era
  -> L.BinaryData ledgerera
  -> HashableScriptData
binaryDataToScriptData :: forall ledgerera era.
Era ledgerera =>
BabbageEraOnwards era -> BinaryData ledgerera -> HashableScriptData
binaryDataToScriptData BabbageEraOnwards era
BabbageEraOnwardsBabbage BinaryData ledgerera
d =
  Data ledgerera -> HashableScriptData
forall ledgerera. Data ledgerera -> HashableScriptData
fromAlonzoData (Data ledgerera -> HashableScriptData)
-> Data ledgerera -> HashableScriptData
forall a b. (a -> b) -> a -> b
$ BinaryData ledgerera -> Data ledgerera
forall era. Era era => BinaryData era -> Data era
L.binaryDataToData BinaryData ledgerera
d
binaryDataToScriptData BabbageEraOnwards era
BabbageEraOnwardsConway BinaryData ledgerera
d =
  Data ledgerera -> HashableScriptData
forall ledgerera. Data ledgerera -> HashableScriptData
fromAlonzoData (Data ledgerera -> HashableScriptData)
-> Data ledgerera -> HashableScriptData
forall a b. (a -> b) -> a -> b
$ BinaryData ledgerera -> Data ledgerera
forall era. Era era => BinaryData era -> Data era
L.binaryDataToData BinaryData ledgerera
d