Skip to content

Commit

Permalink
Remove constraints from ErrBalanceTx data type definition. (#4285)
Browse files Browse the repository at this point in the history
## Issue

ADP-3185

## Description

This PR removes all type class constraints from the `ErrBalanceTx` data
type hierarchy, and adds constraints back in only where necessary — at
the definitions of type class instances.

In practice, this only affects the `IsRecentEra` type class constraint.
  • Loading branch information
jonathanknowles authored Dec 1, 2023
2 parents 362600c + aa902ec commit 4c6db3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 8 additions & 12 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,11 @@ data ErrBalanceTxAssetsInsufficientError = ErrBalanceTxAssetsInsufficientError
deriving (Eq, Generic, Show)

data ErrBalanceTxInternalError era
= IsRecentEra era
=> ErrUnderestimatedFee Coin (Tx era) KeyWitnessCount
= ErrUnderestimatedFee Coin (Tx era) KeyWitnessCount
| ErrFailedBalancing Value

deriving instance Eq (ErrBalanceTxInternalError era)
deriving instance Show (ErrBalanceTxInternalError era)
deriving instance IsRecentEra era => Eq (ErrBalanceTxInternalError era)
deriving instance IsRecentEra era => Show (ErrBalanceTxInternalError era)

-- | Errors that can occur when balancing transactions.
data ErrBalanceTx era
Expand All @@ -418,15 +417,12 @@ data ErrBalanceTx era
| ErrBalanceTxExistingCollateral
| ErrBalanceTxExistingTotalCollateral
| ErrBalanceTxExistingReturnCollateral
| IsRecentEra era
=> ErrBalanceTxInsufficientCollateral
| ErrBalanceTxInsufficientCollateral
(ErrBalanceTxInsufficientCollateralError era)
| ErrBalanceTxConflictingNetworks
| ErrBalanceTxAssignRedeemers ErrAssignRedeemers
| IsRecentEra era
=> ErrBalanceTxInternalError (ErrBalanceTxInternalError era)
| IsRecentEra era
=> ErrBalanceTxInputResolutionConflicts
| ErrBalanceTxInternalError (ErrBalanceTxInternalError era)
| ErrBalanceTxInputResolutionConflicts
(NonEmpty (TxOut era, TxOut era))
| ErrBalanceTxUnresolvedInputs (NonEmpty TxIn)
| ErrBalanceTxOutputError ErrBalanceTxOutputError
Expand All @@ -437,8 +433,8 @@ data ErrBalanceTx era
-- - the given UTxO index is empty.
-- A transaction must have at least one input in order to be valid.

deriving instance Eq (ErrBalanceTx era)
deriving instance Show (ErrBalanceTx era)
deriving instance IsRecentEra era => Eq (ErrBalanceTx era)
deriving instance IsRecentEra era => Show (ErrBalanceTx era)

-- | A 'PartialTx' is an an unbalanced 'SealedTx' along with the necessary
-- information to balance it.
Expand Down
4 changes: 3 additions & 1 deletion lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ instance Write.IsRecentEra era => IsServerError (ErrBalanceTx era) where
, "or sending a smaller amount."
]

instance forall era. IsServerError (ErrBalanceTxInternalError era) where
instance
Write.IsRecentEra era => IsServerError (ErrBalanceTxInternalError era)
where
toServerError = \case
ErrUnderestimatedFee coin candidateTx (KeyWitnessCount nWits nBootWits) ->
apiError err500 (BalanceTxUnderestimatedFee info) $ T.unwords
Expand Down

0 comments on commit 4c6db3c

Please sign in to comment.