-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.scilla
71 lines (61 loc) · 1.45 KB
/
example.scilla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(*****************)
(* Scilla version *)
(*****************)
scilla_version 0
(*****************)
(* Associated library *)
(*****************)
library Chatter
let zero = Uint128 0
let zero_address = 0x0000000000000000000000000000000000000000
let one_msg =
fun (msg: Message) =>
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg
(*****************)
(* The contract definition *)
(*****************)
contract Chatter
(contract_owner: ByStr20)
field initial_contract_owner : ByStr20 = contract_owner
field recent_chat_msg : String = ""
field recent_chat_sender: ByStr20 = zero_address
procedure isOwner()
curr_owner <- initial_contract_owner;
is_owner = builtin eq curr_owner _sender;
match is_owner with
| True =>
| False =>
e = {
_exception: "NotOwnerError"
};
throw e
end
end
transition sendMsg (msg : String, sendTo: ByStr20)
isOwner;
message = {
_tag: "recvMsg";
_recipient: sendTo;
_amount: zero;
message: msg
};
msg_to_sender = one_msg message;
send msg_to_sender;
e = {
_eventname: "sendMsg";
sendTo: sendTo;
message: msg
};
event e
end
transition recvMsg (message: String)
recent_chat_msg := message;
recent_chat_sender := _sender;
e = {
_eventname: "recMsg";
sender: _sender;
message: message
};
event e
end