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

Allow constructing change output from _any_ input #2484

Merged
merged 1 commit into from
Feb 2, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,8 @@ performSelection minCoinValueFor costFor criteria
state <- runSelection
selectionLimit extraCoinSource utxoAvailable balanceRequired
let balanceSelected = fullBalance (selected state) extraCoinSource
if balanceRequired `leq` balanceSelected then do
let predictedChange = NE.toList $ predictChange (selected state)
makeChangeRepeatedly predictedChange state
if balanceRequired `leq` balanceSelected then
makeChangeRepeatedly state

else
pure $ Left $ SelectionInsufficient $ SelectionInsufficientError
Expand Down Expand Up @@ -494,11 +493,11 @@ performSelection minCoinValueFor costFor criteria
-- ada-only inputs are available.
--
makeChangeRepeatedly
:: [Set AssetId]
-> SelectionState
:: SelectionState
-> m (Either SelectionError (SelectionResult TokenBundle))
makeChangeRepeatedly changeSkeleton s@SelectionState{selected,leftover} = do
makeChangeRepeatedly s@SelectionState{selected,leftover} = do
let inputsSelected = mkInputsSelected selected
let changeSkeleton = NE.toList $ predictChange selected
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved this here inside the function body because now, it is possible for the predicted change to change on each iteration due to the selection of new multi-asset outputs.


let cost = costFor SelectionSkeleton
{ inputsSkeleton = selected
Expand All @@ -523,15 +522,14 @@ performSelection minCoinValueFor costFor criteria
, utxoRemaining = leftover
}

Left changeErr ->
let
selectionErr = Left $ UnableToConstructChange changeErr
in
selectMatchingQuantity selectionLimit (WithAdaOnly :| []) s
>>=
maybe
(pure selectionErr)
(makeChangeRepeatedly changeSkeleton)
Left changeErr -> do
result <- s &
selectMatchingQuantity selectionLimit (WithAdaOnly :| [ Any ])
case result of
Nothing ->
pure $ Left $ UnableToConstructChange changeErr
Just s' ->
makeChangeRepeatedly s'

invariantSelectAnyInputs =
-- This should be impossible, as we have already determined
Expand Down