DEV Community

Alejandro Huitemagico
Alejandro Huitemagico

Posted on • Edited on

KMAC : Template for Finite State Machine in Soroban

Image description

KMAC implements, with the Soroban Smart Contracts Platform , a Finite State Machine template.

The KMAC is an freely accessible program, that allows the creation of programs for Finite State Machine model. In the figure, an example of an application model built with the KMAC template is shown.

The boxes painted in blue and green are "states," and the texts on the arrows are "transactions."
The model of the green states, has been defined by a hypothetical "business user" who wants to model a "Coffee Vending Machine."

The business flow includes from select the coffee blend, buyer payment and coffee delivery.

The core of KMAC is responsible for the flow defined by the blue states in the diagram. The other states (green boxes) and their respective transactions are defined by the developer using the KMAC template.

The KMAC core controls all the flow based on his internal FSM logic. The developer of the Vending Machine (or another system) only focuses on the business functions.

Learn about HOW the developer easily code the user part of the flow at KMAC wiki doc.

The image below shows from an "Sequence diagram model" the flow of transactions. The diagram shows how KMAC ensures that transactions are carried out by the appropriate users, in this case, either the 'buyer' or the 'admin'.

Image description

The “Extensible” KMAC Template.
With KMAC you can implement other examples of systems based on Finite State Machine model, without the need to code the logic of the Finite State Machine flow. You only need to focus on programming the specific 'user' functions for your new model.

I invite you to explore the comprehensive documentation of the KMAC system and download the programs from the KMAC GitHub. Go to Soroban smart contract development platform for learning about Soroban.

Top comments (0)