-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.vy
67 lines (52 loc) · 1.63 KB
/
check.vy
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
# @version ^0.3.7
sender: address
receiver: address
expiry_date: uint256
authorized: HashMap[address, bool]
ledger_entry_type: String[5]
event check_create:
sender: address
amount: uint256
receiver: address
expiry_date: uint256
event deposit:
sender: address
amount: uint256
event check_cash:
sender: address
amount: uint256
event check_cancel:
sender: address
amount: uint256
@payable
@external
def __init__(_receiver: address, _expiry_date: uint256):
# assert _expiry_date > block.timestamp, "expiry date is in the past"
self.sender = msg.sender
self.receiver = _receiver
self.expiry_date = block.timestamp + _expiry_date
self.ledger_entry_type = "check"
self.authorized[msg.sender] = True
self.authorized[_receiver] = True
log check_create(msg.sender, msg.value, _receiver, self.expiry_date)
@nonreentrant("lock")
@external
def claim_check():
assert self.authorized[msg.sender], "not authorized claim check"
assert block.timestamp > self.expiry_date, "too early to claim check"
log check_cash(msg.sender, self.balance)
selfdestruct(self.receiver)
@nonreentrant("lock-2")
@external
def cancel_check():
assert self.authorized[msg.sender], "not authorized to cancel check"
assert block.timestamp > self.expiry_date, "unable to cancel check, expiry date not reached"
log check_cancel(msg.sender, self.balance)
selfdestruct(self.sender)
@external
def amount_in_check() -> uint256:
return self.balance
@payable
@external
def __default__():
log deposit(msg.sender, msg.value)