-
Notifications
You must be signed in to change notification settings - Fork 10
As patterns in offchain code #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,60 @@ | ||
| {-# LANGUAGE FlexibleInstances #-} | ||
| {-# LANGUAGE FunctionalDependencies #-} | ||
| {-# LANGUAGE TemplateHaskell #-} | ||
| {-| Error type for endpoints and queries | ||
| -} | ||
| module Wst.AppError( | ||
| AppError(..) | ||
| -- * Programmable token errors | ||
| ProgrammableTokensError(..), | ||
| AsProgrammableTokensError(..), | ||
|
|
||
| -- * WST App error | ||
| AppError(..), | ||
| AsAppError(..) | ||
| ) where | ||
|
|
||
| import Blockfrost.Client.Core (BlockfrostError) | ||
| import Convex.Class (ValidationError) | ||
| import Control.Lens (makeClassyPrisms) | ||
| import Convex.Class (AsValidationError (..), ValidationError) | ||
| import Convex.CoinSelection (AsBalanceTxError (..), AsCoinSelectionError (..)) | ||
| import Convex.CoinSelection qualified as CoinSelection | ||
| import PlutusLedgerApi.V3 (Credential) | ||
|
|
||
| data AppError era = | ||
| data ProgrammableTokensError = | ||
| OperatorNoUTxOs -- ^ The operator does not have any UTxOs | ||
| | GlobalParamsNodeNotFound -- ^ The node with the global parameters was not found | ||
| | BalancingError (CoinSelection.BalanceTxError era) | ||
| | BlockfrostErr BlockfrostError | ||
| -- TODO: The following errors are specific to the regulated stablecoin | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here one would wrap some
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I'll split up the type in another PR. |
||
| -- They should be separated out | ||
| | NoTokensToSeize -- ^ No tokens to seize | ||
| | DuplicateBlacklistNode -- ^ Attempting to add a duplicate blacklist node | ||
| | BlacklistNodeNotFound -- ^ Attempting to remove a blacklist node that does not exist | ||
| | TransferBlacklistedCredential Credential -- ^ Attempting to transfer funds from a blacklisted address | ||
| deriving stock (Show) | ||
|
|
||
| makeClassyPrisms ''ProgrammableTokensError | ||
|
|
||
| data AppError era = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each error type shows up once, good. |
||
| BalancingError (CoinSelection.BalanceTxError era) | ||
| | SubmitError (ValidationError era) | ||
| | ProgTokensError ProgrammableTokensError | ||
| deriving stock (Show) | ||
|
|
||
| makeClassyPrisms ''AppError | ||
|
|
||
| instance AsBalanceTxError (AppError era) era where | ||
| _BalanceTxError = _BalancingError | ||
|
|
||
| instance AsValidationError (AppError era) era where | ||
| _ValidationError = _SubmitError | ||
|
|
||
| instance AsProgrammableTokensError (AppError era) where | ||
| _ProgrammableTokensError = _ProgTokensError | ||
|
|
||
| instance AsCoinSelectionError (AppError era) where | ||
| _CoinSelectionError = _BalancingError . _CoinSelectionError | ||
|
|
||
| instance CoinSelection.AsBalancingError (AppError era) era where | ||
| __BalancingError = _BalanceTxError . CoinSelection.__BalancingError | ||
|
|
||
| -- CoinSelection.AsCoinSelectionError err, CoinSelection.AsBalancingError err era | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, it looks like the main error type holds each suberror only once!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that is the only way to avoid issues with catch, sadly I don't think there is a way to really enforce this