plutus-contract-1.2.0.0
Safe HaskellNone
LanguageHaskell2010

Plutus.Contract.StateMachine.OnChain

Description

On-chain code fragments for creating a state machine. First define a StateMachine s i with input type i and state type s. Then use mkValidator in on-chain code to check the required hashes and validate the transition, and mkRedeemer to make redeemer scripts.

Synopsis

Documentation

data StateMachine s i Source #

Specification of a state machine, consisting of a transition function that determines the next state from the current state and an input, and a checking function that checks the validity of the transition in the context of the current transaction.

Constructors

StateMachine 

Fields

  • smTransition :: State s -> i -> Maybe (TxConstraints Void Void, State s)

    The transition function of the state machine. Nothing indicates an invalid transition from the current state.

  • smFinal :: s -> Bool

    Check whether a state is the final state

  • smCheck :: s -> i -> ScriptContext -> Bool

    The condition checking function. Can be used to perform checks on the pending transaction that aren't covered by the constraints. smCheck is always run in addition to checking the constraints, so the default implementation always returns true.

  • smThreadToken :: Maybe ThreadToken

    The ThreadToken that identifies the contract instance. Make one with getThreadToken and pass it on to mkStateMachine. Initialising the machine will then mint a thread token value.

Instances

Instances details
ValidatorTypes (StateMachine s i) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Associated Types

type RedeemerType (StateMachine s i)

type DatumType (StateMachine s i)

type DatumType (StateMachine s i) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

type DatumType (StateMachine s i) = s
type RedeemerType (StateMachine s i) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

type RedeemerType (StateMachine s i) = i

data StateMachineInstance s i Source #

Constructors

StateMachineInstance 

Fields

data State s Source #

Constructors

State 

Fields

Instances

Instances details
Eq s => Eq (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Methods

(==) :: State s -> State s -> Bool Source #

(/=) :: State s -> State s -> Bool Source #

Show s => Show (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Generic (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Associated Types

type Rep (State s) :: Type -> Type Source #

Methods

from :: State s -> Rep (State s) x Source #

to :: Rep (State s) x -> State s Source #

FromJSON s => FromJSON (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Methods

parseJSON :: Value -> Parser (State s)

parseJSONList :: Value -> Parser [State s]

ToJSON s => ToJSON (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

Methods

toJSON :: State s -> Value

toEncoding :: State s -> Encoding

toJSONList :: [State s] -> Value

toEncodingList :: [State s] -> Encoding

type Rep (State s) Source # 
Instance details

Defined in Plutus.Contract.StateMachine.OnChain

type Rep (State s) = D1 ('MetaData "State" "Plutus.Contract.StateMachine.OnChain" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (C1 ('MetaCons "State" 'PrefixI 'True) (S1 ('MetaSel ('Just "stateData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 s) :*: S1 ('MetaSel ('Just "stateValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))

mkStateMachine :: Maybe ThreadToken -> (State s -> i -> Maybe (TxConstraints Void Void, State s)) -> (s -> Bool) -> StateMachine s i Source #

A state machine that does not perform any additional checks on the ScriptContext (beyond enforcing the constraints)

machineAddress :: StateMachineInstance s i -> CardanoAddress Source #

TODO StateMachine can be use only on a testnet at the moment, to enable it on another network, we need to parametrise the networkId

mkValidator :: forall s i. ToData s => StateMachine s i -> ValidatorType (StateMachine s i) Source #

Turn a state machine into a validator script.

threadTokenValueOrZero :: StateMachineInstance s i -> Value Source #

The Value containing exactly the thread token, if one has been specified.