Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(examples): compile warnings #3033

Merged
merged 1 commit into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/auctions/blind_auction.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Blind Auction # Adapted to Vyper from [Solidity by Example](https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst#blind-auction-1)
# 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
Expand Down Expand Up @@ -82,7 +82,7 @@ def placeBid(bidder: address, _value: uint256) -> bool:
return False

# Refund the previously highest bidder
if (self.highestBidder != ZERO_ADDRESS):
if (self.highestBidder != empty(address)):
self.pendingReturns[self.highestBidder] += self.highestBid

# Place bid successfully and update auction state
Expand Down Expand Up @@ -136,7 +136,7 @@ def reveal(_numBids: int128, _values: uint256[128], _fakes: bool[128], _secrets:
refund -= value

# Make it impossible for the sender to re-claim the same deposit
zeroBytes32: bytes32 = EMPTY_BYTES32
zeroBytes32: bytes32 = empty(bytes32)
bidToCheck.blindedBid = zeroBytes32

# Send refund if non-zero
Expand Down
2 changes: 1 addition & 1 deletion examples/name_registry/name_registry.vy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ registry: HashMap[Bytes[100], address]

@external
def register(name: Bytes[100], owner: address):
assert self.registry[name] == ZERO_ADDRESS # check name has not been set yet.
assert self.registry[name] == empty(address) # check name has not been set yet.
self.registry[name] = owner


Expand Down
26 changes: 13 additions & 13 deletions examples/tokens/ERC1155ownable.vy
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,22 @@ def transferOwnership(newOwner: address):
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Ownable: caller is not the owner"
assert newOwner != self.owner, "This account already owns the contract"
assert newOwner != ZERO_ADDRESS, "Transfer to ZERO_ADDRESS not allowed. Use renounceOwnership() instead."
assert newOwner != empty(address), "Transfer to the zero address not allowed. Use renounceOwnership() instead."
oldOwner: address = self.owner
self.owner = newOwner
log OwnershipTransferred(oldOwner, newOwner)

@external
def renounceOwnership():
"""
@dev Transfer the ownership to ZERO_ADDRESS, this will lock the contract
@dev emits an OwnershipTransferred event with the old and new ZERO_ADDRESS owner addresses
@dev Transfer the ownership to the zero address, this will lock the contract
@dev emits an OwnershipTransferred event with the old and new zero owner addresses
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Ownable: caller is not the owner"
oldOwner: address = self.owner
self.owner = ZERO_ADDRESS
log OwnershipTransferred(oldOwner, ZERO_ADDRESS)
self.owner = empty(address)
log OwnershipTransferred(oldOwner, empty(address))

@external
@view
Expand Down Expand Up @@ -218,10 +218,10 @@ def mint(receiver: address, id: uint256, amount:uint256, data:bytes32):
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
assert receiver != ZERO_ADDRESS, "Can not mint to ZERO ADDRESS"
assert receiver != empty(address), "Can not mint to ZERO ADDRESS"
operator: address = msg.sender
self.balanceOf[receiver][id] += amount
log TransferSingle(operator, ZERO_ADDRESS, receiver, id, amount)
log TransferSingle(operator, empty(address), receiver, id, amount)


@external
Expand All @@ -236,7 +236,7 @@ def mintBatch(receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: Dy
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
assert receiver != ZERO_ADDRESS, "Can not mint to ZERO ADDRESS"
assert receiver != empty(address), "Can not mint to ZERO ADDRESS"
assert len(ids) == len(amounts), "ERC1155: ids and amounts length mismatch"
operator: address = msg.sender

Expand All @@ -245,7 +245,7 @@ def mintBatch(receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: Dy
break
self.balanceOf[receiver][ids[i]] += amounts[i]

log TransferBatch(operator, ZERO_ADDRESS, receiver, ids, amounts)
log TransferBatch(operator, empty(address), receiver, ids, amounts)

## burn ##
@external
Expand All @@ -259,7 +259,7 @@ def burn(id: uint256, amount: uint256):
assert not self.paused, "The contract has been paused"
assert self.balanceOf[msg.sender][id] > 0 , "caller does not own this ID"
self.balanceOf[msg.sender][id] -= amount
log TransferSingle(msg.sender, msg.sender, ZERO_ADDRESS, id, amount)
log TransferSingle(msg.sender, msg.sender, empty(address), id, amount)

@external
def burnBatch(ids: DynArray[uint256, BATCH_SIZE], amounts: DynArray[uint256, BATCH_SIZE]):
Expand All @@ -279,7 +279,7 @@ def burnBatch(ids: DynArray[uint256, BATCH_SIZE], amounts: DynArray[uint256, BAT
break
self.balanceOf[msg.sender][ids[i]] -= amounts[i]

log TransferBatch(msg.sender, msg.sender, ZERO_ADDRESS, ids, amounts)
log TransferBatch(msg.sender, msg.sender, empty(address), ids, amounts)

## approval ##
@external
Expand All @@ -306,7 +306,7 @@ def safeTransferFrom(sender: address, receiver: address, id: uint256, amount: ui
@param amount the amount of tokens for the specified id
"""
assert not self.paused, "The contract has been paused"
assert receiver != ZERO_ADDRESS, "ERC1155: transfer to the zero address"
assert receiver != empty(address), "ERC1155: transfer to the zero address"
assert sender != receiver
assert sender == msg.sender or self.isApprovedForAll[sender][msg.sender], "Caller is neither owner nor approved operator for this ID"
assert self.balanceOf[sender][id] > 0 , "caller does not own this ID or ZERO balance"
Expand All @@ -325,7 +325,7 @@ def safeBatchTransferFrom(sender: address, receiver: address, ids: DynArray[uint
@param amounts a dynamic array of the amounts for the specified list of ids.
"""
assert not self.paused, "The contract has been paused"
assert receiver != ZERO_ADDRESS, "ERC1155: transfer to the zero address"
assert receiver != empty(address), "ERC1155: transfer to the zero address"
assert sender != receiver
assert sender == msg.sender or self.isApprovedForAll[sender][msg.sender], "Caller is neither owner nor approved operator for this ID"
assert len(ids) == len(amounts), "ERC1155: ids and amounts length mismatch"
Expand Down
10 changes: 5 additions & 5 deletions examples/tokens/ERC20.vy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(_name: String[32], _symbol: String[32], _decimals: uint8, _supply:
self.balanceOf[msg.sender] = init_supply
self.totalSupply = init_supply
self.minter = msg.sender
log Transfer(ZERO_ADDRESS, msg.sender, init_supply)
log Transfer(empty(address), msg.sender, init_supply)



Expand Down Expand Up @@ -107,10 +107,10 @@ def mint(_to: address, _value: uint256):
@param _value The amount that will be created.
"""
assert msg.sender == self.minter
assert _to != ZERO_ADDRESS
assert _to != empty(address)
self.totalSupply += _value
self.balanceOf[_to] += _value
log Transfer(ZERO_ADDRESS, _to, _value)
log Transfer(empty(address), _to, _value)


@internal
Expand All @@ -121,10 +121,10 @@ def _burn(_to: address, _value: uint256):
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
assert _to != ZERO_ADDRESS
assert _to != empty(address)
self.totalSupply -= _value
self.balanceOf[_to] -= _value
log Transfer(_to, ZERO_ADDRESS, _value)
log Transfer(_to, empty(address), _value)


@external
Expand Down
26 changes: 13 additions & 13 deletions examples/tokens/ERC721.vy
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def balanceOf(_owner: address) -> uint256:
Throws if `_owner` is the zero address. NFTs assigned to the zero address are considered invalid.
@param _owner Address for whom to query the balance.
"""
assert _owner != ZERO_ADDRESS
assert _owner != empty(address)
return self.ownerToNFTokenCount[_owner]


Expand All @@ -121,7 +121,7 @@ def ownerOf(_tokenId: uint256) -> address:
"""
owner: address = self.idToOwner[_tokenId]
# Throws if `_tokenId` is not a valid NFT
assert owner != ZERO_ADDRESS
assert owner != empty(address)
return owner


Expand All @@ -134,7 +134,7 @@ def getApproved(_tokenId: uint256) -> address:
@param _tokenId ID of the NFT to query the approval of.
"""
# Throws if `_tokenId` is not a valid NFT
assert self.idToOwner[_tokenId] != ZERO_ADDRESS
assert self.idToOwner[_tokenId] != empty(address)
return self.idToApprovals[_tokenId]


Expand Down Expand Up @@ -175,7 +175,7 @@ def _addTokenTo(_to: address, _tokenId: uint256):
Throws if `_tokenId` is owned by someone.
"""
# Throws if `_tokenId` is owned by someone
assert self.idToOwner[_tokenId] == ZERO_ADDRESS
assert self.idToOwner[_tokenId] == empty(address)
# Change the owner
self.idToOwner[_tokenId] = _to
# Change count tracking
Expand All @@ -191,7 +191,7 @@ def _removeTokenFrom(_from: address, _tokenId: uint256):
# Throws if `_from` is not the current owner
assert self.idToOwner[_tokenId] == _from
# Change the owner
self.idToOwner[_tokenId] = ZERO_ADDRESS
self.idToOwner[_tokenId] = empty(address)
# Change count tracking
self.ownerToNFTokenCount[_from] -= 1

Expand All @@ -204,9 +204,9 @@ def _clearApproval(_owner: address, _tokenId: uint256):
"""
# Throws if `_owner` is not the current owner
assert self.idToOwner[_tokenId] == _owner
if self.idToApprovals[_tokenId] != ZERO_ADDRESS:
if self.idToApprovals[_tokenId] != empty(address):
# Reset approvals
self.idToApprovals[_tokenId] = ZERO_ADDRESS
self.idToApprovals[_tokenId] = empty(address)


@internal
Expand All @@ -222,7 +222,7 @@ def _transferFrom(_from: address, _to: address, _tokenId: uint256, _sender: addr
# Check requirements
assert self._isApprovedOrOwner(_sender, _tokenId)
# Throws if `_to` is the zero address
assert _to != ZERO_ADDRESS
assert _to != empty(address)
# Clear approval. Throws if `_from` is not the current owner
self._clearApproval(_from, _tokenId)
# Remove NFT. Throws if `_tokenId` is not a valid NFT
Expand Down Expand Up @@ -292,7 +292,7 @@ def approve(_approved: address, _tokenId: uint256):
"""
owner: address = self.idToOwner[_tokenId]
# Throws if `_tokenId` is not a valid NFT
assert owner != ZERO_ADDRESS
assert owner != empty(address)
# Throws if `_approved` is the current owner
assert _approved != owner
# Check requirements
Expand Down Expand Up @@ -336,10 +336,10 @@ def mint(_to: address, _tokenId: uint256) -> bool:
# Throws if `msg.sender` is not the minter
assert msg.sender == self.minter
# Throws if `_to` is zero address
assert _to != ZERO_ADDRESS
assert _to != empty(address)
# Add NFT. Throws if `_tokenId` is owned by someone
self._addTokenTo(_to, _tokenId)
log Transfer(ZERO_ADDRESS, _to, _tokenId)
log Transfer(empty(address), _to, _tokenId)
return True


Expand All @@ -356,10 +356,10 @@ def burn(_tokenId: uint256):
assert self._isApprovedOrOwner(msg.sender, _tokenId)
owner: address = self.idToOwner[_tokenId]
# Throws if `_tokenId` is not a valid NFT
assert owner != ZERO_ADDRESS
assert owner != empty(address)
self._clearApproval(owner, _tokenId)
self._removeTokenFrom(owner, _tokenId)
log Transfer(owner, ZERO_ADDRESS, _tokenId)
log Transfer(owner, empty(address), _tokenId)


@view
Expand Down
6 changes: 3 additions & 3 deletions examples/voting/ballot.vy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int128Proposals: public(int128)
@view
@internal
def _delegated(addr: address) -> bool:
return self.voters[addr].delegate != ZERO_ADDRESS
return self.voters[addr].delegate != empty(address)


@view
Expand All @@ -40,7 +40,7 @@ def delegated(addr: address) -> bool:
@view
@internal
def _directlyVoted(addr: address) -> bool:
return self.voters[addr].voted and (self.voters[addr].delegate == ZERO_ADDRESS)
return self.voters[addr].voted and (self.voters[addr].delegate == empty(address))


@view
Expand Down Expand Up @@ -125,7 +125,7 @@ def delegate(to: address):
# the default address value of 0x0000000000000000000000000000000000000000
# (the latter might not be problematic, but I don't want to think about it).
assert to != msg.sender
assert to != ZERO_ADDRESS
assert to != empty(address)

self.voters[msg.sender].voted = True
self.voters[msg.sender].delegate = to
Expand Down
2 changes: 1 addition & 1 deletion examples/wallet/wallet.vy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ seq: public(int128)
@external
def __init__(_owners: address[5], _threshold: int128):
for i in range(5):
if _owners[i] != ZERO_ADDRESS:
if _owners[i] != empty(address):
self.owners[i] = _owners[i]
self.threshold = _threshold

Expand Down