Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jul 27, 2021
1 parent a6b2303 commit 3e3ce61
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/core/src/Cardano/Wallet/Primitive/CoinSelection/Collateral.hs
Expand Up @@ -92,14 +92,24 @@ selectCollateral params
[1 .. maximumCollateralEntryCount]

smallestValidCombinationOfSize :: Int -> Maybe (Map inputId Coin)
smallestValidCombinationOfSize size = coinsAvailable
& Map.toList
& (`subsequencesOfSize` size)
& fmap (\ics -> (ics, F.foldMap snd ics))
& L.dropWhile ((< minimumCollateralAmount) . snd)
& L.sortOn snd
& listToMaybe
& fmap (Map.fromList . fst)
smallestValidCombinationOfSize size = guardSearchSpaceSize $
coinsAvailable
& Map.toList
& (`subsequencesOfSize` size)
& fmap (\ics -> (ics, F.foldMap snd ics))
& L.dropWhile ((< minimumCollateralAmount) . snd)
& L.sortOn snd
& listToMaybe
& fmap (Map.fromList . fst)
where
guardSearchSpaceSize :: Maybe a -> Maybe a
guardSearchSpaceSize =
case (requiredSearchSpaceSize, maximumSearchSpaceSize) of
(r, Just m) | r > m -> const Nothing
_ -> id
where
requiredSearchSpaceSize =
Map.size coinsAvailable `numberOfSubsequencesOfSize` size

largestCombinationAvailable :: Map inputId Coin
largestCombinationAvailable = coinsAvailable
Expand All @@ -112,6 +122,7 @@ selectCollateral params
{ coinsAvailable
, minimumCollateralAmount
, maximumCollateralEntryCount
, maximumSearchSpaceSize
} = params

--------------------------------------------------------------------------------
Expand Down

0 comments on commit 3e3ce61

Please sign in to comment.