forked from oxheadalpha/nft-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pausable_simple_admin.mligo
71 lines (59 loc) · 2.06 KB
/
pausable_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
64
65
66
67
68
69
70
71
#if !PAUSABLE_SIMPLE_ADMIN
#define PAUSABLE_SIMPLE_ADMIN
type admin_storage = {
admin : address;
pending_admin : address option;
paused : bool;
}
type admin_entrypoints =
| Set_admin of address
| Confirm_admin of unit
| Pause of bool
let confirm_new_admin (storage : admin_storage) : admin_storage =
match storage.pending_admin with
| None -> (failwith "NO_PENDING_ADMIN" : 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" : admin_storage)
(* Fails if sender is not admin *)
let fail_if_not_admin_ext (storage, extra_msg : admin_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 : admin_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 : admin_storage) : bool =
Tezos.get_sender () = storage.admin
let fail_if_paused (storage : admin_storage) : unit =
if(storage.paused)
then failwith "PAUSED"
else unit
(*Only callable by admin*)
let set_admin (new_admin, storage : address * admin_storage) : admin_storage =
let _ = fail_if_not_admin storage in
{ storage with pending_admin = Some new_admin; }
(*Only callable by admin*)
let pause (paused, storage: bool * admin_storage) : admin_storage =
let _ = fail_if_not_admin storage in
{ storage with paused = paused; }
let admin_main(param, storage : admin_entrypoints * admin_storage)
: (operation list) * admin_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)
| Pause paused ->
let new_s = pause (paused, storage) in
(([]: operation list), new_s)
#endif