Skip to content

Commit

Permalink
parameterize 'SelectionResult' over the change's inner type
Browse files Browse the repository at this point in the history
  The reason for this is to be able to re-use the 'SelectionResult' at various stages in the wallet layer, before and after having assigned change address to each change output.
  It opens room for writing nice functions such as: 'assignChangeAddress :: SelectionResult TokenBundle -> s -> (s, SelectionResult TxOut)' which, from its type signature informs
  nicely about what it is doing.
  • Loading branch information
KtorZ committed Jan 26, 2021
1 parent 1ba9ea7 commit 589855d
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -175,12 +175,12 @@ data SelectionLimit

-- | The result of performing a successful selection.
--
data SelectionResult = SelectionResult
data SelectionResult change = SelectionResult
{ inputsSelected
:: !(NonEmpty (TxIn, TxOut))
-- ^ A (non-empty) list of inputs selected from 'utxoAvailable'.
, changeGenerated
:: !(NonEmpty TokenBundle)
:: !(NonEmpty change)
-- ^ A (non-empty) list of generated change outputs.
, utxoRemaining
:: !UTxOIndex
Expand Down Expand Up @@ -302,7 +302,7 @@ performSelection
-- individual asset quantities held within each change output.
-> SelectionCriteria
-- ^ The selection goal to satisfy.
-> m (Either SelectionError SelectionResult)
-> m (Either SelectionError (SelectionResult TokenBundle))
performSelection minCoinValueFor costFor criteria
| not (balanceRequired `leq` balanceAvailable) =
pure $ Left $ BalanceInsufficient $ BalanceInsufficientError
Expand Down Expand Up @@ -418,7 +418,7 @@ performSelection minCoinValueFor costFor criteria
makeChangeRepeatedly
:: NonEmpty (Set AssetId)
-> SelectionState
-> m (Either SelectionError SelectionResult)
-> m (Either SelectionError (SelectionResult TokenBundle))
makeChangeRepeatedly changeSkeleton s@SelectionState{selected,leftover} = do
let inputsSelected = mkInputsSelected selected

Expand Down

0 comments on commit 589855d

Please sign in to comment.