plutus-contract-1.2.0.0
Safe HaskellNone
LanguageHaskell2010

Plutus.Contract.Types

Synopsis

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

Instances details
IsContract Contract Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

toContract :: forall w (s :: Row Type) e a. Contract w s e a -> Contract w s e a Source #

MonadError e (Contract w s e) Source # 
Instance details

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 # 
Instance details

Defined in Plutus.Contract.Types

Methods

bimap :: (a -> b) -> (c -> d) -> Contract w s a c -> Contract w s b d Source #

first :: (a -> b) -> Contract w s a c -> Contract w s b c Source #

second :: (b -> c) -> Contract w s a b -> Contract w s a c Source #

Monad (Contract w s e) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

(>>=) :: Contract w s e a -> (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 b Source #

return :: a -> Contract w s e a Source #

Functor (Contract w s e) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

fmap :: (a -> b) -> Contract w s e a -> Contract w s e b Source #

(<$) :: a -> Contract w s e b -> Contract w s e a Source #

Applicative (Contract w s e) Source # 
Instance details

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 # 
Instance details

Defined in Plutus.Contract.Types

Methods

pure :: a -> Contract w s e a

(<*>) :: Contract w s e (a -> b) -> Contract w s e a -> Contract w s e b

Functor (Contract w s e) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

fmap :: (a -> b) -> Contract w s e a -> Contract w s e b

Semigroup a => Semigroup (Contract w s e a) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

(<>) :: Contract w s e a -> Contract w s e a -> Contract w s e a Source #

sconcat :: NonEmpty (Contract w s e a) -> Contract w s e a Source #

stimes :: Integral b => b -> Contract w s e a -> 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

Instances details
IsContract Promise Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

toContract :: forall w (s :: Row Type) e a. Promise w s e a -> Contract w s e a Source #

IsContract Contract Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

toContract :: forall w (s :: Row Type) e a. Contract w s e a -> Contract w s e a Source #

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

Instances

Instances details
IsContract Promise Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

toContract :: forall w (s :: Row Type) e a. Promise w s e a -> Contract w s e a Source #

Bifunctor (Promise w s) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

bimap :: (a -> b) -> (c -> d) -> Promise w s a c -> Promise w s b d Source #

first :: (a -> b) -> Promise w s a c -> Promise w s b c Source #

second :: (b -> c) -> Promise w s a b -> Promise w s a c Source #

Functor (Promise w s e) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

fmap :: (a -> b) -> Promise w s e a -> Promise w s e b Source #

(<$) :: a -> Promise w s e b -> Promise w s e a Source #

Apply (Promise w s e) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

(<.>) :: Promise w s e (a -> b) -> Promise w s e a -> Promise w s e b

(.>) :: Promise w s e a -> Promise w s e b -> Promise w s e b

(<.) :: Promise w s e a -> Promise w s e b -> Promise w s e a

liftF2 :: (a -> b -> c) -> Promise w s e a -> Promise w s e b -> Promise w s e c

Semigroup a => Semigroup (Promise w s e a) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

(<>) :: Promise w s e a -> Promise w s e a -> Promise w s e a Source #

sconcat :: NonEmpty (Promise w s e a) -> Promise w s e a Source #

stimes :: Integral b => b -> Promise w s e a -> Promise w s e a Source #

promiseBind :: Promise w s e a -> (a -> Contract w s e b) -> Promise w s e b Source #

Run more Contract code after the Promise.

promiseMap :: (Contract w1 s1 e1 a1 -> Contract w2 s2 e2 a2) -> Promise w1 s1 e1 a1 -> Promise w2 s2 e2 a2 Source #

Lift a mapping function for Contract to a mapping function for Promise.

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 select P2 select P3 and all three can make progress at the same moment, then select 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.

never :: Promise w s e a Source #

A Promise that is never fulfilled. This is the identity of select.

Error handling

data ContractError Source #

Constructors

WalletContractError WalletAPIError 
ChainIndexContractError Text ChainIndexResponse 
ConstraintResolutionContractError MkTxError 
ToCardanoConvertContractError ToCardanoError 
ResumableContractError MatchingError 
CCheckpointContractError CheckpointError 
EndpointDecodeContractError 

Fields

OtherContractError Text 

Instances

Instances details
Eq ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Show ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

IsString ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Generic ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Associated Types

type Rep ContractError :: Type -> Type Source #

FromJSON ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

parseJSON :: Value -> Parser ContractError

parseJSONList :: Value -> Parser [ContractError]

ToJSON ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

toJSON :: ContractError -> Value

toEncoding :: ContractError -> Encoding

toJSONList :: [ContractError] -> Value

toEncodingList :: [ContractError] -> Encoding

Pretty ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

pretty :: ContractError -> Doc ann

prettyList :: [ContractError] -> Doc ann

AsCheckpointError ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

AsContractError ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

type Rep ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

type Rep ContractError = D1 ('MetaData "ContractError" "Plutus.Contract.Error" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (((C1 ('MetaCons "WalletContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 WalletAPIError)) :+: C1 ('MetaCons "ChainIndexContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ChainIndexResponse))) :+: (C1 ('MetaCons "ConstraintResolutionContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MkTxError)) :+: C1 ('MetaCons "ToCardanoConvertContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ToCardanoError)))) :+: ((C1 ('MetaCons "ResumableContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MatchingError)) :+: C1 ('MetaCons "CCheckpointContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointError))) :+: (C1 ('MetaCons "EndpointDecodeContractError" 'PrefixI 'True) (S1 ('MetaSel ('Just "eeEndpointDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EndpointDescription) :*: (S1 ('MetaSel ('Just "eeEndpointValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (EndpointValue Value)) :*: S1 ('MetaSel ('Just "eeErrorMessage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) :+: C1 ('MetaCons "OtherContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))))

class AsContractError r where Source #

Minimal complete definition

_ContractError

Instances

Instances details
AsContractError Text Source #

This lets people use Text as their error type.

Instance details

Defined in Plutus.Contract.Error

AsContractError ContractError Source # 
Instance details

Defined in Plutus.Contract.Error

AsContractError SMContractError Source # 
Instance details

Defined in Plutus.Contract.StateMachine

newtype MatchingError Source #

An error

Constructors

WrongVariantError 

Fields

Instances

Instances details
Eq MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Ord MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Show MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Generic MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Associated Types

type Rep MatchingError :: Type -> Type Source #

FromJSON MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

parseJSON :: Value -> Parser MatchingError

parseJSONList :: Value -> Parser [MatchingError]

ToJSON MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

toJSON :: MatchingError -> Value

toEncoding :: MatchingError -> Encoding

toJSONList :: [MatchingError] -> Value

toEncodingList :: [MatchingError] -> Encoding

Pretty MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

Methods

pretty :: MatchingError -> Doc ann

prettyList :: [MatchingError] -> Doc ann

AsMatchingError MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

type Rep MatchingError Source # 
Instance details

Defined in Plutus.Contract.Error

type Rep MatchingError = D1 ('MetaData "MatchingError" "Plutus.Contract.Error" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'True) (C1 ('MetaCons "WrongVariantError" 'PrefixI 'True) (S1 ('MetaSel ('Just "unWrongVariantError") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

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

data CheckpointError Source #

Constructors

JSONDecodeError Text 

Instances

Instances details
Eq CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Ord CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Show CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Generic CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Associated Types

type Rep CheckpointError :: Type -> Type Source #

FromJSON CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Methods

parseJSON :: Value -> Parser CheckpointError

parseJSONList :: Value -> Parser [CheckpointError]

ToJSON CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Methods

toJSON :: CheckpointError -> Value

toEncoding :: CheckpointError -> Encoding

toJSONList :: [CheckpointError] -> Value

toEncodingList :: [CheckpointError] -> Encoding

Pretty CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

Methods

pretty :: CheckpointError -> Doc ann

prettyList :: [CheckpointError] -> Doc ann

AsCheckpointError CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointError Source # 
Instance details

Defined in Plutus.Contract.Checkpoint

type Rep CheckpointError = D1 ('MetaData "CheckpointError" "Plutus.Contract.Checkpoint" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (C1 ('MetaCons "JSONDecodeError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

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

insertAndUpdate 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 

State

data ResumableResult w e i o a Source #

The result of running a Resumable

Constructors

ResumableResult 

Fields

Instances

Instances details
(Show i, Show o, Show e, Show a, Show w) => Show (ResumableResult w e i o a) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

showsPrec :: Int -> ResumableResult w e i o a -> ShowS Source #

show :: ResumableResult w e i o a -> String Source #

showList :: [ResumableResult w e i o a] -> ShowS Source #

Generic (ResumableResult w e i o a) Source # 
Instance details

Defined in Plutus.Contract.Types

Associated Types

type Rep (ResumableResult w e i o a) :: Type -> Type Source #

Methods

from :: ResumableResult w e i o a -> Rep (ResumableResult w e i o a) x Source #

to :: Rep (ResumableResult w e i o a) x -> ResumableResult w e i o a Source #

(FromJSON i, FromJSON o, FromJSON e, FromJSON a, FromJSON w) => FromJSON (ResumableResult w e i o a) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

parseJSON :: Value -> Parser (ResumableResult w e i o a)

parseJSONList :: Value -> Parser [ResumableResult w e i o a]

(ToJSON w, ToJSON a, ToJSON e, ToJSON o, ToJSON i) => ToJSON (ResumableResult w e i o a) Source # 
Instance details

Defined in Plutus.Contract.Types

Methods

toJSON :: ResumableResult w e i o a -> Value

toEncoding :: ResumableResult w e i o a -> Encoding

toJSONList :: [ResumableResult w e i o a] -> Value

toEncodingList :: [ResumableResult w e i o a] -> Encoding

type Rep (ResumableResult w e i o a) Source # 
Instance details

Defined in Plutus.Contract.Types

type Rep (ResumableResult w e i o a) = D1 ('MetaData "ResumableResult" "Plutus.Contract.Types" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (C1 ('MetaCons "ResumableResult" 'PrefixI 'True) (((S1 ('MetaSel ('Just "_responses") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Responses (CheckpointKey, i))) :*: S1 ('MetaSel ('Just "_requests") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Requests o))) :*: (S1 ('MetaSel ('Just "_finalState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Either e (Maybe a))) :*: S1 ('MetaSel ('Just "_logs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Seq (LogMessage Value))))) :*: ((S1 ('MetaSel ('Just "_lastLogs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Seq (LogMessage Value))) :*: S1 ('MetaSel ('Just "_checkpointStore") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointStore)) :*: (S1 ('MetaSel ('Just "_observableState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 w) :*: S1 ('MetaSel ('Just "_lastState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 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)) 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 #

suspend 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

lastLogs :: forall w e i o a. Lens' (ResumableResult w e i o a) (Seq (LogMessage Value)) Source #