-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguards.pact
73 lines (50 loc) · 1.91 KB
/
guards.pact
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
;; guards.pact
(namespace 'util)
(module guards AUTONOMOUS
"Functions for implementing various user guards."
(defcap AUTONOMOUS ()
(enforce false "Non-upgradeable"))
(defun after-date:guard (date:time)
"Guard to enforce chain time is after DATE."
(create-user-guard (enforce-after-date date)))
(defun enforce-after-date:bool (date:time)
(enforce-time date "after"
(> (chain-time) date)))
(defun at-after-date:guard (date:time)
"Guard to enforce chain time is at or after DATE."
(create-user-guard (enforce-at-after-date date)))
(defun enforce-at-after-date:bool (date:time)
(enforce-time date "at or after"
(>= (chain-time) date)))
(defun before-date:guard (date:time)
"Guard to enforce chain time is before DATE."
(create-user-guard (enforce-before-date date)))
(defun enforce-before-date:bool (date:time)
(enforce-time date "before"
(< (chain-time) date)))
(defun at-before-date:guard (date:time)
"Guard to enforce chain time is at or before DATE."
(create-user-guard (enforce-at-before-date date)))
(defun enforce-at-before-date:bool (date:time)
(enforce-time date "at or before"
(<= (chain-time) date)))
(defun enforce-time:bool (date:time msg:string test:bool)
(enforce test
(format "Chain time must be {} {}" [msg date])))
(defun chain-time:time ()
(at 'block-time (chain-data)))
(defun guard-and:guard (a:guard b:guard)
"Guard to enforce both A and B."
(create-user-guard (enforce-and a b)))
(defun enforce-and:bool (a:guard b:guard)
(enforce-guard a)
(enforce-guard b))
(defun guard-or:guard (a:guard b:guard)
"Guard to enforce A or B."
(create-user-guard (enforce-or a b)))
(defun enforce-or:bool (a:guard b:guard)
(enforce-one
(format "Enforce {} or {}" [a b])
[(enforce-guard a)
(enforce-guard b)]))
)