Skip to content

Commit

Permalink
Within UTxOSelection rename availableUTxO to availableMap.
Browse files Browse the repository at this point in the history
This fixes a slight inconsistency in the API, making `availableMap`
consistent with `leftoverMap` and `selectedMap`.
  • Loading branch information
jonathanknowles committed Feb 25, 2022
1 parent 7120457 commit be299f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ selectAssets ctx pp params transform = do
guardPendingWithdrawal
lift $ traceWith tr $ MsgSelectionStart
(inputMapToUTxO
$ UTxOSelection.availableUTxO
$ UTxOSelection.availableMap
$ params ^. #utxoAvailableForInputs)
(params ^. #outputs)
let selectionConstraints = SelectionConstraints
Expand Down
10 changes: 5 additions & 5 deletions lib/core/src/Cardano/Wallet/Primitive/Types/UTxOSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module Cardano.Wallet.Primitive.Types.UTxOSelection

-- * Accessor functions
, availableBalance
, availableUTxO
, availableMap
, leftoverBalance
, leftoverSize
, leftoverIndex
Expand Down Expand Up @@ -325,7 +325,7 @@ isProperSubSelectionOf s1 s2 = state s1 /= state s2 && s1 `isSubSelectionOf` s2
availableBalance :: IsUTxOSelection s u => s u -> TokenBundle
availableBalance s = leftoverBalance s <> selectedBalance s

-- | Computes the available UTxO set.
-- | Computes the complete map of all available UTxOs.
--
-- The available UTxO set is the union of the selected and leftover UTxO sets.
--
Expand All @@ -334,10 +334,10 @@ availableBalance s = leftoverBalance s <> selectedBalance s
-- This result of this function remains constant over applications of 'select'
-- and 'selectMany':
--
-- >>> availableUTxO s == availableUTxO (selectMany is s)
-- >>> availableMap s == availableMap (selectMany is s)
--
availableUTxO :: IsUTxOSelection s u => Ord u => s u -> Map u TokenBundle
availableUTxO s = leftoverMap s <> selectedMap s
availableMap :: IsUTxOSelection s u => Ord u => s u -> Map u TokenBundle
availableMap s = leftoverMap s <> selectedMap s

-- | Retrieves the balance of leftover UTxOs.
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ spec =

parallel $ describe "Indicator and accessor functions" $ do

it "prop_availableBalance_availableUTxO" $
property prop_availableBalance_availableUTxO
it "prop_availableBalance_availableMap" $
property prop_availableBalance_availableMap
it "prop_isNonEmpty_selectedSize" $
property prop_isNonEmpty_selectedSize
it "prop_isNonEmpty_selectedIndex" $
Expand All @@ -128,8 +128,8 @@ spec =
property prop_select_isProperSubSelectionOf
it "prop_select_availableBalance" $
property prop_select_availableBalance
it "prop_select_availableUTxO" $
property prop_select_availableUTxO
it "prop_select_availableMap" $
property prop_select_availableMap
it "prop_select_leftoverSize" $
property prop_select_leftoverSize
it "prop_select_selectedSize" $
Expand Down Expand Up @@ -249,11 +249,11 @@ prop_toNonEmpty_fromNonEmpty s =
-- Indicator and accessor functions
--------------------------------------------------------------------------------

prop_availableBalance_availableUTxO :: UTxOSelection InputId -> Property
prop_availableBalance_availableUTxO s =
prop_availableBalance_availableMap :: UTxOSelection InputId -> Property
prop_availableBalance_availableMap s =
checkCoverage_UTxOSelection s $
UTxOSelection.availableBalance s
=== F.fold (UTxOSelection.availableUTxO s)
=== F.fold (UTxOSelection.availableMap s)

prop_isNonEmpty_selectedSize :: UTxOSelection InputId -> Property
prop_isNonEmpty_selectedSize s =
Expand Down Expand Up @@ -335,13 +335,13 @@ prop_select_availableBalance i s =
then Just (UTxOSelection.availableBalance s)
else Nothing

prop_select_availableUTxO :: InputId -> UTxOSelection InputId -> Property
prop_select_availableUTxO i s =
prop_select_availableMap :: InputId -> UTxOSelection InputId -> Property
prop_select_availableMap i s =
checkCoverage_select i s $
(UTxOSelection.availableUTxO <$> UTxOSelection.select i s)
(UTxOSelection.availableMap <$> UTxOSelection.select i s)
===
if UTxOSelection.isLeftover i s
then Just (UTxOSelection.availableUTxO s)
then Just (UTxOSelection.availableMap s)
else Nothing

prop_select_leftoverSize :: InputId -> UTxOSelection InputId -> Property
Expand Down

0 comments on commit be299f5

Please sign in to comment.