Skip to content

Commit

Permalink
Use multi-way if statement to clarify applyOurTxToUTxO.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Nov 30, 2021
1 parent edb39cc commit 09d571a
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions lib/core/src/Cardano/Wallet/Primitive/Model.hs
@@ -1,11 +1,13 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -554,26 +556,27 @@ applyOurTxToUTxO !slotNo !blockHeight !tx !prevUTxO = do
Just $ distance totalIn totalOut
(_, Incoming) ->
Nothing
return $ if hasKnownOutput && not hasKnownInput then
let dir = Incoming in
Just
( ( tx { fee = actualFee dir }
, mkTxMeta (TB.getCoin received) dir
)
, ourNextUTxO
)
else if hasKnownInput || hasKnownWithdrawal then
let adaSpent = TB.getCoin spent
adaReceived = TB.getCoin received
dir = if adaSpent > adaReceived then Outgoing else Incoming
amount = distance adaSpent adaReceived
in
Just
( (tx { fee = actualFee dir }, mkTxMeta amount dir)
, ourNextUTxO
)
else
Nothing
return if
| hasKnownOutput && not hasKnownInput ->
let dir = Incoming in
Just
( ( tx { fee = actualFee dir }
, mkTxMeta (TB.getCoin received) dir
)
, ourNextUTxO
)
| hasKnownInput || hasKnownWithdrawal ->
let adaSpent = TB.getCoin spent
adaReceived = TB.getCoin received
dir = if adaSpent > adaReceived then Outgoing else Incoming
amount = distance adaSpent adaReceived
in
Just
( (tx { fee = actualFee dir }, mkTxMeta amount dir)
, ourNextUTxO
)
| otherwise ->
Nothing
where
mkTxMeta :: Coin -> Direction -> TxMeta
mkTxMeta amount dir = TxMeta
Expand Down

0 comments on commit 09d571a

Please sign in to comment.