Skip to content

Commit

Permalink
Add temporary helper function flattenErrBalanceTx.
Browse files Browse the repository at this point in the history
This temporary helper function maps nested errors to top-level errors.

We will remove it once there are no more nested errors.
  • Loading branch information
jonathanknowles committed Feb 6, 2023
1 parent ff13bf0 commit 2d31f57
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Write/Tx/Balance.hs
Expand Up @@ -149,6 +149,7 @@ import Text.Pretty.Simple
import qualified Cardano.Address.Script as CA
import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Tx.Balance.Internal.CoinSelection as CS
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.Coin as W
Expand Down Expand Up @@ -266,6 +267,44 @@ data ErrBalanceTx
| ErrOldEraNotSupported Cardano.AnyCardanoEra
deriving (Show, Eq)

-- | Converts nested 'ErrBalanceTx' errors to top-level errors.
--
-- This is a temporary function that will eventually go away, once we have
-- converted all nested errors to top-level errors.
--
-- Since converting all nested errors at once would give rise to a very large
-- change, this function allows us to convert them one at a time, allowing us
-- to create a series of smaller PRs that take us toward the target in smaller
-- steps, lowering the likelihood and/or difficulty of resolving conflicts.
--
-- TODO: [ADP-2540]
--
-- Remove this function once there are no more nested errors.
--
flattenErrBalanceTx :: ErrBalanceTx -> ErrBalanceTx
flattenErrBalanceTx = \case
ErrBalanceTxSelectAssets
(ErrSelectAssetsSelectionError
(SelectionBalanceErrorOf
(BalanceInsufficient err))) ->
convertBalanceInsufficientError err
anythingElse ->
anythingElse
where
convertBalanceInsufficientError
CS.BalanceInsufficientError
{ utxoBalanceAvailable
, utxoBalanceRequired
, utxoBalanceShortfall
}
=
ErrBalanceTxBalanceInsufficient
ErrBalanceTxBalanceInsufficientInfo
{ utxoBalanceAvailable
, utxoBalanceRequired
, utxoBalanceShortfall
}

-- | A 'PartialTx' is an an unbalanced 'SealedTx' along with the necessary
-- information to balance it.
--
Expand Down

0 comments on commit 2d31f57

Please sign in to comment.