cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.CoinSelection.Internal

Description

This module provides INTERNAL functions and types for coin selection.

It is recommended to import from CoinSelection instead.

Synopsis

Performing selections

performSelection :: ( HasCallStack , MonadRandom m, SelectionContext ctx) => PerformSelection m ctx ( Selection ctx) Source #

Performs a coin selection.

This function has the following responsibilities:

  • selecting inputs from the UTxO set to pay for user-specified outputs;
  • selecting inputs from the UTxO set to pay for collateral;
  • producing change outputs to return excess value to the wallet;
  • balancing a selection to pay for the transaction fee.

This function guarantees that given a set of SelectionConstraints cs and SelectionParams ps :

  • if creation of a selection succeeds, a value s of type Selection will be returned for which the following property holds:

    >>> verifySelection cs ps s == VerificationSuccess
    
  • if creation of a selection fails, a value e of type SelectionError will be returned for which the following property holds:

    >>> verifySelectionError cs ps e == VerificationSuccess
    

data Selection ctx Source #

Represents a balanced selection.

Constructors

Selection

Fields

Instances

Instances details
SelectionContext ctx => Eq ( Selection ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( Selection ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( Selection ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Associated Types

type Rep ( Selection ctx) :: Type -> Type Source #

type Rep ( Selection ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

data SelectionConstraints ctx Source #

Specifies all constraints required for coin selection.

Selection constraints:

  • are dependent on the current set of protocol parameters.
  • are not specific to a given selection.
  • place limits on the coin selection algorithm, enabling it to produce selections that are acceptable to the ledger.

Constructors

SelectionConstraints

Fields

Instances

Instances details
Generic ( SelectionConstraints ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionConstraints ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionConstraints ctx) = D1 (' MetaData "SelectionConstraints" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionConstraints" ' PrefixI ' True ) ((( S1 (' MetaSel (' Just "assessTokenBundleSize") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( TokenBundle -> TokenBundleSizeAssessment )) :*: ( S1 (' MetaSel (' Just "certificateDepositAmount") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin ) :*: S1 (' MetaSel (' Just "computeMinimumAdaQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx -> TokenMap -> Coin )))) :*: ( S1 (' MetaSel (' Just "isBelowMinimumAdaQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx -> TokenBundle -> Bool )) :*: ( S1 (' MetaSel (' Just "computeMinimumCost") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( SelectionSkeleton ctx -> Coin )) :*: S1 (' MetaSel (' Just "computeSelectionLimit") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ([( Address ctx, TokenBundle )] -> SelectionLimit ))))) :*: (( S1 (' MetaSel (' Just "maximumCollateralInputCount") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Int ) :*: ( S1 (' MetaSel (' Just "minimumCollateralPercentage") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Natural ) :*: S1 (' MetaSel (' Just "maximumOutputAdaQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin ))) :*: ( S1 (' MetaSel (' Just "maximumOutputTokenQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 TokenQuantity ) :*: ( S1 (' MetaSel (' Just "maximumLengthChangeAddress") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx)) :*: S1 (' MetaSel (' Just "nullAddress") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx)))))))

data SelectionParams ctx Source #

Specifies all parameters that are specific to a given selection.

Constructors

SelectionParams

Fields

Instances

Instances details
SelectionContext ctx => Eq ( SelectionParams ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionParams ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionParams ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Associated Types

type Rep ( SelectionParams ctx) :: Type -> Type Source #

type Rep ( SelectionParams ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionParams ctx) = D1 (' MetaData "SelectionParams" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionParams" ' PrefixI ' True ) ((( S1 (' MetaSel (' Just "assetsToBurn") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 TokenMap ) :*: ( S1 (' MetaSel (' Just "assetsToMint") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 TokenMap ) :*: S1 (' MetaSel (' Just "extraCoinIn") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Coin ))) :*: ( S1 (' MetaSel (' Just "extraCoinOut") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Coin ) :*: ( S1 (' MetaSel (' Just "outputsToCover") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 [( Address ctx, TokenBundle )]) :*: S1 (' MetaSel (' Just "rewardWithdrawal") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Coin )))) :*: (( S1 (' MetaSel (' Just "certificateDepositsTaken") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Natural ) :*: ( S1 (' MetaSel (' Just "certificateDepositsReturned") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Natural ) :*: S1 (' MetaSel (' Just "collateralRequirement") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 SelectionCollateralRequirement ))) :*: ( S1 (' MetaSel (' Just "utxoAvailableForCollateral") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( Map ( UTxO ctx) Coin )) :*: ( S1 (' MetaSel (' Just "utxoAvailableForInputs") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( UTxOSelection ( UTxO ctx))) :*: S1 (' MetaSel (' Just "selectionStrategy") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 SelectionStrategy ))))))

data SelectionSkeleton ctx Source #

A skeleton selection that can be used to estimate the cost of a final selection.

Change outputs are deliberately stripped of their asset quantities, as the fee estimation function must be agnostic to the magnitudes of these quantities.

Increasing or decreasing the quantity of a particular asset in a change output must not change the estimated cost of a selection.

Instances

Instances details
SelectionContext ctx => Eq ( SelectionSkeleton ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Balance

SelectionContext ctx => Show ( SelectionSkeleton ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Balance

Generic ( SelectionSkeleton ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Balance

type Rep ( SelectionSkeleton ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal.Balance

type Rep ( SelectionSkeleton ctx) = D1 (' MetaData "SelectionSkeleton" "Cardano.Wallet.CoinSelection.Internal.Balance" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionSkeleton" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "skeletonInputCount") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 Int ) :*: ( S1 (' MetaSel (' Just "skeletonOutputs") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 [( Address ctx, TokenBundle )]) :*: S1 (' MetaSel (' Just "skeletonChange") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 [ Set AssetId ]))))

Output preparation

prepareOutputsWith :: forall f address. Functor f => (address -> TokenMap -> Coin ) -> f (address, TokenBundle ) -> f (address, TokenBundle ) Source #

Assigns minimal ada quantities to outputs without ada quantities.

This function only modifies outputs that have an ada quantity of zero. Outputs that have non-zero ada quantities will not be modified.

data SelectionOutputError ctx Source #

Indicates a problem when preparing outputs for a coin selection.

Instances

Instances details
SelectionContext ctx => Eq ( SelectionOutputError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionOutputError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionOutputError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

IsServerError ( SelectionOutputError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

type Rep ( SelectionOutputError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

data SelectionOutputCoinInsufficientError ctx Source #

Instances

Instances details
SelectionContext ctx => Eq ( SelectionOutputCoinInsufficientError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionOutputCoinInsufficientError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionOutputCoinInsufficientError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

IsServerError ( SelectionOutputCoinInsufficientError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

type Rep ( SelectionOutputCoinInsufficientError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionOutputCoinInsufficientError ctx) = D1 (' MetaData "SelectionOutputCoinInsufficientError" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionOutputCoinInsufficientError" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "minimumExpectedCoin") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin ) :*: S1 (' MetaSel (' Just "output") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx, TokenBundle ))))

newtype SelectionOutputSizeExceedsLimitError ctx Source #

Instances

Instances details
SelectionContext ctx => Eq ( SelectionOutputSizeExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionOutputSizeExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionOutputSizeExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

IsServerError ( SelectionOutputSizeExceedsLimitError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

type Rep ( SelectionOutputSizeExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionOutputSizeExceedsLimitError ctx) = D1 (' MetaData "SelectionOutputSizeExceedsLimitError" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "SelectionOutputSizeExceedsLimitError" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "outputThatExceedsLimit") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Address ctx, TokenBundle ))))

data SelectionOutputTokenQuantityExceedsLimitError ctx Source #

Indicates that a token quantity exceeds the maximum quantity that can appear in a transaction output's token bundle.

Constructors

SelectionOutputTokenQuantityExceedsLimitError

Fields

Instances

Instances details
SelectionContext ctx => Eq ( SelectionOutputTokenQuantityExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionOutputTokenQuantityExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionOutputTokenQuantityExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

IsServerError ( SelectionOutputTokenQuantityExceedsLimitError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

type Rep ( SelectionOutputTokenQuantityExceedsLimitError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionOutputTokenQuantityExceedsLimitError ctx) = D1 (' MetaData "SelectionOutputTokenQuantityExceedsLimitError" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionOutputTokenQuantityExceedsLimitError" ' PrefixI ' True ) (( S1 (' MetaSel (' Just "address") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( Address ctx)) :*: S1 (' MetaSel (' Just "asset") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 AssetId )) :*: ( S1 (' MetaSel (' Just "quantity") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 TokenQuantity ) :*: S1 (' MetaSel (' Just "quantityMaxBound") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 TokenQuantity ))))

Verification of post conditions

Verification of selections and selection errors

verifySelection :: SelectionContext ctx => VerifySelection ctx Source #

Verifies a Selection for correctness.

This function is provided primarily as a convenience for testing. As such, it's not usually necessary to call this function from ordinary application code, unless you suspect that a Selection is incorrect in some way.

verifySelectionError :: SelectionContext ctx => VerifySelectionError ( SelectionError ctx) ctx Source #

Verifies a SelectionError for correctness.

This function is provided primarily as a convenience for testing. As such, it's not usually necessary to call this function from ordinary application code, unless you suspect that a SelectionError is incorrect in some way.

Selection deltas

data SelectionDelta a Source #

Indicates the difference between total input value and total output value of a SelectionResult .

There are two possibilities:

Indicates a surplus, when the total input value is greater than or equal to the total output value.

Indicates a deficit, when the total input value is NOT greater than or equal to the total output value.

selectionHasValidSurplus :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool Source #

Indicates whether or not a selection has a valid surplus.

This function returns True if and only if the selection has a delta that is a *surplus*, and that surplus is greater than or equal to the result of selectionMinimumCost .

See SelectionDelta .

selectionMinimumCost :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin Source #

Computes the minimum required cost of a selection.

selectionSurplusCoin :: Selection ctx -> Coin Source #

Calculates the ada selection surplus, assuming there is a surplus.

If there is a surplus, then this function returns that surplus. If there is a deficit, then this function returns zero.

Use selectionDeltaCoin if you wish to handle the case where there is a deficit.

Selection collateral

data SelectionCollateralError ctx Source #

Represents an unsuccessful attempt to select collateral.

Constructors

SelectionCollateralError

Fields

Instances

Instances details
SelectionContext ctx => Eq ( SelectionCollateralError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

SelectionContext ctx => Show ( SelectionCollateralError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ( SelectionCollateralError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

IsServerError ( SelectionCollateralError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

type Rep ( SelectionCollateralError ctx) Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ( SelectionCollateralError ctx) = D1 (' MetaData "SelectionCollateralError" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionCollateralError" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "largestCombinationAvailable") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( Map ( UTxO ctx) Coin )) :*: S1 (' MetaSel (' Just "minimumSelectionAmount") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin )))

data SelectionCollateralRequirement Source #

Indicates the collateral requirement for a selection.

Constructors

SelectionCollateralRequired

Indicates that collateral is required.

SelectionCollateralNotRequired

Indicates that collateral is not required.

Instances

Instances details
Bounded SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Enum SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Eq SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Show SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep SelectionCollateralRequirement Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep SelectionCollateralRequirement = D1 (' MetaData "SelectionCollateralRequirement" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "SelectionCollateralRequired" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "SelectionCollateralNotRequired" ' PrefixI ' False ) ( U1 :: Type -> Type ))

selectionCollateral :: Selection ctx -> Coin Source #

Computes the total amount of collateral within a selection.

selectionCollateralRequired :: SelectionParams ctx -> Bool Source #

Indicates True if and only if collateral is required.

selectionHasSufficientCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Bool Source #

Indicates whether or not a selection has sufficient collateral.

selectionMinimumCollateral :: SelectionConstraints ctx -> SelectionParams ctx -> Selection ctx -> Coin Source #

Computes the minimum required amount of collateral for a selection.

Internal types and functions

data ComputeMinimumCollateralParams Source #

Instances

Instances details
Eq ComputeMinimumCollateralParams Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Show ComputeMinimumCollateralParams Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

Generic ComputeMinimumCollateralParams Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ComputeMinimumCollateralParams Source #
Instance details

Defined in Cardano.Wallet.CoinSelection.Internal

type Rep ComputeMinimumCollateralParams = D1 (' MetaData "ComputeMinimumCollateralParams" "Cardano.Wallet.CoinSelection.Internal" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "ComputeMinimumCollateralParams" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "minimumCollateralPercentage") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Natural ) :*: S1 (' MetaSel (' Just "transactionFee") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Coin )))

computeMinimumCollateral :: ComputeMinimumCollateralParams -> Coin Source #

Computes the minimum required amount of collateral given a fee and a minimum collateral percentage.