@@ -125,9 +125,9 @@ capUTxO utxo target
125
125
-- \| Helper function to recursively select and split UTxO outputs to reach the target value.
126
126
go foundSoFar leftovers currentSum sorted
127
127
| currentSum == target = (foundSoFar, leftovers)
128
- | otherwise = case take 1 sorted of
128
+ | otherwise = case sorted of
129
129
[] -> (foundSoFar, leftovers)
130
- (txIn, txOut) : _ ->
130
+ (txIn, txOut) : rest ->
131
131
let x = selectLovelace (txOutValue txOut)
132
132
in if currentSum + x <= target
133
133
then
@@ -136,7 +136,7 @@ capUTxO utxo target
136
136
(foundSoFar <> UTxO. singleton txIn txOut)
137
137
(UTxO. difference leftovers $ UTxO. singleton txIn txOut)
138
138
(currentSum + x)
139
- (removeOne (txIn, txOut) sorted)
139
+ rest
140
140
else
141
141
-- Split the output to meet the target exactly.
142
142
let cappedValue = target - currentSum
@@ -147,11 +147,7 @@ capUTxO utxo target
147
147
(foundSoFar <> UTxO. singleton txIn cappedTxOut)
148
148
(UTxO. difference leftovers (UTxO. singleton txIn txOut) <> UTxO. singleton txIn leftoverTxOut)
149
149
(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
155
151
156
152
-- | Helper to create a new TxOut with a specified lovelace value
157
153
updateTxOutValue :: TxOut ctx -> Coin -> TxOut ctx
0 commit comments