| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Api.Experimental.Tx
Synopsis
- data UnsignedTx era = EraTx era => UnsignedTx (Tx era)
- data SignedTx era = EraTx (LedgerEra era) => SignedTx (Tx (LedgerEra era))
- makeUnsignedTx :: Era era -> TxBodyContent (LedgerEra era) -> UnsignedTx (LedgerEra era)
- makeKeyWitness :: Era era -> UnsignedTx (LedgerEra era) -> ShelleyWitnessSigningKey -> WitVKey 'Witness
- signTx :: Era era -> [BootstrapWitness] -> [WitVKey 'Witness] -> UnsignedTx (LedgerEra era) -> SignedTx era
- convertTxBodyToUnsignedTx :: HasCallStack => ShelleyBasedEra era -> TxBody era -> UnsignedTx (LedgerEra era)
- hashTxBody :: HashAnnotated (TxBody era) EraIndependentTxBody => TxBody era -> Hash HASH EraIndependentTxBody
- getUnsignedTxFee :: UnsignedTx era -> Coin
- data TxBodyContent era = TxBodyContent {
- txIns :: [(TxIn, AnyWitness era)]
- txInsCollateral :: [TxIn]
- txInsReference :: TxInsReference era
- txOuts :: [TxOut era]
- txTotalCollateral :: Maybe TxTotalCollateral
- txReturnCollateral :: Maybe (TxReturnCollateral era)
- txFee :: Coin
- txValidityLowerBound :: Maybe SlotNo
- txValidityUpperBound :: Maybe SlotNo
- txMetadata :: TxMetadata
- txAuxScripts :: [SimpleScript era]
- txExtraKeyWits :: TxExtraKeyWitnesses
- txProtocolParams :: Maybe (PParams era)
- txWithdrawals :: TxWithdrawals era
- txCertificates :: TxCertificates era
- txMintValue :: TxMintValue era
- txScriptValidity :: ScriptValidity
- txProposalProcedures :: Maybe (TxProposalProcedures era)
- txVotingProcedures :: Maybe (TxVotingProcedures era)
- txCurrentTreasuryValue :: Maybe Coin
- txTreasuryDonation :: Maybe Coin
- defaultTxBodyContent :: TxBodyContent era
- mkTxCertificates :: Era era -> [(Certificate (LedgerEra era), AnyWitness (LedgerEra era))] -> TxCertificates (LedgerEra era)
- mkTxVotingProcedures :: [(VotingProcedures era, AnyWitness era)] -> Either (VotesMergingConflict era) (TxVotingProcedures era)
- mkTxProposalProcedures :: IsEra era => [(ProposalProcedure (LedgerEra era), AnyWitness (LedgerEra era))] -> TxProposalProcedures (LedgerEra era)
- modTxOuts :: ([TxOut era] -> [TxOut era]) -> TxBodyContent era -> TxBodyContent era
- setTxAuxScripts :: [SimpleScript era] -> TxBodyContent era -> TxBodyContent era
- setTxCertificates :: TxCertificates era -> TxBodyContent era -> TxBodyContent era
- setTxReturnCollateral :: TxReturnCollateral era -> TxBodyContent era -> TxBodyContent era
- setTxTotalCollateral :: TxTotalCollateral -> TxBodyContent era -> TxBodyContent era
- setTxCurrentTreasuryValue :: Coin -> TxBodyContent era -> TxBodyContent era
- setTxExtraKeyWits :: TxExtraKeyWitnesses -> TxBodyContent era -> TxBodyContent era
- setTxFee :: Coin -> TxBodyContent era -> TxBodyContent era
- setTxIns :: [(TxIn, AnyWitness era)] -> TxBodyContent era -> TxBodyContent era
- setTxInsCollateral :: [TxIn] -> TxBodyContent era -> TxBodyContent era
- setTxInsReference :: TxInsReference era -> TxBodyContent era -> TxBodyContent era
- setTxMetadata :: TxMetadata -> TxBodyContent era -> TxBodyContent era
- setTxMintValue :: TxMintValue era -> TxBodyContent era -> TxBodyContent era
- setTxOuts :: [TxOut era] -> TxBodyContent era -> TxBodyContent era
- setTxProposalProcedures :: TxProposalProcedures era -> TxBodyContent era -> TxBodyContent era
- setTxProtocolParams :: PParams era -> TxBodyContent era -> TxBodyContent era
- setTxScriptValidity :: ScriptValidity -> TxBodyContent era -> TxBodyContent era
- setTxTreasuryDonation :: Coin -> TxBodyContent era -> TxBodyContent era
- setTxValidityLowerBound :: SlotNo -> TxBodyContent era -> TxBodyContent era
- setTxValidityUpperBound :: SlotNo -> TxBodyContent era -> TxBodyContent era
- setTxVotingProcedures :: TxVotingProcedures era -> TxBodyContent era -> TxBodyContent era
- setTxWithdrawals :: TxWithdrawals era -> TxBodyContent era -> TxBodyContent era
- newtype DatumDecodingError = DatumDecodingError String
- legacyDatumToDatum :: IsEra era => TxOutDatum CtxTx era -> Maybe (Datum CtxTx (LedgerEra era))
- fromLegacyTxOut :: IsEra era => TxOut CtxTx era -> Either DatumDecodingError (TxOut (LedgerEra era))
- newtype TxCertificates era = TxCertificates {
- unTxCertificates :: OMap (Certificate era) (Maybe (StakeCredential, AnyWitness era))
- newtype TxMintValue era = TxMintValue {
- unTxMintValue :: Map PolicyId (PolicyAssets, AnyScriptWitness era)
- data TxOut era where
- newtype TxProposalProcedures era = TxProposalProcedures (OMap (ProposalProcedure era) (AnyWitness era))
- data TxVotingProcedures era = TxVotingProcedures (VotingProcedures era) (Map Voter (AnyWitness era))
- newtype TxWithdrawals era = TxWithdrawals {
- unTxWithdrawals :: [(StakeAddress, Coin, AnyWitness era)]
- newtype TxReturnCollateral era = TxReturnCollateral {
- unTxReturnCollateral :: TxOut era
- newtype TxTotalCollateral = TxTotalCollateral {}
- newtype TxExtraKeyWitnesses = TxExtraKeyWitnesses [Hash PaymentKey]
- data TxInsReference era = TxInsReference [TxIn] (Set (Datum CtxTx era))
- data AnyWitness era where
- 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
- getAnyWitnessScript :: AlonzoEraScript era => AnyWitness era -> Maybe (Script era)
- getAnyWitnessReferenceInput :: AnyWitness era -> Maybe TxIn
- getAnyWitnessPlutusLanguage :: AnyWitness era -> Maybe Language
- getAnyWitnessScriptData :: Era era => AnyWitness era -> TxDats era
- data TxScriptWitnessRequirements era = TxScriptWitnessRequirements (Set Language) [Script era] (TxDats era) (Redeemers era)
- data Datum ctx era where
- 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
- getDatums :: IsEra era => TxInsReference (LedgerEra era) -> [TxOut (LedgerEra era)] -> TxDats (LedgerEra era)
- extractDatumsAndHashes :: Datum ctx era -> Maybe (DataHash, Data era)
- collectPlutusScriptHashes :: IsEra era => UnsignedTx (LedgerEra era) -> UTxO (LedgerEra era) -> Map ScriptWitnessIndex ScriptHash
- extractAllIndexedPlutusScriptWitnesses :: Era era -> TxBodyContent (LedgerEra era) -> Either DecoderError [AnyIndexedPlutusScriptWitness (LedgerEra era)]
- getTxScriptWitnessesRequirements :: forall era (witnessable :: WitnessableItem). (AlonzoEraScript era, Monoid (TxScriptWitnessRequirements era)) => [(Witnessable witnessable era, AnyWitness era)] -> TxScriptWitnessRequirements era
- obtainMonoidConstraint :: Era era -> (Monoid (TxScriptWitnessRequirements (LedgerEra era)) => a) -> a
- calculateMinimumUTxO :: HasCallStack => PParams (LedgerEra era) -> TxOut (LedgerEra era) -> Coin
- evaluateTransactionExecutionUnits :: IsEra era => SystemStart -> LedgerEpochInfo -> PParams (LedgerEra era) -> UTxO (LedgerEra era) -> Tx (LedgerEra era) -> Map ScriptWitnessIndex (Either ScriptExecutionError (EvalTxExecutionUnitsLog, ExecutionUnits))
- makeTransactionBodyAutoBalance :: (HasCallStack, IsEra era) => SystemStart -> LedgerEpochInfo -> PParams (LedgerEra era) -> Set PoolId -> Map StakeCredential Coin -> Map (Credential 'DRepRole) Coin -> UTxO (LedgerEra era) -> TxBodyContent (LedgerEra era) -> AddressInEra era -> Maybe Word -> Either (TxBodyErrorAutoBalance (LedgerEra era)) (UnsignedTx (LedgerEra era), TxBodyContent (LedgerEra era))
- data TxBodyErrorAutoBalance era
- = TxBodyErrorBalanceNegative Coin MultiAsset
- | TxBodyErrorAdaBalanceTooSmall (TxOut era) Coin Coin
- | TxBodyErrorMinUTxONotMet (TxOut era) Coin
- | TxBodyErrorNonAdaAssetsUnbalanced Value
- | TxBodyErrorScriptWitnessIndexMissingFromExecUnitsMap ScriptWitnessIndex (Map ScriptWitnessIndex ExecutionUnits)
- | TxBodyScriptExecutionError [(ScriptWitnessIndex, ScriptExecutionError)]
- | TxBodyScriptBadScriptValidity
- | BalanceIsNegative Coin (UnsignedTx (LedgerEra ConwayEra))
- | NotEnoughAdaInUTxO MaryValue Coin MaryValue
- data TxFeeEstimationError era
- extractExecutionUnits :: TxScriptWitnessRequirements era -> [ExecutionUnits]
- getTxScriptWitnessRequirements :: forall era (witnessable :: WitnessableItem). (AlonzoEraScript era, Monoid (TxScriptWitnessRequirements era)) => [(Witnessable witnessable era, AnyWitness era)] -> TxScriptWitnessRequirements era
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:
let (Right unsignedTx) = Exp.makeUnsignedTx era txBodyContent
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 era) |
Instances
| Typeable era => HasTypeProxy (UnsignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx.Internal.Type Associated Types
Methods proxyToAsType :: Proxy (UnsignedTx era) -> AsType (UnsignedTx era) Source # | |||||
| EraTx era => SerialiseAsRawBytes (UnsignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx.Internal.Type Methods serialiseToRawBytes :: UnsignedTx era -> ByteString Source # deserialiseFromRawBytes :: AsType (UnsignedTx era) -> ByteString -> Either SerialiseAsRawBytesError (UnsignedTx era) Source # | |||||
| Show (UnsignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx.Internal.Type | |||||
| Eq (UnsignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx.Internal.Type Methods (==) :: UnsignedTx era -> UnsignedTx era -> Bool Source # (/=) :: UnsignedTx era -> UnsignedTx era -> Bool Source # | |||||
| data AsType (UnsignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx.Internal.Type | |||||
A transaction that has been witnesssed
Instances
| HasTypeProxy era => HasTypeProxy (SignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx Associated Types
| |||||
| (HasTypeProxy era, EraTx (LedgerEra era)) => SerialiseAsRawBytes (SignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx Methods serialiseToRawBytes :: SignedTx era -> ByteString Source # deserialiseFromRawBytes :: AsType (SignedTx era) -> ByteString -> Either SerialiseAsRawBytesError (SignedTx era) Source # | |||||
| Show (SignedTx era) Source # | |||||
| Eq (SignedTx era) Source # | |||||
| data AsType (SignedTx era) Source # | |||||
Defined in Cardano.Api.Experimental.Tx | |||||
makeUnsignedTx :: Era era -> TxBodyContent (LedgerEra era) -> UnsignedTx (LedgerEra era) Source #
makeKeyWitness :: Era era -> UnsignedTx (LedgerEra era) -> ShelleyWitnessSigningKey -> WitVKey 'Witness Source #
signTx :: Era era -> [BootstrapWitness] -> [WitVKey 'Witness] -> UnsignedTx (LedgerEra era) -> SignedTx era Source #
convertTxBodyToUnsignedTx :: HasCallStack => ShelleyBasedEra era -> TxBody era -> UnsignedTx (LedgerEra era) Source #
hashTxBody :: HashAnnotated (TxBody era) EraIndependentTxBody => TxBody era -> Hash HASH EraIndependentTxBody Source #
getUnsignedTxFee :: UnsignedTx era -> Coin Source #
TxBodyContent
data TxBodyContent era Source #
Constructors
| TxBodyContent | |
Fields
| |
defaultTxBodyContent :: TxBodyContent era Source #
mkTxCertificates :: Era era -> [(Certificate (LedgerEra era), AnyWitness (LedgerEra era))] -> TxCertificates (LedgerEra 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.
mkTxVotingProcedures :: [(VotingProcedures era, AnyWitness era)] -> Either (VotesMergingConflict 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.
modTxOuts :: ([TxOut era] -> [TxOut era]) -> TxBodyContent era -> TxBodyContent era Source #
setTxAuxScripts :: [SimpleScript era] -> TxBodyContent era -> TxBodyContent era Source #
setTxCertificates :: TxCertificates era -> TxBodyContent era -> TxBodyContent era Source #
setTxReturnCollateral :: TxReturnCollateral era -> TxBodyContent era -> TxBodyContent era Source #
setTxTotalCollateral :: TxTotalCollateral -> TxBodyContent era -> TxBodyContent era Source #
setTxCurrentTreasuryValue :: Coin -> TxBodyContent era -> TxBodyContent era Source #
setTxExtraKeyWits :: TxExtraKeyWitnesses -> TxBodyContent era -> TxBodyContent era Source #
setTxFee :: Coin -> TxBodyContent era -> TxBodyContent era Source #
setTxIns :: [(TxIn, AnyWitness era)] -> TxBodyContent era -> TxBodyContent era Source #
setTxInsCollateral :: [TxIn] -> TxBodyContent era -> TxBodyContent era Source #
setTxInsReference :: TxInsReference era -> TxBodyContent era -> TxBodyContent era Source #
setTxMetadata :: TxMetadata -> TxBodyContent era -> TxBodyContent era Source #
setTxMintValue :: TxMintValue era -> TxBodyContent era -> TxBodyContent era Source #
setTxOuts :: [TxOut era] -> TxBodyContent era -> TxBodyContent era Source #
setTxProposalProcedures :: TxProposalProcedures era -> TxBodyContent era -> TxBodyContent era Source #
setTxProtocolParams :: PParams era -> TxBodyContent era -> TxBodyContent era Source #
setTxScriptValidity :: ScriptValidity -> TxBodyContent era -> TxBodyContent era Source #
setTxTreasuryDonation :: Coin -> TxBodyContent era -> TxBodyContent era Source #
setTxValidityLowerBound :: SlotNo -> TxBodyContent era -> TxBodyContent era Source #
setTxValidityUpperBound :: SlotNo -> TxBodyContent era -> TxBodyContent era Source #
setTxVotingProcedures :: TxVotingProcedures era -> TxBodyContent era -> TxBodyContent era Source #
setTxWithdrawals :: TxWithdrawals era -> TxBodyContent era -> TxBodyContent era Source #
Legacy Conversions
newtype DatumDecodingError Source #
Constructors
| DatumDecodingError String |
Instances
| Error DatumDecodingError Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods prettyError :: DatumDecodingError -> Doc ann Source # | |
| Show DatumDecodingError Source # | |
| Eq DatumDecodingError Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: DatumDecodingError -> DatumDecodingError -> Bool Source # (/=) :: DatumDecodingError -> DatumDecodingError -> Bool Source # | |
legacyDatumToDatum :: IsEra era => TxOutDatum CtxTx era -> Maybe (Datum CtxTx (LedgerEra era)) Source #
fromLegacyTxOut :: IsEra era => TxOut CtxTx era -> Either DatumDecodingError (TxOut (LedgerEra era)) Source #
TxBodyContent sub type
newtype TxCertificates era Source #
Constructors
| TxCertificates | |
Fields
| |
Instances
| Show (TxCertificates era) Source # | |
| Eq (TxCertificates era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: TxCertificates era -> TxCertificates era -> Bool Source # (/=) :: TxCertificates era -> TxCertificates era -> Bool Source # | |
newtype TxMintValue era Source #
Constructors
| TxMintValue | |
Fields
| |
Instances
| Show (TxMintValue era) Source # | |
| Eq (TxMintValue era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: TxMintValue era -> TxMintValue era -> Bool Source # (/=) :: TxMintValue era -> TxMintValue era -> Bool Source # | |
newtype TxProposalProcedures era Source #
Constructors
| TxProposalProcedures (OMap (ProposalProcedure era) (AnyWitness era)) |
Instances
| EraPParams era => Show (TxProposalProcedures era) Source # | |
| EraPParams era => Eq (TxProposalProcedures era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: TxProposalProcedures era -> TxProposalProcedures era -> Bool Source # (/=) :: TxProposalProcedures era -> TxProposalProcedures era -> Bool Source # | |
data TxVotingProcedures era Source #
Constructors
| TxVotingProcedures (VotingProcedures era) (Map Voter (AnyWitness era)) |
Instances
| Show (TxVotingProcedures era) Source # | |
| Eq (TxVotingProcedures era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: TxVotingProcedures era -> TxVotingProcedures era -> Bool Source # (/=) :: TxVotingProcedures era -> TxVotingProcedures era -> Bool Source # | |
newtype TxWithdrawals era Source #
Constructors
| TxWithdrawals | |
Fields
| |
Instances
| Show (TxWithdrawals era) Source # | |
| Eq (TxWithdrawals era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.BodyContent.New Methods (==) :: TxWithdrawals era -> TxWithdrawals era -> Bool Source # (/=) :: TxWithdrawals era -> TxWithdrawals era -> Bool Source # | |
newtype TxReturnCollateral era Source #
Constructors
| TxReturnCollateral | |
Fields
| |
newtype TxTotalCollateral Source #
Constructors
| TxTotalCollateral | |
Fields | |
newtype TxExtraKeyWitnesses Source #
Constructors
| TxExtraKeyWitnesses [Hash PaymentKey] |
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
| Show (AnyWitness era) Source # | |
| Eq (AnyWitness era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.AnyWitness Methods (==) :: AnyWitness era -> AnyWitness era -> Bool Source # (/=) :: AnyWitness era -> AnyWitness era -> Bool Source # | |
getAnyWitnessScript :: AlonzoEraScript era => AnyWitness era -> Maybe (Script era) Source #
getAnyWitnessReferenceInput :: AnyWitness era -> Maybe TxIn Source #
getAnyWitnessPlutusLanguage :: AnyWitness era -> Maybe Language Source #
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
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 |
Arguments
| :: IsEra era | |
| => TxInsReference (LedgerEra era) | reference inputs |
| -> [TxOut (LedgerEra era)] | |
| -> TxDats (LedgerEra era) |
Extract datum: 1. supplemental datums from transaction outputs 2. datums from reference inputs
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.
extractAllIndexedPlutusScriptWitnesses :: Era era -> TxBodyContent (LedgerEra era) -> Either DecoderError [AnyIndexedPlutusScriptWitness (LedgerEra era)] Source #
getTxScriptWitnessesRequirements :: forall era (witnessable :: WitnessableItem). (AlonzoEraScript era, Monoid (TxScriptWitnessRequirements era)) => [(Witnessable witnessable era, AnyWitness era)] -> TxScriptWitnessRequirements era Source #
obtainMonoidConstraint :: Era era -> (Monoid (TxScriptWitnessRequirements (LedgerEra era)) => a) -> a Source #
Balancing transactions
calculateMinimumUTxO :: HasCallStack => PParams (LedgerEra era) -> TxOut (LedgerEra era) -> Coin Source #
evaluateTransactionExecutionUnits :: IsEra era => SystemStart -> LedgerEpochInfo -> PParams (LedgerEra era) -> UTxO (LedgerEra era) -> Tx (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.
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 |
| -> Map (Credential 'DRepRole) Coin | The map of all deposits for DRep credentials that are being unregistered in this transaction |
| -> UTxO (LedgerEra era) | The transaction inputs (including reference and collateral ones), not the entire |
| -> 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 currentProtocolParameters, 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. |
| TxBodyErrorMinUTxONotMet | The minimum spendable UTxO threshold has not been met. |
| TxBodyErrorNonAdaAssetsUnbalanced Value | |
| 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 | |
Instances
| Error (TxBodyErrorAutoBalance era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.Fee Methods prettyError :: TxBodyErrorAutoBalance era -> Doc ann Source # | |
| Show (TxBodyErrorAutoBalance era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.Fee | |
data TxFeeEstimationError era Source #
Constructors
| TxFeeEstimationScriptExecutionError (TxBodyErrorAutoBalance (LedgerEra era)) | |
| TxFeeEstimationBalanceError (TxBodyErrorAutoBalance (LedgerEra era)) |
Instances
| Error (TxFeeEstimationError era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.Fee Methods prettyError :: TxFeeEstimationError era -> Doc ann Source # | |
| Show (TxFeeEstimationError era) Source # | |
Defined in Cardano.Api.Experimental.Tx.Internal.Fee | |
Internal functions
getTxScriptWitnessRequirements :: forall era (witnessable :: WitnessableItem). (AlonzoEraScript era, Monoid (TxScriptWitnessRequirements era)) => [(Witnessable witnessable era, AnyWitness era)] -> TxScriptWitnessRequirements era Source #