| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Transaction.Building
Description
Standalone transaction building calculations. Obtain a protocol snapshot, assemble outputs and witnesses, evaluate scripts, then calculate commitments and fees explicitly. Calculations leave the supplied transaction unchanged.
import qualified Cometa.Transaction.Building as Building priceOutput output = Building.minimumAda 4310 output
Synopsis
- coinSize :: Word64 -> Int
- outputSize :: Output -> Int
- scriptSize :: Script -> Int
- transactionSize :: Transaction -> Int
- totalExecutionUnits :: [Redeemer] -> Either Error ExUnits
- minimumAda :: Word64 -> Output -> IO (Either Error Word64)
- baseFee :: Word64 -> Word64 -> Transaction -> IO (Either Error Word64)
- minimumFee :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Word64)
- executionFee :: ExUnitPrices -> ExUnits -> Either Error Word64
- referenceScriptFee :: Parameters -> [Utxo] -> IO (Either Error Word64)
- scriptDataHash :: CostModels -> EncodedWitnesses -> IO (Either Error (Maybe Hash32))
- data ImplicitCoin = ImplicitCoin {
- withdrawals :: !Word64
- deposits :: !Word64
- reclaimedDeposits :: !Word64
- implicitCoin :: Parameters -> Transaction -> IO (Either Error ImplicitCoin)
- subTransactionImplicitCoin :: Parameters -> SubTransaction -> IO (Either Error ImplicitCoin)
- imbalance :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Value)
- subTransactionImbalance :: Parameters -> [Utxo] -> SubTransaction -> IO (Either Error Value)
- batchImbalance :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Value)
- isBalanced :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Bool)
Documentation
coinSize :: Word64 -> Int Source #
Size in bytes of the shortest unsigned CBOR encoding of a lovelace amount. Zero through 23 require one byte; every unsigned 64-bit amount is supported.
outputSize :: Output -> Int Source #
Size in bytes of this output's public CBOR encoding, including its value, datum and reference script. Does not calculate the minimum required Ada.
scriptSize :: Script -> Int Source #
Script size in bytes charged by reference-script pricing. Native scripts use their exact CBOR; Plutus scripts use their compiled bytes without the outer CBOR bytestring or the language-tag envelope.
transactionSize :: Transaction -> Int Source #
Complete encoded transaction size in bytes, including the validity flag
when present, actual witnesses and auxiliary data. This is not the ledger
size used by baseFee, which excludes the validity flag.
totalExecutionUnits :: [Redeemer] -> Either Error ExUnits Source #
Sum declared memory units and CPU steps without executing scripts. Counts
every supplied redeemer, including repeated purpose/index pairs. Empty input
returns zero. Either total exceeding 2^64-1 returns InvalidExUnits
rather than wrapping. Nested transaction redeemers must be supplied explicitly.
minimumAda :: Word64 -> Output -> IO (Either Error Word64) Source #
Minimum output coin in lovelace, accounting for the size of the resulting coin encoding. The first argument is lovelace per UTxO byte. Zero is allowed; amounts exceeding native 64-bit calculation bounds return a native error.
baseFee :: Word64 -> Word64 -> Transaction -> IO (Either Error Word64) Source #
Linear fee in lovelace: constant plus coefficient times ledger transaction size, excluding the script-validity flag. Arguments are the constant lovelace charge, then lovelace per byte. Uses actual included witnesses and auxiliary data; callers must account for any witnesses they intend to add. Overflow is an error. No execution or reference script charge is included.
minimumFee :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Word64) Source #
Fee in lovelace for the complete supplied transaction, including execution
units of top-level and subtransaction redeemers and reference script prices.
Resolved UTxOs must be unique and cover exactly the union of spending and
reference inputs in all bodies. A reference script is charged once per UTxO
within each body, even if both spent and referenced there. The same UTxO
appearing in several bodies is priced for each body. Missing execution or reference prices and invalid coverage
return InvalidBuildingRequest. Uses actual included witnesses;
adding signatures or changing budgets requires recalculation. No evaluation,
witness estimation, input resolution or fee installation is performed.
executionFee :: ExUnitPrices -> ExUnits -> Either Error Word64 Source #
Exact execution charge in lovelace for supplied prices and aggregate
budgets: round the sum of memory and CPU charges upward once. Does not price
reference scripts or execute scripts. Zero budgets cost zero. A result above
2^64-1 returns InvalidBuildingRequest. Aggregate transaction and
subtransaction redeemers with totalExecutionUnits before pricing a batch.
referenceScriptFee :: Parameters -> [Utxo] -> IO (Either Error Word64) Source #
Price reference scripts in exactly these unique resolved UTxOs, in lovelace. Uses exact rational tier prices and floors the total once. Missing stride or multiplier uses Conway values 25600 bytes and 6/5; supplied values use protocol tiers. A reference byte price is required. Duplicate references are invalid.
scriptDataHash :: CostModels -> EncodedWitnesses -> IO (Either Error (Maybe Hash32)) Source #
Script-data commitment for the exact redeemer and datum field encodings in
these witnesses. Supply only cost models for the languages used by the body:
every supplied language view contributes when redeemers are present. No
redeemers and no datums returns Nothing; datum-only witnesses use empty
language views. Does not install the commitment in a body or evaluate scripts.
data ImplicitCoin Source #
Top-level reward withdrawals, deposits charged and deposits reclaimed, all in lovelace. The three totals are separate unsigned 64-bit quantities.
Constructors
| ImplicitCoin | |
Fields
| |
Instances
| Show ImplicitCoin Source # | |
Defined in Cometa.Internal.Building Methods showsPrec :: Int -> ImplicitCoin -> ShowS # show :: ImplicitCoin -> String # showList :: [ImplicitCoin] -> ShowS # | |
| Eq ImplicitCoin Source # | |
Defined in Cometa.Internal.Building | |
implicitCoin :: Parameters -> Transaction -> IO (Either Error ImplicitCoin) Source #
Top-level body's withdrawals, paid deposits and reclaimed deposits. Nested subtransactions are excluded. Each pool is charged once within this body; already registered pools are also charged because no chain registration state is supplied. Pool retirement refunds occur at epoch boundaries and contribute zero here. This is an accounting component, not a ledger balance assertion. Native unsigned 64-bit overflow is reported as an error.
subTransactionImplicitCoin :: Parameters -> SubTransaction -> IO (Either Error ImplicitCoin) Source #
The same accounting as implicitCoin for one subtransaction body. Pool
deposits are charged once per pool within this body, independently of other
bodies in a batch; this does not compute the deduplicated batch balance.
imbalance :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Value) Source #
Top-level consumed value minus produced value. Positive quantities are a
surplus; negative quantities are a deficit. Includes mint/burn, withdrawals,
refunds, deposits, fee, donation and direct deposits; excludes nested bodies.
Resolve every spending input exactly once. Extra resolved UTxOs are allowed;
reference and collateral inputs do not contribute. Signed 64-bit intermediate
overflow or missing/duplicate resolution returns InvalidBuildingRequest.
subTransactionImbalance :: Parameters -> [Utxo] -> SubTransaction -> IO (Either Error Value) Source #
The same accounting for one subtransaction, which has no fee. A nonzero result is normal for an intent awaiting matching in a batch.
batchImbalance :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Value) Source #
Whole-batch surplus or deficit, charging each registered pool's deposit once across all bodies. Supply a unique resolved snapshot covering spending inputs at every level. Positive and negative intermediate totals must each fit signed 64-bit bounds. This checks value conservation, not ledger admission, signatures, script success or availability of inputs on chain.
isBalanced :: Parameters -> [Utxo] -> Transaction -> IO (Either Error Bool) Source #
Whether the complete batch has zero coin and asset imbalance. Does not validate other ledger rules. Resolution and arithmetic errors remain explicit.