2020-02-10 22:07:20 +04:00
|
|
|
type storage is int
|
|
|
|
|
|
|
|
type parameter is
|
|
|
|
Increment of int
|
2019-11-08 03:19:27 +04:00
|
|
|
| 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)
|