-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpiggybank.clsp
36 lines (30 loc) · 876 Bytes
/
piggybank.clsp
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
(mod (
my_amount
new_amount
my_puzzlehash
)
(include condition_codes.clib)
(defconstant TARGET_AMOUNT 500)
(defconstant CASH_OUT_PUZZLE_HASH 0xa6a4ed372c785816fb92fb79b96fd7f9758811907f74ebe189c93310e3ba89e6)
(defun-inline cash_out (CASH_OUT_PUZZLE_HASH new_amount my_puzzlehash)
(list
(list CREATE_COIN CASH_OUT_PUZZLE_HASH new_amount)
(list CREATE_COIN my_puzzlehash 0)
(list CREATE_PUZZLE_ANNOUNCEMENT "approved")
)
)
(defun-inline recreate_self (new_amount my_puzzlehash)
(list
(list CREATE_COIN my_puzzlehash new_amount)
(list CREATE_PUZZLE_ANNOUNCEMENT "approved")
)
)
; main
(if (> new_amount my_amount)
(if (> new_amount TARGET_AMOUNT)
(cash_out CASH_OUT_PUZZLE_HASH new_amount my_puzzlehash)
(recreate_self new_amount my_puzzlehash)
)
(x)
)
)