cardano-coin-selection-1.0.1: Algorithms for coin selection and fee balancing.

Cardano.CoinSelection.Algorithm.LargestFirst

Description

This module contains an implementation of the Largest-First coin selection algorithm.

Synopsis

Documentation

largestFirst :: (Ord i, Monad m) => CoinSelectionAlgorithm i o m Source #

An implementation of the Largest-First coin selection algorithm.

The Largest-First coin selection algorithm considers available inputs in descending order of value, from largest to smallest.

When applied to a set of requested outputs, the algorithm repeatedly selects entries from the available inputs set until the total value of selected entries is greater than or equal to the total value of requested outputs.

Change Values

If the total value of selected inputs is greater than the total value of all requested outputs, the change set of the resulting selection will contain a single coin with the excess value.

If the total value of selected inputs is exactly equal to the total value of all requested outputs, the change set of the resulting selection will be empty.

Failure Modes

The algorithm terminates with an error if:

1. The total value of inputsAvailable (the amount of money available) is less than the total value of outputsRequested (the amount of money required).

See: InputValueInsufficientError.

2. It is not possible to cover the total value of outputsRequested without selecting a number of inputs from inputsAvailable that would exceed the maximum defined by limit.

See: InputLimitExceededError.

Since: 1.0.0