Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependency constraints on cardano-coin-selection #4995

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions lib/coin-selection/cardano-coin-selection.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@ library
hs-source-dirs: lib

build-depends:
, base
, base >= 4.14 && < 5
, cardano-numeric
, cardano-wallet-primitive
, cardano-wallet-test-utils
, containers
, deepseq
, exact-combinatorics
, extra
, generic-lens
, generics-sop
, int-cast
, lattices
, math-functions
, MonadRandom
, monoid-subclasses
, monoidmap
, QuickCheck
, transformers
, containers >= 0.5 && < 0.8
, deepseq >= 1.4.4 && < 1.6
, exact-combinatorics >= 0.2 && < 0.3
, generic-lens >= 2.2.2.0 && < 2.3
, generics-sop >= 0.5.1.4 && < 0.6
, int-cast >= 0.2.0.0 && < 0.3
, lattices >= 2.2 && < 2.3
, math-functions >= 0.3.4.4 && < 0.4
, MonadRandom >= 0.6 && < 0.7
, monoid-subclasses >= 1.2.5.1 && < 1.3
, monoidmap >= 0.0.1.6 && < 0.1
, QuickCheck >= 2.14 && < 2.16
, transformers >= 0.6.1.0 && < 0.7

exposed-modules:
Cardano.CoinSelection
Expand All @@ -79,29 +78,29 @@ test-suite test
main-is: run-test-suite.hs
build-depends:
, base
, bytestring
, bytestring >= 0.10.6 && < 0.13
, cardano-coin-selection
, cardano-numeric
, cardano-wallet-primitive
, cardano-wallet-test-utils
, containers
, fmt
, fmt >= 0.6.3 && < 0.7
, generic-lens
, generics-sop
, hspec
, hspec >= 2.11.0 && < 2.12
, hspec-core
, int-cast
, lattices
, MonadRandom
, monoid-subclasses
, pretty-simple
, pretty-simple >= 4.1.2.0 && < 4.2
, QuickCheck
, quickcheck-classes
, quickcheck-quid
, safe
, text
, transformers
, with-utf8
, quickcheck-classes >= 0.6.5 && < 0.7
, quickcheck-quid >= 0.0.1.5 && < 0.1
, safe >= 0.3.19 && < 0.4
, text >= 1.2 && < 2.2
, transformers >= 0.6.1.0 && < 0.7
, with-utf8 >= 1.1.0 && < 1.2
build-tool-depends: hspec-discover:hspec-discover
other-modules:
Cardano.CoinSelection.BalanceSpec
Expand All @@ -128,7 +127,7 @@ benchmark utxo-index
, cardano-wallet-test-utils
, containers
, deepseq
, format-numbers
, format-numbers >= 0.1.0.1 && < 0.2
, QuickCheck
, tasty-bench
, tasty-bench >= 0.4 && < 0.5
, text
19 changes: 8 additions & 11 deletions lib/coin-selection/lib/Cardano/CoinSelection/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,15 @@ import Cardano.Wallet.Primitive.Types.TokenMap
import Cardano.Wallet.Primitive.Types.TokenQuantity
( TokenQuantity (..)
)
import Control.Monad.Extra
( andM
, (<=<)
import Control.Monad
( (<=<)
)
import Control.Monad.Random.Class
( MonadRandom (..)
)
import Data.Bifunctor
( first
)
import Data.Either.Extra
( maybeToEither
)
import Data.Function
( (&)
)
Expand Down Expand Up @@ -594,11 +590,11 @@ selectionHasValidSurplus constraints selection =
SelectionDeficit _ -> False
where
surplusIsValid :: TokenBundle -> Bool
surplusIsValid = andM
[ surplusHasNoNonAdaAssets
surplusIsValid tokenBundle = all ($ tokenBundle)
([ surplusHasNoNonAdaAssets
, surplusNotBelowMinimumCost
, surplusNotAboveMaximumCost
]
] :: [TokenBundle -> Bool])

-- None of the non-ada assets can have a surplus.
surplusHasNoNonAdaAssets :: TokenBundle -> Bool
Expand Down Expand Up @@ -1344,8 +1340,9 @@ makeChange criteria
totalOutputCoinValueIsZero
| otherwise =
first mkUnableToConstructChangeError $ do
adaAvailable <- maybeToEither
(requiredCost <\> excessCoin)
adaAvailable <- maybe
(Left $ requiredCost <\> excessCoin)
Right
(excessCoin </> requiredCost)
assignCoinsToChangeMaps
adaAvailable minCoinFor changeMapOutputCoinPairs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ import Prelude hiding
import Control.DeepSeq
( NFData
)
import Control.Monad.Extra
( firstJustM
)
import Control.Monad.Random.Class
( MonadRandom (..)
)
Expand Down Expand Up @@ -497,6 +494,10 @@ selectRandomWithPriority
-> m (Maybe ((u, W.TokenBundle), UTxOIndex u))
selectRandomWithPriority i =
firstJustM (selectRandom i) . NE.toList
where
firstJustM _ [] = pure Nothing
firstJustM p (x:xs) =
maybe (firstJustM p xs) (pure . Just) =<< p x

--------------------------------------------------------------------------------
-- Internal Interface
Expand Down
Loading