-
Notifications
You must be signed in to change notification settings - Fork 2
/
safe_remote_purchase.vif
49 lines (42 loc) · 1.3 KB
/
safe_remote_purchase.vif
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
# Author: Sheela Vats, 2018
# 1.Seller posts item for sale,posts safety deposit of double the item value.
# The Balance is 2*value
# (1.1. Seller can reclaim deposit and close the sale as long as there was nothing purchased.)
# 2.Buyer purchases item (value) plus posts an additional safety deposit (Item value).
# Balance is 4*value.
# 3. Seller ships item.
# 4. Buyer confirms receiving the item. Buyer's deposit (value) is returned.
# Seller's deposit (2*value) + items value is returned. Balance is 0.
value : IFL(wei_value, value)
seller : IFL(address, seller)
buyer : IFL(address, buyer)
unlocked: public(bool)
@public
@payable
@IFL_this
def __init__():
assert (msg.value % 2) == 0
self.value = msg.value / 2
self.seller = msg.sender
self.unlocked = True
@public
@IFL_seller
def abort():
assert self.unlocked
assert msg.sender == self.seller
selfdestruct(endorse(self.seller,seller,this))
@public
@payable
@IFL_this
def purchase():
assert self.unlocked
assert msg.value == (2 * self.value)
self.buyer = msg.sender
self.unlocked = False
@public
@IFL_seller
def received():
assert not self.unlocked
assert msg.sender == self.buyer
send(endorse(self.buyer, buyer,this),endorse(self.value,value,this))
selfdestruct(endorse(self.seller, seller,this ))