Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- data StateMachine s i = StateMachine {
- smTransition :: State s -> i -> Maybe (TxConstraints Void Void, State s)
- smFinal :: s -> Bool
- smCheck :: s -> i -> ScriptContext -> Bool
- smThreadToken :: Maybe ThreadToken
- data StateMachineInstance s i = StateMachineInstance {
- stateMachine :: StateMachine s i
- typedValidator :: TypedValidator (StateMachine s i)
- data State s = State {
- stateData :: s
- stateValue :: Value
- mkStateMachine :: Maybe ThreadToken -> (State s -> i -> Maybe (TxConstraints Void Void, State s)) -> (s -> Bool) -> StateMachine s i
- machineAddress :: StateMachineInstance s i -> CardanoAddress
- mkValidator :: forall s i. ToData s => StateMachine s i -> ValidatorType (StateMachine s i)
- threadTokenValueOrZero :: StateMachineInstance s i -> Value
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.
StateMachine | |
|
Instances
ValidatorTypes (StateMachine s i) Source # | |
Defined in Plutus.Contract.StateMachine.OnChain type RedeemerType (StateMachine s i) type DatumType (StateMachine s i) | |
type DatumType (StateMachine s i) Source # | |
Defined in Plutus.Contract.StateMachine.OnChain type DatumType (StateMachine s i) = s | |
type RedeemerType (StateMachine s i) Source # | |
Defined in Plutus.Contract.StateMachine.OnChain type RedeemerType (StateMachine s i) = i |
data StateMachineInstance s i Source #
StateMachineInstance | |
|
State | |
|
Instances
Eq s => Eq (State s) Source # | |
Show s => Show (State s) Source # | |
Generic (State s) Source # | |
FromJSON s => FromJSON (State s) Source # | |
Defined in Plutus.Contract.StateMachine.OnChain parseJSON :: Value -> Parser (State s) parseJSONList :: Value -> Parser [State s] | |
ToJSON s => ToJSON (State s) Source # | |
Defined in Plutus.Contract.StateMachine.OnChain toEncoding :: State s -> Encoding toJSONList :: [State s] -> Value toEncodingList :: [State s] -> Encoding | |
type Rep (State s) Source # | |
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.