-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfungible-util.pact
45 lines (34 loc) · 896 Bytes
/
fungible-util.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
(namespace (read-msg 'ns))
(module fungible-util GOVERNANCE
(defcap GOVERNANCE ()
true)
(defun enforce-valid-amount
( precision:integer
amount:decimal
)
(enforce (> amount 0.0) "Positive non-zero amount")
(enforce-precision precision amount)
)
(defun enforce-valid-account (account:string)
(enforce (> (length account) 2) "minimum account length")
)
(defun enforce-precision
( precision:integer
amount:decimal
)
(enforce
(= (floor amount precision) amount)
"precision violation")
)
(defun enforce-valid-transfer
( sender:string
receiver:string
precision:integer
amount:decimal)
(enforce (!= sender receiver)
"sender cannot be the receiver of a transfer")
(enforce-valid-amount precision amount)
(enforce-valid-account sender)
(enforce-valid-account receiver)
)
)