| License | Apache-2.0 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Singular.Registry.TxBuilder.Prepare
Description
When no output of the payer's wallet can fund a command (every output carries tokens or a reference script beside the ada, or none holds enough), the command spends one transaction first that puts the ada the command needs into an output of its own. This module is the pure builder of that transaction: selection and body from explicit inputs, priced by the ledger's own balancing, never a typed constant.
A preparation spends the fewest spendable outputs it needs, largest
first; an output carrying a reference script is never spent, while any
other output, token-carrying or not, may be. It makes the funding output
as its first output — ada only, holding exactly the requirement, so the
journal reads it back as the transaction's first output — and returns
everything else the spent outputs held, tokens included, in one remainder
output at the payer's address at or above the ledger minimum for its
assets. The fee is the ledger's price of the built body, found by the
same balancing the other builders use (balanceTx,
which iterates the fee to its fixpoint and appends the change), not a
typed number. The transaction carries no scripts, so it needs no
collateral, and the one signing key it assumes is priced into the fee.
planPreparation judges the whole thing before anything is signed: it
returns the balanced transaction with its funding reference and fee, or
a PrepareError naming the requirement, the best fee balancing measured,
the remainder floor, what the wallet may spend and its largest output. A
wallet whose spendable ada cannot cover preparation plus command is
refused from that error, before anything is submitted. An exact cover —
spent equals funding plus fee to the lovelace, leaving no remainder — is
refused the same way: the balancer always appends a change output, and a
zero-ada one is not a valid output. Real wallets never land on it; the
boundary spec pins the behaviour around it.
Synopsis
- data PrepareError = PrepareShortfall {
- prepareRequired :: Integer
- prepareFee :: Maybe Integer
- prepareRemainderMin :: Integer
- prepareHeld :: Integer
- prepareLargest :: Integer
- data Preparation = Preparation {
- prepSpent :: [(TxIn, TxOut ConwayEra)]
- prepTx :: ConwayTx
- prepFunding :: TxIn
- prepFee :: Integer
- prepFundingCoin :: Integer
- prepRemainderCoin :: Integer
- planPreparation :: PParams ConwayEra -> Addr -> Integer -> [(TxIn, TxOut ConwayEra)] -> Either PrepareError Preparation
- spendableOuts :: [(TxIn, TxOut ConwayEra)] -> [(TxIn, TxOut ConwayEra)]
- spendableHeld :: [(TxIn, TxOut ConwayEra)] -> Integer
Documentation
data PrepareError Source #
Why no preparation can be planned: what shortfall the wallet leaves.
Constructors
| PrepareShortfall | |
Fields
| |
Instances
| Show PrepareError Source # | |
Defined in Singular.Registry.TxBuilder.Prepare Methods showsPrec :: Int -> PrepareError -> ShowS Source # show :: PrepareError -> String Source # showList :: [PrepareError] -> ShowS Source # | |
| Eq PrepareError Source # | |
Defined in Singular.Registry.TxBuilder.Prepare Methods (==) :: PrepareError -> PrepareError -> Bool Source # (/=) :: PrepareError -> PrepareError -> Bool Source # | |
data Preparation Source #
A planned preparation: the balanced transaction and what it makes.
Constructors
| Preparation | |
Fields
| |
Instances
| Show Preparation Source # | |
Defined in Singular.Registry.TxBuilder.Prepare Methods showsPrec :: Int -> Preparation -> ShowS Source # show :: Preparation -> String Source # showList :: [Preparation] -> ShowS Source # | |
| Eq Preparation Source # | |
Defined in Singular.Registry.TxBuilder.Prepare Methods (==) :: Preparation -> Preparation -> Bool Source # (/=) :: Preparation -> Preparation -> Bool Source # | |
Arguments
| :: PParams ConwayEra | |
| -> Addr | |
| -> Integer | The funding the command needs. |
| -> [(TxIn, TxOut ConwayEra)] | |
| -> Either PrepareError Preparation |
Plan one preparation transaction that makes an ada-only output holding the requirement: the fewest largest-first spendable outputs that cover it, balanced by the ledger's own fee. Returns the balanced transaction or the shortfall, before anything is signed or submitted.
spendableOuts :: [(TxIn, TxOut ConwayEra)] -> [(TxIn, TxOut ConwayEra)] Source #
What the wallet may spend: every output carrying no reference script, token-carrying or not. Reference-script outputs are never spent: a transaction may not both spend an output and reference it.
spendableHeld :: [(TxIn, TxOut ConwayEra)] -> Integer Source #
What the wallet may spend, in total lovelace.