Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
c8c2309
Role tests (#1228)
nventuro Aug 22, 2018
ed04195
Removed RBAC tokens (#1229)
nventuro Aug 22, 2018
5b7ec56
Roles can now be transfered. (#1235)
nventuro Aug 28, 2018
0530e1e
True Ownership (#1247)
nventuro Aug 30, 2018
128c4c0
Improve encapsulation on ERC165
Sep 3, 2018
0d8a5e4
Improve encapsulation on ERC20
Sep 3, 2018
1c365fe
Improve encapsulation on ERC721
Sep 3, 2018
9ebdae6
Add tests, use standard getters
Sep 3, 2018
963a00b
fix tests
Sep 3, 2018
4d8db8d
Fix lint
Sep 3, 2018
dc7b21e
Merge branch 'master' into refactor/1174/private-state-vars-erc
Sep 4, 2018
d8e7c25
MintableToken using Roles (#1236)
nventuro Sep 4, 2018
0b0d6c6
move interface ids to implementation contracts
frangio Sep 4, 2018
68094d1
Do not prefix getters
Sep 5, 2018
2ea79e9
Merge branch 'master' into refactor/1174/private-state-vars-erc
Sep 5, 2018
5fc3742
Improve encapsulation on Pausable
Sep 3, 2018
172b720
add the underscore
Sep 3, 2018
86bbab3
Improve encapsulation on ownership
Sep 3, 2018
faed52d
fix rebase
Sep 3, 2018
21ae177
fix ownership
Sep 3, 2018
917a019
Improve encapsulation on payments
Sep 3, 2018
478d974
Add missing tests
Sep 4, 2018
0fecbac
add missing test
Sep 4, 2018
9449572
Do not prefix getters
Sep 5, 2018
1856f07
Fix tests.
Sep 5, 2018
f61acdc
Improve encapsulation on Crowdsales
Sep 3, 2018
44d113a
add missing tests
Sep 3, 2018
0257670
remove only
Sep 3, 2018
5a476d1
Do not prefix getters
Sep 5, 2018
85a0fc3
Update modifiers to call public view functions.
Sep 5, 2018
c420563
Improve encapsulation on Pausable
Sep 3, 2018
fcd369a
add the underscore
Sep 3, 2018
1eb1340
Improve encapsulation on ownership
Sep 3, 2018
211e2aa
fix rebase
Sep 3, 2018
411058f
fix ownership
Sep 3, 2018
0be5129
Improve encapsulation on payments
Sep 3, 2018
1c1399c
Add missing tests
Sep 4, 2018
cbe4f36
add missing test
Sep 4, 2018
869b364
Do not prefix getters
Sep 5, 2018
526ff31
Fix tests.
Sep 5, 2018
b4d64d4
Improve encapsulation on Crowdsales
Sep 3, 2018
2e2d634
add missing tests
Sep 3, 2018
4be20f7
remove only
Sep 3, 2018
8559477
Do not prefix getters
Sep 5, 2018
edf8ea5
Improve encapsulation on BreakInvariantBounty
Sep 3, 2018
b64cdef
Make researchers private
Sep 3, 2018
148ef64
Do not prefix getters
Sep 5, 2018
4080385
tmp
Sep 5, 2018
24761a5
remove isMinter
Sep 5, 2018
c14d597
fix is owner call
Sep 5, 2018
ba7fa16
fix isOpen
Sep 5, 2018
776d47a
Merge branch 'master' into feature/1179/modifiers-call-functions
Sep 6, 2018
7a37725
Fix merge
Sep 6, 2018
cab8bdb
Merge branch 'master' into refactor/underscores-final-final
Sep 6, 2018
093a9d5
tmp
Sep 6, 2018
52352ce
Improve encapsulation on TimedCrowdsale
Sep 6, 2018
7d10c0e
tmp
Sep 6, 2018
63b93cc
Add missing parentheses
Sep 6, 2018
4403e49
Merge branch 'refactor/1174/private-state-vars-timed-crowdsale' into …
Sep 6, 2018
093bcd3
Use prefix underscore for state variables and no underscore for param…
Sep 6, 2018
a14963b
Improved Roles API. (#1280)
nventuro Sep 6, 2018
4d4a004
Added PauserRole. (#1283)
nventuro Sep 6, 2018
b6bddb2
Merge branch 'master' into refactor/1174/private-state-vars-timed-cro…
frangio Sep 6, 2018
369b8d6
remove duplicate function definition
frangio Sep 6, 2018
b2f350d
Remove Claimable, DelayedClaimable, Heritable (#1274)
frangio Sep 5, 2018
c529524
Merge remote-tracking branch 'upstream/master' into rbac-migration
frangio Sep 6, 2018
145962d
Merge branch 'refactor/1174/private-state-vars-timed-crowdsale' into …
Sep 6, 2018
cb836c3
Merge branch 'master' into refactor/underscores-final-final
Sep 6, 2018
bf4a211
Role behavior tests (#1285)
nventuro Sep 6, 2018
199e156
Migrate Ownable to Roles (#1287)
nventuro Sep 6, 2018
d4dea3c
Remove RBAC, SignatureBouncer refactor (#1289)
nventuro Sep 6, 2018
e9cc437
feat: implement ERC721Mintable and ERC721Burnable (#1276)
shrugs Sep 6, 2018
075334a
Merge branch 'master' into refactor/underscores-final-final
Sep 7, 2018
abd946d
Merge branch 'master' into refactor/underscores-final-final
Sep 7, 2018
436c89f
Merge branch 'master' into rbac-migration
Sep 7, 2018
c81e75d
Fix the merge with the privatization branch
Sep 7, 2018
a49efc0
Merge branch 'master' into refactor/underscores-final-final
Sep 7, 2018
be372f2
Merge branch 'rbac-migration' into refactor/underscores-final-final
Sep 7, 2018
1002c20
fix lint
Sep 7, 2018
58524e3
Remove underscore
Sep 7, 2018
d4a1178
Merge branch 'master' of github.com:OpenZeppelin/openzeppelin-solidit…
frangio Sep 7, 2018
2458d72
Delete CapperRole.test.js
nventuro Sep 7, 2018
58e1050
fix increaseApproval
frangio Sep 7, 2018
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
Prev Previous commit
Next Next commit
Improve encapsulation on ERC721
  • Loading branch information
Leo Arias committed Sep 3, 2018
commit 1c365fe9287800f4ae2c6a965195bbfa9fac4ff8
64 changes: 32 additions & 32 deletions contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
string internal symbol_;

// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
mapping(address => uint256[]) private ownedTokens_;

// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
mapping(uint256 => uint256) private ownedTokensIndex_;

// Array with all token ids, used for enumeration
uint256[] internal allTokens;
uint256[] private allTokens_;

// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
mapping(uint256 => uint256) private allTokensIndex_;

// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
mapping(uint256 => string) private tokenURIs_;

/**
* @dev Constructor function
Expand Down Expand Up @@ -69,7 +69,7 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
return tokenURIs_[_tokenId];
}

/**
Expand All @@ -87,15 +87,15 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
return ownedTokens_[_owner][_index];
}

/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
return allTokens_.length;
}

/**
Expand All @@ -106,7 +106,7 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
return allTokens_[_index];
}

/**
Expand All @@ -117,7 +117,7 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
tokenURIs_[_tokenId] = _uri;
}

/**
Expand All @@ -127,9 +127,9 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
uint256 length = ownedTokens_[_to].length;
ownedTokens_[_to].push(_tokenId);
ownedTokensIndex_[_tokenId] = length;
}

/**
Expand All @@ -142,20 +142,20 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {

// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
uint256 tokenIndex = ownedTokensIndex_[_tokenId];
uint256 lastTokenIndex = ownedTokens_[_from].length.sub(1);
uint256 lastToken = ownedTokens_[_from][lastTokenIndex];

ownedTokens[_from][tokenIndex] = lastToken;
ownedTokens_[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
ownedTokens_[_from].length--;

// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list

ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
ownedTokensIndex_[_tokenId] = 0;
ownedTokensIndex_[lastToken] = tokenIndex;
}

/**
Expand All @@ -167,8 +167,8 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);

allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
allTokensIndex_[_tokenId] = allTokens_.length;
allTokens_.push(_tokenId);
}

/**
Expand All @@ -181,21 +181,21 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
super._burn(_owner, _tokenId);

// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
if (bytes(tokenURIs_[_tokenId]).length != 0) {
delete tokenURIs_[_tokenId];
}

// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
uint256 tokenIndex = allTokensIndex_[_tokenId];
uint256 lastTokenIndex = allTokens_.length.sub(1);
uint256 lastToken = allTokens_[lastTokenIndex];

allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens_[tokenIndex] = lastToken;
allTokens_[lastTokenIndex] = 0;

allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
allTokens_.length--;
allTokensIndex_[_tokenId] = 0;
allTokensIndex_[lastToken] = tokenIndex;
}

}
36 changes: 18 additions & 18 deletions contracts/token/ERC721/ERC721Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
bytes4 private constant ERC721_RECEIVED = 0x150b7a02;

// Mapping from token ID to owner
mapping (uint256 => address) internal tokenOwner;
mapping (uint256 => address) private tokenOwner_;

// Mapping from token ID to approved address
mapping (uint256 => address) internal tokenApprovals;
mapping (uint256 => address) private tokenApprovals_;

// Mapping from owner to number of owned token
mapping (address => uint256) internal ownedTokensCount;
mapping (address => uint256) private ownedTokensCount_;

// Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) internal operatorApprovals;
mapping (address => mapping (address => bool)) private operatorApprovals_;

constructor()
public
Expand All @@ -46,7 +46,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownedTokensCount[_owner];
return ownedTokensCount_[_owner];
}

/**
Expand All @@ -55,7 +55,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @return owner address currently marked as the owner of the given token ID
*/
function ownerOf(uint256 _tokenId) public view returns (address) {
address owner = tokenOwner[_tokenId];
address owner = tokenOwner_[_tokenId];
require(owner != address(0));
return owner;
}
Expand All @@ -73,7 +73,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
require(_to != owner);
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));

tokenApprovals[_tokenId] = _to;
tokenApprovals_[_tokenId] = _to;
emit Approval(owner, _to, _tokenId);
}

Expand All @@ -83,7 +83,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @return address currently approved for the given token ID
*/
function getApproved(uint256 _tokenId) public view returns (address) {
return tokenApprovals[_tokenId];
return tokenApprovals_[_tokenId];
}

/**
Expand All @@ -94,7 +94,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
*/
function setApprovalForAll(address _to, bool _approved) public {
require(_to != msg.sender);
operatorApprovals[msg.sender][_to] = _approved;
operatorApprovals_[msg.sender][_to] = _approved;
emit ApprovalForAll(msg.sender, _to, _approved);
}

Expand All @@ -112,7 +112,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
view
returns (bool)
{
return operatorApprovals[_owner][_operator];
return operatorApprovals_[_owner][_operator];
}

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @return whether the token exists
*/
function _exists(uint256 _tokenId) internal view returns (bool) {
address owner = tokenOwner[_tokenId];
address owner = tokenOwner_[_tokenId];
return owner != address(0);
}

Expand Down Expand Up @@ -255,8 +255,8 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
*/
function clearApproval(address _owner, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _owner);
if (tokenApprovals[_tokenId] != address(0)) {
tokenApprovals[_tokenId] = address(0);
if (tokenApprovals_[_tokenId] != address(0)) {
tokenApprovals_[_tokenId] = address(0);
}
}

Expand All @@ -266,9 +266,9 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
require(tokenOwner[_tokenId] == address(0));
tokenOwner[_tokenId] = _to;
ownedTokensCount[_to] = ownedTokensCount[_to].add(1);
require(tokenOwner_[_tokenId] == address(0));
tokenOwner_[_tokenId] = _to;
ownedTokensCount_[_to] = ownedTokensCount_[_to].add(1);
}

/**
Expand All @@ -278,8 +278,8 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _from);
ownedTokensCount[_from] = ownedTokensCount[_from].sub(1);
tokenOwner[_tokenId] = address(0);
ownedTokensCount_[_from] = ownedTokensCount_[_from].sub(1);
tokenOwner_[_tokenId] = address(0);
}

/**
Expand Down