Ether and time units
Ether amounts are wei. Points in time are timestamp. Durations such as 1days add to timestamps, and subtracting two timestamps gives a number of seconds.
units.lithe
import "std/evm";
storage is record {
price : wei;
unlockAt : timestamp;
}
external function configure() is {
(* Ether units produce `wei`. *)
storage.price := 1eth + 500gwei + 7wei;
(* Time units produce durations; adding one to a timestamp gives a timestamp. *)
storage.unlockAt := Evm.blockTimestamp() + 1days + 12hours + 30minutes;
}
external view function secondsLeft() : uint is {
var left : uint := 0;
if Evm.blockTimestamp() < storage.unlockAt then {
(* timestamp - timestamp is a plain uint of seconds. *)
left := storage.unlockAt - Evm.blockTimestamp();
}
} with left
external pure function oneWeek() : uint is
7days
(* `wei` scales by literals, and converts to `uint` explicitly. *)
external view function doublePrice() : wei is
storage.price * 2
external view function priceInWei() : uint is
uint(storage.price)1eth + 500gwei + 7weiis aweivalue.Evm.blockTimestamp() + 1daysis atimestamp. Auintcan't be stored in atimestampfield by accident.- Convert out explicitly with
uint(price).

