-
Notifications
You must be signed in to change notification settings - Fork 0
/
pay2password.clsp
45 lines (38 loc) · 1.68 KB
/
pay2password.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
(mod (
OWNER_PUBKEY ; (curryed) The public key of the address that is allowed to spend the coin before time timelock expires
RETURN_PUZZLE_HASH; (curryed) This is the puzzle hash of the owner of the coin to spend coin to if WAIT_TIME > THRESHOLD
WAIT_TIME ; (curryed) The amount of time before the timelock expires, in seconds
AMOUNT ; (curryed) The coin value
spend_pubkey ; The public key of the address that is attempting to spend the coin;
spend_puzzle_hash ; This is a solution puzzle hash of the winning wallet where coin will be sent
)
(include condition_codes.clib)
(include sha256tree1.clvm)
; check if wait's over, then return funds
(defun-inline return_to_sender (WAIT_TIME RETURN_PUZZLE_HASH AMOUNT)
(c
(list ASSERT_SECONDS_RELATIVE WAIT_TIME)
(if RETURN_PUZZLE_HASH
(list CREATE_COIN RETURN_PUZZLE_HASH AMOUNT)
(list CREATE_COIN_ANNOUNCEMENT AMOUNT)
)
)
)
; sign_and_spend will sign with the spend_pubkey and spend the coin to winner .
(defun-inline sign_and_spend (spend_pubkey spend_puzzle_hash)
(c
(list AGG_SIG_ME spend_pubkey (sha256tree1 spend_puzzle_hash))
(list CREATE_COIN spend_puzzlehash AMOUNT)
(list CREATE_COIN_ANNOUNCEMENT AMOUNT)
)
)
; Main method
;
; if the spend_pubkey matches the OWNER_PUBKEY spend coin to winner
; else check if it is time to return funds to owner
;
(if (= OWNER_PUBKEY spend_pubkey)
(sign_and_spend spend_pubkey spend_puzzle_hash)
(return_to_sender WAIT_TIME RETURN_PUZZLE_HASH AMOUNT)
)
)