-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdog.clsp
100 lines (93 loc) · 3.34 KB
/
dog.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
; Asserts that the parent is a dog launcher
; Creates 0 amount launchers as an output
; Has an actual amount, but uses a flash loan
(mod (
MOD_HASH
LAUNCHER_SELF_HASH
INNER_PUZZLE
(parent_inner_puzzle_hash . parent_amount) ; launcher proof
inner_solution
next_coin_delta
prev_coin_delta
prev_coin_id
(next_coin_parent_id next_coin_inner_puzzle_hash next_coin_amount) ; next_coin_proof
my_amount
)
(include curry.clib)
(include condition_codes.clib)
(defconstant ANNOUNCEMENT_PREFIX 0xd0)
(defun-inline launcher_coin_puzzle_hash (MOD_HASH LAUNCHER_SELF_HASH inner_puzzle_hash amount)
(curry_hashes LAUNCHER_SELF_HASH
(sha256 1 LAUNCHER_SELF_HASH)
(sha256 1 MOD_HASH)
(sha256 1 amount)
(sha256 1 inner_puzzle_hash)
)
)
(defun create_launcher_coin (MOD_HASH LAUNCHER_SELF_HASH (inner_puzzle_hash amount . rest))
(c CREATE_COIN (c
(launcher_coin_puzzle_hash MOD_HASH LAUNCHER_SELF_HASH inner_puzzle_hash amount)
(c 0 rest)
))
)
(defun wrap_conditions (MOD_HASH LAUNCHER_SELF_HASH conditions remaining_amount)
(if conditions
(if (= (f (f conditions)) CREATE_COIN)
(c
(create_launcher_coin MOD_HASH LAUNCHER_SELF_HASH (r (f conditions)))
(wrap_conditions MOD_HASH LAUNCHER_SELF_HASH (r conditions) (- remaining_amount (f (r (r (f conditions))))))
)
(if (all
(any (= (f (f conditions)) RECEIVE_MESSAGE) (= (f (f conditions)) SEND_MESSAGE))
(= (f (r (f conditions))) 63)
(= (strlen (f (r (r (f conditions))))) 33)
(= (substr (f (r (r (f conditions)))) 0 1) ANNOUNCEMENT_PREFIX)
)
(x "xyz")
; else
(c (f conditions) (wrap_conditions MOD_HASH LAUNCHER_SELF_HASH (r conditions) remaining_amount))
)
)
(if (= remaining_amount 0) () (x "abc"))
)
)
(defun-inline create_ring (conditions)
(c
(list SEND_MESSAGE
63 ; coin-coin
(concat ANNOUNCEMENT_PREFIX (sha256 next_coin_delta))
(coinid
next_coin_parent_id
(curry_hashes MOD_HASH
(sha256 1 MOD_HASH)
(sha256 1 LAUNCHER_SELF_HASH)
next_coin_inner_puzzle_hash
)
next_coin_amount
)
)
(c
(list RECEIVE_MESSAGE
63 ; coin-coin
(concat ANNOUNCEMENT_PREFIX (sha256 prev_coin_delta))
prev_coin_id
)
conditions
)
)
)
(c
(list RECEIVE_MESSAGE
20 ; puzzle hash (sender) -> parent (receiver - this coin)
my_amount
(launcher_coin_puzzle_hash MOD_HASH LAUNCHER_SELF_HASH parent_inner_puzzle_hash parent_amount)
)
(create_ring
(wrap_conditions
MOD_HASH LAUNCHER_SELF_HASH
(a INNER_PUZZLE inner_solution)
(- (+ my_amount prev_coin_delta) next_coin_delta)
)
)
)
)