Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Contract w (s :: Row *) e a
- data State w e = State {
- record :: Responses e
- checkpoints :: CheckpointStore
- observableState :: w
- data ContractRequest w s = ContractRequest {
- oldState :: State w (CheckpointKey, s)
- event :: Response s
- data ContractResponse w e s h = ContractResponse {}
- mapE :: forall e f w s h. (e -> f) -> ContractResponse w e s h -> ContractResponse w f s h
- mapW :: forall w q e s h. (w -> q) -> ContractResponse w e s h -> ContractResponse q e s h
- insertAndUpdateContract :: forall w s e a. Monoid w => Contract w s e a -> ContractRequest w PABResp -> ContractResponse w e PABResp PABReq
- initialiseContract :: forall w s e a. Monoid w => Contract w s e a -> ContractResponse w e PABResp PABReq
- mkResponse :: forall w e s h a. Monoid w => w -> ResumableResult w e s h a -> ContractResponse w e s h
Contract state
Types for initialising and running instances of Contract
s. The types and
functions in this module are convenient wrappers around types and functions
from Types
, exposing an interface that is suitable
for consumption by the PAB. In particular this means that
insertAndUpdateContract
has a single argument, and its argument & return
types can be serialised to JSON easily.
To actually run a contract, follow this workflow:
- Call
initialiseContract
to get the initialContractResponse
. - Look at the
hooks
of this value and generate an answer to one of them. This answer is aResponse
s
value. - Call
insertAndUpdateContract
with aContractRequest
whoseoldState
field has the value ofnewState
of the previous response, and whoseevent
is the next answer (step 2). - Take the new
ContractResponse
and go back to step 2, until you get a response with no requests, or an error.
data 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].
Instances
IsContract Contract Source # | |
Defined in Plutus.Contract.Types | |
MonadError e (Contract w s e) Source # | |
Defined in Plutus.Contract.Types 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 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 # | |
The state of a Contract
, containing all responses that have been fed to
it, and checkpoints that it produced.
State | |
|
Instances
Bifunctor State Source # | |
Functor (State w) Source # | |
Foldable (State w) Source # | |
Defined in Plutus.Contract.State fold :: Monoid m => State w m -> m Source # foldMap :: Monoid m => (a -> m) -> State w a -> m Source # foldMap' :: Monoid m => (a -> m) -> State w a -> m Source # foldr :: (a -> b -> b) -> b -> State w a -> b Source # foldr' :: (a -> b -> b) -> b -> State w a -> b Source # foldl :: (b -> a -> b) -> b -> State w a -> b Source # foldl' :: (b -> a -> b) -> b -> State w a -> b Source # foldr1 :: (a -> a -> a) -> State w a -> a Source # foldl1 :: (a -> a -> a) -> State w a -> a Source # toList :: State w a -> [a] Source # null :: State w a -> Bool Source # length :: State w a -> Int Source # elem :: Eq a => a -> State w a -> Bool Source # maximum :: Ord a => State w a -> a Source # minimum :: Ord a => State w a -> a Source # | |
Traversable (State w) Source # | |
Defined in Plutus.Contract.State | |
(Eq e, Eq w) => Eq (State w e) Source # | |
(Show e, Show w) => Show (State w e) Source # | |
Generic (State w e) Source # | |
(FromJSON e, FromJSON w) => FromJSON (State w e) Source # | |
Defined in Plutus.Contract.State parseJSON :: Value -> Parser (State w e) parseJSONList :: Value -> Parser [State w e] | |
(ToJSON w, ToJSON e) => ToJSON (State w e) Source # | |
Defined in Plutus.Contract.State toEncoding :: State w e -> Encoding toJSONList :: [State w e] -> Value toEncodingList :: [State w e] -> Encoding | |
type Rep (State w e) Source # | |
Defined in Plutus.Contract.State type Rep (State w e) = D1 ('MetaData "State" "Plutus.Contract.State" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (C1 ('MetaCons "State" 'PrefixI 'True) (S1 ('MetaSel ('Just "record") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Responses e)) :*: (S1 ('MetaSel ('Just "checkpoints") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CheckpointStore) :*: S1 ('MetaSel ('Just "observableState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 w)))) |
data ContractRequest w s Source #
A request sent to a contract instance. It contains the previous State
of
the instance, and a Response
to one of the requests of the instance.
ContractRequest | |
|
Instances
data ContractResponse w e s h Source #
A response produced by a contract instance. It contains the new State
,
the list of endpoints that can be called, logs produced by the contract,
possibly an error message, and the accumulated observable state.
ContractResponse | |
|
Instances
mapE :: forall e f w s h. (e -> f) -> ContractResponse w e s h -> ContractResponse w f s h Source #
mapW :: forall w q e s h. (w -> q) -> ContractResponse w e s h -> ContractResponse q e s h Source #
insertAndUpdateContract Source #
:: forall w s e a. Monoid w | |
=> Contract w s e a | The |
-> ContractRequest w PABResp | The |
-> ContractResponse w e PABResp PABReq |
Run one step of the contract by restoring it to its previous state and
feeding it a single new Response
event.
initialiseContract :: forall w s e a. Monoid w => Contract w s e a -> ContractResponse w e PABResp PABReq Source #
The ContractResponse
with the initial state of the contract.
mkResponse :: forall w e s h a. Monoid w => w -> ResumableResult w e s h a -> ContractResponse w e s h Source #