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

Replacing custom interface with stock openzeppelin IERC721.sol #5376

Merged
merged 11 commits into from
Dec 9, 2019
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
7 changes: 1 addition & 6 deletions smart-contracts/contracts/PublicLock.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pragma solidity 0.5.13;

import './interfaces/IERC721.sol';
import './interfaces/IERC721Enumerable.sol';

import './interfaces/IPublicLock.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/introspection/ERC165.sol';
import '@openzeppelin/upgrades/contracts/Initializable.sol';
nfurfaro marked this conversation as resolved.
Show resolved Hide resolved
import './mixins/MixinApproval.sol';
import './mixins/MixinDisableAndDestroy.sol';
import './mixins/MixinERC721Enumerable.sol';
Expand All @@ -28,10 +26,7 @@ import './mixins/MixinSignatures.sol';
* https://eips.ethereum.org/EIPS/eip-721
*/
contract PublicLock is
IERC721Enumerable,
IERC721,
IPublicLock,
Initializable,
ERC165,
Ownable,
MixinSignatures,
Expand Down
105 changes: 0 additions & 105 deletions smart-contracts/contracts/interfaces/IERC721.sol

This file was deleted.

23 changes: 0 additions & 23 deletions smart-contracts/contracts/interfaces/IERC721Enumerable.sol

This file was deleted.

7 changes: 2 additions & 5 deletions smart-contracts/contracts/interfaces/IPublicLock.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
pragma solidity ^0.5.0;

import './IERC721.sol';
import './IERC721Enumerable.sol';

import '@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721Enumerable.sol';
/**
* @title The PublicLock Interface
* @author Nick Furfaro (unlock-protocol.com)
*/


contract IPublicLock is IERC721Enumerable, IERC721 {
contract IPublicLock is IERC721Enumerable {

// See indentationissue description here:
// https://github.com/duaraghav8/Ethlint/issues/268
// solium-disable indentation

///===================================================================
/// Events
event Destroy(
uint balance,
Expand Down
13 changes: 5 additions & 8 deletions smart-contracts/contracts/mixins/MixinApproval.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pragma solidity 0.5.13;

import '../interfaces/IERC721.sol';
import './MixinDisableAndDestroy.sol';
import './MixinKeys.sol';

Expand All @@ -13,7 +12,6 @@ import './MixinKeys.sol';
* separates logically groupings of code to ease readability.
*/
contract MixinApproval is
IERC721,
MixinDisableAndDestroy,
MixinKeys
{
Expand All @@ -40,7 +38,7 @@ contract MixinApproval is
require(
isKeyOwner(_tokenId, msg.sender) ||
_isApproved(_tokenId, msg.sender) ||
isApprovedForAll(ownerOf[_tokenId], msg.sender),
isApprovedForAll(_ownerOf[_tokenId], msg.sender),
nfurfaro marked this conversation as resolved.
Show resolved Hide resolved
'ONLY_KEY_OWNER_OR_APPROVED');
_;
}
Expand All @@ -54,15 +52,14 @@ contract MixinApproval is
address _approved,
uint _tokenId
)
external
payable
public
onlyIfAlive
onlyKeyOwnerOrApproved(_tokenId)
{
require(msg.sender != _approved, 'APPROVE_SELF');

approved[_tokenId] = _approved;
emit Approval(ownerOf[_tokenId], _approved, _tokenId);
emit Approval(_ownerOf[_tokenId], _approved, _tokenId);
}

/**
Expand All @@ -74,7 +71,7 @@ contract MixinApproval is
function setApprovalForAll(
address _to,
bool _approved
) external
) public
onlyIfAlive
{
require(_to != msg.sender, 'APPROVE_SELF');
Expand All @@ -87,7 +84,7 @@ contract MixinApproval is
*/
function getApproved(
uint _tokenId
) external view
) public view
returns (address)
{
address approvedRecipient = approved[_tokenId];
Expand Down
2 changes: 0 additions & 2 deletions smart-contracts/contracts/mixins/MixinDisableAndDestroy.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pragma solidity 0.5.13;

import '../interfaces/IERC721.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol';
import './MixinFunds.sol';

Expand All @@ -12,7 +11,6 @@ import './MixinFunds.sol';
* separates logically groupings of code to ease readability.
*/
contract MixinDisableAndDestroy is
IERC721,
Ownable,
MixinFunds
{
Expand Down
9 changes: 4 additions & 5 deletions smart-contracts/contracts/mixins/MixinERC721Enumerable.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pragma solidity 0.5.13;

import './MixinERC721Enumerable.sol';
import './MixinKeys.sol';
import './MixinLockCore.sol';
import '../interfaces/IERC721Enumerable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721Enumerable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/introspection/ERC165.sol';


Expand Down Expand Up @@ -35,10 +34,10 @@ contract MixinERC721Enumerable is
/// (sort order not specified)
function tokenByIndex(
uint256 _index
) external view
) public view
returns (uint256)
{
require(_index < totalSupply, 'OUT_OF_RANGE');
require(_index < _totalSupply, 'OUT_OF_RANGE');
return _index;
}

Expand All @@ -52,7 +51,7 @@ contract MixinERC721Enumerable is
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
) external view
) public view
returns (uint256)
{
require(_index == 0, 'ONLY_ONE_KEY_PER_OWNER');
Expand Down
2 changes: 0 additions & 2 deletions smart-contracts/contracts/mixins/MixinGrantKeys.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pragma solidity 0.5.13;

import '../interfaces/IERC721.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol';
import './MixinKeys.sol';

Expand All @@ -12,7 +11,6 @@ import './MixinKeys.sol';
* separates logically groupings of code to ease readability.
*/
contract MixinGrantKeys is
IERC721,
Ownable,
MixinKeys
{
Expand Down
27 changes: 18 additions & 9 deletions smart-contracts/contracts/mixins/MixinKeys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract MixinKeys is
// Returns 0 if the token does not exist
// TODO: once we decouple tokenId from owner address (incl in js), then we can consider
// merging this with totalSupply into an array instead.
mapping (uint => address) public ownerOf;
mapping (uint => address) internal _ownerOf;

// Addresses of owners are also stored in an array.
// Addresses are never removed by design to avoid abuses around referals
Expand Down Expand Up @@ -64,7 +64,7 @@ contract MixinKeys is
uint _tokenId
) {
require(
ownerOf[_tokenId] != address(0), 'NO_SUCH_KEY'
_ownerOf[_tokenId] != address(0), 'NO_SUCH_KEY'
);
_;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ contract MixinKeys is
function balanceOf(
address _owner
)
external
public
view
returns (uint)
{
Expand Down Expand Up @@ -180,7 +180,7 @@ contract MixinKeys is
) public view
returns (bool)
{
return ownerOf[_tokenId] == _owner;
return _ownerOf[_tokenId] == _owner;
}

/**
Expand Down Expand Up @@ -208,6 +208,15 @@ contract MixinKeys is
{
return owners.length;
}
// Returns the owner of a given tokenId
function ownerOf(
uint _tokenId
) public view
isKey(_tokenId)
returns(address)
{
return _ownerOf[_tokenId];
}

/**
* Assigns the key a new tokenId (from totalSupply) if it does not already have
Expand All @@ -220,9 +229,9 @@ contract MixinKeys is
if (_key.tokenId == 0) {
// This is a brand new owner
// We increment the tokenId counter
totalSupply++;
// we assign the incremented `totalSupply` as the tokenId for the new key
_key.tokenId = totalSupply;
_totalSupply++;
// we assign the incremented `_totalSupply` as the tokenId for the new key
_key.tokenId = _totalSupply;
}
}

Expand All @@ -234,11 +243,11 @@ contract MixinKeys is
uint _tokenId
) internal
{
if (ownerOf[_tokenId] != _owner) {
if (_ownerOf[_tokenId] != _owner) {
// TODO: this may include duplicate entries
owners.push(_owner);
// We register the owner of the tokenID
ownerOf[_tokenId] = _owner;
_ownerOf[_tokenId] = _owner;
}
}
}
Loading