-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescrow.vy
More file actions
81 lines (63 loc) · 2.16 KB
/
escrow.vy
File metadata and controls
81 lines (63 loc) · 2.16 KB
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
# @version ^0.3.7
# previous_txn_id: String[256]
# destination_tag: uint256
# flags: uint256
# condition: String[256]
# fulfillment: String[256]
sender: address
receiver: address
claim_date: uint256
expiry_date: uint256
authorized: HashMap[address, bool]
ledger_entry_type: String[6]
event escrow_create:
sender: address
amount: uint256
receiver: address
claim_date: uint256
expiry_date: uint256
event deposit:
sender: address
amount: uint256
event escrow_claim:
sender: address
amount: uint256
event escrow_cancel:
sender: address
amount: uint256
@payable
@external
def __init__(_receiver: address, _claim_date: uint256, _expiry_date: uint256):
# assert _claim_date > block.timestamp, "claim date is in the past"
# assert _expiry_date > block.timestamp, "expiry date is in the past"
assert _expiry_date > _claim_date, "error, expiry date cannot be earlier than claim date"
self.sender = msg.sender
self.receiver = _receiver
self.claim_date = block.timestamp + _claim_date
self.expiry_date = block.timestamp + _expiry_date
self.ledger_entry_type = "escrow"
self.authorized[msg.sender] = True
self.authorized[_receiver] = True
log escrow_create(msg.sender, msg.value, _receiver, self.claim_date, self.expiry_date)
@nonreentrant("lock")
@external
def claim_escrow():
assert self.authorized[msg.sender], "not authorized to claim escrow"
assert block.timestamp > self.claim_date, "too early to claim"
assert block.timestamp < self.expiry_date, "too late to claim, can only cancel escrow"
log escrow_claim(msg.sender, self.balance)
selfdestruct(self.receiver)
@nonreentrant("lock-2")
@external
def cancel_escrow():
assert self.authorized[msg.sender], "not authorized to cancel escrow"
assert block.timestamp > self.expiry_date, "unable to cancel escrow, expiry date not reached"
log escrow_cancel(msg.sender, self.balance)
selfdestruct(self.sender)
@external
def amount_in_escrow() -> uint256:
return self.balance
@payable
@external
def __default__():
log deposit(msg.sender, msg.value)