Skip to content

Commit

Permalink
Update blind auction example to use named structs
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Dec 3, 2018
1 parent eaaa40a commit cf4c85d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/auctions/blind_auction.vy
@@ -1,5 +1,9 @@
# Blind Auction # Adapted to Vyper from [Solidity by Example](https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst#blind-auction-1)

struct Bid:
blindedBid: bytes32
deposit: wei_value

# Note: because Vyper does not allow for dynamic arrays, we have limited the
# number of bids that can be placed by one address to 128 in this example
MAX_BIDS: constant(int128) = 128
Expand All @@ -20,7 +24,7 @@ highestBid: public(wei_value)
highestBidder: public(address)

# State of the bids
bids: map(address, {blindedBid: bytes32, deposit: wei_value}[128])
bids: map(address, Bid[128])
bidCounts: map(address, int128)

# Allowed withdrawals of previous bids
Expand Down Expand Up @@ -61,7 +65,10 @@ def bid(_blindedBid: bytes32):
assert numBids < MAX_BIDS

# Add bid to mapping of all bids
(self.bids[msg.sender])[numBids] = {blindedBid: _blindedBid, deposit: msg.value}
self.bids[msg.sender][numBids] = Bid({
blindedBid: _blindedBid,
deposit: msg.value
})
self.bidCounts[msg.sender] += 1


Expand Down Expand Up @@ -104,7 +111,7 @@ def reveal(_numBids: int128, _values: wei_value[128], _fakes: bool[128], _secret
break

# Get bid to check
bidToCheck: {blindedBid: bytes32, deposit: wei_value} = (self.bids[msg.sender])[i]
bidToCheck: Bid = (self.bids[msg.sender])[i]

# Check against encoded packet
value: wei_value = _values[i]
Expand Down

0 comments on commit cf4c85d

Please sign in to comment.