diff --git a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs index a2944ca7879..ff5e2dafa95 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs @@ -246,8 +246,8 @@ toBalanceConstraintsParams (constraints, params) = -- there is still space available. -- adjustSelectionLimit :: SelectionLimit -> SelectionLimit - adjustSelectionLimit = fmap - (subtract (view #maximumCollateralInputCount constraints)) + adjustSelectionLimit = flip Balance.reduceSelectionLimitBy + (view #maximumCollateralInputCount constraints) balanceParams = Balance.SelectionParams { assetsToBurn = diff --git a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection/Balance.hs b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection/Balance.hs index d344d5b597f..44e313126e0 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/CoinSelection/Balance.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/CoinSelection/Balance.hs @@ -47,6 +47,7 @@ module Cardano.Wallet.Primitive.CoinSelection.Balance , SelectionLimitOf (..) , selectionLimitExceeded , SelectionLimitReachedError (..) + , reduceSelectionLimitBy -- * Querying selections , SelectionDelta (..) @@ -442,6 +443,21 @@ selectionLimitExceeded s = \case NoLimit -> False MaximumInputLimit n -> UTxOSelection.selectedSize s > n +-- | Reduces a selection limit by a given reduction amount. +-- +-- If the given reduction amount is positive, then this function will reduce +-- the selection limit by that amount. +-- +-- If the given reduction amount is zero or negative, then this function will +-- return the original limit unchanged. +-- +reduceSelectionLimitBy :: SelectionLimit -> Int -> SelectionLimit +reduceSelectionLimitBy limit reduction + | reduction <= 0 = + limit + | otherwise = + subtract reduction <$> limit + type SelectionResult = SelectionResultOf [TxOut] -- | The result of performing a successful selection.