-
Notifications
You must be signed in to change notification settings - Fork 33
/
alias.liq
102 lines (95 loc) · 2.85 KB
/
alias.liq
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
type kind =
| Official
| Contrib of address
| Default
type alias = {
alias : string ;
avatar : bytes option;
fees : tez ;
kind : kind ;
date : timestamp ;
}
type alias_map = (address, alias) big_map
type alias_operation = address * string * bytes option
type storage = {
map : alias_map;
min_fees : tez;
owners : address set;
update : ( alias_operation -> operation ) option;
}
let%init storage = {
map = BigMap;
min_fees = 0tz;
owners = Set [ ( tz1ZLyEcFfXyu75ASsjAt5hgaR4sU5PSbLkg : address ) ];
update = None;
}
let return = [] [@@inline]
let sender = Current.sender () [@@inline]
let%entry set_alias (alias_operation : alias_operation) storage =
let owned = Set.mem sender storage.owners in
match storage.update with
| Some lambda ->
( [lambda alias_operation], storage )
| None ->
let (address, alias, avatar ) = alias_operation in
let amount = Current.amount () in
if amount < storage.min_fees && not owned then
failwith ("bad amount, minimum = ", storage.min_fees)
else
let alias = {
alias;
avatar;
fees = amount;
kind = (if address = sender then
Official
else
if owned then Default
else Contrib sender);
date = Current.time ();
} in
begin
match Map.find address storage.map with
| None -> ()
| Some old_alias ->
match old_alias.kind with
| Official ->
if sender = address then ()
else
failwith "can't change official alias"
| Default -> ()
| Contrib contributor ->
if sender <> address &&
sender <> contributor &&
old_alias.fees >= amount &&
not owned then
failwith ( "Bad amount, minimum = ", old_alias.fees )
end;
let storage = storage.map <- Map.add address alias storage.map in
( return , storage )
let%entry set_fees (min_fees : tez) storage =
let owned = Set.mem sender storage.owners in
if owned then
let storage = storage.min_fees <- min_fees in
( return, storage )
else failwith "forbidden"
let%entry set_owner (param : address * bool) storage =
let address, add = param in
let owned = Set.mem sender storage.owners in
if owned then
let storage = storage.owners <-
(if add then
Set.add address storage.owners
else
if Set.size storage.owners = 1p then
failwith "cannot remove last owner"
else
Set.remove address storage.owners)
in
( return , storage )
else failwith "forbidden"
let%entry set_update (lambda : alias_operation -> operation) storage =
let owned = Set.mem sender storage.owners in
if owned then
let storage = storage.update <- Some lambda in
( return, storage )
else failwith "forbidden"