Skip to content

Commit 2590c3d

Browse files
Fix formatting
1 parent 768a23c commit 2590c3d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import Control.Monad.Trans.Either (EitherT, hoistEither, newEitherT, runEitherT)
2121
import Data.Coerce (coerce)
2222
import Data.Either.Combinators (rightToMaybe)
2323
import Data.Kind (Type)
24-
import Data.List (partition, (\\), find)
24+
import Data.List (find, partition, (\\))
2525
import Data.Map (Map)
2626
import Data.Map qualified as Map
27-
import Data.Maybe (fromMaybe, mapMaybe, isJust)
27+
import Data.Maybe (fromMaybe, isJust, mapMaybe)
2828
import Data.Set (Set)
2929
import Data.Set qualified as Set
3030
import Data.Text (Text)
@@ -281,22 +281,25 @@ balanceTxIns utxos tx = do
281281
(suboptimally we just pick a random utxo from the tx inputs)
282282
-}
283283
addTxCollaterals :: Map TxOutRef TxOut -> Tx -> Either Text Tx
284-
addTxCollaterals utxos tx = if not $ usesScripts tx then Right tx else do
285-
let txIns = mapMaybe (rightToMaybe . txOutToTxIn) $ Map.toList $ filterAdaOnly utxos
286-
txIn <- findPubKeyTxIn txIns
287-
pure $ tx {txCollateral = Set.singleton txIn}
284+
addTxCollaterals utxos tx =
285+
if not $ usesScripts tx
286+
then Right tx
287+
else do
288+
let txIns = mapMaybe (rightToMaybe . txOutToTxIn) $ Map.toList $ filterAdaOnly utxos
289+
txIn <- findPubKeyTxIn txIns
290+
pure $ tx {txCollateral = Set.singleton txIn}
288291
where
289292
findPubKeyTxIn = \case
290293
x@(TxIn _ (Just ConsumePublicKeyAddress)) : _ -> Right x
291294
x@(TxIn _ Nothing) : _ -> Right x
292295
_ : xs -> findPubKeyTxIn xs
293296
_ -> Left "There are no utxos to be used as collateral"
294297
filterAdaOnly = Map.filter (isAdaOnly . txOutValue)
295-
usesScripts Tx{txInputs, txMintScripts}
296-
= not (null txMintScripts)
298+
usesScripts Tx {txInputs, txMintScripts} =
299+
not (null txMintScripts)
297300
|| isJust
298-
(find (\TxIn{txInType} -> case txInType of { Just ConsumeScriptAddress{} -> True; _ -> False })
299-
$ Set.toList txInputs
301+
( find (\TxIn {txInType} -> case txInType of Just ConsumeScriptAddress {} -> True; _ -> False) $
302+
Set.toList txInputs
300303
)
301304

302305
-- | Ensures all non ada change goes back to user

0 commit comments

Comments
 (0)