cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Documentation

newtype Selector Source #

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

data Strategy Source #

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

Instances details
Bounded Strategy Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Enum Strategy Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Show Strategy Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Eq Strategy Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Ord Strategy Source # 
Instance details

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

  • selectionPreselected :: ![Utxo]

    Mandatory selected inputs. Each must survive in a successful selection.

  • selectionAvailable :: ![Utxo]

    Eligible candidate inputs, including any optional overlap with preselected.

  • selectionTarget :: !Value

    Authoritative signed value to fund, including externally assessed fees, deposits, withdrawals and mint. Negative components are implicit surplus that must return as change. Ada counts lovelace; quantities fit Int64.

  • selectionOutputHints :: !(Maybe [Output])

    Optional output-shape hints, independent of authoritative target arithmetic.

  • selectionChangeAddress :: !Address

    Required destination for every generated change output.

  • selectionParameters :: !Parameters

    Current protocol snapshot. Ada-per-UTxO-byte must be present for change minimum-Ada validation. This does not promise consistent chain observations.

Instances

Instances details
Show SelectionOptions Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Eq SelectionOptions Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

data SelectionRequest Source #

Validated request. Equality compares all owned fields and preserves list order; validation does not select coins or access chain state.

Instances

Instances details
Show SelectionRequest Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Eq SelectionRequest Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

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.

data Selection Source #

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 

Fields

  • selected :: ![Utxo]

    Complete selected inputs, including the preselected inputs, with unique refs.

  • remaining :: ![Utxo]

    Exactly the available candidates not selected, with unique references.

  • change :: ![Output]

    Locally balanced outputs returning all excess value to the change address.

Instances

Instances details
Show Selection Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

Eq Selection Source # 
Instance details

Defined in Cometa.Internal.CoinSelection

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.