cardano-api
Safe HaskellNone
LanguageHaskell2010

Cardano.Api.Experimental.Tx

Synopsis

Creating transactions using the new API

Both the old and new APIs can be used to create transactions, and it is possible to transform a transaction from one format to the other as they share the same representation. However, the focus will shift towards using the new API, while the old API will be deprecated to ensure simplicity, closer alignment with the ledger, and easier maintenance.

In both the new and old APIs, constructing a transaction requires creating a TxBodyContent, along with at least one witness (for example, a ShelleyWitnessSigningKey) to sign the transaction. This process remains unchanged.

To learn how to create a transaction using the old API, see the Cardano.Api.Tx.Internal.Body documentation.

In the examples below, the following qualified modules are used:

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
import qualified Cardano.Api.Experimental as Exp   -- the experimental API

For instructions on how to do this, refer to the Test.Cardano.Api.Experimental documentation.

Creating a TxBodyContent

Regardless of whether the experimental or the traditional API is used, creating a TxBodyContent is necessary.

You can see how to do this in the documentation of the Cardano.Api.Tx.Internal.Body module.

Balancing a transaction

If a UTXO has exactly 12 ada, the transaction could be constructed as described in Cardano.Api.Tx.Internal.Body, and it would be valid. However:

  • Ada may be wasted
  • The UTXO that we intend to spend may not contain exactly 12 ada
  • The transaction may not be this simple.

For these reasons, it is recommended to balance the transaction before proceeding with signing and submitting.

For instructions on how to balance a transaction, refer to the Cardano.Api.Tx.Internal.Fee documentation.

Creating a ShelleyWitnessSigningKey

Signing a transaction requires a witness, such as a ShelleyWitnessSigningKey.

For instructions on creating a ShelleyWitnessSigningKey refer to the Cardano.Api.Tx.Internal.Sign documentation.

Creating a transaction using the new API

This section outlines how to create a transaction using the new API. First, create an UnsignedTx using the makeUnsignedTx function and the Era and TxBodyContent that we defined earlier:

case Exp.makeUnsignedTx era txBodyContent of
  Left err -> error (show err)
  Right unsignedTx -> ...

Next, use the key witness to sign the unsigned transaction with the makeKeyWitness function:

let transactionWitness = Exp.makeKeyWitness era unsignedTx (Api.WitnessPaymentKey signingKey)

Finally, sign the transaction using the signTx function:

let newApiSignedTx :: Ledger.Tx (Exp.LedgerEra Exp.ConwayEra) = Exp.signTx era [] [transactionWitness] unsignedTx

The empty list represents the bootstrap witnesses, which are not needed in this case.

The transaction is now signed.

Converting a transaction from the new API to the old API

A transaction created with the new API can be easily converted to the old API by wrapping it with the ShelleyTx constructor:

let oldStyleTx :: Api.Tx Api.ConwayEra = ShelleyTx sbe newApiSignedTx

Inspecting transactions

When using a Tx created with the experimental API, the TxBody and TxWits can be extracted using the txBody and txWits lenses from Cardano.Api.Ledger respectively.

Contents

data UnsignedTx era Source #

A transaction that can contain everything except key witnesses.

Constructors

EraTx era => UnsignedTx (Tx 'TopTx era) 

Instances

Instances details
Typeable era => HasTypeProxy (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

Associated Types

data AsType (UnsignedTx era) 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

data AsType (UnsignedTx era) = AsUnsignedTx (AsType (ToApiEra era))
EraTx era => SerialiseAsRawBytes (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

Eq (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

Methods

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

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

Show (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

data AsType (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

data AsType (UnsignedTx era) = AsUnsignedTx (AsType (ToApiEra era))

data SignedTx era Source #

A transaction that has been witnesssed

Constructors

EraTx (ShelleyLedgerEra era) => SignedTx (Tx 'TopTx (ShelleyLedgerEra era)) 

Instances

Instances details
HasTypeProxy era => HasTypeProxy (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

Associated Types

data AsType (SignedTx era) 
Instance details

Defined in Cardano.Api.Experimental.Tx

data AsType (SignedTx era) = AsSignedTx (AsType era)
(HasTypeProxy era, EraTx (ShelleyLedgerEra era)) => SerialiseAsRawBytes (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

Eq (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

Methods

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

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

Show (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

data AsType (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

data AsType (SignedTx era) = AsSignedTx (AsType era)

data MakeUnsignedTxError Source #

Error that can occur when constructing an unsigned transaction.

Constructors

MakeUnsignedTxMissingProtocolParams

Plutus scripts are present in the transaction but no protocol parameters were provided. Protocol parameters are required to compute the script integrity hash (script_data_hash).

MakeUnsignedTxFieldsNotSupportedInEra (Some Era) (NonEmpty Text)

Fields were set on the body content that the ledger body of the target era has no slot for. The body content record is shared by all eras, so this is only detected when the body is built. The field names are those of the TxBodyContent record.

hashTxBody :: forall (l :: TxLevel) era. HashAnnotated (TxBody l era) EraIndependentTxBody => TxBody l era -> Hash HASH EraIndependentTxBody Source #

The hash of a transaction body, which is what key witnesses sign. Works at either transaction level: a TopTx body is an ordinary transaction, a SubTx body is a Dijkstra sub-transaction embedded in one.

TxBodyContent

Body content is one type, BodyContent, indexed by the transaction level. TxBodyContent is a top-level body and SubTxBodyContent is a Dijkstra sub-transaction body. A setter typed BodyContent l era works on both; a setter typed TxBodyContent era sets a field that only a top-level body has.

data BodyContent (l :: TxLevel) era where Source #

Content of a transaction body at either transaction level.

The transaction level is the ledger's TxLevel kind. A TopTx body is an ordinary transaction, the thing that is submitted to the chain. A SubTx body is a Dijkstra sub-transaction: a transaction built and signed on its own, then embedded whole in a top-level transaction's txSubTransactions. Both levels share most of their fields; a sub-transaction has no fee, collateral, script validity flag, required signers or sub-transactions of its own, since the top level carries those.

The fields shared by both levels live directly in the record. The fields that exist only in a top-level body live in TopTxOnlyFields. Use the TxBodyContent pattern for a top-level body and the SubTxBodyContent pattern for a sub-transaction body: each presents a flat record, so the nesting is never visible outside this module. A function typed BodyContent l era works on bodies of either level.

Bundled Patterns

pattern SubTxBodyContent :: [(TxIn, AnyWitness era)] -> TxInsReference era -> [TxOut era] -> Maybe SlotNo -> Maybe SlotNo -> TxMetadata -> [SimpleScript era] -> Maybe (PParams era) -> TxWithdrawals era -> TxCertificates era -> TxMintValue era -> Maybe (TxProposalProcedures era) -> Maybe (TxVotingProcedures era) -> Maybe Coin -> Maybe Coin -> Map DataHash (Data era) -> OSet (Credential 'Guard) -> Map (Credential 'Guard) (StrictMaybe (Data era)) -> DirectDeposits -> AccountBalanceIntervals era -> SubTxBodyContent era

A sub-transaction body as one flat record.

pattern TxBodyContent :: [(TxIn, AnyWitness era)] -> [TxIn] -> TxInsReference era -> [TxOut era] -> Maybe TxTotalCollateral -> Maybe (TxReturnCollateral era) -> Coin -> Maybe SlotNo -> Maybe SlotNo -> TxMetadata -> [SimpleScript era] -> TxExtraKeyWitnesses -> Maybe (PParams era) -> TxWithdrawals era -> TxCertificates era -> TxMintValue era -> ScriptValidity -> Maybe (TxProposalProcedures era) -> Maybe (TxVotingProcedures era) -> Maybe Coin -> Maybe Coin -> Map DataHash (Data era) -> OSet (Credential 'Guard) -> OMap TxId (Tx 'SubTx era) -> Map (Credential 'Guard) (StrictMaybe (Data era)) -> DirectDeposits -> AccountBalanceIntervals era -> AccountBalanceIntervals era -> TxBodyContent era

A top-level transaction body as one flat record.

type TxBodyContent = BodyContent 'TopTx Source #

Content of a top-level transaction body. See the TxBodyContent pattern.

type SubTxBodyContent = BodyContent 'SubTx Source #

Content of a Dijkstra sub-transaction body. See the SubTxBodyContent pattern.

Compared to a top-level TxBodyContent, a sub-transaction body has no collateral inputs, no total or return collateral, no fee, no extra key witnesses (guards replace them), no script validity flag, no sub-transactions of its own and no starting account balance intervals.

mkTxCertificates :: Era era -> [(Certificate (LedgerEra era), AnyWitness (LedgerEra era))] -> TxCertificates (LedgerEra era) Source #

Create TxCertificates. Note that 'Certificate era' will be deduplicated. Certificates that require a witness will be stored with Just the caller-supplied witness; those that do not (e.g. deposit-less stake registration in Conway) will be stored with Nothing.

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.

mkTxVotingProcedures :: [(VotingProcedures era, AnyWitness era)] -> Either (VotingError era) (TxVotingProcedures 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.

mkTxProposalProcedures :: IsEra era => [(ProposalProcedure (LedgerEra era), AnyWitness (LedgerEra era))] -> TxProposalProcedures (LedgerEra 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.

Fields of a top-level body

Fields of a sub-transaction body

Setters shared by both levels

modTxOuts :: forall era (l :: TxLevel). ([TxOut era] -> [TxOut era]) -> BodyContent l era -> BodyContent l era Source #

setTxAuxScripts :: forall era (l :: TxLevel). [SimpleScript era] -> BodyContent l era -> BodyContent l era Source #

setTxCertificates :: forall era (l :: TxLevel). TxCertificates era -> BodyContent l era -> BodyContent l era Source #

setTxCurrentTreasuryValue :: forall (l :: TxLevel) era. Coin -> BodyContent l era -> BodyContent l era Source #

setTxIns :: forall era (l :: TxLevel). [(TxIn, AnyWitness era)] -> BodyContent l era -> BodyContent l era Source #

setTxInsReference :: forall era (l :: TxLevel). TxInsReference era -> BodyContent l era -> BodyContent l era Source #

setTxMetadata :: forall (l :: TxLevel) era. TxMetadata -> BodyContent l era -> BodyContent l era Source #

setTxMintValue :: forall era (l :: TxLevel). TxMintValue era -> BodyContent l era -> BodyContent l era Source #

setTxOuts :: forall era (l :: TxLevel). [TxOut era] -> BodyContent l era -> BodyContent l era Source #

setTxProtocolParams :: forall era (l :: TxLevel). PParams era -> BodyContent l era -> BodyContent l era Source #

setTxSupplementalDatums :: forall era (l :: TxLevel). Map DataHash (Data era) -> BodyContent l era -> BodyContent l era Source #

setTxTreasuryDonation :: forall (l :: TxLevel) era. Coin -> BodyContent l era -> BodyContent l era Source #

setTxValidityLowerBound :: forall (l :: TxLevel) era. SlotNo -> BodyContent l era -> BodyContent l era Source #

setTxValidityUpperBound :: forall (l :: TxLevel) era. SlotNo -> BodyContent l era -> BodyContent l era Source #

setTxVotingProcedures :: forall era (l :: TxLevel). TxVotingProcedures era -> BodyContent l era -> BodyContent l era Source #

setTxWithdrawals :: forall era (l :: TxLevel). TxWithdrawals era -> BodyContent l era -> BodyContent l era Source #

setTxGuards :: forall (l :: TxLevel) era. OSet (Credential 'Guard) -> BodyContent l era -> BodyContent l era Source #

setTxDirectDeposits :: forall (l :: TxLevel) era. DirectDeposits -> BodyContent l era -> BodyContent l era Source #

Setters for top-level bodies only

setTxSubTransactions :: EraTx era => [Tx 'SubTx era] -> TxBodyContent era -> TxBodyContent era Source #

Sub-transactions are keyed by their transaction id, which is derived from each sub-transaction here so callers never compute it by hand.

setTxSignedSubTransactions :: [SignedSubTx] -> TxBodyContent (LedgerEra DijkstraEra) -> TxBodyContent (LedgerEra DijkstraEra) Source #

Embed signed sub-transactions in a top-level transaction body, replacing any that are already there.

Sub-transactions (Dijkstra era onwards)

newtype UnsignedSubTx Source #

A sub-transaction with script witnesses but no key witnesses.

Instances

Instances details
HasTypeProxy UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

SerialiseAsCBOR UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

HasTextEnvelope UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

Eq UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

Show UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

data AsType UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

newtype SignedSubTx Source #

A sub-transaction with its key witnesses, see setTxSignedSubTransactions.

Instances

Instances details
HasTypeProxy SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

SerialiseAsCBOR SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

HasTextEnvelope SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

Eq SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

Show SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

data AsType SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

makeUnsignedSubTx :: SubTxBodyContent (LedgerEra DijkstraEra) -> Either MakeUnsignedTxError UnsignedSubTx Source #

Build a sub-transaction body and its script witness set from SubTxBodyContent.

makeSubTxKeyWitness :: UnsignedSubTx -> ShelleyWitnessSigningKey -> WitVKey 'Witness Source #

Sign the body of an unsigned sub-transaction with one key.

signSubTx :: [BootstrapWitness] -> [WitVKey 'Witness] -> UnsignedSubTx -> SignedSubTx Source #

Add key witnesses to an unsigned sub-transaction.

getUnsignedSubTxId :: UnsignedSubTx -> TxId Source #

The hash of the sub-transaction body. Unchanged by signing.

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
Typeable t => Show (AsType t) Source #

Generalised show instance for all singletons of AsType displaying the type.

Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType ByteString Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType ByteString Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType AddressAny Source # 
Instance details

Defined in Cardano.Api.Address

data AsType ByronAddr Source # 
Instance details

Defined in Cardano.Api.Address

data AsType ShelleyAddr Source # 
Instance details

Defined in Cardano.Api.Address

data AsType StakeAddress Source # 
Instance details

Defined in Cardano.Api.Address

data AsType BlockHeader Source # 
Instance details

Defined in Cardano.Api.Block

data AsType ByronUpdateProposal Source # 
Instance details

Defined in Cardano.Api.Byron.Internal.Proposal

data AsType ByronVote Source # 
Instance details

Defined in Cardano.Api.Byron.Internal.Proposal

data AsType DRepMetadata Source # 
Instance details

Defined in Cardano.Api.Certificate.Internal.DRepMetadata

data AsType StakePoolMetadata Source # 
Instance details

Defined in Cardano.Api.Certificate.Internal.StakePoolMetadata

data AsType AllegraEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType AlonzoEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType BabbageEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType ByronEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType ConwayEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType DijkstraEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType MaryEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType ShelleyEra Source # 
Instance details

Defined in Cardano.Api.Era.Internal.Core

data AsType SignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

data AsType UnsignedSubTx Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.SubTransaction

data AsType GovernancePoll Source # 
Instance details

Defined in Cardano.Api.Governance.Internal.Poll

data AsType GovernancePollAnswer Source # 
Instance details

Defined in Cardano.Api.Governance.Internal.Poll

data AsType PlutusScriptV1 Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType PlutusScriptV2 Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType PlutusScriptV3 Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType PlutusScriptV4 Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType ScriptHash Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType ScriptInAnyLang Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType SimpleScript' Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType HashableScriptData Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.ScriptData

data AsType ScriptData Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.ScriptData

data AsType PraosNonce Source # 
Instance details

Defined in Cardano.Api.ProtocolParameters

data AsType EraHistory Source # 
Instance details

Defined in Cardano.Api.Query.Internal.Type.QueryInMode

data AsType TxId Source # 
Instance details

Defined in Cardano.Api.Tx.Internal.TxIn

data AsType TxMetadata Source # 
Instance details

Defined in Cardano.Api.Tx.Internal.TxMetadata

data AsType AssetName Source # 
Instance details

Defined in Cardano.Api.Value.Internal

data AsType PolicyId Source # 
Instance details

Defined in Cardano.Api.Value.Internal

data AsType ByronKey Source # 
Instance details

Defined in Cardano.Keys.Byron

data AsType ByronKeyLegacy Source # 
Instance details

Defined in Cardano.Keys.Byron

data AsType BlsKey Source # 
Instance details

Defined in Cardano.Keys.Leios

data AsType BlsPossessionProof Source # 
Instance details

Defined in Cardano.Keys.Leios

data AsType OperationalCertificate Source # 
Instance details

Defined in Cardano.Keys.OperationalCertificate

data AsType OperationalCertificateIssueCounter Source # 
Instance details

Defined in Cardano.Keys.OperationalCertificate

data AsType KesKey Source # 
Instance details

Defined in Cardano.Keys.Praos

data AsType VrfKey Source # 
Instance details

Defined in Cardano.Keys.Praos

data AsType TextEnvelope Source # 
Instance details

Defined in Cardano.Keys.Serialise.TextEnvelope

data AsType CommitteeColdExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType CommitteeColdKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType CommitteeHotExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType CommitteeHotKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType DRepExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType DRepKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GenesisDelegateExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GenesisDelegateKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GenesisExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GenesisKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GenesisUTxOKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType PaymentExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType PaymentKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType StakeExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType StakeKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType StakePoolExtendedKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType StakePoolKey Source # 
Instance details

Defined in Cardano.Keys.Shelley

data AsType GovActionId Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType GovActionIx Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType Term Source # 
Instance details

Defined in Cardano.Api.Serialise.Cbor.Canonical

data AsType Word16 Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType Word32 Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType Word64 Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType Word8 Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType Natural Source # 
Instance details

Defined in Cardano.Keys.HasTypeProxy

data AsType (Address addrtype) Source # 
Instance details

Defined in Cardano.Api.Address

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

Defined in Cardano.Api.Address

data AsType (UpdateProposal era) Source # 
Instance details

Defined in Cardano.Api.Compatible.ProtocolParametersUpdate

data AsType (AnyScript era) Source # 
Instance details

Defined in Cardano.Api.Experimental.AnyScript

data AsType (SimpleScript era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Simple.Script

data AsType (SignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx

data AsType (SignedTx era) = AsSignedTx (AsType era)
data AsType (Certificate era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Certificate.Type

data AsType (UnsignedTx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.Type

data AsType (UnsignedTx era) = AsUnsignedTx (AsType (ToApiEra era))
data AsType (Proposal era) Source # 
Instance details

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

data AsType (VotingProcedure era) Source # 
Instance details

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

data AsType (VotingProcedures era) Source # 
Instance details

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

data AsType (PlutusScript lang) Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType (Script lang) Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

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

Defined in Cardano.Api.Plutus.Internal.Script

data AsType (KeyWitness era) Source # 
Instance details

Defined in Cardano.Api.Tx.Internal.Sign

data AsType (Tx era) Source # 
Instance details

Defined in Cardano.Api.Tx.Internal.Sign

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

Defined in Cardano.Api.Tx.Internal.Sign

data AsType (TxBody era) = AsTxBody (AsType era)
data AsType (SigningKey a) Source # 
Instance details

Defined in Cardano.Keys.Class

data AsType (VerificationKey a) Source # 
Instance details

Defined in Cardano.Keys.Class

data AsType (Hash a) Source # 
Instance details

Defined in Cardano.Keys.Hash

data AsType (Hash a) = AsHash (AsType a)
data AsType (Credential 'ColdCommitteeRole) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (Credential 'DRepRole) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (Credential 'HotCommitteeRole) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (SLanguage 'PlutusV1) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (SLanguage 'PlutusV2) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (SLanguage 'PlutusV3) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (SLanguage 'PlutusV4) Source # 
Instance details

Defined in Cardano.Api.Internal.Orphans.Serialisation

data AsType (PlutusScriptInEra lang era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Plutus.Internal.Script

data AsType (PlutusScriptInEra era lang) Source # 
Instance details

Defined in Cardano.Api.Plutus.Internal.Script

data AsType (TxOut ctx era) Source # 
Instance details

Defined in Cardano.Api.Tx.Internal.Output

data AsType (TxOut ctx era) = AsTxOut (AsType era)

TxBodyContent sub type

newtype TxMintValue era Source #

Instances

Instances details
Eq (TxMintValue era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

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

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

Show (TxMintValue era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

data TxOut era where Source #

Constructors

TxOut :: forall era. EraTxOut era => TxOut era -> TxOut era 

Instances

Instances details
FromJSON (TxOut AllegraEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut AllegraEra) #

parseJSONList :: Value -> Parser [TxOut AllegraEra] #

omittedField :: Maybe (TxOut AllegraEra) #

FromJSON (TxOut AlonzoEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut AlonzoEra) #

parseJSONList :: Value -> Parser [TxOut AlonzoEra] #

omittedField :: Maybe (TxOut AlonzoEra) #

FromJSON (TxOut BabbageEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut BabbageEra) #

parseJSONList :: Value -> Parser [TxOut BabbageEra] #

omittedField :: Maybe (TxOut BabbageEra) #

FromJSON (TxOut ConwayEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut ConwayEra) #

parseJSONList :: Value -> Parser [TxOut ConwayEra] #

omittedField :: Maybe (TxOut ConwayEra) #

FromJSON (TxOut MaryEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut MaryEra) #

parseJSONList :: Value -> Parser [TxOut MaryEra] #

omittedField :: Maybe (TxOut MaryEra) #

FromJSON (TxOut ShelleyEra) Source #

Pre-Alonzo eras have no datums or reference scripts, so parsing

Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

parseJSON :: Value -> Parser (TxOut ShelleyEra) #

parseJSONList :: Value -> Parser [TxOut ShelleyEra] #

omittedField :: Maybe (TxOut ShelleyEra) #

ToJSON (TxOut AllegraEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

ToJSON (TxOut AlonzoEra) Source #

Note: Unlike the legacy API's TxOut, this instance does not render supplemental datums. At the ledger level, a supplemental datum is not stored in the TxOut — only its hash is. The full datum lives in the transaction witness set (TxDats). The legacy API bundled the full datum into TxOut for convenience, but since this type wraps the ledger's TxOut directly, supplemental datums are indistinguishable from hash-only datums here.

Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

toJSON :: TxOut AlonzoEra -> Value #

toEncoding :: TxOut AlonzoEra -> Encoding #

toJSONList :: [TxOut AlonzoEra] -> Value #

toEncodingList :: [TxOut AlonzoEra] -> Encoding #

omitField :: TxOut AlonzoEra -> Bool #

ToJSON (TxOut BabbageEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

ToJSON (TxOut ConwayEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

toJSON :: TxOut ConwayEra -> Value #

toEncoding :: TxOut ConwayEra -> Encoding #

toJSONList :: [TxOut ConwayEra] -> Value #

toEncodingList :: [TxOut ConwayEra] -> Encoding #

omitField :: TxOut ConwayEra -> Bool #

ToJSON (TxOut MaryEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

toJSON :: TxOut MaryEra -> Value #

toEncoding :: TxOut MaryEra -> Encoding #

toJSONList :: [TxOut MaryEra] -> Value #

toEncodingList :: [TxOut MaryEra] -> Encoding #

omitField :: TxOut MaryEra -> Bool #

ToJSON (TxOut ShelleyEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Eq (TxOut era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

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

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

Show (TxOut era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

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

show :: TxOut era -> String Source #

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

data TxInsReference era Source #

Constructors

TxInsReference [TxIn] (Set (Datum CtxTx era)) 

Witness

Any witness (key, simple script, plutus script).

data AnyWitness era where Source #

Here we consider three types of witnesses in Cardano: * key witnesses * simple script witnesses * Plutus script witnesses

Note that AnyKeyWitnessPlaceholder does not contain the actual key witness. This is because key witnesses are provided in the signing stage of the transaction. However we need this constuctor to index the witnessable things correctly when plutus scripts are being used within the transaction. AnyWitness is solely used to contruct the transaction body.

Constructors

AnyKeyWitnessPlaceholder :: forall era. AnyWitness era 
AnySimpleScriptWitness :: forall era. SimpleScriptOrReferenceInput era -> AnyWitness era 
AnyPlutusScriptWitness :: forall (lang :: Language) (purpose :: PlutusScriptPurpose) era. AnyPlutusScriptWitness lang purpose era -> AnyWitness era 

Instances

Instances details
Eq (AnyWitness era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.AnyWitness

Methods

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

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

Show (AnyWitness era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.AnyWitness

getAnyWitnessScriptData :: Era era => AnyWitness era -> TxDats era Source #

NB this does not include datums from inline datums existing at tx outputs!

All the parts that constitute a plutus script witness but also including simple scripts

data TxScriptWitnessRequirements era Source #

This type collects all the requirements for script witnesses in a transaction.

Instances

Instances details
Monoid (TxScriptWitnessRequirements AlonzoEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Monoid (TxScriptWitnessRequirements BabbageEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Monoid (TxScriptWitnessRequirements ConwayEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Monoid (TxScriptWitnessRequirements DijkstraEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Semigroup (TxScriptWitnessRequirements AlonzoEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Semigroup (TxScriptWitnessRequirements BabbageEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Semigroup (TxScriptWitnessRequirements ConwayEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Semigroup (TxScriptWitnessRequirements DijkstraEra) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements

Plutus related

data Datum ctx era where Source #

Constructors

TxOutDatumHash :: forall ctx era. DataHash -> Datum ctx era 
TxOutSupplementalDatum :: forall era. DataHash -> Data era -> Datum CtxTx era 
TxOutDatumInline :: forall era ctx. DataHash -> Data era -> Datum ctx era 

Instances

Instances details
Eq (Datum ctx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

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

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

Show (Datum ctx era) Source # 
Instance details

Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent

Methods

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

show :: Datum ctx era -> String Source #

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

getDatums Source #

Arguments

:: IsEra era 
=> TxInsReference (LedgerEra era)

reference inputs

-> Map DataHash (Data (LedgerEra era))

supplemental datums

-> TxDats (LedgerEra era) 

Collect datums for the transaction witness set (TxDats): 1. supplemental datums provided explicitly 2. datums from reference inputs

Supplemental datums are datums whose hashes correspond to datum hashes in transaction outputs. They are included for communication purposes only (the Alonzo ledger spec uses subset equality for these).

Note that this function does not check whose datum hashes are present in the reference inputs. This means if there are redundant datums in TxInsReference, a submission of such transaction will fail.

Collecting plutus script witness related transaction requirements.

collectPlutusScriptHashes :: IsEra era => UnsignedTx (LedgerEra era) -> UTxO (LedgerEra era) -> Map ScriptWitnessIndex ScriptHash Source #

Collect all plutus script hashes that are needed to validate the given transaction and return them in a map with their corresponding ScriptWitnessIndex as key.

Transaction evaluation

evaluateTransaction Source #

Arguments

:: IsEra era 
=> SystemStart

Start time of the blockchain

-> LedgerEpochInfo

Epoch info for slot/time conversions

-> PParams (LedgerEra era)

Protocol parameters

-> Set PoolId

Registered stake pools

-> Map StakeCredential Coin

Stake delegation deposits

-> UTxO (LedgerEra era)

UTxO set for the transaction inputs

-> Tx 'TopTx (LedgerEra era)

Signed transaction to evaluate

-> TxEvaluationResult (LedgerEra era) 

Run all scripts, compute the minimum fee, and check the balance.

evaluateSignedTx Source #

Arguments

:: IsEra era 
=> SystemStart

Start time of the blockchain

-> LedgerEpochInfo

Epoch info for slot/time conversions

-> PParams (LedgerEra era)

Protocol parameters

-> Set PoolId

Registered stake pools

-> Map StakeCredential Coin

Stake delegation deposits

-> UTxO (LedgerEra era)

UTxO set for the transaction inputs

-> SignedTx era

Signed transaction to evaluate

-> TxEvaluationResult (LedgerEra era) 

Like evaluateTransaction but accepts a SignedTx directly.

data TxEvaluationResult era Source #

Result of evaluating a signed transaction against the current ledger state.

Constructors

Show (Value era) => TxEvaluationResult 

Fields

evaluateTransactionExecutionUnits :: IsEra era => SystemStart -> LedgerEpochInfo -> PParams (LedgerEra era) -> UTxO (LedgerEra era) -> Tx 'TopTx (LedgerEra era) -> Map ScriptWitnessIndex (Either ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits)) Source #

Compute the ExecutionUnits required for each script in the transaction.

This process involves executing all scripts and counting the actual execution units consumed.

Balancing transactions

makeTransactionBodyAutoBalance Source #

Arguments

:: (HasCallStack, IsEra era) 
=> SystemStart 
-> LedgerEpochInfo 
-> PParams (LedgerEra era) 
-> Set PoolId

The set of registered stake pools, being unregistered in this transaction.

-> Map StakeCredential Coin

The map of all deposits for stake credentials that are being unregistered in this transaction

-> UTxO (LedgerEra era)

The transaction inputs (including reference and collateral ones), not the entire UTxO.

-> TxBodyContent (LedgerEra era) 
-> AddressInEra era

Change address

-> Maybe Word

Override key witnesses

-> Either (TxBodyErrorAutoBalance (LedgerEra era)) (UnsignedTx (LedgerEra era), TxBodyContent (LedgerEra era)) 

This is similar to makeTransactionBody but with greater automation to calculate suitable values for several things.

In particular:

  • It calculates the correct script ExecutionUnits (ignoring the provided values, which can thus be zero).
  • It calculates the transaction fees based on the script ExecutionUnits, the current ProtocolParameters, and an estimate of the number of key witnesses (i.e. signatures). There is an override for the number of key witnesses.
  • It accepts a change address, calculates the balance of the transaction and puts the excess change into the change output.
  • It also checks that the balance is positive and the change is above the minimum threshold.

To do this, it requires more information than makeTransactionBody, all of which can be queried from a local node.

data TxBodyErrorAutoBalance era Source #

Constructors

TxBodyErrorBalanceNegative Coin MultiAsset

There is not enough ada and non-ada to cover both the outputs and the fees. The transaction should be changed to provide more input assets, or otherwise adjusted to need less (e.g. outputs, script etc).

TxBodyErrorAdaBalanceTooSmall

There is enough ada to cover both the outputs and the fees, but the resulting change is too small: it is under the minimum value for new UTXO entries. The transaction should be changed to provide more input ada.

Fields

TxBodyErrorMinUTxONotMet

The minimum spendable UTxO threshold has not been met.

Fields

TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap ScriptWitnessIndex (Map ScriptWitnessIndex ExecutionUnits) 
TxBodyScriptExecutionError [(ScriptWitnessIndex, ScriptExecutionError)]

One or more scripts failed to execute correctly.

TxBodyScriptBadScriptValidity

One or more scripts were expected to fail validation, but none did.

BalanceIsNegative 

Fields

NotEnoughAdaInUTxO 

Fields

TxBodyErrorCollateral CollateralError

The transaction's collateral was rejected: the collateral fields could not be computed (the ledger would reject a transaction built with them), or collateral was provided for a transaction that does not run Plutus scripts and so does not need it.

TxBodyErrorMakeUnsignedTx MakeUnsignedTxError 

Internal functions

extractWitnessableCertificates :: IsEra era => TxCertificates (LedgerEra era) -> [(Witnessable 'CertItem (LedgerEra era), AnyWitness (LedgerEra era))] Source #

Wrap every certificate as a Witnessable, paired with its witness.

An unwitnessed certificate still occupies a redeemer index slot: the ledger indexes the Certifying purpose by position in the full certificate sequence, not just the witnessed subset, so the result below keeps one entry per certificate in insertion order.

In the Conway era only, a certificate may legitimately have no witness (deposit-less stake registration), so a missing witness defaults to AnyKeyWitnessPlaceholder. From Dijkstra onwards mkTxCertificates guarantees every entry has a Just witness, so the placeholder is dead code for those eras.