-
Notifications
You must be signed in to change notification settings - Fork 25
/
simple_admin.mligo
63 lines (50 loc) · 1.78 KB
/
simple_admin.mligo
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
#if !SIMPLE_ADMIN
#define SIMPLE_ADMIN
#include "./admin_sig.mligo"
module Admin : AdminSig = struct
type storage = {
admin : address;
pending_admin : address option;
}
type entrypoints =
| Set_admin of address
| Confirm_admin of unit
let confirm_new_admin (storage : storage) : storage =
match storage.pending_admin with
| None -> (failwith "NO_PENDING_ADMIN" : storage)
| Some pending ->
if Tezos.get_sender () = pending
then { storage with
pending_admin = (None : address option);
admin = Tezos.get_sender ();
}
else (failwith "NOT_A_PENDING_ADMIN" : storage)
(* Fails if sender is not admin *)
let fail_if_not_admin_ext (storage, extra_msg : storage * string) : unit =
if Tezos.get_sender () <> storage.admin
then failwith ("NOT_AN_ADMIN" ^ " " ^ extra_msg)
else unit
(* Fails if sender is not admin *)
let fail_if_not_admin (storage : storage) : unit =
if Tezos.get_sender () <> storage.admin
then failwith "NOT_AN_ADMIN"
else unit
(* Returns true if sender is admin *)
let is_admin (storage : storage) : bool =
Tezos.get_sender () = storage.admin
[@inline]
let fail_if_paused (_storage : storage) : unit = unit
(*Only callable by admin*)
let set_admin (new_admin, storage : address * storage) : storage =
let _ = fail_if_not_admin storage in
{ storage with pending_admin = Some new_admin; }
let main(param, storage : entrypoints * storage) : (operation list) * storage =
match param with
| Set_admin new_admin ->
let new_s = set_admin (new_admin, storage) in
(([] : operation list), new_s)
| Confirm_admin _ ->
let new_s = confirm_new_admin storage in
(([]: operation list), new_s)
end
#endif