ligo/gitlab-pages/docs/intro/src/what-and-why/ligo-counter.ligo

26 lines
669 B
Plaintext
Raw Normal View History

2020-02-10 22:07:20 +04:00
type storage is int
type parameter is
Increment of int
| Decrement of int
2020-02-10 22:07:20 +04:00
| Reset
type return is list (operation) * storage
(* Two entrypoints *)
function add (const store : storage; const delta : int) : storage is store + delta
function sub (const store : storage; const delta : int) : storage is store - delta
(* Main access point that dispatches to the entrypoints according to
the smart contract parameter. *)
function main (const action : parameter; const store : storage) : return is
((nil : list (operation)), // No operations
case action of
Increment (n) -> add (store, n)
| Decrement (n) -> sub (store, n)
| Reset -> 0
end)