Skip to content

Commit

Permalink
fixup! BalancingError with explicit script evaluation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
choener committed Jan 30, 2025
1 parent fa2993b commit e643786
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/coin-selection/lib/Convex/CoinSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,15 @@ data BalancingError era
= BalancingError Text
| -- | A single type of balancing error is treated specially: the type with
-- 'C.ScriptExecutionError's.
-- TODO: I would like to retain the actual error structure, but this collides (quite massively)
-- with the required JSON encoding / decoding.
ScriptExecutionErr Text -- [(C.ScriptWitnessIndex, C.ScriptExecutionError)]
ScriptExecutionErr [(C.ScriptWitnessIndex, C.ScriptExecutionError)]
| CheckMinUtxoValueError (C.TxOut C.CtxTx era) C.Quantity
| BalanceCheckError (BalancingError era)
| ComputeBalanceChangeError
deriving stock (Show, Generic)
deriving anyclass (ToJSON, FromJSON)

-- TODO: I would like to retain the actual error structure in ScriptExecutionError, but this collides (quite massively)
-- with the required JSON encoding / decoding.
-- deriving anyclass (ToJSON, FromJSON)

makeClassyPrisms ''BalancingError

Expand All @@ -238,7 +239,7 @@ data constructor.
balancingError :: (MonadError (BalancingError era) m) => Either (C.TxBodyErrorAutoBalance era) a -> m a
balancingError = \case
Right a -> pure a
Left err@(C.TxBodyScriptExecutionError _es) -> throwError $ ScriptExecutionErr (asText err)
Left (C.TxBodyScriptExecutionError es) -> throwError $ ScriptExecutionErr es
Left err -> throwError . BalancingError $ asText err
where
asText = Text.pack . C.docToString . C.prettyError
Expand Down Expand Up @@ -646,7 +647,8 @@ data BalanceTxError era
= ACoinSelectionError CoinSelectionError
| ABalancingError (BalancingError era)
deriving stock (Show, Generic)
deriving anyclass (ToJSON, FromJSON)

-- deriving anyclass (ToJSON, FromJSON)

makeClassyPrisms ''BalanceTxError

Expand Down

0 comments on commit e643786

Please sign in to comment.