Skip to content

Commit

Permalink
Merge pull request vyperlang#1240 from ssteiger/patch-5
Browse files Browse the repository at this point in the history
Fixed commenting aesthetics in example contract
  • Loading branch information
fubuloubu authored Feb 10, 2019
2 parents 2eab2ad + 6ab955c commit a8f49ff
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions examples/safe_remote_purchase/safe_remote_purchase.vy
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,39 @@ ended: public(bool)
@payable
def __init__():
assert (msg.value % 2) == 0
self.value = msg.value / 2 #The seller initializes the contract by
#posting a safety deposit of 2*value of the item up for sale.
self.value = msg.value / 2 # The seller initializes the contract by
# posting a safety deposit of 2*value of the item up for sale.
self.seller = msg.sender
self.unlocked = True

@public
def abort():
assert self.unlocked #Is the contract still refundable?
assert msg.sender == self.seller #Only the seller can refund
assert msg.sender == self.seller # Only the seller can refund
# his deposit before any buyer purchases the item.
selfdestruct(self.seller) #Refunds the seller and deletes the contract.
selfdestruct(self.seller) # Refunds the seller and deletes the contract.

@public
@payable
def purchase():
assert self.unlocked #Is the contract still open (is the item still up for sale)?
assert msg.value == (2 * self.value) #Is the deposit the correct value?
assert self.unlocked # Is the contract still open (is the item still up
# for sale)?
assert msg.value == (2 * self.value) # Is the deposit the correct value?
self.buyer = msg.sender
self.unlocked = False

@public
def received():
# 1. Conditions
assert not self.unlocked #Is the item already purchased and pending confirmation
# from the buyer?
assert not self.unlocked # Is the item already purchased and pending
# confirmation from the buyer?
assert msg.sender == self.buyer
assert not self.ended

# 2. Effects
self.ended = True

# 3. Interaction
send(self.buyer, self.value) #Return the buyer's deposit (=value) to the buyer.
selfdestruct(self.seller) #Return the seller's deposit (=2*value)
# and the purchase price (=value) to the seller.
send(self.buyer, self.value) # Return the buyer's deposit (=value) to the buyer.
selfdestruct(self.seller) # Return the seller's deposit (=2*value) and the
# purchase price (=value) to the seller.

0 comments on commit a8f49ff

Please sign in to comment.