| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Plutus.Contract.Types
Synopsis
- type ContractEffs w e = '[Error e, LogMsg Value, Writer w, Checkpoint, Resumable PABResp PABReq]
- handleContractEffs :: forall w e effs a. (Member (Error e) effs, Member (State CheckpointStore) effs, Member (State CheckpointKey) effs, Member (State (AccumState w)) effs, Member (LogMsg CheckpointLogMsg) effs, Member (LogMsg Value) effs, Monoid w) => Eff (ContractEffs w e) a -> Eff effs (Maybe (MultiRequestContStatus PABResp PABReq effs a))
- newtype Contract w (s :: Row *) e a = Contract {
- unContract :: Eff (ContractEffs w e) a
- class IsContract c where
- toContract :: c w s e a -> Contract w s e a
- newtype Promise w (s :: Row *) e a = Promise {
- awaitPromise :: Contract w s e a
- promiseBind :: Promise w s e a -> (a -> Contract w s e b) -> Promise w s e b
- promiseMap :: (Contract w1 s1 e1 a1 -> Contract w2 s2 e2 a2) -> Promise w1 s1 e1 a1 -> Promise w2 s2 e2 a2
- select :: forall w s e a. Promise w s e a -> Promise w s e a -> Promise w s e a
- selectEither :: forall w s e a b. Promise w s e a -> Promise w s e b -> Promise w s e (Either a b)
- selectList :: [Promise w s e a] -> Contract w s e a
- never :: Promise w s e a
- data ContractError
- = WalletContractError WalletAPIError
- | ChainIndexContractError Text ChainIndexResponse
- | ConstraintResolutionContractError MkTxError
- | ToCardanoConvertContractError ToCardanoError
- | ResumableContractError MatchingError
- | CCheckpointContractError CheckpointError
- | EndpointDecodeContractError {
- eeEndpointDescription :: EndpointDescription
- eeEndpointValue :: EndpointValue Value
- eeErrorMessage :: Text
- | OtherContractError Text
- class AsContractError r where
- _ContractError :: Prism' r ContractError
- _WalletContractError :: Prism' r WalletAPIError
- _ChainIndexContractError :: Prism' r (Text, ChainIndexResponse)
- _ConstraintResolutionContractError :: Prism' r MkTxError
- _ToCardanoConvertContractError :: Prism' r ToCardanoError
- _ResumableContractError :: Prism' r MatchingError
- _CCheckpointContractError :: Prism' r CheckpointError
- _EndpointDecodeContractError :: Prism' r (EndpointDescription, EndpointValue Value, Text)
- _OtherContractError :: Prism' r Text
- newtype MatchingError = WrongVariantError {
- unWrongVariantError :: Text
- mapError :: forall w s e e' a. (e -> e') -> Contract w s e a -> Contract w s e' a
- throwError :: MonadError e m => e -> m a
- runError :: forall w s e e0 a. Contract w s e a -> Contract w s e0 (Either e a)
- handleError :: forall w s e e' a. (e -> Contract w s e' a) -> Contract w s e a -> Contract w s e' a
- class AsCheckpointError r where
- _CheckpointError :: Prism' r CheckpointError
- data CheckpointError = JSONDecodeError Text
- checkpoint :: forall w s e a. (AsCheckpointError e, FromJSON a, ToJSON a) => Contract w s e a -> Contract w s e a
- checkpointLoop :: forall w s e a b. (AsCheckpointError e, FromJSON a, ToJSON a, ToJSON b, FromJSON b) => (a -> Contract w s e (Either b a)) -> a -> Contract w s e b
- runResumable :: Monoid w => [Response PABResp] -> CheckpointStore -> Eff (ContractEffs w e) a -> ResumableResult w e PABResp PABReq a
- insertAndUpdate :: forall w e a. Monoid w => Eff (ContractEffs w e) a -> CheckpointStore -> Responses (CheckpointKey, PABResp) -> Response PABResp -> ResumableResult w e PABResp PABReq a
- runWithRecord :: forall w e a. Monoid w => Eff (ContractEffs w e) a -> CheckpointStore -> Responses PABResp -> ResumableResult w e PABResp PABReq a
- data ResumableResult w e i o a = ResumableResult {
- _responses :: Responses (CheckpointKey, i)
- _requests :: Requests o
- _finalState :: Either e (Maybe a)
- _logs :: Seq (LogMessage Value)
- _lastLogs :: Seq (LogMessage Value)
- _checkpointStore :: CheckpointStore
- _observableState :: w
- _lastState :: w
- responses :: forall w e i o a i. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Responses (CheckpointKey, i)) (Responses (CheckpointKey, i))
- requests :: forall w e i o a o. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Requests o) (Requests o)
- finalState :: forall w e i o a e a. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Either e (Maybe a)) (Either e (Maybe a))
- logs :: forall w e i o a. Lens' (ResumableResult w e i o a) (Seq (LogMessage Value))
- lastState :: forall w e i o a. Lens' (ResumableResult w e i o a) w
- checkpointStore :: forall w e i o a. Lens' (ResumableResult w e i o a) CheckpointStore
- observableState :: forall w e i o a. Lens' (ResumableResult w e i o a) w
- shrinkResumableResult :: ResumableResult w e i o a -> ResumableResult w e i o a
- data SuspendedContract w e i o a = SuspendedContract {
- _resumableResult :: ResumableResult w e i o a
- _continuations :: Maybe (MultiRequestContStatus i o (SuspendedContractEffects w e) a)
- _checkpointKey :: CheckpointKey
- resumableResult :: forall w e i o a. Lens' (SuspendedContract w e i o a) (ResumableResult w e i o a)
- continuations :: forall w e i o a. Lens' (SuspendedContract w e i o a) (Maybe (MultiRequestContStatus i o (SuspendedContractEffects w e) a))
- checkpointKey :: forall w e i o a. Lens' (SuspendedContract w e i o a) CheckpointKey
- suspend :: forall w e a. Monoid w => CheckpointStore -> Eff (ContractEffs w e) a -> SuspendedContract w e PABResp PABReq a
- runStep :: forall w e a. Monoid w => SuspendedContract w e PABResp PABReq a -> Response PABResp -> Maybe (SuspendedContract w e PABResp PABReq a)
- lastLogs :: forall w e i o a. Lens' (ResumableResult w e i o a) (Seq (LogMessage Value))
Documentation
type ContractEffs w e = '[Error e, LogMsg Value, Writer w, Checkpoint, Resumable PABResp PABReq] Source #
Effects that are available to contracts.
handleContractEffs :: forall w e effs a. (Member (Error e) effs, Member (State CheckpointStore) effs, Member (State CheckpointKey) effs, Member (State (AccumState w)) effs, Member (LogMsg CheckpointLogMsg) effs, Member (LogMsg Value) effs, Monoid w) => Eff (ContractEffs w e) a -> Eff effs (Maybe (MultiRequestContStatus PABResp PABReq effs a)) Source #
newtype Contract w (s :: Row *) e a Source #
Contract w s e a is a contract with schema s, producing a value of
type a or an error e. See note [Contract Schema].
Constructors
| Contract | |
Fields
| |
Instances
| IsContract Contract Source # | |
Defined in Plutus.Contract.Types | |
| MonadError e (Contract w s e) Source # | |
Defined in Plutus.Contract.Types Methods throwError :: e -> Contract w s e a # catchError :: Contract w s e a -> (e -> Contract w s e a) -> Contract w s e a | |
| Bifunctor (Contract w s) Source # | |
| Monad (Contract w s e) Source # | |
| Functor (Contract w s e) Source # | |
| Applicative (Contract w s e) Source # | |
Defined in Plutus.Contract.Types Methods pure :: a -> Contract w s e a Source # (<*>) :: Contract w s e (a -> b) -> Contract w s e a -> Contract w s e b Source # liftA2 :: (a -> b -> c) -> Contract w s e a -> Contract w s e b -> Contract w s e c Source # (*>) :: Contract w s e a -> Contract w s e b -> Contract w s e b Source # (<*) :: Contract w s e a -> Contract w s e b -> Contract w s e a Source # | |
| Applicative (Contract w s e) Source # | |
| Functor (Contract w s e) Source # | |
Defined in Plutus.Contract.Types | |
| Semigroup a => Semigroup (Contract w s e a) Source # | |
class IsContract c where Source #
Class of types that can be trivially converted to a Contract.
For use with functions where it is convenient to accept both Contract and Promise types.
Methods
toContract :: c w s e a -> Contract w s e a Source #
Instances
| IsContract Promise Source # | |
Defined in Plutus.Contract.Types | |
| IsContract Contract Source # | |
Defined in Plutus.Contract.Types | |
Select
newtype Promise w (s :: Row *) e a Source #
A wrapper indicating that this contract starts with a waiting action. For use with select.
Constructors
| Promise | |
Fields
| |
promiseMap :: (Contract w1 s1 e1 a1 -> Contract w2 s2 e2 a2) -> Promise w1 s1 e1 a1 -> Promise w2 s2 e2 a2 Source #
select :: forall w s e a. Promise w s e a -> Promise w s e a -> Promise w s e a Source #
select returns the contract that makes progress first, discarding the
other one.
However, note that if multiples promises are chained together like
P1 and all three can make progress at the same
moment, then select P2 select P3select will prioritize the promises starting from the right
(first P3 then P2 then P1).
selectEither :: forall w s e a b. Promise w s e a -> Promise w s e b -> Promise w s e (Either a b) Source #
A variant of select for contracts with different return types.
selectList :: [Promise w s e a] -> Contract w s e a Source #
selectList returns the contract that makes progress first, discarding the
other ones.
However, if multiple contracts can make progress, selectList prioritizes
the ones appearing first in the input list. Therefore, the order of the
list of promises is important.
Error handling
data ContractError Source #
Constructors
| WalletContractError WalletAPIError | |
| ChainIndexContractError Text ChainIndexResponse | |
| ConstraintResolutionContractError MkTxError | |
| ToCardanoConvertContractError ToCardanoError | |
| ResumableContractError MatchingError | |
| CCheckpointContractError CheckpointError | |
| EndpointDecodeContractError | |
Fields
| |
| OtherContractError Text | |
Instances
class AsContractError r where Source #
Minimal complete definition
Methods
_ContractError :: Prism' r ContractError Source #
_WalletContractError :: Prism' r WalletAPIError Source #
_ChainIndexContractError :: Prism' r (Text, ChainIndexResponse) Source #
_ConstraintResolutionContractError :: Prism' r MkTxError Source #
_ToCardanoConvertContractError :: Prism' r ToCardanoError Source #
_ResumableContractError :: Prism' r MatchingError Source #
_CCheckpointContractError :: Prism' r CheckpointError Source #
_EndpointDecodeContractError :: Prism' r (EndpointDescription, EndpointValue Value, Text) Source #
_OtherContractError :: Prism' r Text Source #
Instances
newtype MatchingError Source #
An error
Constructors
| WrongVariantError | |
Fields
| |
Instances
mapError :: forall w s e e' a. (e -> e') -> Contract w s e a -> Contract w s e' a Source #
Transform any exceptions thrown by the Contract using the given function.
throwError :: MonadError e m => e -> m a #
runError :: forall w s e e0 a. Contract w s e a -> Contract w s e0 (Either e a) Source #
Turn a contract with error type e and return type a into one with
any error type (ie. throwing no errors) that returns 'Either e a'
handleError :: forall w s e e' a. (e -> Contract w s e' a) -> Contract w s e a -> Contract w s e' a Source #
Handle errors, potentially throwing new errors.
Checkpoints
class AsCheckpointError r where Source #
Methods
_CheckpointError :: Prism' r CheckpointError Source #
Instances
| AsCheckpointError CheckpointError Source # | |
Defined in Plutus.Contract.Checkpoint Methods _CheckpointError :: Prism' CheckpointError CheckpointError Source # _JSONDecodeError :: Prism' CheckpointError Text Source # | |
| AsCheckpointError ContractError Source # | |
Defined in Plutus.Contract.Error Methods _CheckpointError :: Prism' ContractError CheckpointError Source # _JSONDecodeError :: Prism' ContractError Text Source # | |
data CheckpointError Source #
Constructors
| JSONDecodeError Text |
Instances
checkpoint :: forall w s e a. (AsCheckpointError e, FromJSON a, ToJSON a) => Contract w s e a -> Contract w s e a Source #
Write the current state of the contract to a checkpoint.
checkpointLoop :: forall w s e a b. (AsCheckpointError e, FromJSON a, ToJSON a, ToJSON b, FromJSON b) => (a -> Contract w s e (Either b a)) -> a -> Contract w s e b Source #
Run and update
runResumable :: Monoid w => [Response PABResp] -> CheckpointStore -> Eff (ContractEffs w e) a -> ResumableResult w e PABResp PABReq a Source #
Arguments
| :: forall w e a. Monoid w | |
| => Eff (ContractEffs w e) a | |
| -> CheckpointStore | Checkpoint store |
| -> Responses (CheckpointKey, PABResp) | Previous responses |
| -> Response PABResp | |
| -> ResumableResult w e PABResp PABReq a |
runWithRecord :: forall w e a. Monoid w => Eff (ContractEffs w e) a -> CheckpointStore -> Responses PABResp -> ResumableResult w e PABResp PABReq a Source #
State
data ResumableResult w e i o a Source #
The result of running a Resumable
Constructors
| ResumableResult | |
Fields
| |
Instances
responses :: forall w e i o a i. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Responses (CheckpointKey, i)) (Responses (CheckpointKey, i)) Source #
requests :: forall w e i o a o. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Requests o) (Requests o) Source #
finalState :: forall w e i o a e a. Lens (ResumableResult w e i o a) (ResumableResult w e i o a) (Either e (Maybe a)) (Either e (Maybe a)) Source #
logs :: forall w e i o a. Lens' (ResumableResult w e i o a) (Seq (LogMessage Value)) Source #
lastState :: forall w e i o a. Lens' (ResumableResult w e i o a) w Source #
checkpointStore :: forall w e i o a. Lens' (ResumableResult w e i o a) CheckpointStore Source #
observableState :: forall w e i o a. Lens' (ResumableResult w e i o a) w Source #
shrinkResumableResult :: ResumableResult w e i o a -> ResumableResult w e i o a Source #
Shrink the ResumableResult by deleting everything that's not needed to restore the
state of the contract instance.
Run with continuations
data SuspendedContract w e i o a Source #
Constructors
| SuspendedContract | |
Fields
| |
resumableResult :: forall w e i o a. Lens' (SuspendedContract w e i o a) (ResumableResult w e i o a) Source #
continuations :: forall w e i o a. Lens' (SuspendedContract w e i o a) (Maybe (MultiRequestContStatus i o (SuspendedContractEffects w e) a)) Source #
checkpointKey :: forall w e i o a. Lens' (SuspendedContract w e i o a) CheckpointKey Source #
Arguments
| :: forall w e a. Monoid w | |
| => CheckpointStore | |
| -> Eff (ContractEffs w e) a | The contract |
| -> SuspendedContract w e PABResp PABReq a |
Run an action of ContractEffs until it requests input for the first
time, returning the SuspendedContract
runStep :: forall w e a. Monoid w => SuspendedContract w e PABResp PABReq a -> Response PABResp -> Maybe (SuspendedContract w e PABResp PABReq a) Source #
Feed a Response to a SuspendedContract.
lastLogs :: forall w e i o a. Lens' (ResumableResult w e i o a) (Seq (LogMessage Value)) Source #