State Machines
StateMachines
Library to handle Finite State Machines and codify their transitions in a uint256. NOTE: the number of states is limited to 16. Rewritten by Hadrien Croubois, https://github.com/Amxx
Machine
EMPTY_MACHINE
State
statesToEdge
function statesToEdge(enum StateMachines.State fromState, enum StateMachines.State toState) internal pure returns (uint256)
isTransitionValid
function isTransitionValid(StateMachines.Machine self, enum StateMachines.State fromState, enum StateMachines.State toState) internal pure returns (bool)
addEdgeTransition
function addEdgeTransition(StateMachines.Machine self, enum StateMachines.State fromState, enum StateMachines.State toState) internal pure returns (StateMachines.Machine newMachine)
removeEdgeTransition
function removeEdgeTransition(StateMachines.Machine self, enum StateMachines.State fromState, enum StateMachines.State toState) internal pure returns (StateMachines.Machine newMachine)
StateMachineController
Contract that allows for the creation and management of finite state machines. The state machines will transition following a commonly defined state set. What each state and state transition means, as well as the business logic of defining a valid transition are left to the inheriting contract.
StateTransition
event StateTransition(uint256 machineId, enum StateMachines.State fromState, enum StateMachines.State toState)
InvalidState
InvalidStateTransition
_machines
onlyInState
transitionTable
_transition
currentState
Checks the current state of a machine.
Name | Type | Description |
---|---|---|
_machineId | uint256 | the identifier of a machine. |
Name | Type | Description |
---|---|---|
[0] | enum StateMachines.State | current state identifier. |