Skip to content

Commit

Permalink
Clarify auxilliary function definitions in RoundRobinSpec.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jul 6, 2021
1 parent 0026cfc commit efdf9a6
Showing 1 changed file with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,22 +614,18 @@ genSelectionCriteria genUTxOIndex = do
, assetsToMint
, assetsToBurn
}

where
-- We look at a UTxO and remove from it the outputs we need to cover,
-- whatever is leftover we can choose to burn.
availableTokensToBurn
:: UTxOIndex
-> NonEmpty TxOut
-> [(AssetId, TokenQuantity)]
availableTokensToBurn index outputsToCover =
let
(TokenBundle _ availableTokens) =
UTxOIndex.balance index
`TokenBundle.difference`
F.foldMap (view #tokens) outputsToCover
in
TokenMap.toFlatList availableTokens
availableTokensToBurn index outputsToCover
= TokenMap.toFlatList
$ TokenMap.difference
(view #tokens $ UTxOIndex.balance index)
(F.foldMap (view (#tokens . #tokens)) outputsToCover)

-- If a token is spent or burnt, it is typically satisfied by the UTxO.
-- However, we can choose to instead mint those tokens and have the mint
Expand All @@ -638,14 +634,11 @@ genSelectionCriteria genUTxOIndex = do
:: NonEmpty TxOut
-> TokenMap
-> [(AssetId, TokenQuantity)]
allSpentOrBurntTokens outputsToCover burntTokens =
let
(TokenBundle _ requestedTokens) =
F.foldMap (view #tokens) outputsToCover
in
TokenMap.toFlatList $ burntTokens <> requestedTokens


allSpentOrBurntTokens outputsToCover burnedTokens
= TokenMap.toFlatList
$ TokenMap.add
(burnedTokens)
(F.foldMap (view (#tokens. #tokens)) outputsToCover)

balanceSufficient :: SelectionCriteria -> Bool
balanceSufficient criteria =
Expand Down Expand Up @@ -1774,7 +1767,6 @@ genMakeChangeData = flip suchThat isValidMakeChangeData $ do
<*> pure outputBundles
<*> pure assetsToMint
<*> pure assetsToBurn

where
genTokenBundles :: Int -> Gen (NonEmpty TokenBundle)
genTokenBundles count = (:|)
Expand All @@ -1785,12 +1777,11 @@ genMakeChangeData = flip suchThat isValidMakeChangeData $ do
:: NonEmpty TokenBundle
-> NonEmpty TokenBundle
-> [(AssetId, TokenQuantity)]
difference' a b =
let
(TokenBundle _ availableTokens) =
F.fold a `TokenBundle.difference` F.fold b
in
TokenMap.toFlatList availableTokens
difference' a b
= TokenMap.toFlatList
$ TokenMap.difference
(F.foldMap (view #tokens) a)
(F.foldMap (view #tokens) b)

makeChangeWith
:: MakeChangeData
Expand Down

0 comments on commit efdf9a6

Please sign in to comment.