cardano-api
Safe HaskellNone
LanguageHaskell2010

Cardano.Api.Internal.Tx.Body

Synopsis

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

Transaction bodies

data TxBody era where Source #

Constructors

ShelleyTxBody 

Fields

Bundled Patterns

pattern TxBody :: TxBodyContent ViewTx era -> TxBody era

Deprecated: Use getTxBodyContent $ getTxBody instead

Instances

Instances details
Show (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

Methods

showsPrec :: Int -> TxBody era -> ShowS Source #

show :: TxBody era -> String Source #

showList :: [TxBody era] -> ShowS Source #

HasTypeProxy era => HasTypeProxy (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

Associated Types

data AsType (TxBody era) 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data AsType (TxBody era) = AsTxBody (AsType era)

Methods

proxyToAsType :: Proxy (TxBody era) -> AsType (TxBody era) Source #

IsShelleyBasedEra era => SerialiseAsCBOR (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

IsShelleyBasedEra era => HasTextEnvelope (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

Eq (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

Methods

(==) :: TxBody era -> TxBody era -> Bool Source #

(/=) :: TxBody era -> TxBody era -> Bool Source #

data AsType (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data AsType (TxBody era) = AsTxBody (AsType era)

createAndValidateTransactionBody :: ShelleyBasedEra era -> TxBodyContent BuildTx era -> Either TxBodyError (TxBody era) Source #

Deprecated: Use createTransactionBody instead

data TxBodyContent build era Source #

Instances

Instances details
IsShelleyBasedEra era => Show (TxBodyContent build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxBodyContent build era -> ShowS Source #

show :: TxBodyContent build era -> String Source #

showList :: [TxBodyContent build era] -> ShowS Source #

IsShelleyBasedEra era => Eq (TxBodyContent build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxBodyContent build era -> TxBodyContent build era -> Bool Source #

(/=) :: TxBodyContent build era -> TxBodyContent build era -> Bool Source #

Byron only

Transaction body builders

setTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era Source #

modTxIns :: (TxIns build era -> TxIns build era) -> TxBodyContent build era -> TxBodyContent build era Source #

addTxIn :: (TxIn, BuildTxWith build (Witness WitCtxTxIn era)) -> TxBodyContent build era -> TxBodyContent build era Source #

addTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era Source #

setTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era Source #

modTxOuts :: ([TxOut CtxTx era] -> [TxOut CtxTx era]) -> TxBodyContent build era -> TxBodyContent build era Source #

addTxOut :: TxOut CtxTx era -> TxBodyContent build era -> TxBodyContent build era Source #

addTxOuts :: [TxOut CtxTx era] -> TxBodyContent build era -> TxBodyContent build era Source #

setTxFee :: TxFee era -> TxBodyContent build era -> TxBodyContent build era Source #

modTxFee :: (TxFee era -> TxFee era) -> TxBodyContent build era -> TxBodyContent build era Source #

modTxAuxScripts :: (TxAuxScripts era -> TxAuxScripts era) -> TxBodyContent build era -> TxBodyContent build era Source #

setTxWithdrawals :: TxWithdrawals build era -> TxBodyContent build era -> TxBodyContent build era Source #

modTxWithdrawals :: (TxWithdrawals build era -> TxWithdrawals build era) -> TxBodyContent build era -> TxBodyContent build era Source #

setTxCertificates :: TxCertificates build era -> TxBodyContent build era -> TxBodyContent build era Source #

modTxCertificates :: (TxCertificates build era -> TxCertificates build era) -> TxBodyContent build era -> TxBodyContent build era Source #

setTxMintValue :: TxMintValue build era -> TxBodyContent build era -> TxBodyContent build era Source #

modTxMintValue :: (TxMintValue build era -> TxMintValue build era) -> TxBodyContent build era -> TxBodyContent build era Source #

subtractTxMintValue :: IsMaryBasedEra era => Map PolicyId [(AssetName, Quantity, BuildTxWith build (ScriptWitness WitCtxMint era))] -> TxBodyContent build era -> TxBodyContent build era Source #

Adds the negation of the provided assets and quantities to the txMintValue field of the TxBodyContent.

data TxScriptValidity era where Source #

A representation of whether the era supports tx script validity.

The Alonzo and subsequent eras support script validity.

Constructors

TxScriptValidityNone :: forall era. TxScriptValidity era 
TxScriptValidity :: forall era. AlonzoEraOnwards era -> ScriptValidity -> TxScriptValidity era

Tx script validity is supported in transactions in the Alonzo era onwards.

Instances

Instances details
Show (TxScriptValidity era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

Eq (TxScriptValidity era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data ScriptValidity Source #

Indicates whether a script is expected to fail or pass validation.

Constructors

ScriptInvalid

Script is expected to fail validation. Transactions marked as such can include scripts that fail validation. Such transactions may be submitted to the chain, in which case the collateral will be taken upon on chain script validation failure.

ScriptValid

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

Transaction Ids

newtype TxId Source #

Instances

Instances details
FromJSON TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

parseJSON :: Value -> Parser TxId

parseJSONList :: Value -> Parser [TxId]

omittedField :: Maybe TxId

FromJSONKey TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

fromJSONKey :: FromJSONKeyFunction TxId

fromJSONKeyList :: FromJSONKeyFunction [TxId]

ToJSON TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

toJSON :: TxId -> Value

toEncoding :: TxId -> Encoding

toJSONList :: [TxId] -> Value

toEncodingList :: [TxId] -> Encoding

omitField :: TxId -> Bool

ToJSONKey TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

toJSONKey :: ToJSONKeyFunction TxId

toJSONKeyList :: ToJSONKeyFunction [TxId]

IsString TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Show TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

HasTypeProxy TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Associated Types

data AsType TxId 
Instance details

Defined in Cardano.Api.Internal.TxIn

SerialiseAsRawBytes TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Eq TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

(==) :: TxId -> TxId -> Bool Source #

(/=) :: TxId -> TxId -> Bool Source #

Ord TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

data AsType TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

getTxId :: TxBody era -> TxId Source #

Calculate the transaction identifier for a TxBody.

Transaction inputs

data TxIn Source #

Constructors

TxIn TxId TxIx 

Instances

Instances details
FromJSON TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

parseJSON :: Value -> Parser TxIn

parseJSONList :: Value -> Parser [TxIn]

omittedField :: Maybe TxIn

FromJSONKey TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

fromJSONKey :: FromJSONKeyFunction TxIn

fromJSONKeyList :: FromJSONKeyFunction [TxIn]

ToJSON TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

toJSON :: TxIn -> Value

toEncoding :: TxIn -> Encoding

toJSONList :: [TxIn] -> Value

toEncodingList :: [TxIn] -> Encoding

omitField :: TxIn -> Bool

ToJSONKey TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

toJSONKey :: ToJSONKeyFunction TxIn

toJSONKeyList :: ToJSONKeyFunction [TxIn]

Show TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Eq TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

(==) :: TxIn -> TxIn -> Bool Source #

(/=) :: TxIn -> TxIn -> Bool Source #

Ord TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Pretty TxIn Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

pretty :: TxIn -> Doc ann #

prettyList :: [TxIn] -> Doc ann #

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

indexTxIns :: TxIns BuildTx era -> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)] Source #

Index transaction inputs ordered by TxIn Please note that the result can contain also KeyWitnesses. See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf

newtype TxIx Source #

Constructors

TxIx Word 

Instances

Instances details
FromJSON TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

parseJSON :: Value -> Parser TxIx

parseJSONList :: Value -> Parser [TxIx]

omittedField :: Maybe TxIx

ToJSON TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

toJSON :: TxIx -> Value

toEncoding :: TxIx -> Encoding

toJSONList :: [TxIx] -> Value

toEncodingList :: [TxIx] -> Encoding

omitField :: TxIx -> Bool

Enum TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Show TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Eq TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

Methods

(==) :: TxIx -> TxIx -> Bool Source #

(/=) :: TxIx -> TxIx -> Bool Source #

Ord TxIx Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

genesisUTxOPseudoTxIn :: NetworkId -> Hash GenesisUTxOKey -> TxIn Source #

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.

getReferenceInputsSizeForTxIds :: ShelleyLedgerEra era ~ ledgerera => BabbageEraOnwards era -> UTxO ledgerera -> Set TxIn -> Int Source #

Calculate the reference inputs size in bytes for provided set of transaction IDs and UTXOs.

Transaction outputs

data CtxTx Source #

The context is a transaction body

Instances

Instances details
IsShelleyBasedEra era => FromJSON (TxOut CtxTx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

parseJSON :: Value -> Parser (TxOut CtxTx era)

parseJSONList :: Value -> Parser [TxOut CtxTx era]

omittedField :: Maybe (TxOut CtxTx era)

data CtxUTxO Source #

The context is the UTxO

Instances

Instances details
IsShelleyBasedEra era => FromJSON (TxOut CtxUTxO era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

parseJSON :: Value -> Parser (TxOut CtxUTxO era)

parseJSONList :: Value -> Parser [TxOut CtxUTxO era]

omittedField :: Maybe (TxOut CtxUTxO era)

data TxOut ctx era Source #

Constructors

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

Instances

Instances details
IsShelleyBasedEra era => FromJSON (TxOut CtxTx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

parseJSON :: Value -> Parser (TxOut CtxTx era)

parseJSONList :: Value -> Parser [TxOut CtxTx era]

omittedField :: Maybe (TxOut CtxTx era)

IsShelleyBasedEra era => FromJSON (TxOut CtxUTxO era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

parseJSON :: Value -> Parser (TxOut CtxUTxO era)

parseJSONList :: Value -> Parser [TxOut CtxUTxO era]

omittedField :: Maybe (TxOut CtxUTxO era)

IsCardanoEra era => ToJSON (TxOut ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

toJSON :: TxOut ctx era -> Value

toEncoding :: TxOut ctx era -> Encoding

toJSONList :: [TxOut ctx era] -> Value

toEncodingList :: [TxOut ctx era] -> Encoding

omitField :: TxOut ctx era -> Bool

Show (TxOut ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxOut ctx era -> ShowS Source #

show :: TxOut ctx era -> String Source #

showList :: [TxOut ctx era] -> ShowS Source #

Eq (TxOut ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxOut ctx era -> TxOut ctx era -> Bool Source #

(/=) :: TxOut ctx era -> TxOut ctx era -> Bool Source #

data TxOutValue era where Source #

Constructors

TxOutValueByron :: forall era. Coin -> TxOutValue era 
TxOutValueShelleyBased :: forall era. (Eq (Value (ShelleyLedgerEra era)), Show (Value (ShelleyLedgerEra era))) => ShelleyBasedEra era -> Value (ShelleyLedgerEra era) -> TxOutValue era 

Instances

Instances details
IsShelleyBasedEra era => FromJSON (TxOutValue era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

parseJSON :: Value -> Parser (TxOutValue era)

parseJSONList :: Value -> Parser [TxOutValue era]

omittedField :: Maybe (TxOutValue era)

IsCardanoEra era => ToJSON (TxOutValue era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

toJSON :: TxOutValue era -> Value

toEncoding :: TxOutValue era -> Encoding

toJSONList :: [TxOutValue era] -> Value

toEncodingList :: [TxOutValue era] -> Encoding

omitField :: TxOutValue era -> Bool

Show (TxOutValue era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxOutValue era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxOutValue era -> TxOutValue era -> Bool Source #

(/=) :: TxOutValue era -> TxOutValue era -> Bool Source #

data TxOutDatum ctx era where Source #

Constructors

TxOutDatumNone :: forall ctx era. TxOutDatum ctx era 
TxOutDatumHash :: forall era ctx. AlonzoEraOnwards era -> Hash ScriptData -> TxOutDatum ctx era

A transaction output that only specifies the hash of the datum, but not the full datum value.

TxOutSupplementalDatum :: forall era. AlonzoEraOnwards era -> HashableScriptData -> TxOutDatum CtxTx 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.

TxOutDatumInline :: forall era ctx. BabbageEraOnwards era -> HashableScriptData -> TxOutDatum ctx 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.

Instances

Instances details
Show (TxOutDatum ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxOutDatum ctx era -> ShowS Source #

show :: TxOutDatum ctx era -> String Source #

showList :: [TxOutDatum ctx era] -> ShowS Source #

Eq (TxOutDatum ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxOutDatum ctx era -> TxOutDatum ctx era -> Bool Source #

(/=) :: TxOutDatum ctx era -> TxOutDatum ctx era -> Bool Source #

txOutInAnyEra :: CardanoEra era -> TxOut CtxTx era -> TxOutInAnyEra Source #

Convenience constructor for TxOutInAnyEra

Other transaction body types

data TxInsCollateral era where Source #

Constructors

TxInsCollateralNone :: forall era. TxInsCollateral era 
TxInsCollateral :: forall era. AlonzoEraOnwards era -> [TxIn] -> TxInsCollateral era 

Instances

Instances details
Show (TxInsCollateral era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxInsCollateral era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxInsReference era where Source #

Constructors

TxInsReferenceNone :: forall era. TxInsReference era 
TxInsReference :: forall era. BabbageEraOnwards era -> [TxIn] -> TxInsReference era 

Instances

Instances details
Show (TxInsReference era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxInsReference era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxReturnCollateral ctx era where Source #

Constructors

TxReturnCollateralNone :: forall ctx era. TxReturnCollateral ctx era 
TxReturnCollateral :: forall era ctx. BabbageEraOnwards era -> TxOut ctx era -> TxReturnCollateral ctx era 

Instances

Instances details
Show (TxReturnCollateral ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxReturnCollateral ctx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxTotalCollateral era where Source #

Constructors

TxTotalCollateralNone :: forall era. TxTotalCollateral era 
TxTotalCollateral :: forall era. BabbageEraOnwards era -> Coin -> TxTotalCollateral era 

data TxFee era where Source #

Constructors

TxFeeExplicit :: forall era. ShelleyBasedEra era -> Coin -> TxFee era 

Instances

Instances details
Show (TxFee era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxFee era -> ShowS Source #

show :: TxFee era -> String Source #

showList :: [TxFee era] -> ShowS Source #

Eq (TxFee era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxFee era -> TxFee era -> Bool Source #

(/=) :: TxFee era -> TxFee era -> Bool Source #

data TxValidityUpperBound era where Source #

This was formerly known as the TTL.

Constructors

TxValidityUpperBound :: forall era. ShelleyBasedEra era -> Maybe SlotNo -> TxValidityUpperBound era 

data TxMetadataInEra era where Source #

Constructors

TxMetadataNone :: forall era. TxMetadataInEra era 
TxMetadataInEra :: forall era. ShelleyBasedEra era -> TxMetadata -> TxMetadataInEra era 

Instances

Instances details
Show (TxMetadataInEra era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxMetadataInEra era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxAuxScripts era where Source #

Constructors

TxAuxScriptsNone :: forall era. TxAuxScripts era 
TxAuxScripts :: forall era. AllegraEraOnwards era -> [ScriptInEra era] -> TxAuxScripts era 

Instances

Instances details
Show (TxAuxScripts era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxAuxScripts era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxWithdrawals build era where Source #

Constructors

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

Instances

Instances details
Show (TxWithdrawals build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxWithdrawals build era -> ShowS Source #

show :: TxWithdrawals build era -> String Source #

showList :: [TxWithdrawals build era] -> ShowS Source #

Eq (TxWithdrawals build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxWithdrawals build era -> TxWithdrawals build era -> Bool Source #

(/=) :: TxWithdrawals build era -> TxWithdrawals build era -> Bool Source #

data TxCertificates build era where Source #

Constructors

TxCertificatesNone :: forall build era. TxCertificates build era

No certificates

TxCertificates :: forall era build. ShelleyBasedEra era -> OMap (Certificate era) (BuildTxWith build (Maybe (StakeCredential, Witness WitCtxStake era))) -> TxCertificates build era

Represents certificates present in transaction. Prefer using mkTxCertificates to constructing this type with a constructor

Instances

Instances details
Show (TxCertificates build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxCertificates build era -> ShowS Source #

show :: TxCertificates build era -> String Source #

showList :: [TxCertificates build era] -> ShowS Source #

Eq (TxCertificates build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxCertificates build era -> TxCertificates build era -> Bool Source #

(/=) :: TxCertificates build era -> TxCertificates build era -> Bool Source #

mkTxCertificates :: Applicative (BuildTxWith build) => ShelleyBasedEra era -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))] -> TxCertificates build era Source #

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.

indexTxCertificates :: TxCertificates BuildTx era -> [(ScriptWitnessIndex, Certificate era, StakeCredential, Witness WitCtxStake era)] Source #

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

data TxUpdateProposal era where Source #

Constructors

TxUpdateProposalNone :: forall era. TxUpdateProposal era 
TxUpdateProposal :: forall era. ShelleyToBabbageEra era -> UpdateProposal -> TxUpdateProposal era 

Instances

Instances details
Show (TxUpdateProposal era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxUpdateProposal era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data TxMintValue build era where Source #

Constructors

TxMintNone :: forall build era. TxMintValue build era 
TxMintValue :: forall era build. MaryEraOnwards era -> Map PolicyId [(AssetName, Quantity, BuildTxWith build (ScriptWitness WitCtxMint era))] -> TxMintValue build era 

Instances

Instances details
Show (TxMintValue build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> TxMintValue build era -> ShowS Source #

show :: TxMintValue build era -> String Source #

showList :: [TxMintValue build era] -> ShowS Source #

Eq (TxMintValue build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxMintValue build era -> TxMintValue build era -> Bool Source #

(/=) :: TxMintValue build era -> TxMintValue build era -> Bool Source #

txMintValueToValue :: TxMintValue build era -> Value Source #

Convert TxMintValue to a more handy Value.

data TxVotingProcedures build era where Source #

Constructors

TxVotingProceduresNone :: forall build era. TxVotingProcedures build era 
TxVotingProcedures :: forall era build. VotingProcedures (ShelleyLedgerEra era) -> BuildTxWith build (Map (Voter (EraCrypto (ShelleyLedgerEra era))) (ScriptWitness WitCtxStake era)) -> TxVotingProcedures build era 

Instances

Instances details
Show (TxVotingProcedures build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxVotingProcedures build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxVotingProcedures build era -> TxVotingProcedures build era -> Bool Source #

(/=) :: TxVotingProcedures build era -> TxVotingProcedures build era -> Bool Source #

mkTxVotingProcedures :: Applicative (BuildTxWith build) => [(VotingProcedures era, Maybe (ScriptWitness WitCtxStake era))] -> Either (VotesMergingConflict era) (TxVotingProcedures build era) Source #

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.

indexTxVotingProcedures :: TxVotingProcedures BuildTx era -> [(ScriptWitnessIndex, Voter (EraCrypto (ShelleyLedgerEra era)), ScriptWitness WitCtxStake era)] Source #

Index voting procedures by the order of the votes (Ord).

data TxProposalProcedures build era where Source #

Constructors

TxProposalProceduresNone :: forall build era. TxProposalProcedures build era

No proposals in transaction..

TxProposalProcedures :: forall era build. EraPParams (ShelleyLedgerEra era) => OMap (ProposalProcedure (ShelleyLedgerEra era)) (BuildTxWith build (Maybe (ScriptWitness WitCtxStake era))) -> TxProposalProcedures build era

Represents proposal procedures present in transaction.

Instances

Instances details
Show (TxProposalProcedures build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (TxProposalProcedures build era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: TxProposalProcedures build era -> TxProposalProcedures build era -> Bool Source #

(/=) :: TxProposalProcedures build era -> TxProposalProcedures build era -> Bool Source #

mkTxProposalProcedures :: forall era build. (Applicative (BuildTxWith build), IsShelleyBasedEra era) => [(ProposalProcedure (ShelleyLedgerEra era), Maybe (ScriptWitness WitCtxStake era))] -> TxProposalProcedures build era Source #

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.

Building vs viewing transactions

data BuildTxWith build a where Source #

Constructors

ViewTx :: forall a. BuildTxWith ViewTx a 
BuildTxWith :: forall a. a -> BuildTxWith BuildTx a 

Instances

Instances details
Applicative (BuildTxWith BuildTx) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Applicative (BuildTxWith ViewTx) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Functor (BuildTxWith build) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

fmap :: (a -> b) -> BuildTxWith build a -> BuildTxWith build b Source #

(<$) :: a -> BuildTxWith build b -> BuildTxWith build a Source #

Show a => Show (BuildTxWith build a) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

showsPrec :: Int -> BuildTxWith build a -> ShowS Source #

show :: BuildTxWith build a -> String Source #

showList :: [BuildTxWith build a] -> ShowS Source #

Eq a => Eq (BuildTxWith build a) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Methods

(==) :: BuildTxWith build a -> BuildTxWith build a -> Bool Source #

(/=) :: BuildTxWith build a -> BuildTxWith build a -> Bool Source #

Inspecting ScriptWitnesses

data AnyScriptWitness era where Source #

A ScriptWitness in any WitCtx. This lets us handle heterogeneous collections of script witnesses from multiple contexts.

Constructors

AnyScriptWitness :: forall witctx era. Typeable witctx => ScriptWitness witctx era -> AnyScriptWitness era 

Instances

Instances details
Show (AnyScriptWitness era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

Eq (AnyScriptWitness era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Body

data ScriptWitnessIndex Source #

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.

Constructors

ScriptWitnessIndexTxIn !Word32

The n'th transaction input, in the order of the TxIds.

ScriptWitnessIndexMint !Word32

The n'th minting PolicyId, in the order of the PolicyIds.

ScriptWitnessIndexCertificate !Word32

The n'th certificate, in the list order of the certificates.

ScriptWitnessIndexWithdrawal !Word32

The n'th withdrawal, in the order of the StakeAddresss.

ScriptWitnessIndexVoting !Word32

The n'th vote, in the order of the votes.

ScriptWitnessIndexProposing !Word32

The n'th proposal, in the order of the proposals.

Conversion to inline data

scriptDataToInlineDatum :: Era ledgerera => HashableScriptData -> Datum ledgerera Source #

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

Internal conversion functions & types

convScripts :: ShelleyLedgerEra era ~ ledgerera => [(ScriptWitnessIndex, AnyScriptWitness era)] -> [Script ledgerera] Source #

convTxOuts :: forall ctx era ledgerera. (HasCallStack, ShelleyLedgerEra era ~ ledgerera) => ShelleyBasedEra era -> [TxOut ctx era] -> StrictSeq (TxOut ledgerera) Source #

convTxUpdateProposal Source #

Arguments

:: ShelleyBasedEra era 
-> TxUpdateProposal era 
-> Either TxBodyError (StrictMaybe (Update (ShelleyLedgerEra era)))

Left when there's protocol params conversion error, Right otherwise, 'Right SNothing' means that there's no update proposal

Convert transaction update proposal into ledger update proposal

mkCommonTxBody :: HasCallStack => ShelleyBasedEra era -> TxIns BuildTx era -> [TxOut ctx era] -> TxFee era -> TxWithdrawals build era -> Maybe (TxAuxData (ShelleyLedgerEra era)) -> TxBody era Source #

A helper function that constructs a TxBody with all of the fields that are common for all eras

toAuxiliaryData :: ShelleyBasedEra era -> TxMetadataInEra era -> TxAuxScripts era -> Maybe (TxAuxData (ShelleyLedgerEra era)) Source #

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.

toShelleyTxIn :: TxIn -> TxIn StandardCrypto Source #

This function may overflow on the transaction index. Call sites must ensure that all uses of this function are appropriately guarded.

toShelleyTxOut :: (HasCallStack, ShelleyLedgerEra era ~ ledgerera) => ShelleyBasedEra era -> TxOut CtxUTxO era -> TxOut ledgerera Source #

toShelleyTxOutAny :: forall ctx era ledgerera. (HasCallStack, ShelleyLedgerEra era ~ ledgerera) => ShelleyBasedEra era -> TxOut ctx era -> TxOut ledgerera Source #

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

Misc helpers

Data family instances

data family AsType t Source #

A family of singleton types used in this API to indicate which type to use where it would otherwise be ambiguous or merely unclear.

Values of this type are passed to deserialisation functions for example.

Instances

Instances details
data AsType AddressAny Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType ByronAddr Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType ShelleyAddr Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType StakeAddress Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType BlockHeader Source # 
Instance details

Defined in Cardano.Api.Internal.Block

data AsType DRepMetadata Source # 
Instance details

Defined in Cardano.Api.Internal.DRepMetadata

data AsType AllegraEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType AlonzoEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType BabbageEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType ByronEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType ConwayEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType MaryEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType ShelleyEra Source # 
Instance details

Defined in Cardano.Api.Internal.Eras.Core

data AsType GovernancePoll Source # 
Instance details

Defined in Cardano.Api.Internal.Governance.Poll

data AsType GovernancePollAnswer Source # 
Instance details

Defined in Cardano.Api.Internal.Governance.Poll

data AsType ByronKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Byron

data AsType ByronKeyLegacy Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Byron

data AsType KesKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Praos

data AsType VrfKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Praos

data AsType CommitteeColdExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType CommitteeColdKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType CommitteeHotExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType CommitteeHotKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType DRepExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType DRepKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType GenesisDelegateExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType GenesisDelegateKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType GenesisExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType GenesisKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType GenesisUTxOKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType PaymentExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType PaymentKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType StakeExtendedKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType StakeKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType StakePoolKey Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Shelley

data AsType OperationalCertificate Source # 
Instance details

Defined in Cardano.Api.Internal.OperationalCertificate

data AsType OperationalCertificateIssueCounter Source # 
Instance details

Defined in Cardano.Api.Internal.OperationalCertificate

data AsType PraosNonce Source # 
Instance details

Defined in Cardano.Api.Internal.ProtocolParameters

data AsType UpdateProposal Source # 
Instance details

Defined in Cardano.Api.Internal.ProtocolParameters

data AsType PlutusScriptV1 Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType PlutusScriptV2 Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType PlutusScriptV3 Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType ScriptHash Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType ScriptInAnyLang Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType SimpleScript' Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType HashableScriptData Source # 
Instance details

Defined in Cardano.Api.Internal.ScriptData

data AsType ScriptData Source # 
Instance details

Defined in Cardano.Api.Internal.ScriptData

data AsType TextEnvelope Source # 
Instance details

Defined in Cardano.Api.Internal.SerialiseTextEnvelope

data AsType ByronUpdateProposal Source # 
Instance details

Defined in Cardano.Api.Internal.SpecialByron

data AsType ByronVote Source # 
Instance details

Defined in Cardano.Api.Internal.SpecialByron

data AsType StakePoolMetadata Source # 
Instance details

Defined in Cardano.Api.Internal.StakePoolMetadata

data AsType TxId Source # 
Instance details

Defined in Cardano.Api.Internal.TxIn

data AsType TxMetadata Source # 
Instance details

Defined in Cardano.Api.Internal.TxMetadata

data AsType AssetName Source # 
Instance details

Defined in Cardano.Api.Internal.Value

data AsType PolicyId Source # 
Instance details

Defined in Cardano.Api.Internal.Value

data AsType (Address addrtype) Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType (Address addrtype) = AsAddress (AsType addrtype)
data AsType (AddressInEra era) Source # 
Instance details

Defined in Cardano.Api.Internal.Address

data AsType (Certificate era) Source # 
Instance details

Defined in Cardano.Api.Internal.Certificate

data AsType (Proposal era) Source # 
Instance details

Defined in Cardano.Api.Internal.Governance.Actions.ProposalProcedure

data AsType (VotingProcedure era) Source # 
Instance details

Defined in Cardano.Api.Internal.Governance.Actions.VotingProcedure

data AsType (VotingProcedures era) Source # 
Instance details

Defined in Cardano.Api.Internal.Governance.Actions.VotingProcedure

data AsType (Hash a) Source # 
Instance details

Defined in Cardano.Api.Internal.Hash

data AsType (Hash a) = AsHash (AsType a)
data AsType (SigningKey a) Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Class

data AsType (VerificationKey a) Source # 
Instance details

Defined in Cardano.Api.Internal.Keys.Class

data AsType (PlutusScript lang) Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType (Script lang) Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType (Script lang) = AsScript (AsType lang)
data AsType (ScriptInEra era) Source # 
Instance details

Defined in Cardano.Api.Internal.Script

data AsType (KeyWitness era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data AsType (Tx era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data AsType (Tx era) = AsTx (AsType era)
data AsType (TxBody era) Source # 
Instance details

Defined in Cardano.Api.Internal.Tx.Sign

data AsType (TxBody era) = AsTxBody (AsType era)
data AsType (PlutusScriptInEra era lang) Source # 
Instance details

Defined in Cardano.Api.Internal.Script