Skip to content

Commit

Permalink
Merge #3157
Browse files Browse the repository at this point in the history
3157: Parameterize UTxO identifier type in internal coin selection modules. r=Anviking a=jonathanknowles

## Issue Number

ADP-1478

## Summary

This PR parameterizes the UTxO identifier type in all modules within the `CoinSelection.Internal` hierarchy.

As before, we use the type parameter `u` to represent the type of unique identifiers for individual UTxOs (unspent transaction outputs).

In general, callers of coin selection can instantiate `u` to any type for which there is an `Ord` instance.

## Not tackled by this PR

A future PR will update the test suite to use a more general type of UTxO identifier. For now, we continue to generate arbitrary values of `(TxIn, Address)` to act as UTxO identifiers.

Co-authored-by: Jonathan Knowles <[email protected]>
  • Loading branch information
iohk-bors[bot] and jonathanknowles authored Feb 25, 2022
2 parents 32b3915 + be299f5 commit cc0f201
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 345 deletions.
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ selectAssets ctx pp params transform = do
guardPendingWithdrawal
lift $ traceWith tr $ MsgSelectionStart
(inputMapToUTxO
$ UTxOSelection.availableUTxO
$ UTxOSelection.availableMap
$ params ^. #utxoAvailableForInputs)
(params ^. #outputs)
let selectionConstraints = SelectionConstraints
Expand Down Expand Up @@ -3242,7 +3242,7 @@ data ErrSelectAssets
= ErrSelectAssetsPrepareOutputsError SelectionOutputError
| ErrSelectAssetsNoSuchWallet ErrNoSuchWallet
| ErrSelectAssetsAlreadyWithdrawing Tx
| ErrSelectAssetsSelectionError SelectionError
| ErrSelectAssetsSelectionError (SelectionError InputId)
deriving (Generic, Eq, Show)

data ErrStakePoolDelegation
Expand Down Expand Up @@ -3392,7 +3392,7 @@ data WalletFollowLog
-- | Log messages from API server actions running in a wallet worker context.
data WalletLog
= MsgSelectionStart UTxO [TxOut]
| MsgSelectionError SelectionError
| MsgSelectionError (SelectionError InputId)
| MsgSelectionReportSummarized SelectionReportSummarized
| MsgSelectionReportDetailed SelectionReportDetailed
| MsgMigrationUTxOBefore UTxOStatistics
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4387,7 +4387,7 @@ instance IsServerError ErrSelectAssets where
ErrSelectAssetsSelectionError (SelectionOutputErrorOf e) ->
toServerError e

instance IsServerError (SelectionBalanceError) where
instance IsServerError (SelectionBalanceError (TxIn, Address)) where
toServerError = \case
BalanceInsufficient e ->
apiError err403 NotEnoughMoney $ mconcat
Expand Down Expand Up @@ -4430,7 +4430,7 @@ instance IsServerError (SelectionBalanceError) where
, "required in order to create a transaction."
]

instance IsServerError SelectionCollateralError where
instance IsServerError (SelectionCollateralError (TxIn, Address)) where
toServerError e =
apiError err403 InsufficientCollateral $ T.unwords
[ "I'm unable to create this transaction because the balance"
Expand Down
9 changes: 5 additions & 4 deletions lib/core/src/Cardano/Wallet/CoinSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ data SelectionParams = SelectionParams
}
deriving (Eq, Generic, Show)

toInternalSelectionParams :: SelectionParams -> Internal.SelectionParams
toInternalSelectionParams :: SelectionParams -> Internal.SelectionParams InputId
toInternalSelectionParams SelectionParams {..} =
Internal.SelectionParams
{ utxoAvailableForCollateral =
Expand Down Expand Up @@ -328,7 +328,8 @@ data SelectionOf change = Selection
--
type Selection = SelectionOf TokenBundle

toExternalSelection :: SelectionParams -> Internal.Selection -> Selection
toExternalSelection
:: SelectionParams -> Internal.Selection InputId -> Selection
toExternalSelection _ps Internal.Selection {..} =
Selection
{ collateral =
Expand All @@ -345,7 +346,7 @@ toExternalSelection _ps Internal.Selection {..} =
toInternalSelection
:: (change -> TokenBundle)
-> SelectionOf change
-> Internal.Selection
-> Internal.Selection InputId
toInternalSelection getChangeBundle Selection {..} =
Internal.Selection
{ change = getChangeBundle
Expand Down Expand Up @@ -378,7 +379,7 @@ performSelection
:: (HasCallStack, MonadRandom m)
=> SelectionConstraints
-> SelectionParams
-> ExceptT SelectionError m Selection
-> ExceptT (SelectionError InputId) m Selection
performSelection cs ps =
toExternalSelection ps <$>
Internal.performSelection
Expand Down
Loading

0 comments on commit cc0f201

Please sign in to comment.