2020-01-22 03:01:21 -08:00
|
|
|
type storage = {
|
2020-01-22 23:05:41 -08:00
|
|
|
next_use: timestamp;
|
2020-01-22 03:01:21 -08:00
|
|
|
interval: int;
|
|
|
|
execute: unit -> operation list;
|
|
|
|
}
|
|
|
|
|
|
|
|
let main (p,s: unit * storage) : operation list * storage =
|
2020-01-22 23:05:41 -08:00
|
|
|
(* Multiple calls to Current.time give different values *)
|
|
|
|
let now: timestamp = Current.time in
|
|
|
|
if now > s.next_use
|
2020-01-22 03:01:21 -08:00
|
|
|
then
|
|
|
|
let s: storage = {
|
2020-01-22 23:05:41 -08:00
|
|
|
next_use = now + s.interval;
|
2020-01-22 03:01:21 -08:00
|
|
|
interval = s.interval;
|
|
|
|
execute = s.execute;
|
|
|
|
}
|
|
|
|
in
|
|
|
|
(s.execute (), s)
|
|
|
|
else
|
|
|
|
(* TODO: Add the time until next use to this message *)
|
|
|
|
(failwith "You have to wait before you can execute this contract again.":
|
|
|
|
operation list * storage)
|