From 4a273e29f143c6e44fc135e2615b270acdd992f4 Mon Sep 17 00:00:00 2001 From: v0d1ch Date: Wed, 12 Jun 2024 12:44:39 +0200 Subject: [PATCH] Improve splitUTxO --- hydra-node/src/Hydra/Chain/Direct/State.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index 3f11119eacf..27b7757b6c6 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -1040,9 +1040,9 @@ genDecrementTx numParties = do splitUTxO :: UTxO -> (UTxO, UTxO) splitUTxO utxo = let pairs = UTxO.pairs utxo - toDecommit = List.head $ List.filter ((> 0) . selectLovelace . txOutValue . snd) pairs - restOfUTxO = List.filter ((fst toDecommit /=) . fst) pairs - in (UTxO.fromPairs restOfUTxO, UTxO.singleton toDecommit) + in case uncons $ List.filter ((> 0) . selectLovelace . txOutValue . snd) pairs of + Nothing -> (mempty, mempty) + Just (toDecommit, rest) -> (UTxO.fromPairs rest, UTxO.singleton toDecommit) genCloseTx :: Int -> Gen (ChainContext, OpenState, Tx, ConfirmedSnapshot Tx) genCloseTx numParties = do