Skip to content

Commit 7914797

Browse files
vrom911v0d1ch
authored andcommitted
Remove usage of removeOne fn
1 parent b9faf88 commit 7914797

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

hydra-tx/src/Hydra/Tx/Deposit.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ capUTxO utxo target
125125
-- \| Helper function to recursively select and split UTxO outputs to reach the target value.
126126
go foundSoFar leftovers currentSum sorted
127127
| currentSum == target = (foundSoFar, leftovers)
128-
| otherwise = case take 1 sorted of
128+
| otherwise = case sorted of
129129
[] -> (foundSoFar, leftovers)
130-
(txIn, txOut) : _ ->
130+
(txIn, txOut) : rest ->
131131
let x = selectLovelace (txOutValue txOut)
132132
in if currentSum + x <= target
133133
then
@@ -136,7 +136,7 @@ capUTxO utxo target
136136
(foundSoFar <> UTxO.singleton txIn txOut)
137137
(UTxO.difference leftovers $ UTxO.singleton txIn txOut)
138138
(currentSum + x)
139-
(removeOne (txIn, txOut) sorted)
139+
rest
140140
else
141141
-- Split the output to meet the target exactly.
142142
let cappedValue = target - currentSum
@@ -147,11 +147,7 @@ capUTxO utxo target
147147
(foundSoFar <> UTxO.singleton txIn cappedTxOut)
148148
(UTxO.difference leftovers (UTxO.singleton txIn txOut) <> UTxO.singleton txIn leftoverTxOut)
149149
(currentSum + cappedValue)
150-
(removeOne (txIn, txOut) sorted)
151-
152-
-- \| Removes the first occurrence of a specific (TxIn, TxOut) pair from a list.
153-
removeOne :: (TxIn, TxOut CtxUTxO) -> [(TxIn, TxOut CtxUTxO)] -> [(TxIn, TxOut CtxUTxO)]
154-
removeOne x xs' = let (before, after) = break (== x) xs' in before ++ drop 1 after
150+
rest
155151

156152
-- | Helper to create a new TxOut with a specified lovelace value
157153
updateTxOutValue :: TxOut ctx -> Coin -> TxOut ctx

0 commit comments

Comments
 (0)