-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathError.hs
More file actions
76 lines (70 loc) · 2.81 KB
/
Error.hs
File metadata and controls
76 lines (70 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- | This module exposes the errors that can be raised during a mockchain run
module Cooked.MockChain.Error
( -- * Mockchain errors
BalancingError (..),
MockChainError (..),
-- * Interpretating effects into `Error MockChainError`
runToCardanoErrorInMockChainError,
runFailInMockChainError,
)
where
import Cooked.Skeleton.User
import Ledger.Index qualified as Ledger
import Ledger.Slot qualified as Ledger
import Ledger.Tx qualified as Ledger
import PlutusLedgerApi.V3 qualified as Api
import Polysemy
import Polysemy.Error
import Polysemy.Fail
-- | Errors that can be produced during balancing
data BalancingError
= -- | The balancing user theoretically has enough funds to balancing the
-- trasaction, but this balancing results in a surplus payment which they
-- cannot afford ADA-wise.
NotEnoughFundForExtraMinAda Peer
| -- | The balancing does not have enough funds to sustain the fee required to
-- balance the transaction.
NotEnoughFundForProperFee Peer
| -- | The balancing wallet does not have enough funds to balance the
-- transaction
NotEnoughFund Peer Api.Value
| -- | The provided of collateral UTxOs does not have enough funds to cover
-- the potential collateral cost
NoSuitableCollateral Integer Integer Api.Value
| -- | The balancing user has not be provided, but the balancing requires it
MissingBalancingUser
deriving (Show, Eq)
-- | Errors that can be produced by the blockchain
data MockChainError
= -- | Validation errors, either in Phase 1 or Phase 2
MCEValidationError Ledger.ValidationPhase Ledger.ValidationError
| -- | Balancing errors
MCEBalancingError BalancingError
| -- | Translating a skeleton element to its Cardano counterpart failed
MCEToCardanoError Ledger.ToCardanoError
| -- | The required reference script is missing from a witness utxo
MCEWrongReferenceScriptError Api.TxOutRef Api.ScriptHash (Maybe Api.ScriptHash)
| -- | A UTxO is missing from the mockchain state
MCEUnknownOutRef Api.TxOutRef
| -- | A jump in time would result in a past slot
MCEPastSlot Ledger.Slot Ledger.Slot
| -- | An attempt to invoke an unsupported feature has been made
MCEUnsupportedFeature String
| -- | Used to provide 'MonadFail' instances.
MCEFailure String
deriving (Show, Eq)
-- | Interpreting `Ledger.ToCardanoError` in terms of `MockChainError`
runToCardanoErrorInMockChainError ::
forall effs a.
(Member (Error MockChainError) effs) =>
Sem (Error Ledger.ToCardanoError : effs) a ->
Sem effs a
runToCardanoErrorInMockChainError = mapError MCEToCardanoError
-- | Interpreting failures in terms of `MockChainError`
runFailInMockChainError ::
forall effs a.
(Member (Error MockChainError) effs) =>
Sem (Fail : effs) a ->
Sem effs a
runFailInMockChainError = interpret $
\(Fail s) -> throw $ MCEFailure s