cardano-ledger-core-1.17.0.0: Core components of Cardano ledgers from the Shelley release on.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Ledger.Tools

Description

This is a module that contains functionality that is not necessary for ledger operation, but is useful for testing as well as for downstream users of ledger

Synopsis

Tx

setMinFeeTx Source #

Arguments

EraTx era 
PParams era 
Tx era 
Int

Size in bytes of reference scripts present in this transaction

Tx era 

Calculate and update the fee in the transaction until it has the smallest possible value according to the settings in the protocol parameters.

This function potentially changes the feeTxBodyL field of the TxBody, as such it affects the hash of the body, which consequently invalidates all of the signature in the attached witnesses.

setMinFeeTxUtxoEraUTxO era ⇒ PParams era → Tx era → UTxO era → Tx era Source #

calcMinFeeTx Source #

Arguments

∷ ∀ era. EraUTxO era 
UTxO era

All TxOuts available for this transaction. In other words TxIns produced by allInputsTxBodyF should be present in this UTxO map, however this is not checked.

PParams era

The current protocol parameters.

Tx era

The transaction.

Int

Number of extra KeyHash witnesses that will be supplied for satisfying native scripts. It is impossible to know how many of these is required without knowing the actual witnesses supplied and the time when the transaction will be submitted. Therefore we put this burden on the user.

This number can also be used to specify all of the redundant extra key witnesses that will be supplied.

Coin

The required minimum fee.

This is a more accurate version estimateMinFeeTx that looks into transaction and figures out how many and what kind of key witnesses this transaction needs. It requires access to the portion of the UTxO that is relevant for this transaction. The only type of witnesses that it cannot figure out reliably is the witnesses needed for satisfying native scripts included in the transaction. For this reason number of witnesses needed for native scripts must be supplied as an extra argument.

Example

Expand
>>> let relevantUtxo = txInsFilter utxo (tx ^. bodyTxL . allInputsTxBodyF)
>>> calcMinFeeTx relevantUtxo pp tx 5

calcMinFeeTxNativeScriptWits Source #

Arguments

∷ ∀ era. EraUTxO era 
UTxO era

All TxOuts available for this transaction. In other words TxIns produced by allInputsTxBodyF should be present in this UTxO map, however this is not checked.

PParams era

The current protocol parameters.

Tx era

The transaction.

Set (KeyHash 'Witness)

KeyHash witnesses that will be supplied for satisfying native scripts. It is impossible to know how many of these is required without knowing the actual witnesses supplied and the time when the transaction will be submitted. Therefore we put this burden on the user.

Coin

The required minimum fee.

Same as calcMinFeeTx, except this function allows to specify hashes of key witnesses that will be supplied, instead of their count. That is only useful whenever there is a chance of some of the required witnesses being the same as the witnesses that will be supplied for native scripts.

estimateMinFeeTx Source #

Arguments

∷ ∀ era. EraTx era 
PParams era

The current protocol parameters.

Tx era

The transaction.

Int

The number of key witnesses still to be added to the transaction.

Int

The number of Byron key witnesses still to be added to the transaction.

Int

The total size in bytes of reference scripts

Coin

The required minimum fee.

Estimate a minimum transaction fee for a transaction that does not yet have all of the VKey witnesses. This calculation is not very accurate in estimating Byron witnesses, but it should work for the most part. If you have access to UTxO necessary for the transaction that it is better and easier to use calcMinFeeTx instead.

Since: 1.8.0

addDummyWitsTx Source #

Arguments

∷ ∀ era. EraTx era 
PParams era

The current protocol parameters.

Tx era

The transaction.

Int

The number of key witnesses still to be added to the transaction.

→ [Attributes AddrAttributes]

List of attributes from TxOuts with Byron addresses that are being spent

Tx era

The required minimum fee.

Create dummy witnesses and add them to the transaction

TxOut

setMinCoinTxOutEraTxOut era ⇒ PParams era → TxOut era → TxOut era Source #

Same as setMinCoinSizedTxOut, except it doesn't require the size of the TxOut and will recompute it if needed. Initial amount is not important.

ensureMinCoinTxOutEraTxOut era ⇒ PParams era → TxOut era → TxOut era Source #

Similar to setMinCoinTxOut it will guarantee that the minimum requirement for the output amount is satisified, however it makes it possible to set a higher amount than the minimaly required.

> ensureMinCoinTxOut pp (txOut & coinTxOutL .~ zero) == setMinCoinTxOut pp (txOut & coinTxOutL .~ zero)
> (ensureMinCoinTxOut pp txOut ^. coinTxOutL) >= (setMinCoinTxOut pp txOut ^. coinTxOutL)

setMinCoinTxOutWithEraTxOut era ⇒ (CoinCoinBool) → PParams era → TxOut era → TxOut era Source #

General tools

boomHasCallStack ⇒ a Source #

Warning: BOOM!

A helpful placeholder to use during development.

byteStringToNum ∷ (Bits i, Num i) ⇒ ByteString → i Source #