| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.CoinSelection
Description
Select spending inputs with largest-first, random-improve or an application
supplied selector. Validate a request once, then use select to check full
selection and change laws. Target values include externally assessed fees
and deposits; this boundary selects inputs and change without submitting.
selectLargest = select largestFirst
Synopsis
- newtype Selector = Selector {
- selectCoins :: SelectionRequest -> IO (Either Error Selection)
- data Strategy
- largestFirst :: Selector
- randomImprove :: Selector
- randomImproveWithSeed :: Word64 -> Selector
- randomImproveWithOptions :: Word64 -> Strategy -> Selector
- data SelectionOptions = SelectionOptions {
- selectionPreselected :: ![Utxo]
- selectionAvailable :: ![Utxo]
- selectionTarget :: !Value
- selectionOutputHints :: !(Maybe [Output])
- selectionChangeAddress :: !Address
- selectionParameters :: !Parameters
- data SelectionRequest
- mkSelectionRequest :: SelectionOptions -> Either Error SelectionRequest
- preselected :: SelectionRequest -> [Utxo]
- available :: SelectionRequest -> [Utxo]
- target :: SelectionRequest -> Value
- outputHints :: SelectionRequest -> Maybe [Output]
- changeAddress :: SelectionRequest -> Address
- parameters :: SelectionRequest -> Parameters
- data Selection = Selection {}
- validateSelection :: SelectionRequest -> Selection -> Either Error ()
- select :: Selector -> SelectionRequest -> IO (Either Error Selection)
Documentation
Application-supplied coin selection. The function receives an immutable,
validated request and returns the complete selection, remaining candidates and
change. Use select to check contextual laws and change minimum Ada. Exceptions
propagate normally; Left represents an expected selection failure.
Constructors
| Selector | |
Fields
| |
Random-improve input selection policy. Both policies may acquire more Ada to fund change. Neither policy changes the authoritative target.
Constructors
| Minimal | Select enough of each asset to meet its required quantity. |
| Optimal | Attempt approximately twice the required quantity to improve change. |
Instances
| Bounded Strategy Source # | |
| Enum Strategy Source # | |
Defined in Cometa.Internal.CoinSelection | |
| Show Strategy Source # | |
| Eq Strategy Source # | |
| Ord Strategy Source # | |
Defined in Cometa.Internal.CoinSelection | |
largestFirst :: Selector Source #
Select the largest available quantities of required assets, with Ada last.
Aggregate eligible and hinted quantities must fit signed 64-bit arithmetic;
excessive minimum-Ada multiplication bounds return InvalidSelectionRequest.
Output hints are ignored. A successful selection always spends an input,
including when the target is zero. Insufficient funding or change Ada returns
the native balance failure. Change respects a supplied maximum value size;
absent or zero maximum value size disables splitting.
randomImprove :: Selector Source #
Round-robin random-improve with the Optimal policy, seeded from the native
secure entropy source separately on every invocation. Aggregate bounds are
checked as for largestFirst. Output hints influence
change shape, never the authoritative funding requirement.
randomImproveWithSeed :: Word64 -> Selector Source #
Deterministic random-improve using Optimal. The same seed and request
replay the same selection on each call; this is not a persistent random stream.
randomImproveWithOptions :: Word64 -> Strategy -> Selector Source #
Deterministic random-improve with an explicit seed and policy. Output hints shape change; additional Ada inputs may be selected to satisfy minimum Ada. Selection replays from the seed on each call. Deterministic replay applies to the same library version; ordering can change between versions.
data SelectionOptions Source #
Named input to request validation. Candidate lists must have unique references. Identical references may occur once in both lists; conflicting resolved outputs are rejected. Preselected inputs may be outside available.
Constructors
| SelectionOptions | |
Fields
| |
Instances
| Show SelectionOptions Source # | |
Defined in Cometa.Internal.CoinSelection Methods showsPrec :: Int -> SelectionOptions -> ShowS # show :: SelectionOptions -> String # showList :: [SelectionOptions] -> ShowS # | |
| Eq SelectionOptions Source # | |
Defined in Cometa.Internal.CoinSelection Methods (==) :: SelectionOptions -> SelectionOptions -> Bool # (/=) :: SelectionOptions -> SelectionOptions -> Bool # | |
data SelectionRequest Source #
Validated request. Equality compares all owned fields and preserves list order; validation does not select coins or access chain state.
Instances
| Show SelectionRequest Source # | |
Defined in Cometa.Internal.CoinSelection Methods showsPrec :: Int -> SelectionRequest -> ShowS # show :: SelectionRequest -> String # showList :: [SelectionRequest] -> ShowS # | |
| Eq SelectionRequest Source # | |
Defined in Cometa.Internal.CoinSelection Methods (==) :: SelectionRequest -> SelectionRequest -> Bool # (/=) :: SelectionRequest -> SelectionRequest -> Bool # | |
mkSelectionRequest :: SelectionOptions -> Either Error SelectionRequest Source #
Validate unique references and nonconflicting overlapping snapshots, a
signed native-range target, an available Ada-per-UTxO-byte parameter,
and supported parameter bounds. Failure returns InvalidSelectionRequest or
InvalidParameterSnapshot. This does not query input eligibility on chain.
preselected :: SelectionRequest -> [Utxo] Source #
Mandatory input snapshots in caller order.
available :: SelectionRequest -> [Utxo] Source #
Eligible candidate snapshots in caller order.
target :: SelectionRequest -> Value Source #
Authoritative funding requirement; output hints do not change it.
outputHints :: SelectionRequest -> Maybe [Output] Source #
Optional output-shape hints, retaining absence versus an empty hint list.
changeAddress :: SelectionRequest -> Address Source #
Destination required for each change output.
parameters :: SelectionRequest -> Parameters Source #
Protocol snapshot supplied with the request.
Full selection result. Assembly is total; select checks contextual
eligibility, balance, remaining candidates, change destination and minimum Ada.
Equality compares list order and semantic fields; no random-choice equivalence
is implied. Empty change means an exact target match.
Constructors
| Selection | |
validateSelection :: SelectionRequest -> Selection -> Either Error () Source #
Check unique references, unaltered eligible snapshots, mandatory inclusion,
exact remaining accounting and componentwise selected = target + change.
Change destinations must match. Ordering does not affect these laws. This
pure check does not assess minimum Ada; select performs that additional check.
select :: Selector -> SelectionRequest -> IO (Either Error Selection) Source #
Invoke an application selector once, validate its complete result and check minimum Ada for every change output. No fees, additional inputs, witnesses or output amounts are changed implicitly. Expected failures retain their error; callback exceptions and asynchronous cancellation propagate normally.