Skip to content

Commit

Permalink
Rename {to,from}UTxO to {to,from}Map in module UTxOIndex.
Browse files Browse the repository at this point in the history
These names better reflect the types involved.
  • Loading branch information
jonathanknowles committed Feb 23, 2022
1 parent dced45c commit 6d8a198
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ balanceTransaction
(internalUtxoAvailable, externalSelectedUtxo)

let utxoAvailableForCollateral =
UTxOIndex.toUTxO internalUtxoAvailable
UTxOIndex.toMap internalUtxoAvailable

-- NOTE: It is not possible to know the script execution cost in
-- advance because it actually depends on the final transaction. Inputs
Expand Down Expand Up @@ -1868,7 +1868,7 @@ readWalletUTxOIndex
-> ExceptT ErrNoSuchWallet IO (UTxOIndex InputId, Wallet s, Set Tx)
readWalletUTxOIndex ctx wid = do
(cp, _, pending) <- readWallet @ctx @s @k ctx wid
let utxo = UTxOIndex.fromUTxO $ utxoToInputMap $ availableUTxO @s pending cp
let utxo = UTxOIndex.fromMap $ utxoToInputMap $ availableUTxO @s pending cp
return (utxo, cp, pending)

-- | Calculate the minimum coin values required for a bunch of specified
Expand Down
18 changes: 9 additions & 9 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ selectCoins ctx genChange (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
transform
Expand Down Expand Up @@ -1653,7 +1653,7 @@ selectCoinsForJoin ctx knownPools getPoolStatus pid wid = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
transform
Expand Down Expand Up @@ -1706,7 +1706,7 @@ selectCoinsForQuit ctx (ApiT wid) = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
transform
Expand Down Expand Up @@ -1974,7 +1974,7 @@ postTransactionOld ctx genChange (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
(const Prelude.id)
Expand Down Expand Up @@ -2122,7 +2122,7 @@ postTransactionFeeOld ctx (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
} getFee
where getFee = const (selectionDelta TokenBundle.getCoin)
Expand Down Expand Up @@ -2227,7 +2227,7 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
} transform

Expand Down Expand Up @@ -2587,7 +2587,7 @@ joinStakePool ctx knownPools getPoolStatus apiPoolId (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
(const Prelude.id)
Expand Down Expand Up @@ -2652,7 +2652,7 @@ delegationFee ctx (ApiT wid) = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
} calcFee
where
Expand Down Expand Up @@ -2702,7 +2702,7 @@ quitStakePool ctx (ApiT wid) body = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
}
(const Prelude.id)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Primitive/Types/UTxOIndex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ module Cardano.Wallet.Primitive.Types.UTxOIndex
-- * Construction
, empty
, singleton
, fromMap
, fromSequence
, fromUTxO

-- * Deconstruction
, toList
, toUTxO
, toMap

-- * Folding
, fold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ module Cardano.Wallet.Primitive.Types.UTxOIndex.Internal
, empty
, singleton
, fromSequence
, fromUTxO
, fromMap

-- * Deconstruction
, toList
, toUTxO
, toMap

-- * Folding
, fold
Expand Down Expand Up @@ -215,8 +215,8 @@ fromSequence = flip insertMany empty
-- Note that this operation is potentially expensive as it must construct an
-- index from scratch, and therefore should only be used sparingly.
--
fromUTxO :: Ord u => Map u TokenBundle -> UTxOIndex u
fromUTxO = fromSequence . Map.toList
fromMap :: Ord u => Map u TokenBundle -> UTxOIndex u
fromMap = fromSequence . Map.toList

--------------------------------------------------------------------------------
-- Deconstruction
Expand All @@ -233,8 +233,8 @@ toList = fold (\ubs u b -> (u, b) : ubs) []
--
-- Consider using 'fold' if your goal is to consume all entries in the output.
--
toUTxO :: UTxOIndex u -> Map u TokenBundle
toUTxO = universe
toMap :: UTxOIndex u -> Map u TokenBundle
toMap = universe

--------------------------------------------------------------------------------
-- Folding
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Primitive/Types/UTxOSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ leftoverIndex = leftover . state
-- | Retrieves the leftover UTxO set.
--
leftoverUTxO :: IsUTxOSelection u => u -> Map InputId TokenBundle
leftoverUTxO = UTxOIndex.toUTxO . leftoverIndex
leftoverUTxO = UTxOIndex.toMap . leftoverIndex

-- | Retrieves a list of the leftover UTxOs.
--
Expand All @@ -380,7 +380,7 @@ selectedIndex = selected . state
-- | Retrieves the selected UTxO set.
--
selectedUTxO :: IsUTxOSelection u => u -> Map InputId TokenBundle
selectedUTxO = UTxOIndex.toUTxO . selectedIndex
selectedUTxO = UTxOIndex.toMap . selectedIndex

--------------------------------------------------------------------------------
-- Modification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ checkCoverage_filter_partition f u
where
u1 `isNonEmptyProperSubsetOf` u2 =
not (UTxOIndex.null u1)
&& UTxOIndex.toUTxO u1 `Map.isSubmapOf` UTxOIndex.toUTxO u2
&& UTxOIndex.toMap u1 `Map.isSubmapOf` UTxOIndex.toMap u2
&& u1 /= u2

filterSize g = UTxOIndex.size . UTxOIndex.filter g
Expand Down
4 changes: 2 additions & 2 deletions lib/shelley/bench/restore-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ benchmarksRnd _ w wid wname benchname restoreTime = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
} getFee
runExceptT $ withExceptT show $ W.estimateFee runSelection
Expand Down Expand Up @@ -569,7 +569,7 @@ benchmarksSeq _ w wid _wname benchname restoreTime = do
, utxoAvailableForInputs =
UTxOSelection.fromIndex utxoAvailable
, utxoAvailableForCollateral =
UTxOIndex.toUTxO utxoAvailable
UTxOIndex.toMap utxoAvailable
, wallet
} getFee
runExceptT $ withExceptT show $ W.estimateFee runSelection
Expand Down

0 comments on commit 6d8a198

Please sign in to comment.