contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_burn
function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); }
/** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 12634, 13184 ] }
58,261
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_transfer
function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); }
/** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 13516, 14120 ] }
58,262
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_setTokenURI
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; }
/** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 14271, 14491 ] }
58,263
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_setBaseURI
function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; }
/** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 14716, 14821 ] }
58,264
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_checkOnERC721Received
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); }
/** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 15381, 15990 ] }
58,265
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_approve
function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner }
/** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 16104, 16301 ] }
58,266
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, conmightygojiraenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, conmightygojiraenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_beforeTokenTransfer
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
/** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 16909, 17007 ] }
58,267
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view virtual returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 506, 598 ] }
58,268
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1157, 1310 ] }
58,269
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1460, 1709 ] }
58,270
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 94, 154 ] }
58,271
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 237, 310 ] }
58,272
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 543, 625 ] }
58,273
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 904, 992 ] }
58,274
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1665, 1744 ] }
58,275
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indimightygojiraing whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 2066, 2168 ] }
58,276
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
name
function name() public view returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 902, 990 ] }
58,277
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1104, 1196 ] }
58,278
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1829, 1917 ] }
58,279
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
totalSupply
function totalSupply() public view override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 1977, 2082 ] }
58,280
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) public view override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 2140, 2264 ] }
58,281
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 2472, 2652 ] }
58,282
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 2710, 2866 ] }
58,283
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 3008, 3182 ] }
58,284
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; }
/** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 3660, 3986 ] }
58,285
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 4399, 4622 ] }
58,286
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; }
/** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 5129, 5403 ] }
58,287
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_transfer
function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 5888, 6432 ] }
58,288
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_mint
function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); }
/** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 6708, 7091 ] }
58,289
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_burn
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); }
/** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 7418, 7841 ] }
58,290
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_approve
function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); }
/** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 8274, 8625 ] }
58,291
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_setupDecimals
function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; }
/** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 8961, 9056 ] }
58,292
mightygojirascontract
@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol
0x9cc103edf0a60e07dd7a6fd4a16fd2cbf7981d92
Solidity
ERC20
contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indimightygojiraing the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indimightygojiraing the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applimightygojiraions that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applimightygojiraions. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applimightygojiraions to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specifimightygojiraion. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_beforeTokenTransfer
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
/** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */
NatSpecMultiLine
v0.7.6+commit.7338295f
MIT
ipfs://93fbf3ab6f1da163317b7b28fa738cb098bf07cbb4f7cbca91e163cb6a9cb11a
{ "func_code_index": [ 9654, 9751 ] }
58,293
TinlakeSpell
TinlakeSpell.sol
0x129bd9f30a2d880090d5928c7c70932f86e70e6f
Solidity
TinlakeSpell
contract TinlakeSpell { // { // "DEPLOYMENT_NAME": "NewSilver 2 mainnet deployment", // "ROOT_CONTRACT": "0x53b2d22d07E069a3b132BfeaaD275b10273d381E", // "TINLAKE_CURRENCY": "0x6b175474e89094c44da98b954eedeac495271d0f", // "BORROWER_DEPLOYER": "0x9137BFdbB43BDf83DB5B8e691B5D2ceBE6475392", // "TITLE_FAB": "0x8bA230C8b7C6B4C5d6A1bfC53B4d992CD0963661", // "SHELF_FAB": "0xEa66cD92CaFF63c82A31BAa2BdA274ACbBA6323a", // "PILE_FAB": "0xc1C9330Fcc5694B902CB27bCB615fB126DfACc55", // "COLLECTOR_FAB": "0x7d882A8513C9cf5D7623222607Ea67a6C03676d2", // "FEED_FAB": "0xC2f81D0e9744ca806f024c884FD18462Ce787550", // "TITLE": "0x07cdD617c53B07208b0371C93a02deB8d8D49C6e", // "PILE": "0x3eC5c16E7f2C6A80E31997C68D8Fa6ACe089807f", // "SHELF": "0x7d057A056939bb96D682336683C10EC89b78D7CE", // "COLLECTOR": "0x62f290512c690a817f47D2a4a544A5d48D1408BE", // "FEED": "0x41fAD1Eb242De19dA0206B0468763333BB6C2B3D", // "LENDER_DEPLOYER": "0xed0d554A3125E79B9E77A919c7cc651d235A3B1A", // "OPERATOR_FAB": "0x782436a28B5d45645C8b56f4456f1593AF29FD8f", // "ASSESSOR_FAB": "0xc2ACC63c37634f37a8Fa26F041CC2FA4331a3184", // "ASSESSOR_ADMIN_FAB": "0xcA0fA916eB9003AD35d1356bE867c0CF28a9aab4", // "COORDINATOR_FAB": "0x2b0E830af4353CDeED11E3FB32b35E67a6641162", // "TRANCHE_FAB": "0xFA75dFDa070dC69EadCD6eb17fE08BAECBa23C88", // "MEMBERLIST_FAB": "0x7E3bd3ee54febd930DA077479093C527F11d1729", // "RESTRICTEDTOKEN_FAB": "0x0e9A86D770EDa4dea6c1d7C8cd23245318F4327a", // "RESERVE_FAB": "0x067129E2D2f1aE84B1014c33C54eAE92D18A5454", // "JUNIOR_OPERATOR": "0x4c4Cc6a0573db5823ECAA1d1d65EB64E5E0E5F01", // "SENIOR_OPERATOR": "0x230f2E19D6c2Dc0c441c2150D4dD9d67B563A60C", // "JUNIOR_TRANCHE": "0x7cD2a6Be6ca8fEB02aeAF08b7F350d7248dA7707", // "SENIOR_TRANCHE": "0x636214f455480D19F17FE1aa45B9989C86041767", // "JUNIOR_TOKEN": "0x961e1d4c9A7C0C3e05F17285f5FA34A66b62dBb1", // "SENIOR_TOKEN": "0xE4C72b4dE5b0F9ACcEA880Ad0b1F944F85A9dAA0", // "JUNIOR_MEMBERLIST": "0x42C2483EEE8c1Fe46C398Ac296C59674F9eb88CD", // "SENIOR_MEMBERLIST": "0x5B5CFD6E45F1407ABCb4BFD9947aBea1EA6649dA", // "ASSESSOR": "0x83E2369A33104120746B589Cc90180ed776fFb91", // "ASSESSOR_ADMIN": "0x46470030e1c732A9C2b541189471E47661311375", // "COORDINATOR": "0xcC7AFB5DeED34CF67E72d4C53B142F44c9268ab9", // "RESERVE": "0xD9E4391cF31638a8Da718Ff0Bf69249Cdc48fB2B", // "GOVERNANCE": "0xf3BceA7494D8f3ac21585CA4b0E52aa175c24C25", // "MAIN_DEPLOYER": "0x1a5a533BcF4ef8A884732056f413114159d03058", // "CLERK": "0xA9eCF012dD36512e5fFCD5585D72386E46135Cdd", // "MAKER_MGR": "0x2474F297214E5d96Ba4C81986A9F0e5C260f445D", // "COMMIT_HASH": "fc1f8e275a9d05d877e64f46810c107cde0808ce", // } // senior // dapp create 'src/lender/tranche.sol:Tranche' 0x6b175474e89094c44da98b954eedeac495271d0f 0xE4C72b4dE5b0F9ACcEA880Ad0b1F944F85A9dAA0 // 0x3f06DB6334435fF4150e14aD69F6280BF8E8dA64 // junior // dapp create 'src/lender/tranche.sol:Tranche' 0x6b175474e89094c44da98b954eedeac495271d0f 0x961e1d4c9A7C0C3e05F17285f5FA34A66b62dBb1 // 0x53CF3CCd97CA914F9e441B8cd9A901E69B170f27 bool public done; string constant public description = "Tinlake NS2 migration mainnet Spell"; address constant public ROOT = 0x53b2d22d07E069a3b132BfeaaD275b10273d381E; address constant public SENIOR_TOKEN = 0xE4C72b4dE5b0F9ACcEA880Ad0b1F944F85A9dAA0; address constant public JUNIOR_TOKEN = 0x961e1d4c9A7C0C3e05F17285f5FA34A66b62dBb1; address constant public SENIOR_OPERATOR = 0x230f2E19D6c2Dc0c441c2150D4dD9d67B563A60C; address constant public JUNIOR_OPERATOR = 0x4c4Cc6a0573db5823ECAA1d1d65EB64E5E0E5F01; address constant public ASSESSOR = 0x83E2369A33104120746B589Cc90180ed776fFb91; address constant public COORDINATOR = 0xcC7AFB5DeED34CF67E72d4C53B142F44c9268ab9; address constant public RESERVE = 0xD9E4391cF31638a8Da718Ff0Bf69249Cdc48fB2B; address constant public CLERK = 0xA9eCF012dD36512e5fFCD5585D72386E46135Cdd; address constant public MGR = 0x2474F297214E5d96Ba4C81986A9F0e5C260f445D; address constant public SENIOR_TRANCHE_OLD = 0x636214f455480D19F17FE1aa45B9989C86041767; address constant public JUNIOR_TRANCHE_OLD = 0x7cD2a6Be6ca8fEB02aeAF08b7F350d7248dA7707; address constant public TINLAKE_CURRENCY = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // DAI // new contracts -> to be migrated address constant public SENIOR_TRANCHE_NEW = 0x3f06DB6334435fF4150e14aD69F6280BF8E8dA64; address constant public JUNIOR_TRANCHE_NEW = 0x53CF3CCd97CA914F9e441B8cd9A901E69B170f27; address self; // permissions to be set function cast() public { require(!done, "spell-already-cast"); done = true; execute(); } function execute() internal { SpellTinlakeRootLike root = SpellTinlakeRootLike(ROOT); self = address(this); // set spell as ward on the core contract to be able to wire the new contracts correctly root.relyContract(JUNIOR_TRANCHE_OLD, self); root.relyContract(SENIOR_TRANCHE_OLD, self); root.relyContract(SENIOR_TRANCHE_NEW, self); root.relyContract(JUNIOR_TRANCHE_NEW, self); root.relyContract(SENIOR_OPERATOR, self); root.relyContract(JUNIOR_OPERATOR, self); root.relyContract(SENIOR_TOKEN, self); root.relyContract(JUNIOR_TOKEN, self); root.relyContract(ASSESSOR, self); root.relyContract(COORDINATOR, self); root.relyContract(RESERVE, self); root.relyContract(CLERK, self); root.relyContract(MGR, self); // contract migration --> assumption: root contract is already ward on the new contracts migrateTranches(); } function migrateTranches() internal { // senior TrancheLike seniorTranche = TrancheLike(SENIOR_TRANCHE_NEW); require((seniorTranche.totalSupply() == 0 && seniorTranche.totalRedeem() == 0), "senior-tranche-has-orders"); // dependencies DependLike(SENIOR_TRANCHE_NEW).depend("reserve", RESERVE); DependLike(SENIOR_TRANCHE_NEW).depend("epochTicker", COORDINATOR); DependLike(SENIOR_OPERATOR).depend("tranche", SENIOR_TRANCHE_NEW); DependLike(ASSESSOR).depend("seniorTranche", SENIOR_TRANCHE_NEW); DependLike(COORDINATOR).depend("seniorTranche", SENIOR_TRANCHE_NEW); DependLike(CLERK).depend("tranche", SENIOR_TRANCHE_NEW); FileLike(MGR).file("tranche", SENIOR_TRANCHE_NEW); // permissions AuthLike(SENIOR_TRANCHE_NEW).rely(SENIOR_OPERATOR); AuthLike(SENIOR_TRANCHE_NEW).rely(COORDINATOR); AuthLike(SENIOR_TRANCHE_NEW).rely(CLERK); AuthLike(SENIOR_TOKEN).deny(SENIOR_TRANCHE_OLD); AuthLike(SENIOR_TOKEN).rely(SENIOR_TRANCHE_NEW); AuthLike(RESERVE).deny(SENIOR_TRANCHE_OLD); AuthLike(RESERVE).rely(SENIOR_TRANCHE_NEW); // junior TrancheLike juniorTranche = TrancheLike(SENIOR_TRANCHE_NEW); require((juniorTranche.totalSupply() == 0 && juniorTranche.totalRedeem() == 0), "junior-tranche-has-orders"); // dependencies DependLike(JUNIOR_TRANCHE_NEW).depend("reserve", RESERVE); DependLike(JUNIOR_TRANCHE_NEW).depend("epochTicker", COORDINATOR); DependLike(JUNIOR_OPERATOR).depend("tranche", JUNIOR_TRANCHE_NEW); DependLike(ASSESSOR).depend("juniorTranche", JUNIOR_TRANCHE_NEW); DependLike(COORDINATOR).depend("juniorTranche", JUNIOR_TRANCHE_NEW); // permissions AuthLike(JUNIOR_TRANCHE_NEW).rely(JUNIOR_OPERATOR); AuthLike(JUNIOR_TRANCHE_NEW).rely(COORDINATOR); AuthLike(JUNIOR_TOKEN).deny(JUNIOR_TRANCHE_OLD); AuthLike(JUNIOR_TOKEN).rely(JUNIOR_TRANCHE_NEW); AuthLike(RESERVE).deny(JUNIOR_TRANCHE_OLD); AuthLike(RESERVE).rely(JUNIOR_TRANCHE_NEW); } }
// spell for: ns2 tranche migration
LineComment
cast
function cast() public { require(!done, "spell-already-cast"); done = true; execute(); }
// permissions to be set
LineComment
v0.5.15+commit.6a57276f
Unknown
bzzr://18dae78835aa7dfec024bdfb78040f31b174bb13681c462843146ed6cd78a0ac
{ "func_code_index": [ 4656, 4781 ] }
58,294
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; }
// fetch the api endpoint
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 1046, 1164 ] }
58,295
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
setBaseURI
function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; }
// set the api endpoint, useful if the endpoint needs to be changed to a different location
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 1266, 1372 ] }
58,296
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
setPrice
function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; }
// let the owner of the contract change the price of the LMC token, set amount in WEI!!!!
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 1472, 1567 ] }
58,297
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
withdrawAll
function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); }
// withdraw the funds of the contract to the owner of the smart contract
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 1650, 2004 ] }
58,298
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
pause
function pause(bool val) public onlyOwner { salePaused = val; }
// pause or start the sale
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 2041, 2123 ] }
58,299
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
walletOfOwner
function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; }
// view the tokens of the holder, if the owner does not hold any tokens, return an empty array
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 2228, 2576 ] }
58,300
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
mintLMC
function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } }
// mint los muertos, max. 20
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 2615, 3259 ] }
58,301
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
setProvenanceHash
function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; }
// set the provenance hash
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 3296, 3425 ] }
58,302
LosMuertosClub
LosMuertosClub.sol
0x401253bd4333014c73d81a308166ade05d954c2f
Solidity
LosMuertosClub
contract LosMuertosClub is ERC721Enumerable, Ownable { string baseTokenURI; uint256 public price = 0.02 ether; bool public salePaused = true; uint256 public reserved = 26; // Team gets 4 LMC (minted in constructor), 26 are used for giveaways and other competitions uint256 public constant MAX_LMCS = 10000; string public LMC_PROVENANCE; address a1 = 0xFCDE8D498c3C722db4f7aaf554050dDF1B79FaA4; address a2 = 0x5c716bEDAe1CE71794F39a2055cbaE235723524F; address a3 = 0xe013DF7bED2c8D4E1642e8CD71CBe4FB25856336; address a4 = 0xb18ec35495748904279dcCE0c4EDDB49bf4Ef270; // constructor is executed when the contract is deployed. Sets name and symbol and mints the first 4 LMCs for team constructor(string memory baseURI) ERC721("Los Muertos Club", "LMC") { setBaseURI(baseURI); // the team gets the first 4 token _safeMint( a1, 0); _safeMint( a2, 1); _safeMint( a3, 2); _safeMint( a4, 3); } // fetch the api endpoint function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } // set the api endpoint, useful if the endpoint needs to be changed to a different location function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } // let the owner of the contract change the price of the LMC token, set amount in WEI!!!! function setPrice(uint256 _newPrice) public onlyOwner { price = _newPrice; } // withdraw the funds of the contract to the owner of the smart contract function withdrawAll() public payable onlyOwner { //require(payable(msg.sender).send(address(this).balance)); uint256 _each = address(this).balance / 4; require(payable(a1).send(_each)); require(payable(a2).send(_each)); require(payable(a3).send(_each)); require(payable(a4).send(_each)); } // pause or start the sale function pause(bool val) public onlyOwner { salePaused = val; } // view the tokens of the holder, if the owner does not hold any tokens, return an empty array function walletOfOwner(address _owner) public view returns(uint256[] memory) { uint256 tokenCount = balanceOf(_owner); uint256[] memory tokenIDs = new uint256[](tokenCount); for(uint256 i; i < tokenCount; i++) { tokenIDs[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIDs; } // mint los muertos, max. 20 function mintLMC(uint256 amountOfTokens) public payable { require(!salePaused, "Sale paused"); require(amountOfTokens > 0 && amountOfTokens < 21, "Minimum mint is 1 and max are 20 LMCs at a time"); require(msg.value == price * amountOfTokens, "Ether sent is not correct"); uint256 supply = totalSupply(); require((supply + amountOfTokens) <= MAX_LMCS - reserved, "Purchase would exceed max supply of LMCs"); for (uint256 i; i < amountOfTokens; i++) { _safeMint(msg.sender, supply + i); } } // set the provenance hash function setProvenanceHash(string memory provenanceHash) public onlyOwner { LMC_PROVENANCE = provenanceHash; } // reserve LMCs for giveaways function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; } }
reserveLMC
function reserveLMC(address to, uint256 amount) public onlyOwner { require(amount > 0 && amount <= reserved, "Requested LMC amount exceeds reserve"); uint256 supply = totalSupply(); for (uint256 i; i < amount; i++) { _safeMint(to, supply + i); } reserved -= amount; }
// reserve LMCs for giveaways
LineComment
v0.8.0+commit.c7dfd78e
MIT
ipfs://cc478c31312dda3db4f8b77056a6c0f698cdea79f290ae53ec97d2ef0ffcb317
{ "func_code_index": [ 3465, 3820 ] }
58,303
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
transfer
function transfer(address _to, uint256 _value) public returns (bool) { balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 270, 516 ] }
58,304
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } }
/** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; }
/** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 722, 838 ] }
58,305
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amout of tokens to be transfered */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // require (_value <= _allowance); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifing the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // require (_value <= _allowance); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); Transfer(_from, _to, _value); return true; }
/** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amout of tokens to be transfered */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 383, 893 ] }
58,306
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amout of tokens to be transfered */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // require (_value <= _allowance); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifing the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
approve
function approve(address _spender, uint256 _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; }
/** * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 1124, 1679 ] }
58,307
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amout of tokens to be transfered */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // require (_value <= _allowance); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 require((_value == 0) || (allowed[msg.sender][_spender] == 0)); allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifing the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
allowance
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifing the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 1997, 2142 ] }
58,308
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
Ownable
contract Ownable { address public owner; /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
Ownable
function Ownable() public { owner = msg.sender; }
/** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 166, 226 ] }
58,309
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
Ownable
contract Ownable { address public owner; /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); owner = newOwner; }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 540, 672 ] }
58,310
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will recieve the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) public onlyOwner canMint returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() public onlyOwner returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
mint
function mint(address _to, uint256 _amount) public onlyOwner canMint returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); return true; }
/** * @dev Function to mint tokens * @param _to The address that will recieve the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 480, 710 ] }
58,311
DbiCapitalToken
DbiCapitalToken.sol
0x6e5c02cf6fa4770a8c91d19cf58d24bd24bcc6b8
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will recieve the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) public onlyOwner canMint returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() public onlyOwner returns (bool) { mintingFinished = true; MintFinished(); return true; } }
/** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */
NatSpecMultiLine
finishMinting
function finishMinting() public onlyOwner returns (bool) { mintingFinished = true; MintFinished(); return true; }
/** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */
NatSpecMultiLine
v0.4.20-nightly.2018.1.6+commit.2548228b
bzzr://0072e4a12713420877533462089c6f82e4381491f119877b6a795c9463895c11
{ "func_code_index": [ 824, 958 ] }
58,312
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
setAuthenticationPeriod
function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; }
/* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 1156, 1289 ] }
58,313
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
authenticate
function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; }
/* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 1495, 1685 ] }
58,314
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
addWhitelisted
function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); }
/* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 1850, 2034 ] }
58,315
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
addWhitelistedWithDID
function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); }
/* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 2199, 2421 ] }
58,316
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
removeWhitelisted
function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); }
/* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 2592, 2782 ] }
58,317
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
renounceWhitelisted
function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); }
/* @dev Renounces message sender from whitelisted */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 2849, 2955 ] }
58,318
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
isWhitelisted
function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); }
/* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 3160, 3437 ] }
58,319
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
lastAuthenticated
function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; }
/* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 3607, 3738 ] }
58,320
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
addBlacklisted
function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); }
/* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 5052, 5273 ] }
58,321
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
removeBlacklisted
function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); }
/* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 5443, 5672 ] }
58,322
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
addContract
function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); }
/* @dev Function to add a Contract to list of contracts * @param account The address to add */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 5787, 6115 ] }
58,323
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
removeContract
function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); }
/* @dev Function to remove a Contract from list of contracts * @param account The address to add */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 6235, 6500 ] }
58,324
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
isDAOContract
function isDAOContract(address account) public view returns (bool) { return contracts.has(account); }
/* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 6687, 6807 ] }
58,325
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
_addWhitelisted
function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); }
/* @dev Internal function to add to whitelisted * @param account the address to add */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 6914, 7255 ] }
58,326
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
_addWhitelistedWithDID
function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); }
/* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 7415, 7754 ] }
58,327
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
_removeWhitelisted
function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); }
/* @dev Internal function to remove from whitelisted * @param account the address to add */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 7866, 8403 ] }
58,328
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
isBlacklisted
function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); }
/* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 8616, 8736 ] }
58,329
GoodDollar
contracts/identity/Identity.sol
0x67c5870b4a41d4ebef24d2456547a03f1f3e094b
Solidity
Identity
contract Identity is IdentityAdminRole, SchemeGuard, Pausable { using Roles for Roles.Role; using SafeMath for uint256; Roles.Role private blacklist; Roles.Role private whitelist; Roles.Role private contracts; uint256 public whitelistedCount = 0; uint256 public whitelistedContracts = 0; uint256 public authenticationPeriod = 14; mapping(address => uint256) public dateAuthenticated; mapping(address => uint256) public dateAdded; mapping(address => string) public addrToDID; mapping(bytes32 => address) public didHashToAddress; event BlacklistAdded(address indexed account); event BlacklistRemoved(address indexed account); event WhitelistedAdded(address indexed account); event WhitelistedRemoved(address indexed account); event ContractAdded(address indexed account); event ContractRemoved(address indexed account); constructor() public SchemeGuard(Avatar(0)) {} /* @dev Sets a new value for authenticationPeriod. * Can only be called by Identity Administrators. * @param period new value for authenticationPeriod */ function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused { authenticationPeriod = period; } /* @dev Sets the authentication date of `account` * to the current time. * Can only be called by Identity Administrators. * @param account address to change its auth date */ function authenticate(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { dateAuthenticated[account] = now; } /* @dev Adds an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to add as whitelisted */ function addWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelisted(account); } /* @dev Adds an address as whitelisted under a specific ID * @param account The address to add * @param did the ID to add account under */ function addWhitelistedWithDID(address account, string memory did) public onlyRegistered onlyIdentityAdmin whenNotPaused { _addWhitelistedWithDID(account, did); } /* @dev Removes an address as whitelisted. * Can only be called by Identity Administrators. * @param account address to remove as whitelisted */ function removeWhitelisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { _removeWhitelisted(account); } /* @dev Renounces message sender from whitelisted */ function renounceWhitelisted() public whenNotPaused { _removeWhitelisted(msg.sender); } /* @dev Returns true if given address has been added to whitelist * @param account the address to check * @return a bool indicating weather the address is present in whitelist */ function isWhitelisted(address account) public view returns (bool) { uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days; return (daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account); } /* @dev Function that gives the date the given user was added * @param account The address to check * @return The date the address was added */ function lastAuthenticated(address account) public view returns (uint256) { return dateAuthenticated[account]; } // /** // * // * @dev Function to transfer whitelisted privilege to another address // * relocates did of sender to give address // * @param account The address to transfer to // */ // function transferAccount(address account) public whenNotPaused { // ERC20 token = avatar.nativeToken(); // require(!isBlacklisted(account), "Cannot transfer to blacklisted"); // require(token.balanceOf(account) == 0, "Account is already in use"); // require(isWhitelisted(msg.sender), "Requester need to be whitelisted"); // require( // keccak256(bytes(addrToDID[account])) == keccak256(bytes("")), // "address already has DID" // ); // string memory did = addrToDID[msg.sender]; // bytes32 pHash = keccak256(bytes(did)); // uint256 balance = token.balanceOf(msg.sender); // token.transferFrom(msg.sender, account, balance); // _removeWhitelisted(msg.sender); // _addWhitelisted(account); // addrToDID[account] = did; // didHashToAddress[pHash] = account; // } /* @dev Adds an address to blacklist. * Can only be called by Identity Administrators. * @param account address to add as blacklisted */ function addBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.add(account); emit BlacklistAdded(account); } /* @dev Removes an address from blacklist * Can only be called by Identity Administrators. * @param account address to remove as blacklisted */ function removeBlacklisted(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { blacklist.remove(account); emit BlacklistRemoved(account); } /* @dev Function to add a Contract to list of contracts * @param account The address to add */ function addContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { require(isContract(account), "Given address is not a contract"); contracts.add(account); _addWhitelisted(account); emit ContractAdded(account); } /* @dev Function to remove a Contract from list of contracts * @param account The address to add */ function removeContract(address account) public onlyRegistered onlyIdentityAdmin whenNotPaused { contracts.remove(account); _removeWhitelisted(account); emit ContractRemoved(account); } /* @dev Function to check if given contract is on list of contracts. * @param address to check * @return a bool indicating if address is on list of contracts */ function isDAOContract(address account) public view returns (bool) { return contracts.has(account); } /* @dev Internal function to add to whitelisted * @param account the address to add */ function _addWhitelisted(address account) internal { whitelist.add(account); whitelistedCount += 1; dateAdded[account] = now; dateAuthenticated[account] = now; if (isContract(account)) { whitelistedContracts += 1; } emit WhitelistedAdded(account); } /* @dev Internal whitelisting with did function. * @param account the address to add * @param did the id to register account under */ function _addWhitelistedWithDID(address account, string memory did) internal { bytes32 pHash = keccak256(bytes(did)); require(didHashToAddress[pHash] == address(0), "DID already registered"); addrToDID[account] = did; didHashToAddress[pHash] = account; _addWhitelisted(account); } /* @dev Internal function to remove from whitelisted * @param account the address to add */ function _removeWhitelisted(address account) internal { whitelist.remove(account); whitelistedCount -= 1; delete dateAuthenticated[account]; if (isContract(account)) { whitelistedContracts -= 1; } string memory did = addrToDID[account]; bytes32 pHash = keccak256(bytes(did)); delete dateAuthenticated[account]; delete addrToDID[account]; delete didHashToAddress[pHash]; emit WhitelistedRemoved(account); } /* @dev Returns true if given address has been added to the blacklist * @param account the address to check * @return a bool indicating weather the address is present in the blacklist */ function isBlacklisted(address account) public view returns (bool) { return blacklist.has(account); } /* @dev Function to see if given address is a contract * @return true if address is a contract */ function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; } }
/* @title Identity contract responsible for whitelisting * and keeping track of amount of whitelisted users */
Comment
isContract
function isContract(address _addr) internal view returns (bool) { uint256 length; assembly { length := extcodesize(_addr) } return length > 0; }
/* @dev Function to see if given address is a contract * @return true if address is a contract */
Comment
v0.5.16+commit.9c3226ce
MIT
bzzr://377577b98803c2210dfa17f6feaf68d6a856726073543a35d4a8526c1f78cc9f
{ "func_code_index": [ 8854, 9057 ] }
58,330
Urn
contracts/Urn.sol
0xe4520f883c7760bfb35071463346c5eafbb25622
Solidity
Urn
contract Urn is ERC20("URN", "URN"), ERC20Permit("URN"), ERC20Burnable, ReentrancyGuard, Ownable(5, true, true) { /// Track controller contracts and their permissions mapping(address => bool) private _controllers; /// Authorises known addresses to mint URN tokens. /// @param contractAddress The address to associate permissions /// @param canMint Is the address allowed to mint URN function setController(address contractAddress, bool canMint) external onlyOwner { require(Address.isContract(contractAddress), "Only contracts can be added as controllers"); _controllers[contractAddress] = canMint; } /// Mint URN Tokens from controllers /// @param to The address to mint tokens for /// @param amount The amount of tokens to mint function mint(address to, uint256 amount) external nonReentrant { require(_controllers[_msgSender()] == true, "Only controllers with mint permissions can mint URN"); _mint(to, amount); } }
/// @title Graveyard NFT Project's URN Token /// @author @0xyamyam /// @notice URN tokens have no specified utility or value, who knows what the future holds. /// URN tokens are minted when you commit failed NFT project tokens to the Graveyard (more if you own a CRYPT).
NatSpecSingleLine
setController
function setController(address contractAddress, bool canMint) external onlyOwner { require(Address.isContract(contractAddress), "Only contracts can be added as controllers"); _controllers[contractAddress] = canMint; }
/// Authorises known addresses to mint URN tokens. /// @param contractAddress The address to associate permissions /// @param canMint Is the address allowed to mint URN
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 404, 645 ] }
58,331
Urn
contracts/Urn.sol
0xe4520f883c7760bfb35071463346c5eafbb25622
Solidity
Urn
contract Urn is ERC20("URN", "URN"), ERC20Permit("URN"), ERC20Burnable, ReentrancyGuard, Ownable(5, true, true) { /// Track controller contracts and their permissions mapping(address => bool) private _controllers; /// Authorises known addresses to mint URN tokens. /// @param contractAddress The address to associate permissions /// @param canMint Is the address allowed to mint URN function setController(address contractAddress, bool canMint) external onlyOwner { require(Address.isContract(contractAddress), "Only contracts can be added as controllers"); _controllers[contractAddress] = canMint; } /// Mint URN Tokens from controllers /// @param to The address to mint tokens for /// @param amount The amount of tokens to mint function mint(address to, uint256 amount) external nonReentrant { require(_controllers[_msgSender()] == true, "Only controllers with mint permissions can mint URN"); _mint(to, amount); } }
/// @title Graveyard NFT Project's URN Token /// @author @0xyamyam /// @notice URN tokens have no specified utility or value, who knows what the future holds. /// URN tokens are minted when you commit failed NFT project tokens to the Graveyard (more if you own a CRYPT).
NatSpecSingleLine
mint
function mint(address to, uint256 amount) external nonReentrant { require(_controllers[_msgSender()] == true, "Only controllers with mint permissions can mint URN"); _mint(to, amount); }
/// Mint URN Tokens from controllers /// @param to The address to mint tokens for /// @param amount The amount of tokens to mint
NatSpecSingleLine
v0.8.9+commit.e5eed63a
{ "func_code_index": [ 788, 998 ] }
58,332
LinkPriceOracle
LinkPriceOracle.sol
0x24391869e7d7ae4a410d613c17396b6ece227f54
Solidity
LinkPriceOracle
contract LinkPriceOracle is Ownable { mapping(address => ILinkOracle) public linkOracles; mapping(address => uint) private tokenPrices; event AddLinkOracle(address indexed token, address oracle); event RemoveLinkOracle(address indexed token); event PriceUpdate(address indexed token, uint amount); function addLinkOracle(address _token, ILinkOracle _linkOracle) external onlyOwner { require(_linkOracle.decimals() == 8, "LinkPriceOracle: non-usd pairs not allowed"); linkOracles[_token] = _linkOracle; emit AddLinkOracle(_token, address(_linkOracle)); } function removeLinkOracle(address _token) external onlyOwner { linkOracles[_token] = ILinkOracle(address(0)); emit RemoveLinkOracle(_token); } function setTokenPrice(address _token, uint _value) external onlyOwner { tokenPrices[_token] = _value; emit PriceUpdate(_token, _value); } // _token price in USD with 18 decimals function tokenPrice(address _token) external view returns(uint) { if (address(linkOracles[_token]) != address(0)) { uint latestAnswer = linkOracles[_token].latestAnswer(); require(latestAnswer > 1, "LinkPriceOracle: invalid oracle value"); return latestAnswer * 1e10; } else if (tokenPrices[_token] != 0) { return tokenPrices[_token]; } else { revert("LinkPriceOracle: token not supported"); } } function tokenSupported(address _token) external view returns(bool) { return ( address(linkOracles[_token]) != address(0) || tokenPrices[_token] != 0 ); } }
tokenPrice
function tokenPrice(address _token) external view returns(uint) { if (address(linkOracles[_token]) != address(0)) { uint latestAnswer = linkOracles[_token].latestAnswer(); require(latestAnswer > 1, "LinkPriceOracle: invalid oracle value"); return latestAnswer * 1e10; } else if (tokenPrices[_token] != 0) { return tokenPrices[_token]; } else { revert("LinkPriceOracle: token not supported"); } }
// _token price in USD with 18 decimals
LineComment
v0.8.6+commit.11564f7e
None
ipfs://3d69d6d990cf279579f884901a02dd8a7964a3d289072ea13bc38adff7491e96
{ "func_code_index": [ 962, 1426 ] }
58,333
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
IERC165
contract IERC165 { /** * @notice Query if a contract implements an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @dev Interface identification is specified in ERC-165. This function * uses less than 30,000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
/** * @title IERC165 * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
supportsInterface
function supportsInterface(bytes4 interfaceId) external view returns (bool);
/** * @notice Query if a contract implements an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @dev Interface identification is specified in ERC-165. This function * uses less than 30,000 gas. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 287, 368 ] }
58,334
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
IERC721Receiver
contract IERC721Receiver { /** * @notice Handle the receipt of an NFT * @dev The ERC721 smart contract calls this function on the recipient * after a `safeTransfer`. This function MUST return the function selector, * otherwise the caller will revert the transaction. The selector to be * returned can be obtained as `this.onERC721Received.selector`. This * function MAY throw to revert and reject the transfer. * Note: the ERC721 contract address is always the message sender. * @param operator The address which called `safeTransferFrom` function * @param from The address which previously owned the token * @param tokenId The NFT identifier which is being transferred * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` */ function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) public returns (bytes4); }
/** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */
NatSpecMultiLine
onERC721Received
function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) public returns (bytes4);
/** * @notice Handle the receipt of an NFT * @dev The ERC721 smart contract calls this function on the recipient * after a `safeTransfer`. This function MUST return the function selector, * otherwise the caller will revert the transaction. The selector to be * returned can be obtained as `this.onERC721Received.selector`. This * function MAY throw to revert and reject the transfer. * Note: the ERC721 contract address is always the message sender. * @param operator The address which called `safeTransferFrom` function * @param from The address which previously owned the token * @param tokenId The NFT identifier which is being transferred * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 893, 1016 ] }
58,335
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
ERC165
contract ERC165 is IERC165 { bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @dev a mapping of interface id to whether or not it's supported */ mapping(bytes4 => bool) private _supportedInterfaces; /** * @dev A contract implementing SupportsInterfaceWithLookup * implement ERC165 itself */ constructor () internal { _registerInterface(_InterfaceId_ERC165); } /** * @dev implement supportsInterface(bytes4) using a lookup table */ function supportsInterface(bytes4 interfaceId) external view returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev internal method for registering an interface */ function _registerInterface(bytes4 interfaceId) internal { require(interfaceId != 0xffffffff); _supportedInterfaces[interfaceId] = true; } }
/** * @title ERC165 * @author Matt Condon (@shrugs) * @dev Implements ERC165 using a lookup table. */
NatSpecMultiLine
supportsInterface
function supportsInterface(bytes4 interfaceId) external view returns (bool) { return _supportedInterfaces[interfaceId]; }
/** * @dev implement supportsInterface(bytes4) using a lookup table */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 639, 779 ] }
58,336
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
ERC165
contract ERC165 is IERC165 { bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @dev a mapping of interface id to whether or not it's supported */ mapping(bytes4 => bool) private _supportedInterfaces; /** * @dev A contract implementing SupportsInterfaceWithLookup * implement ERC165 itself */ constructor () internal { _registerInterface(_InterfaceId_ERC165); } /** * @dev implement supportsInterface(bytes4) using a lookup table */ function supportsInterface(bytes4 interfaceId) external view returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev internal method for registering an interface */ function _registerInterface(bytes4 interfaceId) internal { require(interfaceId != 0xffffffff); _supportedInterfaces[interfaceId] = true; } }
/** * @title ERC165 * @author Matt Condon (@shrugs) * @dev Implements ERC165 using a lookup table. */
NatSpecMultiLine
_registerInterface
function _registerInterface(bytes4 interfaceId) internal { require(interfaceId != 0xffffffff); _supportedInterfaces[interfaceId] = true; }
/** * @dev internal method for registering an interface */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 858, 1024 ] }
58,337
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
owner
function owner() public view returns (address) { return _owner; }
/** * @return the address of the owner. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 457, 541 ] }
58,338
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
isOwner
function isOwner() public view returns (bool) { return msg.sender == _owner; }
/** * @return true if `msg.sender` is the owner of the contract. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 792, 889 ] }
58,339
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 1170, 1315 ] }
58,340
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 1487, 1601 ] }
58,341
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */
NatSpecMultiLine
_transferOwnership
function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 1746, 1938 ] }
58,342
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
add
function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; }
/** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 259, 445 ] }
58,343
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 723, 864 ] }
58,344
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 1162, 1359 ] }
58,345
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mul
function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; }
/** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 1613, 2089 ] }
58,346
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); }
/** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 2560, 2697 ] }
58,347
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; }
/** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 3188, 3471 ] }
58,348
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 3931, 4066 ] }
58,349
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 4546, 4717 ] }
58,350
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Address
library Address { /** * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param account address of the account to check * @return whether the target address is a contract */ function isContract(address account) internal view returns (bool) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solium-disable-next-line security/no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } }
/** * Utility library of inline functions on addresses */
NatSpecMultiLine
isContract
function isContract(address account) internal view returns (bool) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solium-disable-next-line security/no-inline-assembly assembly { size := extcodesize(account) } return size > 0; }
/** * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param account address of the account to check * @return whether the target address is a contract */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 382, 1022 ] }
58,351
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
mintUnicorn
function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); quire(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; ICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); icornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); }
// Get the Unicorn's head item
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 4320, 5088 ] }
58,352
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getIndividualCount
function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; }
// The total supply of any one item // Ask for example how many of "Torch" item exist
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 6203, 6710 ] }
58,353
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getIndividualOwnedCount
function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; }
// Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 6841, 7474 ] }
58,354
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getIndividualCountByID
function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; }
// Given a _tokenId returns how many other tokens exist with // the same _templateId
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 7577, 8104 ] }
58,355
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getIndividualOwnedCountByID
function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; }
// Given a _tokenId returns how many other tokens the _owner has // with the same _templateId
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 8216, 8922 ] }
58,356
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getTemplateCountsByTokenIDs
function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; }
/* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */
Comment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 9050, 9442 ] }
58,357
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getTemplateCountsByTokenIDsOfOwner
function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; }
/* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */
Comment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 9591, 10029 ] }
58,358
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getTemplateIDsByTokenIDs
function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; }
/* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */
Comment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 10245, 10646 ] }
58,359
Inventory
Inventory.sol
0x9680223f7069203e361f55fefc89b7c1a952cdcc
Solidity
Inventory
contract Inventory is ERC165, IERC721, IERC721Metadata, IERC721Enumerable, Ownable { using SafeMath for uint256; using Address for address; string private _name; string private _symbol; string private _pathStart; string private _pathEnd; bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; bytes4 private constant _InterfaceId_ERC721Enumerable = 0x780e9d63; bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd; bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Treasure chest reward token (VIDYA) ERC20Token public constant treasureChestRewardToken = ERC20Token(0x3D3D35bb9bEC23b06Ca00fe472b50E7A4c692C30); // Uniswap token ERC20Token public constant UNI_ADDRESS = ERC20Token(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // Unicorn's Head uint256 private constant UNICORN_TEMPLATE_ID = 11; uint256 public UNICORN_TOTAL_SUPPLY = 0; mapping (address => bool) public unicornClaimed; // Mapping from token ID to owner mapping (uint256 => address) private _tokenOwner; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to number of owned tokens mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Mapping of contract addresses that are allowed to edit item features mapping (address => bool) private _approvedGameContract; // Mapping from token ID to respective treasure chest rewards in VIDYA tokens mapping (uint256 => uint256) public treasureChestRewards; // Mapping to calculate how many treasure hunts an address has participated in mapping (address => uint256) public treasureHuntPoints; // Mapping for the different equipment items of each address/character // 0 - head, 1 - left hand, 2 - neck, 3 - right hand, 4 - chest, 5 - legs mapping (address => uint256[6]) public characterEquipment; // To check if a template exists mapping (uint256 => bool) _templateExists; /* Item struct holds the templateId, a total of 4 additional features and the burned status */ struct Item { uint256 templateId; // id of Template in the itemTemplates array uint8 feature1; uint8 feature2; uint8 feature3; uint8 feature4; uint8 equipmentPosition; bool burned; } /* Template struct holds the uri for each Item- a reference to the json file which describes them */ struct Template { string uri; } // All items created, ever, both burned and not burned Item[] public allItems; // Admin editable templates for each item Template[] public itemTemplates; modifier onlyApprovedGame() { require(_approvedGameContract[msg.sender], "msg.sender is not an approved game contract"); _; } modifier tokenExists(uint256 _tokenId) { require(_exists(_tokenId), "Token does not exist"); _; } modifier isOwnedByOrigin(uint256 _tokenId) { require(ownerOf(_tokenId) == tx.origin, "tx.origin is not the token owner"); _; } modifier isOwnerOrApprovedGame(uint256 _tokenId) { require(ownerOf(_tokenId) == msg.sender || _approvedGameContract[msg.sender], "Not owner or approved game"); _; } modifier templateExists(uint256 _templateId) { require(_templateExists[_templateId], "Template does not exist"); _; } constructor() public { _name = "Inventory"; _symbol = "ITEM"; _pathStart = "https://team3d.io/inventory/json/"; _pathEnd = ".json"; _registerInterface(InterfaceId_ERC721Metadata); _registerInterface(_InterfaceId_ERC721Enumerable); _registerInterface(_InterfaceId_ERC721); // Add the "nothing" item to msg.sender // This is a dummy item so that valid items in allItems start with 1 addNewItem(0,0); } // Get the Unicorn's head item function mintUnicorn() external { uint256 id; require(UNICORN_TOTAL_SUPPLY < 100, "Unicorns are now extinct"); require(!unicornClaimed[msg.sender], "You have already claimed a unicorn"); require(UNI_ADDRESS.balanceOf(msg.sender) >= 1000 * 10**18, "Min balance 1000 UNI"); require(_templateExists[UNICORN_TEMPLATE_ID], "Unicorn template has not been added yet"); checkAndTransferVIDYA(1000 * 10**18); // Unicorn's head costs 1000 VIDYA id = allItems.push(Item(UNICORN_TEMPLATE_ID,0,0,0,0,0,false)) -1; UNICORN_TOTAL_SUPPLY = UNICORN_TOTAL_SUPPLY.add(1); unicornClaimed[msg.sender] = true; // Materialize _mint(msg.sender, id); } function checkAndTransferVIDYA(uint256 _amount) private { require(treasureChestRewardToken.transferFrom(msg.sender, address(this), _amount) == true, "transfer must succeed"); } function equip( uint256 _tokenId, uint8 _equipmentPosition ) external tokenExists(_tokenId) { require(_equipmentPosition < 6); require(allItems[_tokenId].equipmentPosition == _equipmentPosition, "Item cannot be equipped in this slot"); characterEquipment[msg.sender][_equipmentPosition] = _tokenId; } function unequip( uint8 _equipmentPosition ) external { require(_equipmentPosition < 6); characterEquipment[msg.sender][_equipmentPosition] = 0; } function getEquipment( address player ) public view returns(uint256[6] memory) { return characterEquipment[player]; } // The total supply of any one item // Ask for example how many of "Torch" item exist function getIndividualCount( uint256 _templateId ) public view returns(uint256) { uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If match found & is not burned if (allItems[i].templateId == _templateId && !allItems[i].burned) { counter++; } } // Total supply of item using the _templateId return counter; } // Total supply of any one item owned by _owner // Ask for example how many of "Torch" item does the _owner have function getIndividualOwnedCount( uint256 _templateId, address _owner ) public view returns(uint256) { uint counter = 0; uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { /* If ownedItems[i]'s templateId matches the one in allItems[] */ if(allItems[ownedItems[i]].templateId == _templateId) { counter++; } } // Total supply of _templateId that _owner owns return counter; } // Given a _tokenId returns how many other tokens exist with // the same _templateId function getIndividualCountByID( uint256 _tokenId ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for for(uint i = 0; i < allItems.length; i++) { if(templateId == allItems[i].templateId && !allItems[i].burned) { counter++; } } return counter; } // Given a _tokenId returns how many other tokens the _owner has // with the same _templateId function getIndividualOwnedCountByID( uint256 _tokenId, address _owner ) public view tokenExists(_tokenId) returns(uint256) { uint256 counter = 0; uint256 templateId = allItems[_tokenId].templateId; // templateId we are looking for uint[] memory ownedItems = getItemsByOwner(_owner); for(uint i = 0; i < ownedItems.length; i++) { // The item cannot be burned because of getItemsByOwner(_owner), no need to check if(templateId == allItems[ownedItems[i]].templateId) { counter++; } } return counter; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds */ function getTemplateCountsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualCountByID(_tokenIds[i]); } return counts; } /* Given an array of _tokenIds return the corresponding _templateId count for each of those _tokenIds that the _owner owns */ function getTemplateCountsByTokenIDsOfOwner( uint[] memory _tokenIds, address _owner ) public view returns(uint[] memory) { uint[] memory counts = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { counts[i] = getIndividualOwnedCountByID(_tokenIds[i], _owner); } return counts; } /* Given an array of _tokenIds return the corresponding _templateIds for each of those _tokenIds Useful for cross referencing / weeding out duplicates to populate the UI */ function getTemplateIDsByTokenIDs( uint[] memory _tokenIds ) public view returns(uint[] memory) { uint[] memory templateIds = new uint[](_tokenIds.length); for(uint i = 0; i < _tokenIds.length; i++) { templateIds[i] = allItems[_tokenIds[i]].templateId; } return templateIds; } // Get all the item id's by owner function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; } // Function to withdraw any ERC20 tokens function withdrawERC20Tokens( address _tokenContract ) external onlyOwner returns(bool) { ERC20Token token = ERC20Token(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(msg.sender, amount); } // Admin can approve (or disapprove) game contracts function approveGameContract( address _game, bool _status ) external onlyOwner { _approvedGameContract[_game] = _status; } // Admin function to set _pathStart and _pathEnd function setPaths( string calldata newPathStart, string calldata newPathEnd ) external onlyOwner returns(bool) { bool success; if(keccak256(abi.encodePacked(_pathStart)) != keccak256(abi.encodePacked(newPathStart))) { _pathStart = newPathStart; success = true; } if(keccak256(abi.encodePacked(_pathEnd)) != keccak256(abi.encodePacked(newPathEnd))) { _pathEnd = newPathEnd; success = true; } return success; } /* Admin can add new item template The _templateId is a reference to Template struct in itemTemplates[] */ function addNewItem( uint256 _templateId, uint8 _equipmentPosition ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(msg.sender, id); } /* Admin can add new item template and send it to receiver in one call */ function addNewItemAndTransfer( uint256 _templateId, uint8 _equipmentPosition, address receiver ) public onlyOwner { uint256 id; // Does the _templateId exist or do we need to add it? if(!_templateExists[_templateId]) { // Add template id for this item as reference itemTemplates.push(Template(uint2str(_templateId))); _templateExists[_templateId] = true; } id = allItems.push(Item(_templateId,0,0,0,0,_equipmentPosition,false)) -1; // Materialize _mint(receiver, id); } /* Allows approved game contracts to create new items from already existing templates (added by admin) In other words this function allows a game to spawn more of ie. "Torch" and set its default features etc */ function createFromTemplate( uint256 _templateId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public templateExists(_templateId) onlyApprovedGame returns(uint256) { uint256 id; address player = tx.origin; id = allItems.push( Item( _templateId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition, false ) ) -1; // Materialize to tx.origin (and not msg.sender aka. the game contract) _mint(player, id); // id of the new item return id; } /* Change feature values of _tokenId Only succeeds when: the tx.origin (a player) owns the item the msg.sender (game contract) is a manually approved game address */ function changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) public onlyApprovedGame // msg.sender has to be a manually approved game address tokenExists(_tokenId) // check if _tokenId exists in the first place isOwnedByOrigin(_tokenId) // does the tx.origin (player in a game) own the token? returns(bool) { return ( _changeFeaturesForItem( _tokenId, _feature1, _feature2, _feature3, _feature4, _equipmentPosition ) ); } function _changeFeaturesForItem( uint256 _tokenId, uint8 _feature1, uint8 _feature2, uint8 _feature3, uint8 _feature4, uint8 _equipmentPosition ) internal returns(bool) { Item storage item = allItems[_tokenId]; if(item.feature1 != _feature1) { item.feature1 = _feature1; } if(item.feature2 != _feature2) { item.feature2 = _feature2; } if(item.feature3 != _feature3) { item.feature3 = _feature3; } if(item.feature4 != _feature4) { item.feature4 = _feature4; } if(item.equipmentPosition != _equipmentPosition) { item.equipmentPosition = _equipmentPosition; } return true; } /* Features of _tokenId Useful in various games where the _tokenId should have traits etc. Example: a "Torch" could start with 255 and degrade during gameplay over time Note: maximum value for uint8 type is 255 */ function getFeaturesOfItem( uint256 _tokenId ) public view returns(uint8[] memory) { Item storage item = allItems[_tokenId]; uint8[] memory features = new uint8[](4); features[0] = item.feature1; features[1] = item.feature2; features[2] = item.feature3; features[3] = item.feature4; return features; } /* Turn uint256 into a string Reason: ERC721 standard needs token uri to return as string, but we don't want to store long urls to the json files on-chain. Instead we use this returned string (which is actually just an ID) and say to front ends that the token uri can be found at somethingsomething.io/tokens/<id>.json */ function uint2str( uint256 i ) internal pure returns(string memory) { if (i == 0) return "0"; uint256 j = i; uint256 length; while (j != 0) { length++; j /= 10; } bytes memory bstr = new bytes(length); uint256 k = length - 1; while (i != 0) { bstr[k--] = byte(uint8(48 + i % 10)); i /= 10; } return string(bstr); } function append( string memory a, string memory b, string memory c ) internal pure returns(string memory) { return string( abi.encodePacked(a, b, c) ); } /* * Adds an NFT and the corresponding reward for whoever finds it and burns it. */ function addTreasureChest(uint256 _tokenId, uint256 _rewardsAmount) external tokenExists(_tokenId) onlyApprovedGame { treasureChestRewards[_tokenId] = _rewardsAmount; } /* Burn the _tokenId Succeeds when: token exists msg.sender is either direct owner of the token OR msg.sender is a manually approved game contract If tx.origin and msg.sender are different, burn the _tokenId of the tx.origin (the player, not the game contract) */ function burn( uint256 _tokenId ) public tokenExists(_tokenId) isOwnerOrApprovedGame(_tokenId) returns(bool) { if (tx.origin == msg.sender) { return _burn(_tokenId, msg.sender); } else { return _burn(_tokenId, tx.origin); } } // Burn owner's tokenId function _burn( uint256 _tokenId, address owner ) internal returns(bool) { // Set burned status on token allItems[_tokenId].burned = true; // Set new owner to 0x0 _tokenOwner[_tokenId] = address(0); // Remove from old owner _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); // Check if it's a treasure hunt token uint256 treasureChestRewardsForToken = treasureChestRewards[_tokenId]; if (treasureChestRewardsForToken > 0) { treasureChestRewardToken.transfer(msg.sender, treasureChestRewardsForToken); treasureHuntPoints[owner]++; } // Fire event emit Transfer(owner, address(0), _tokenId); return true; } function getLevel(address player) public view returns(uint256) { return treasureHuntPoints[player]; } // Return the total supply function totalSupply() public view returns(uint256) { uint256 counter; for(uint i = 0; i < allItems.length; i++) { if(!allItems[i].burned) { counter++; } } // All tokens which are not burned return counter; } // Return the templateId of _index token function tokenByIndex( uint256 _index ) public view returns(uint256) { require(_index < totalSupply()); return allItems[_index].templateId; } // Return The token templateId for the index'th token assigned to owner function tokenOfOwnerByIndex( address owner, uint256 index ) public view returns (uint256 tokenId) { require(index < balanceOf(owner)); return getItemsByOwner(owner)[index]; } /** * @dev Gets the token name * @return string representing the token name */ function name() external view returns(string memory) { return _name; } /** * @dev Gets the token symbol * @return string representing the token symbol */ function symbol() external view returns(string memory) { return _symbol; } /** * @dev Returns an URI for a given token ID * Throws if the token ID does not exist. May return an empty string. * @param tokenId uint256 ID of the token to query */ function tokenURI( uint256 tokenId ) external view returns(string memory) { require(_exists(tokenId)); uint256 tokenTemplateId = allItems[tokenId].templateId; string memory id = uint2str(tokenTemplateId); return append(_pathStart, id, _pathEnd); } /** * @dev Gets the balance of the specified address * @param owner address to query the balance of * @return uint256 representing the amount owned by the passed address */ function balanceOf( address owner ) public view returns(uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; } /** * @dev Gets the owner of the specified token ID * @param tokenId uint256 ID of the token to query the owner of * @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]; require(owner != address(0)); require(!allItems[tokenId].burned, "This token is burned"); // Probably useless require at this point return owner; } /** * @dev Approves another address to transfer the given token ID * The zero address indicates there is no approved address. * There can only be one approved address per token at a given time. * Can only be called by the token owner or an approved operator. * @param to address to be approved for the given token ID * @param tokenId uint256 ID of the token to be approved */ function approve( address to, uint256 tokenId ) public { address owner = ownerOf(tokenId); require(to != owner); require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Gets the approved address for a token ID, or zero if no address set * Reverts if the token ID does not exist. * @param tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved( uint256 tokenId ) public view returns(address) { require(_exists(tokenId)); return _tokenApprovals[tokenId]; } /** * @dev Sets or unsets the approval of a given operator * An operator is allowed to transfer all tokens of the sender on their behalf * @param to operator address to set the approval * @param approved representing the status of the approval to be set */ function setApprovalForAll( address to, bool approved ) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); } /** * @dev Tells whether an operator is approved by a given owner * @param owner owner address which you want to query the approval of * @param operator operator address which you want to query the approval of * @return bool whether the given operator is approved by the given owner */ function isApprovedForAll( address owner, address operator ) public view returns(bool) { return _operatorApprovals[owner][operator]; } /** * @dev Transfers the ownership of a given token ID to another address * Usage of this method is discouraged, use `safeTransferFrom` whenever possible * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function transferFrom( address from, address to, uint256 tokenId ) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function safeTransferFrom( address from, address to, uint256 tokenId ) public { // solium-disable-next-line arg-overflow safeTransferFrom(from, to, tokenId, ""); } /** * @dev Safely transfers the ownership of a given token ID to another address * If the target address is a contract, it must implement `onERC721Received`, * which is called upon a safe transfer, and return the magic value * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, * the transfer is reverted. * Requires the msg sender to be the owner, approved, or operator * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public { transferFrom(from, to, tokenId); // solium-disable-next-line arg-overflow require(_checkOnERC721Received(from, to, tokenId, _data)); } /** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */ function _exists( uint256 tokenId ) internal view returns(bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); } /** * @dev Returns whether the given spender can transfer a given token ID * @param spender address of the spender to query * @param tokenId uint256 ID of the token to be transferred * @return bool whether the msg.sender is approved for the given token ID, * is an operator of the owner, or is the owner of the token */ function _isApprovedOrOwner( address spender, uint256 tokenId ) internal view returns(bool) { address owner = ownerOf(tokenId); // Disable solium check because of // https://github.com/duaraghav8/Solium/issues/175 // solium-disable-next-line operator-whitespace return ( spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender) ); } /** * @dev Internal function to mint a new token * Reverts if the given token ID already exists * @param to The address that will own the minted token * @param tokenId uint256 ID of the token to be minted */ function _mint( address to, uint256 tokenId ) internal { require(to != address(0)); require(!_exists(tokenId)); _tokenOwner[tokenId] = to; _ownedTokensCount[to] = _ownedTokensCount[to].add(1); emit Transfer(address(0), to, tokenId); } /** * @dev Internal function to transfer ownership of a given token ID to another address. * As opposed to transferFrom, this imposes no restrictions on msg.sender. * @param from current owner of the token * @param to address to receive the ownership of the given token ID * @param tokenId uint256 ID of the token to be transferred */ function _transferFrom( address from, address to, uint256 tokenId ) internal { require(ownerOf(tokenId) == from); require(to != address(0)); _clearApproval(tokenId); _ownedTokensCount[from] = _ownedTokensCount[from].sub(1); _ownedTokensCount[to] = _ownedTokensCount[to].add(1); _tokenOwner[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Internal function to invoke `onERC721Received` on a target address * The call is not executed if the target address is not a contract * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) internal returns(bool) { if (!to.isContract()) { return true; } bytes4 retval = IERC721Receiver(to).onERC721Received( msg.sender, from, tokenId, _data ); return (retval == _ERC721_RECEIVED); } /** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */ function _clearApproval( uint256 tokenId ) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } } }
getItemsByOwner
function getItemsByOwner( address _owner ) public view returns(uint[] memory) { uint[] memory result = new uint[](_ownedTokensCount[_owner]); uint counter = 0; for (uint i = 0; i < allItems.length; i++) { // If owner is _owner and token is not burned if (_tokenOwner[i] == _owner && !allItems[i].burned) { result[counter] = i; counter++; } } // Array of ID's in allItems that _owner owns return result; }
// Get all the item id's by owner
LineComment
v0.5.17+commit.d19bba13
None
bzzr://3d6f0cf075dd3e4b74e4524d3514f301990ef7f34c54193bd247324d93b04317
{ "func_code_index": [ 10689, 11302 ] }
58,360