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
Fridgits
contracts/Fridgits.sol
0x2112cc1f375f698ff0203243fe3eee7d5af969ae
Solidity
Fridgits
contract Fridgits is ERC721A, Ownable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; string public notRevealedUri; uint256 public cost = 0.05 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmount = 100; uint256 public nftPerAddressLimit = 100; bool public paused = false; bool public revealed = false; bool public onlyWhitelisted = true; address[] public whitelistedAddresses; mapping(address => uint256) public addressMintedBalance; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721A(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { require(!paused, "the contract is paused"); uint256 supply = totalSupply(); require(_mintAmount > 0, "need to mint at least 1 NFT"); require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded"); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); if (msg.sender != owner()) { if(onlyWhitelisted == true) { require(isWhitelisted(msg.sender), "user is not whitelisted"); uint256 ownerMintedCount = addressMintedBalance[msg.sender]; require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded"); } require(msg.value >= cost * _mintAmount, "insufficient funds"); } _safeMint(msg.sender, _mintAmount); } function isWhitelisted(address _user) public view returns (bool) { for (uint i = 0; i < whitelistedAddresses.length; i++) { if (whitelistedAddresses[i] == _user) { return true; } } return false; } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setNftPerAddressLimit(uint256 _limit) public onlyOwner { nftPerAddressLimit = _limit; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function pause(bool _state) public onlyOwner { paused = _state; } function setOnlyWhitelisted(bool _state) public onlyOwner { onlyWhitelisted = _state; } function whitelistUsers(address[] calldata _users) public onlyOwner { delete whitelistedAddresses; whitelistedAddresses = _users; } function withdraw() public payable onlyOwner { (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); } }
reveal
function reveal() public onlyOwner { revealed = true; }
//only owner
LineComment
v0.8.7+commit.e28d00a7
MIT
ipfs://4ce3c80292b1d2c0f518b760e06a8e46e92f8c5eb4d9450f122a9749f7204d1f
{ "func_code_index": [ 3184, 3258 ] }
5,900
EXODUS2
ERC165Checker.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC165Checker
library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */ function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); } /** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */ function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } } }
/** * @title ERC165Checker * @dev Use `using ERC165Checker for address`; to include this library * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
_supportsERC165
function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); }
/** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 536, 935 ] }
5,901
EXODUS2
ERC165Checker.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC165Checker
library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */ function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); } /** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */ function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } } }
/** * @title ERC165Checker * @dev Use `using ERC165Checker for address`; to include this library * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
_supportsInterface
function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); }
/** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 1402, 1694 ] }
5,902
EXODUS2
ERC165Checker.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC165Checker
library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */ function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); } /** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */ function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } } }
/** * @title ERC165Checker * @dev Use `using ERC165Checker for address`; to include this library * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
_supportsAllInterfaces
function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; }
/** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 2162, 2704 ] }
5,903
EXODUS2
ERC165Checker.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC165Checker
library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */ function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); } /** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */ function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } } }
/** * @title ERC165Checker * @dev Use `using ERC165Checker for address`; to include this library * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
_supportsERC165Interface
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); }
/** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 3390, 3789 ] }
5,904
EXODUS2
ERC165Checker.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC165Checker
library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * 0x01ffc9a7 === * bytes4(keccak256('supportsInterface(bytes4)')) */ /** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */ function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @notice Query if a contract implements an interface, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return _supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all interfaces in the * interfaceIds list, false otherwise * @dev Interface identification is specified in ERC-165. */ function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with the `supportsERC165` method in this library. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId); return (success && result); } /** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */ function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } } }
/** * @title ERC165Checker * @dev Use `using ERC165Checker for address`; to include this library * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md */
NatSpecMultiLine
_callERC165SupportsInterface
function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assembly { let encodedParams_data := add(0x20, encodedParams) let encodedParams_size := mload(encodedParams) let output := mload(0x40) // Find empty storage location using "free memory pointer" mstore(output, 0x0) success := staticcall( 30000, // 30k gas account, // To addr encodedParams_data, encodedParams_size, output, 0x20 // Outputs are 32 bytes long ) result := mload(output) // Load the result } }
/** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @return result true if the STATICCALL succeeded and the contract at account * indicates support of the interface with identifier interfaceId, false otherwise */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 4302, 5322 ] }
5,905
EXODUS2
ERC721Mintable.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721Mintable
contract ERC721Mintable is ERC721, MinterRole { /** * @dev Function to mint tokens * @param to The address that will receive the minted tokens. * @param tokenId The token id to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address to, uint256 tokenId) public onlyMinter returns (bool) { _mint(to, tokenId); return true; } }
/** * @title ERC721Mintable * @dev ERC721 minting logic */
NatSpecMultiLine
mint
function mint(address to, uint256 tokenId) public onlyMinter returns (bool) { _mint(to, tokenId); return true; }
/** * @dev Function to mint tokens * @param to The address that will receive the minted tokens. * @param tokenId The token id to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 283, 419 ] }
5,906
EXODUS2
ERC721Burnable.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721Burnable
contract ERC721Burnable is ERC721 { /** * @dev Burns a specific ERC721 token. * @param tokenId uint256 id of the ERC721 token to be burned. */ function burn(uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _burn(tokenId); } }
/** * @title ERC721 Burnable Token * @dev ERC721 Token that can be irreversibly burned (destroyed). */
NatSpecMultiLine
burn
function burn(uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _burn(tokenId); }
/** * @dev Burns a specific ERC721 token. * @param tokenId uint256 id of the ERC721 token to be burned. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 162, 293 ] }
5,907
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
append
function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; }
/** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 1123, 2417 ] }
5,908
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
append
function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } }
/** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 2682, 3318 ] }
5,909
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Buffer
library Buffer { struct buffer { bytes buf; uint capacity; } function init(buffer memory buf, uint _capacity) internal pure { uint capacity = _capacity; if(capacity % 32 != 0) capacity += 32 - (capacity % 32); // Allocate space for the buffer data buf.capacity = capacity; assembly { let ptr := mload(0x40) mstore(buf, ptr) mstore(ptr, 0) mstore(0x40, add(ptr, capacity)) } } function resize(buffer memory buf, uint capacity) private pure { bytes memory oldbuf = buf.buf; init(buf, capacity); append(buf, oldbuf); } function max(uint a, uint b) private pure returns(uint) { if(a > b) { return a; } return b; } /** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Start address = buffer address + buffer length + sizeof(buffer length) dest := add(add(bufptr, buflen), 32) // Update buffer length mstore(bufptr, add(buflen, mload(data))) src := add(data, 32) } // Copy word-length chunks while possible for(; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } return buf; } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function append(buffer memory buf, uint8 data) internal pure { if(buf.buf.length + 1 > buf.capacity) { resize(buf, buf.capacity * 2); } assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) let dest := add(add(bufptr, buflen), 32) mstore8(dest, data) // Update buffer length mstore(bufptr, add(buflen, 1)) } } /** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */ function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; } }
/* Begin solidity-cborutils https://github.com/smartcontractkit/solidity-cborutils MIT License Copyright (c) 2018 SmartContract ChainLink, Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
Comment
appendInt
function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) { if(len + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, len) * 2); } uint mask = 256 ** len - 1; assembly { // Memory address of the buffer data let bufptr := mload(buf) // Length of existing buffer data let buflen := mload(bufptr) // Address = buffer address + buffer length + sizeof(buffer length) + len let dest := add(add(bufptr, buflen), len) mstore(dest, or(and(mload(dest), not(mask)), data)) // Update buffer length mstore(bufptr, add(buflen, len)) } return buf; }
/** * @dev Appends a byte to the end of the buffer. Resizes if doing so would * exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 3583, 4365 ] }
5,910
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
parseInt
function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); }
// parseInt
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 27483, 27587 ] }
5,911
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
parseInt
function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; }
// parseInt(parseFloat*10^_b)
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 27625, 28239 ] }
5,912
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
copyBytes
function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 38942, 39633 ] }
5,913
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
safer_ecrecover
function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 39830, 40833 ] }
5,914
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
usingOraclize
contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Ledger = 0x30; byte constant proofType_Android = 0x40; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ return oraclize_setNetwork(); networkID; // silence the warning and remain backwards compatible } function oraclize_setNetwork() internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) public { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) public { return; myid; result; proof; // Silence compiler warnings } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal pure returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal pure returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal pure returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal pure returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal pure returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal pure returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } using CBOR for Buffer.buffer; function stra2cbor(string[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeString(arr[i]); } buf.endSequence(); return buf.buf; } function ba2cbor(bytes[] arr) internal pure returns (bytes) { safeMemoryCleaner(); Buffer.buffer memory buf; Buffer.init(buf, 1024); buf.startArray(); for (uint i = 0; i < arr.length; i++) { buf.encodeBytes(arr[i]); } buf.endSequence(); return buf.buf; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal view returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ require((_nbytes > 0) && (_nbytes <= 32)); // Convert from seconds to ledger timer ticks _delay *= 10; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) // the following variables can be relaxed // check relaxed random contract under ethereum-examples repo // for an idea on how to override and replace comit hash vars mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes memory delay = new bytes(32); assembly { mstore(add(delay, 0x20), _delay) } bytes memory delay_bytes8 = new bytes(8); copyBytes(delay, 24, 8, delay_bytes8, 0); bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay]; bytes32 queryId = oraclize_query("random", args, _customGasLimit); bytes memory delay_bytes8_left = new bytes(8); assembly { let x := mload(add(delay_bytes8, 0x20)) mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000)) mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000)) } oraclize_randomDS_setCommitment(queryId, keccak256(delay_bytes8_left, args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(keccak256(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(keccak256(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = byte(1); //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); require(proofVerified); _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){ bool match_ = true; require(prefix.length == n_random_bytes); for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(keccak256(keyhash) == keccak256(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == keccak256(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } function safeMemoryCleaner() internal pure { assembly { let fmem := mload(0x40) codecopy(fmem, codesize, sub(msize, fmem)) } } }
/* End solidity-cborutils */
Comment
ecrecovery
function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); }
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 40955, 42381 ] }
5,915
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; uint public price = 100; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xf466972B885E59D04f10d122cc38E0258e098bDB; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x62bf50192b3ef428e24Bc8d10f0c2A6Eabe80E08; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } // one token = _price cents function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/price; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
setPrice
function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; }
// one token = _price cents
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 1409, 1529 ] }
5,916
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; uint public price = 100; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xf466972B885E59D04f10d122cc38E0258e098bDB; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x62bf50192b3ef428e24Bc8d10f0c2A6Eabe80E08; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } // one token = _price cents function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/price; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
function () public payable { buyTokens(msg.sender); }
// fallback function can be used to buy tokens
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 1582, 1646 ] }
5,917
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; uint public price = 100; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xf466972B885E59D04f10d122cc38E0258e098bDB; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x62bf50192b3ef428e24Bc8d10f0c2A6Eabe80E08; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } // one token = _price cents function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/price; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
buyTokens
function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); }
// low level token purchase function
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 2284, 2852 ] }
5,918
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; uint public price = 100; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xf466972B885E59D04f10d122cc38E0258e098bDB; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x62bf50192b3ef428e24Bc8d10f0c2A6Eabe80E08; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } // one token = _price cents function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/price; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
forwardFunds
function forwardFunds() internal { wallet.transfer(address(this).balance); }
// send ether to the fund collection wallet // override to create custom fund forwarding mechanisms
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 2961, 3048 ] }
5,919
Crowdsale
Crowdsale.sol
0x9eb409a840c90aa26ac4dca5cd29b20720fdf078
Solidity
Crowdsale
contract Crowdsale is usingOraclize { using SafeMath for uint256; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward; token tokenReward; // amount of raised money in wei uint256 public weiRaised; uint public price = 100; /** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); constructor () public { //You will change this to your wallet where you need the ETH wallet = 0xf466972B885E59D04f10d122cc38E0258e098bDB; //Here will come the checksum address of token we got addressOfTokenUsedAsReward = 0x62bf50192b3ef428e24Bc8d10f0c2A6Eabe80E08; tokenReward = token(addressOfTokenUsedAsReward); } bool public started = true; function startSale() public { require (msg.sender == wallet); started = true; } function stopSale() public { require (msg.sender == wallet); started = false; } function changeWallet(address _wallet) public { require (msg.sender == wallet); wallet = _wallet; } // one token = _price cents function setPrice(uint _price) public { require (msg.sender == wallet && _price != 0); price = _price; } // fallback function can be used to buy tokens function () public payable { buyTokens(msg.sender); } mapping (bytes32 => address) public idToBeneficiary; mapping (bytes32 => uint) public idToWeiAmount; event newOraclizeQuery(string description); function __callback(bytes32 myid, string result) public { require (msg.sender == oraclize_cbAddress()); address beneficiary = idToBeneficiary[myid]; uint weiAmount = idToWeiAmount[myid]; uint ethToCents = parseInt(result,2); uint tokens = weiAmount.mul(ethToCents)/price; tokenReward.transfer(beneficiary, tokens); emit TokenPurchase(beneficiary, beneficiary, weiAmount, tokens); } // low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != 0x0); require(validPurchase()); uint256 weiAmount = msg.value; // update state weiRaised = weiRaised.add(weiAmount); emit newOraclizeQuery("Oraclize query was sent, standing by for the answer.."); bytes32 queryId = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD"); idToBeneficiary[queryId] = beneficiary; idToWeiAmount[queryId] = weiAmount; forwardFunds(); } // send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { wallet.transfer(address(this).balance); } // @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; } function withdrawTokens(uint256 _amount) public { require (msg.sender==wallet); tokenReward.transfer(wallet,_amount); } }
validPurchase
function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; }
// @return true if the transaction can buy tokens
LineComment
v0.4.24+commit.e67f0147
bzzr://36985f8c3c897e5c47572c4524a335afc46ce0d1fd4bd5bc8dc870f1a285c8fb
{ "func_code_index": [ 3104, 3294 ] }
5,920
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @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)); 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
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.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 261, 321 ] }
5,921
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Ownable
contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @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)); 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 { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); 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.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 640, 821 ] }
5,922
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Whitelist
contract Whitelist is Ownable { mapping(address => bool) public whitelist; event WhitelistedAddressAdded(address addr); event WhitelistedAddressRemoved(address addr); /** * @dev Throws if called by any account that's not whitelisted. */ modifier onlyWhitelisted() { require(whitelist[msg.sender]); _; } /** * @dev add an address to the whitelist * @param addr address * @return true if the address was added to the whitelist, false if the address was already in the whitelist */ function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { if (!whitelist[addr]) { whitelist[addr] = true; emit WhitelistedAddressAdded(addr); success = true; } } /** * @dev add addresses to the whitelist * @param addrs addresses * @return true if at least one address was added to the whitelist, * false if all addresses were already in the whitelist */ function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (addAddressToWhitelist(addrs[i])) { success = true; } } } /** * @dev remove an address from the whitelist * @param addr address * @return true if the address was removed from the whitelist, * false if the address wasn't in the whitelist in the first place */ function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { if (whitelist[addr]) { whitelist[addr] = false; emit WhitelistedAddressRemoved(addr); success = true; } } /** * @dev remove addresses from the whitelist * @param addrs addresses * @return true if at least one address was removed from the whitelist, * false if all addresses weren't in the whitelist in the first place */ function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (removeAddressFromWhitelist(addrs[i])) { success = true; } } } }
/** * @title Whitelist * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. * @dev This simplifies the implementation of "user permissions". */
NatSpecMultiLine
addAddressToWhitelist
function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { if (!whitelist[addr]) { whitelist[addr] = true; emit WhitelistedAddressAdded(addr); success = true; } }
/** * @dev add an address to the whitelist * @param addr address * @return true if the address was added to the whitelist, false if the address was already in the whitelist */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 541, 767 ] }
5,923
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Whitelist
contract Whitelist is Ownable { mapping(address => bool) public whitelist; event WhitelistedAddressAdded(address addr); event WhitelistedAddressRemoved(address addr); /** * @dev Throws if called by any account that's not whitelisted. */ modifier onlyWhitelisted() { require(whitelist[msg.sender]); _; } /** * @dev add an address to the whitelist * @param addr address * @return true if the address was added to the whitelist, false if the address was already in the whitelist */ function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { if (!whitelist[addr]) { whitelist[addr] = true; emit WhitelistedAddressAdded(addr); success = true; } } /** * @dev add addresses to the whitelist * @param addrs addresses * @return true if at least one address was added to the whitelist, * false if all addresses were already in the whitelist */ function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (addAddressToWhitelist(addrs[i])) { success = true; } } } /** * @dev remove an address from the whitelist * @param addr address * @return true if the address was removed from the whitelist, * false if the address wasn't in the whitelist in the first place */ function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { if (whitelist[addr]) { whitelist[addr] = false; emit WhitelistedAddressRemoved(addr); success = true; } } /** * @dev remove addresses from the whitelist * @param addrs addresses * @return true if at least one address was removed from the whitelist, * false if all addresses weren't in the whitelist in the first place */ function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (removeAddressFromWhitelist(addrs[i])) { success = true; } } } }
/** * @title Whitelist * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. * @dev This simplifies the implementation of "user permissions". */
NatSpecMultiLine
addAddressesToWhitelist
function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (addAddressToWhitelist(addrs[i])) { success = true; } } }
/** * @dev add addresses to the whitelist * @param addrs addresses * @return true if at least one address was added to the whitelist, * false if all addresses were already in the whitelist */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 985, 1220 ] }
5,924
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Whitelist
contract Whitelist is Ownable { mapping(address => bool) public whitelist; event WhitelistedAddressAdded(address addr); event WhitelistedAddressRemoved(address addr); /** * @dev Throws if called by any account that's not whitelisted. */ modifier onlyWhitelisted() { require(whitelist[msg.sender]); _; } /** * @dev add an address to the whitelist * @param addr address * @return true if the address was added to the whitelist, false if the address was already in the whitelist */ function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { if (!whitelist[addr]) { whitelist[addr] = true; emit WhitelistedAddressAdded(addr); success = true; } } /** * @dev add addresses to the whitelist * @param addrs addresses * @return true if at least one address was added to the whitelist, * false if all addresses were already in the whitelist */ function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (addAddressToWhitelist(addrs[i])) { success = true; } } } /** * @dev remove an address from the whitelist * @param addr address * @return true if the address was removed from the whitelist, * false if the address wasn't in the whitelist in the first place */ function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { if (whitelist[addr]) { whitelist[addr] = false; emit WhitelistedAddressRemoved(addr); success = true; } } /** * @dev remove addresses from the whitelist * @param addrs addresses * @return true if at least one address was removed from the whitelist, * false if all addresses weren't in the whitelist in the first place */ function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (removeAddressFromWhitelist(addrs[i])) { success = true; } } } }
/** * @title Whitelist * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. * @dev This simplifies the implementation of "user permissions". */
NatSpecMultiLine
removeAddressFromWhitelist
function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { if (whitelist[addr]) { whitelist[addr] = false; emit WhitelistedAddressRemoved(addr); success = true; } }
/** * @dev remove an address from the whitelist * @param addr address * @return true if the address was removed from the whitelist, * false if the address wasn't in the whitelist in the first place */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 1447, 1680 ] }
5,925
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Whitelist
contract Whitelist is Ownable { mapping(address => bool) public whitelist; event WhitelistedAddressAdded(address addr); event WhitelistedAddressRemoved(address addr); /** * @dev Throws if called by any account that's not whitelisted. */ modifier onlyWhitelisted() { require(whitelist[msg.sender]); _; } /** * @dev add an address to the whitelist * @param addr address * @return true if the address was added to the whitelist, false if the address was already in the whitelist */ function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { if (!whitelist[addr]) { whitelist[addr] = true; emit WhitelistedAddressAdded(addr); success = true; } } /** * @dev add addresses to the whitelist * @param addrs addresses * @return true if at least one address was added to the whitelist, * false if all addresses were already in the whitelist */ function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (addAddressToWhitelist(addrs[i])) { success = true; } } } /** * @dev remove an address from the whitelist * @param addr address * @return true if the address was removed from the whitelist, * false if the address wasn't in the whitelist in the first place */ function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { if (whitelist[addr]) { whitelist[addr] = false; emit WhitelistedAddressRemoved(addr); success = true; } } /** * @dev remove addresses from the whitelist * @param addrs addresses * @return true if at least one address was removed from the whitelist, * false if all addresses weren't in the whitelist in the first place */ function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (removeAddressFromWhitelist(addrs[i])) { success = true; } } } }
/** * @title Whitelist * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. * @dev This simplifies the implementation of "user permissions". */
NatSpecMultiLine
removeAddressesFromWhitelist
function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { for (uint256 i = 0; i < addrs.length; i++) { if (removeAddressFromWhitelist(addrs[i])) { success = true; } } }
/** * @dev remove addresses from the whitelist * @param addrs addresses * @return true if at least one address was removed from the whitelist, * false if all addresses weren't in the whitelist in the first place */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 1921, 2166 ] }
5,926
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Pausable
contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } }
/** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */
NatSpecMultiLine
pause
function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); }
/** * @dev called by the owner to pause, triggers stopped state */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 513, 609 ] }
5,927
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
Pausable
contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } }
/** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */
NatSpecMultiLine
unpause
function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); }
/** * @dev called by the owner to unpause, returns to normal state */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 693, 791 ] }
5,928
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
BuyLimits
contract BuyLimits { event LogLimitsChanged(uint _minBuy, uint _maxBuy); // Variables holding the min and max payment in wei uint public minBuy; // min buy in wei uint public maxBuy; // max buy in wei, 0 means no maximum /* ** Modifier, reverting if not within limits. */ modifier isWithinLimits(uint _amount) { require(withinLimits(_amount)); _; } /* ** @dev Constructor, define variable: */ function BuyLimits(uint _min, uint _max) public { _setLimits(_min, _max); } /* ** @dev Check TXs value is within limits: */ function withinLimits(uint _value) public view returns(bool) { if (maxBuy != 0) { return (_value >= minBuy && _value <= maxBuy); } return (_value >= minBuy); } /* ** @dev set limits logic: ** @param _min set the minimum buy in wei ** @param _max set the maximum buy in wei, 0 indeicates no maximum */ function _setLimits(uint _min, uint _max) internal { if (_max != 0) { require (_min <= _max); // Sanity Check } minBuy = _min; maxBuy = _max; emit LogLimitsChanged(_min, _max); } }
BuyLimits
function BuyLimits(uint _min, uint _max) public { _setLimits(_min, _max); }
/* ** @dev Constructor, define variable: */
Comment
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 478, 573 ] }
5,929
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
BuyLimits
contract BuyLimits { event LogLimitsChanged(uint _minBuy, uint _maxBuy); // Variables holding the min and max payment in wei uint public minBuy; // min buy in wei uint public maxBuy; // max buy in wei, 0 means no maximum /* ** Modifier, reverting if not within limits. */ modifier isWithinLimits(uint _amount) { require(withinLimits(_amount)); _; } /* ** @dev Constructor, define variable: */ function BuyLimits(uint _min, uint _max) public { _setLimits(_min, _max); } /* ** @dev Check TXs value is within limits: */ function withinLimits(uint _value) public view returns(bool) { if (maxBuy != 0) { return (_value >= minBuy && _value <= maxBuy); } return (_value >= minBuy); } /* ** @dev set limits logic: ** @param _min set the minimum buy in wei ** @param _max set the maximum buy in wei, 0 indeicates no maximum */ function _setLimits(uint _min, uint _max) internal { if (_max != 0) { require (_min <= _max); // Sanity Check } minBuy = _min; maxBuy = _max; emit LogLimitsChanged(_min, _max); } }
withinLimits
function withinLimits(uint _value) public view returns(bool) { if (maxBuy != 0) { return (_value >= minBuy && _value <= maxBuy); } return (_value >= minBuy); }
/* ** @dev Check TXs value is within limits: */
Comment
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 639, 848 ] }
5,930
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
BuyLimits
contract BuyLimits { event LogLimitsChanged(uint _minBuy, uint _maxBuy); // Variables holding the min and max payment in wei uint public minBuy; // min buy in wei uint public maxBuy; // max buy in wei, 0 means no maximum /* ** Modifier, reverting if not within limits. */ modifier isWithinLimits(uint _amount) { require(withinLimits(_amount)); _; } /* ** @dev Constructor, define variable: */ function BuyLimits(uint _min, uint _max) public { _setLimits(_min, _max); } /* ** @dev Check TXs value is within limits: */ function withinLimits(uint _value) public view returns(bool) { if (maxBuy != 0) { return (_value >= minBuy && _value <= maxBuy); } return (_value >= minBuy); } /* ** @dev set limits logic: ** @param _min set the minimum buy in wei ** @param _max set the maximum buy in wei, 0 indeicates no maximum */ function _setLimits(uint _min, uint _max) internal { if (_max != 0) { require (_min <= _max); // Sanity Check } minBuy = _min; maxBuy = _max; emit LogLimitsChanged(_min, _max); } }
_setLimits
function _setLimits(uint _min, uint _max) internal { if (_max != 0) { require (_min <= _max); // Sanity Check } minBuy = _min; maxBuy = _max; emit LogLimitsChanged(_min, _max); }
/* ** @dev set limits logic: ** @param _min set the minimum buy in wei ** @param _max set the maximum buy in wei, 0 indeicates no maximum */
Comment
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 1017, 1263 ] }
5,931
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
DAOstackPreSale
contract DAOstackPreSale is Pausable,BuyLimits,Whitelist { event LogFundsReceived(address indexed _sender, uint _amount); address public wallet; /** * @dev Constructor. * @param _wallet Address where the funds are transfered to * @param _minBuy Address where the funds are transfered to * @param _maxBuy Address where the funds are transfered to */ function DAOstackPreSale(address _wallet, uint _minBuy, uint _maxBuy) public BuyLimits(_minBuy, _maxBuy) { // Set wallet: require(_wallet != address(0)); wallet = _wallet; } /** * @dev Fallback, funds coming in are transfered to wallet */ function () payable whenNotPaused onlyWhitelisted isWithinLimits(msg.value) external { wallet.transfer(msg.value); emit LogFundsReceived(msg.sender, msg.value); } /* ** @dev Drain function, in case of failure. Contract should not hold eth anyhow. */ function drain() external { wallet.transfer((address(this)).balance); } }
/** * @title DAOstackPresale * @dev A contract to allow only whitelisted followers to participate in presale. */
NatSpecMultiLine
DAOstackPreSale
function DAOstackPreSale(address _wallet, uint _minBuy, uint _maxBuy) public BuyLimits(_minBuy, _maxBuy) { // Set wallet: require(_wallet != address(0)); wallet = _wallet; }
/** * @dev Constructor. * @param _wallet Address where the funds are transfered to * @param _minBuy Address where the funds are transfered to * @param _maxBuy Address where the funds are transfered to */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 394, 619 ] }
5,932
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
DAOstackPreSale
contract DAOstackPreSale is Pausable,BuyLimits,Whitelist { event LogFundsReceived(address indexed _sender, uint _amount); address public wallet; /** * @dev Constructor. * @param _wallet Address where the funds are transfered to * @param _minBuy Address where the funds are transfered to * @param _maxBuy Address where the funds are transfered to */ function DAOstackPreSale(address _wallet, uint _minBuy, uint _maxBuy) public BuyLimits(_minBuy, _maxBuy) { // Set wallet: require(_wallet != address(0)); wallet = _wallet; } /** * @dev Fallback, funds coming in are transfered to wallet */ function () payable whenNotPaused onlyWhitelisted isWithinLimits(msg.value) external { wallet.transfer(msg.value); emit LogFundsReceived(msg.sender, msg.value); } /* ** @dev Drain function, in case of failure. Contract should not hold eth anyhow. */ function drain() external { wallet.transfer((address(this)).balance); } }
/** * @title DAOstackPresale * @dev A contract to allow only whitelisted followers to participate in presale. */
NatSpecMultiLine
function () payable whenNotPaused onlyWhitelisted isWithinLimits(msg.value) external { wallet.transfer(msg.value); emit LogFundsReceived(msg.sender, msg.value); }
/** * @dev Fallback, funds coming in are transfered to wallet */
NatSpecMultiLine
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 702, 892 ] }
5,933
DAOstackPreSale
DAOstackPreSale.sol
0x946312616cba7d41e6307e9e7fc16250a470307e
Solidity
DAOstackPreSale
contract DAOstackPreSale is Pausable,BuyLimits,Whitelist { event LogFundsReceived(address indexed _sender, uint _amount); address public wallet; /** * @dev Constructor. * @param _wallet Address where the funds are transfered to * @param _minBuy Address where the funds are transfered to * @param _maxBuy Address where the funds are transfered to */ function DAOstackPreSale(address _wallet, uint _minBuy, uint _maxBuy) public BuyLimits(_minBuy, _maxBuy) { // Set wallet: require(_wallet != address(0)); wallet = _wallet; } /** * @dev Fallback, funds coming in are transfered to wallet */ function () payable whenNotPaused onlyWhitelisted isWithinLimits(msg.value) external { wallet.transfer(msg.value); emit LogFundsReceived(msg.sender, msg.value); } /* ** @dev Drain function, in case of failure. Contract should not hold eth anyhow. */ function drain() external { wallet.transfer((address(this)).balance); } }
/** * @title DAOstackPresale * @dev A contract to allow only whitelisted followers to participate in presale. */
NatSpecMultiLine
drain
function drain() external { wallet.transfer((address(this)).balance); }
/* ** @dev Drain function, in case of failure. Contract should not hold eth anyhow. */
Comment
v0.4.21+commit.dfe3193c
bzzr://88bd35f3a9c7f39d41701afbb62f0c0c148b318ce67cae9c6e544a0ced526e09
{ "func_code_index": [ 997, 1087 ] }
5,934
EXODUS2
IERC721Receiver.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
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.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 878, 1004 ] }
5,935
PropertyFactory
contracts/src/property/Property.sol
0x8a2c73f4d243f35ad62fc651302b742e0b3fa96c
Solidity
Property
contract Property is ERC20, ERC20Detailed, UsingConfig, IProperty { using SafeMath for uint256; uint8 private constant PROPERTY_DECIMALS = 18; uint256 private constant SUPPLY = 10000000000000000000000000; address public author; /** * Initializes the passed value as AddressConfig address, author address, token name, and token symbol. */ constructor( address _config, address _own, string memory _name, string memory _symbol ) public UsingConfig(_config) ERC20Detailed(_name, _symbol, PROPERTY_DECIMALS) { /** * Validates the sender is PropertyFactory contract. */ require( msg.sender == config().propertyFactory(), "this is illegal address" ); /** * Sets the author. */ author = _own; /** * Mints to the author and treasury contract. */ IPolicy policy = IPolicy(config().policy()); uint256 toTreasury = policy.shareOfTreasury(SUPPLY); uint256 toAuthor = SUPPLY.sub(toTreasury); require(toAuthor != 0, "share of author is 0"); _mint(author, toAuthor); _mint(policy.treasury(), toTreasury); } /** * Hook on `transfer` and call `Withdraw.beforeBalanceChange` function. */ function transfer(address _to, uint256 _value) public returns (bool) { /** * Validates the destination is not 0 address. */ require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), msg.sender, _to ); /** * Calls the transfer of ERC20. */ _transfer(msg.sender, _to, _value); return true; } /** * Hook on `transferFrom` and call `Withdraw.beforeBalanceChange` function. */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { /** * Validates the source and destination is not 0 address. */ require(_from != address(0), "this is illegal address"); require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), _from, _to ); /** * Calls the transfer of ERC20. */ _transfer(_from, _to, _value); /** * Reduces the allowance amount. */ uint256 allowanceAmount = allowance(_from, msg.sender); _approve( _from, msg.sender, allowanceAmount.sub( _value, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * Transfers the staking amount to the original owner. */ function withdraw(address _sender, uint256 _value) external { /** * Validates the sender is Lockup contract. */ require(msg.sender == config().lockup(), "this is illegal address"); /** * Transfers the passed amount to the original owner. */ ERC20 devToken = ERC20(config().token()); bool result = devToken.transfer(_sender, _value); require(result, "dev transfer failed"); } }
/** * A contract that represents the assets of the user and collects staking from the stakers. * Property contract inherits ERC20. * Holders of Property contracts(tokens) receive holder rewards according to their share. */
NatSpecMultiLine
transfer
function transfer(address _to, uint256 _value) public returns (bool) { /** * Validates the destination is not 0 address. */ require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), msg.sender, _to ); /** * Calls the transfer of ERC20. */ _transfer(msg.sender, _to, _value); return true; }
/** * Hook on `transfer` and call `Withdraw.beforeBalanceChange` function. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
MPL-2.0
bzzr://07adc538be83a7033ae59daa76abe29e0800df39dc029e9c7485468371a7d2fe
{ "func_code_index": [ 1199, 1838 ] }
5,936
PropertyFactory
contracts/src/property/Property.sol
0x8a2c73f4d243f35ad62fc651302b742e0b3fa96c
Solidity
Property
contract Property is ERC20, ERC20Detailed, UsingConfig, IProperty { using SafeMath for uint256; uint8 private constant PROPERTY_DECIMALS = 18; uint256 private constant SUPPLY = 10000000000000000000000000; address public author; /** * Initializes the passed value as AddressConfig address, author address, token name, and token symbol. */ constructor( address _config, address _own, string memory _name, string memory _symbol ) public UsingConfig(_config) ERC20Detailed(_name, _symbol, PROPERTY_DECIMALS) { /** * Validates the sender is PropertyFactory contract. */ require( msg.sender == config().propertyFactory(), "this is illegal address" ); /** * Sets the author. */ author = _own; /** * Mints to the author and treasury contract. */ IPolicy policy = IPolicy(config().policy()); uint256 toTreasury = policy.shareOfTreasury(SUPPLY); uint256 toAuthor = SUPPLY.sub(toTreasury); require(toAuthor != 0, "share of author is 0"); _mint(author, toAuthor); _mint(policy.treasury(), toTreasury); } /** * Hook on `transfer` and call `Withdraw.beforeBalanceChange` function. */ function transfer(address _to, uint256 _value) public returns (bool) { /** * Validates the destination is not 0 address. */ require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), msg.sender, _to ); /** * Calls the transfer of ERC20. */ _transfer(msg.sender, _to, _value); return true; } /** * Hook on `transferFrom` and call `Withdraw.beforeBalanceChange` function. */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { /** * Validates the source and destination is not 0 address. */ require(_from != address(0), "this is illegal address"); require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), _from, _to ); /** * Calls the transfer of ERC20. */ _transfer(_from, _to, _value); /** * Reduces the allowance amount. */ uint256 allowanceAmount = allowance(_from, msg.sender); _approve( _from, msg.sender, allowanceAmount.sub( _value, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * Transfers the staking amount to the original owner. */ function withdraw(address _sender, uint256 _value) external { /** * Validates the sender is Lockup contract. */ require(msg.sender == config().lockup(), "this is illegal address"); /** * Transfers the passed amount to the original owner. */ ERC20 devToken = ERC20(config().token()); bool result = devToken.transfer(_sender, _value); require(result, "dev transfer failed"); } }
/** * A contract that represents the assets of the user and collects staking from the stakers. * Property contract inherits ERC20. * Holders of Property contracts(tokens) receive holder rewards according to their share. */
NatSpecMultiLine
transferFrom
function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { /** * Validates the source and destination is not 0 address. */ require(_from != address(0), "this is illegal address"); require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), _from, _to ); /** * Calls the transfer of ERC20. */ _transfer(_from, _to, _value); /** * Reduces the allowance amount. */ uint256 allowanceAmount = allowance(_from, msg.sender); _approve( _from, msg.sender, allowanceAmount.sub( _value, "ERC20: transfer amount exceeds allowance" ) ); return true; }
/** * Hook on `transferFrom` and call `Withdraw.beforeBalanceChange` function. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
MPL-2.0
bzzr://07adc538be83a7033ae59daa76abe29e0800df39dc029e9c7485468371a7d2fe
{ "func_code_index": [ 1931, 2912 ] }
5,937
PropertyFactory
contracts/src/property/Property.sol
0x8a2c73f4d243f35ad62fc651302b742e0b3fa96c
Solidity
Property
contract Property is ERC20, ERC20Detailed, UsingConfig, IProperty { using SafeMath for uint256; uint8 private constant PROPERTY_DECIMALS = 18; uint256 private constant SUPPLY = 10000000000000000000000000; address public author; /** * Initializes the passed value as AddressConfig address, author address, token name, and token symbol. */ constructor( address _config, address _own, string memory _name, string memory _symbol ) public UsingConfig(_config) ERC20Detailed(_name, _symbol, PROPERTY_DECIMALS) { /** * Validates the sender is PropertyFactory contract. */ require( msg.sender == config().propertyFactory(), "this is illegal address" ); /** * Sets the author. */ author = _own; /** * Mints to the author and treasury contract. */ IPolicy policy = IPolicy(config().policy()); uint256 toTreasury = policy.shareOfTreasury(SUPPLY); uint256 toAuthor = SUPPLY.sub(toTreasury); require(toAuthor != 0, "share of author is 0"); _mint(author, toAuthor); _mint(policy.treasury(), toTreasury); } /** * Hook on `transfer` and call `Withdraw.beforeBalanceChange` function. */ function transfer(address _to, uint256 _value) public returns (bool) { /** * Validates the destination is not 0 address. */ require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), msg.sender, _to ); /** * Calls the transfer of ERC20. */ _transfer(msg.sender, _to, _value); return true; } /** * Hook on `transferFrom` and call `Withdraw.beforeBalanceChange` function. */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { /** * Validates the source and destination is not 0 address. */ require(_from != address(0), "this is illegal address"); require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing through the Allocator contract is due to the historical reason for the old Property contract. */ IAllocator(config().allocator()).beforeBalanceChange( address(this), _from, _to ); /** * Calls the transfer of ERC20. */ _transfer(_from, _to, _value); /** * Reduces the allowance amount. */ uint256 allowanceAmount = allowance(_from, msg.sender); _approve( _from, msg.sender, allowanceAmount.sub( _value, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * Transfers the staking amount to the original owner. */ function withdraw(address _sender, uint256 _value) external { /** * Validates the sender is Lockup contract. */ require(msg.sender == config().lockup(), "this is illegal address"); /** * Transfers the passed amount to the original owner. */ ERC20 devToken = ERC20(config().token()); bool result = devToken.transfer(_sender, _value); require(result, "dev transfer failed"); } }
/** * A contract that represents the assets of the user and collects staking from the stakers. * Property contract inherits ERC20. * Holders of Property contracts(tokens) receive holder rewards according to their share. */
NatSpecMultiLine
withdraw
function withdraw(address _sender, uint256 _value) external { /** * Validates the sender is Lockup contract. */ require(msg.sender == config().lockup(), "this is illegal address"); /** * Transfers the passed amount to the original owner. */ ERC20 devToken = ERC20(config().token()); bool result = devToken.transfer(_sender, _value); require(result, "dev transfer failed"); }
/** * Transfers the staking amount to the original owner. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
MPL-2.0
bzzr://07adc538be83a7033ae59daa76abe29e0800df39dc029e9c7485468371a7d2fe
{ "func_code_index": [ 2984, 3398 ] }
5,938
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
ERC20Interface
contract ERC20Interface { event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed from, address indexed spender, uint256 value); function totalSupply() constant returns(uint256 supply); function balanceOf(address _owner) constant returns(uint256 balance); function transfer(address _to, uint256 _value) returns(bool success); function transferFrom(address _from, address _to, uint256 _value) returns(bool success); function approve(address _spender, uint256 _value) returns(bool success); function allowance(address _owner, address _spender) constant returns(uint256 remaining); // function symbol() constant returns(string); function decimals() constant returns(uint8); // function name() constant returns(string); }
decimals
function decimals() constant returns(uint8);
// function symbol() constant returns(string);
LineComment
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 724, 773 ] }
5,939
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
init
function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; }
/** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 602, 923 ] }
5,940
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
_getAsset
function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); }
/** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 1436, 1562 ] }
5,941
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
totalSupply
function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); }
/** * Returns asset total supply. * * @return asset total supply. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 1829, 1940 ] }
5,942
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
balanceOf
function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); }
/** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 2102, 2231 ] }
5,943
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
allowance
function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); }
/** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 2481, 2636 ] }
5,944
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
decimals
function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); }
/** * Returns asset decimals. * * @return asset decimals. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 2729, 2835 ] }
5,945
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transfer
function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); }
/** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 3056, 3183 ] }
5,946
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferWithReference
function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); }
/** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 3648, 3847 ] }
5,947
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferToICAP
function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); }
/** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 4066, 4209 ] }
5,948
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferToICAPWithReference
function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); }
/** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 4672, 4887 ] }
5,949
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); }
/** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 5156, 5313 ] }
5,950
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferFromWithReference
function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); }
/** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 5826, 6055 ] }
5,951
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
_forwardTransferFromWithReference
function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); }
/** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 6550, 6840 ] }
5,952
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferFromToICAP
function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); }
/** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 7119, 7292 ] }
5,953
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferFromToICAPWithReference
function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); }
/** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 7815, 8060 ] }
5,954
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
_forwardTransferFromToICAPWithReference
function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); }
/** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 8583, 8874 ] }
5,955
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
approve
function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); }
/** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 9228, 9378 ] }
5,956
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
_forwardApprove
function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); }
/** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 9754, 9965 ] }
5,957
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
emitTransfer
function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); }
/** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 10129, 10258 ] }
5,958
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
emitApprove
function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); }
/** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 10427, 10565 ] }
5,959
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); }
/** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 10755, 10899 ] }
5,960
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
transferToICAP
function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); }
// Interface functions to allow specifying ICAP addresses as strings.
LineComment
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 10977, 11119 ] }
5,961
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
getVersionFor
function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; }
/** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 12884, 13057 ] }
5,962
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
getLatestVersion
function getLatestVersion() constant returns(address) { return latestVersion; }
/** * Returns current asset implementation contract address. * * @return asset implementation contract address. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 13204, 13302 ] }
5,963
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
getPendingVersion
function getPendingVersion() constant returns(address) { return pendingVersion; }
/** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 13455, 13555 ] }
5,964
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
getPendingVersionTimestamp
function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; }
/** * Returns upgrade freeze-time start. * * @return freeze-time start. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 13662, 13777 ] }
5,965
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
proposeUpgrade
function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; }
/** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 14103, 14774 ] }
5,966
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
purgeUpgrade
function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; }
/** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 14931, 15170 ] }
5,967
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
commitUpgrade
function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; }
/** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 15376, 15746 ] }
5,968
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
optOut
function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; }
/** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 15937, 16151 ] }
5,969
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
optIn
function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; }
/** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */
NatSpecMultiLine
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 16339, 16452 ] }
5,970
REMME
REMME.sol
0x83984d6142934bb535793a82adb0a46ef0f66b6d
Solidity
REMME
contract REMME is ERC20Interface, AssetProxyInterface, Bytes32, ReturnData { // Assigned EToken2, immutable. EToken2Interface public etoken2; // Assigned symbol, immutable. bytes32 public etoken2Symbol; // Assigned name, immutable. For UI. string public name; string public symbol; /** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */ function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; } /** * Only EToken2 is allowed to call. */ modifier onlyEToken2() { if (msg.sender == address(etoken2)) { _; } } /** * Only current asset owner is allowed to call. */ modifier onlyAssetOwner() { if (etoken2.isOwner(msg.sender, etoken2Symbol)) { _; } } /** * Returns asset implementation contract for current caller. * * @return asset implementation contract. */ function _getAsset() internal returns(AssetInterface) { return AssetInterface(getVersionFor(msg.sender)); } function recoverTokens(uint _value) onlyAssetOwner() returns(bool) { return this.transferWithReference(msg.sender, _value, 'Tokens recovery'); } /** * Returns asset total supply. * * @return asset total supply. */ function totalSupply() constant returns(uint) { return etoken2.totalSupply(etoken2Symbol); } /** * Returns asset balance for a particular holder. * * @param _owner holder address. * * @return holder balance. */ function balanceOf(address _owner) constant returns(uint) { return etoken2.balanceOf(_owner, etoken2Symbol); } /** * Returns asset allowance from one holder to another. * * @param _from holder that allowed spending. * @param _spender holder that is allowed to spend. * * @return holder to spender allowance. */ function allowance(address _from, address _spender) constant returns(uint) { return etoken2.allowance(_from, _spender, etoken2Symbol); } /** * Returns asset decimals. * * @return asset decimals. */ function decimals() constant returns(uint8) { return etoken2.baseUnit(etoken2Symbol); } /** * Transfers asset balance from the caller to specified receiver. * * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transfer(address _to, uint _value) returns(bool) { return transferWithReference(_to, _value, ''); } /** * Transfers asset balance from the caller to specified receiver adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferWithReference(address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferWithReference(_to, _value, _reference, msg.sender); } /** * Transfers asset balance from the caller to specified ICAP. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * * @return success. */ function transferToICAP(bytes32 _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } /** * Transfers asset balance from the caller to specified ICAP adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _icap recipient ICAP to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferToICAPWithReference(bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferToICAPWithReference(_icap, _value, _reference, msg.sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * * @return success. */ function transferFrom(address _from, address _to, uint _value) returns(bool) { return transferFromWithReference(_from, _to, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromWithReference(address _from, address _to, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromWithReference(_from, _to, _value, _reference, msg.sender); } /** * Performs transfer call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _to holder address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromWithReference(_from, _to, _value, etoken2Symbol, _reference, _sender); } /** * Prforms allowance transfer of asset balance between holders. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * * @return success. */ function transferFromToICAP(address _from, bytes32 _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } /** * Prforms allowance transfer of asset balance between holders adding specified comment. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * * @return success. */ function transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference) returns(bool) { return _getAsset()._performTransferFromToICAPWithReference(_from, _icap, _value, _reference, msg.sender); } /** * Performs allowance transfer to ICAP call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _from holder address to take from. * @param _icap recipient ICAP address to give to. * @param _value amount to transfer. * @param _reference transfer comment to be included in a EToken2's Transfer event. * @param _sender initial caller. * * @return success. */ function _forwardTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); } /** * Sets asset spending allowance for a specified spender. * Resolves asset implementation contract for the caller and forwards there arguments along with * the caller address. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * * @return success. */ function approve(address _spender, uint _value) returns(bool) { return _getAsset()._performApprove(_spender, _value, msg.sender); } /** * Performs allowance setting call on the EToken2 by the name of specified sender. * * Can only be called by asset implementation contract assigned to sender. * * @param _spender holder address to set allowance to. * @param _value amount to allow. * @param _sender initial caller. * * @return success. */ function _forwardApprove(address _spender, uint _value, address _sender) onlyImplementationFor(_sender) returns(bool) { return etoken2.proxyApprove(_spender, _value, etoken2Symbol, _sender); } /** * Emits ERC20 Transfer event on this contract. * * Can only be, and, called by assigned EToken2 when asset transfer happens. */ function emitTransfer(address _from, address _to, uint _value) onlyEToken2() { Transfer(_from, _to, _value); } /** * Emits ERC20 Approval event on this contract. * * Can only be, and, called by assigned EToken2 when asset allowance set happens. */ function emitApprove(address _from, address _spender, uint _value) onlyEToken2() { Approval(_from, _spender, _value); } /** * Resolves asset implementation contract for the caller and forwards there transaction data, * along with the value. This allows for proxy interface growth. */ function () payable { _getAsset()._performGeneric.value(msg.value)(msg.data, msg.sender); _returnReturnData(true); } // Interface functions to allow specifying ICAP addresses as strings. function transferToICAP(string _icap, uint _value) returns(bool) { return transferToICAPWithReference(_icap, _value, ''); } function transferToICAPWithReference(string _icap, uint _value, string _reference) returns(bool) { return transferToICAPWithReference(_bytes32(_icap), _value, _reference); } function transferFromToICAP(address _from, string _icap, uint _value) returns(bool) { return transferFromToICAPWithReference(_from, _icap, _value, ''); } function transferFromToICAPWithReference(address _from, string _icap, uint _value, string _reference) returns(bool) { return transferFromToICAPWithReference(_from, _bytes32(_icap), _value, _reference); } /** * Indicates an upgrade freeze-time start, and the next asset implementation contract. */ event UpgradeProposal(address newVersion); // Current asset implementation contract address. address latestVersion; // Proposed next asset implementation contract address. address pendingVersion; // Upgrade freeze-time start. uint pendingVersionTimestamp; // Timespan for users to review the new implementation and make decision. uint constant UPGRADE_FREEZE_TIME = 3 days; // Asset implementation contract address that user decided to stick with. // 0x0 means that user uses latest version. mapping(address => address) userOptOutVersion; /** * Only asset implementation contract assigned to sender is allowed to call. */ modifier onlyImplementationFor(address _sender) { if (getVersionFor(_sender) == msg.sender) { _; } } /** * Returns asset implementation contract address assigned to sender. * * @param _sender sender address. * * @return asset implementation contract address. */ function getVersionFor(address _sender) constant returns(address) { return userOptOutVersion[_sender] == 0 ? latestVersion : userOptOutVersion[_sender]; } /** * Returns current asset implementation contract address. * * @return asset implementation contract address. */ function getLatestVersion() constant returns(address) { return latestVersion; } /** * Returns proposed next asset implementation contract address. * * @return asset implementation contract address. */ function getPendingVersion() constant returns(address) { return pendingVersion; } /** * Returns upgrade freeze-time start. * * @return freeze-time start. */ function getPendingVersionTimestamp() constant returns(uint) { return pendingVersionTimestamp; } /** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */ function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { return false; } // Don't apply freeze-time for the initial setup. if (latestVersion == 0x0) { latestVersion = _newVersion; return true; } pendingVersion = _newVersion; pendingVersionTimestamp = now; UpgradeProposal(_newVersion); return true; } /** * Cancel the pending upgrade process. * * Can only be called by current asset owner. * * @return success. */ function purgeUpgrade() onlyAssetOwner() returns(bool) { if (pendingVersion == 0x0) { return false; } delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */ function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingVersionTimestamp; return true; } /** * Disagree with proposed upgrade, and stick with current asset implementation * until further explicit agreement to upgrade. * * @return success. */ function optOut() returns(bool) { if (userOptOutVersion[msg.sender] != 0x0) { return false; } userOptOutVersion[msg.sender] = latestVersion; return true; } /** * Implicitly agree to upgrade to current and future asset implementation upgrades, * until further explicit disagreement. * * @return success. */ function optIn() returns(bool) { delete userOptOutVersion[msg.sender]; return true; } // Backwards compatibility. function multiAsset() constant returns(EToken2Interface) { return etoken2; } }
/** * @title EToken2 Asset Proxy. * * Proxy implements ERC20 interface and acts as a gateway to a single EToken2 asset. * Proxy adds etoken2Symbol and caller(sender) when forwarding requests to EToken2. * Every request that is made by caller first sent to the specific asset implementation * contract, which then calls back to be forwarded onto EToken2. * * Calls flow: Caller -> * Proxy.func(...) -> * Asset._performFunc(..., Caller.address) -> * Proxy._forwardFunc(..., Caller.address) -> * Platform.proxyFunc(..., symbol, Caller.address) * * Generic call flow: Caller -> * Proxy.unknownFunc(...) -> * Asset._performGeneric(..., Caller.address) -> * Asset.unknownFunc(...) * * Asset implementation contract is mutable, but each user have an option to stick with * old implementation, through explicit decision made in timely manner, if he doesn't agree * with new rules. * Each user have a possibility to upgrade to latest asset contract implementation, without the * possibility to rollback. * * Note: all the non constant functions return false instead of throwing in case if state change * didn't happen yet. */
NatSpecMultiLine
multiAsset
function multiAsset() constant returns(EToken2Interface) { return etoken2; }
// Backwards compatibility.
LineComment
v0.4.15+commit.bbb8e64f
bzzr://b63519aefab850441fb9213a9c60c38a9226690754cd394c422c3ed96d0e3dff
{ "func_code_index": [ 16488, 16583 ] }
5,971
EXODUS2
strings.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
strings
library strings { struct slice { uint _len; uint _ptr; } function memcpy(uint dest, uint src, uint len) private pure { // Copy word-length chunks while possible for (; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } } /* * @dev Returns a slice containing the entire string. * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */ function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { ptr := add(self, 0x20) } return slice(bytes(self).length, ptr); } /* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */ function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); memcpy(retptr + self._len, other._ptr, other._len); return ret; } }
toSlice
function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { ptr := add(self, 0x20) } return slice(bytes(self).length, ptr); }
/* * @dev Returns a slice containing the entire string. * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */
Comment
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 831, 1045 ] }
5,972
EXODUS2
strings.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
strings
library strings { struct slice { uint _len; uint _ptr; } function memcpy(uint dest, uint src, uint len) private pure { // Copy word-length chunks while possible for (; len >= 32; len -= 32) { assembly { mstore(dest, mload(src)) } dest += 32; src += 32; } // Copy remaining bytes uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src), not(mask)) let destpart := and(mload(dest), mask) mstore(dest, or(destpart, srcpart)) } } /* * @dev Returns a slice containing the entire string. * @param self The string to make a slice from. * @return A newly allocated slice containing the entire string. */ function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { ptr := add(self, 0x20) } return slice(bytes(self).length, ptr); } /* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */ function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); memcpy(retptr + self._len, other._ptr, other._len); return ret; } }
concat
function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); memcpy(retptr + self._len, other._ptr, other._len); return ret; }
/* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */
Comment
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 1328, 1707 ] }
5,973
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
balanceOf
function balanceOf(address owner) public view returns (uint256) { require(owner != address(0)); return _ownedTokensCount[owner]; }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 1814, 1968 ] }
5,974
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
ownerOf
function ownerOf(uint256 tokenId) public view returns (address) { address owner = _tokenOwner[tokenId]; require(owner != address(0)); return 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 2188, 2369 ] }
5,975
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
approve
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 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 2786, 3082 ] }
5,976
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
getApproved
function getApproved(uint256 tokenId) public view returns (address) { require(_exists(tokenId)); return _tokenApprovals[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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 3363, 3518 ] }
5,977
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
setApprovalForAll
function setApprovalForAll(address to, bool approved) public { require(to != msg.sender); _operatorApprovals[msg.sender][to] = approved; emit ApprovalForAll(msg.sender, to, approved); }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 3806, 4023 ] }
5,978
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
isApprovedForAll
function isApprovedForAll(address owner, address operator) public view returns (bool) { return _operatorApprovals[owner][operator]; }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 4340, 4489 ] }
5,979
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
transferFrom
function transferFrom(address from, address to, uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId)); _transferFrom(from, to, tokenId); }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 4918, 5102 ] }
5,980
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
safeTransferFrom
function safeTransferFrom(address from, address to, uint256 tokenId) public { 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 5737, 5873 ] }
5,981
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
safeTransferFrom
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public { transferFrom(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data)); }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 6574, 6789 ] }
5,982
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_exists
function _exists(uint256 tokenId) internal view returns (bool) { address owner = _tokenOwner[tokenId]; return owner != address(0); }
/** * @dev Returns whether the specified token exists * @param tokenId uint256 ID of the token to query the existence of * @return whether the token exists */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 6974, 7130 ] }
5,983
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_isApprovedOrOwner
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); }
/** * @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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 7489, 7739 ] }
5,984
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_mint
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 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 7978, 8260 ] }
5,985
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_burn
function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); }
/** * @dev Internal function to burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 8529, 8838 ] }
5,986
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_burn
function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), tokenId); }
/** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 9013, 9107 ] }
5,987
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_transferFrom
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 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 9477, 9883 ] }
5,988
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_checkOnERC721Received
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 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 10402, 10753 ] }
5,989
EXODUS2
ERC721.sol
0x76e422de0ce8842ebe837bc7ab6984b4fff88055
Solidity
ERC721
contract ERC721 is ERC165, IERC721 { using SafeMath for uint256; using Address for address; // 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 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 token mapping (address => uint256) private _ownedTokensCount; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * 0x80ac58cd === * bytes4(keccak256('balanceOf(address)')) ^ * bytes4(keccak256('ownerOf(uint256)')) ^ * bytes4(keccak256('approve(address,uint256)')) ^ * bytes4(keccak256('getApproved(uint256)')) ^ * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ * bytes4(keccak256('isApprovedForAll(address,address)')) ^ * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) */ constructor () public { // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); } /** * @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)); 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 { 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); 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); 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 burn a specific token * Reverts if the token does not exist * Deprecated, use _burn(uint256) instead. * @param owner owner of the token to burn * @param tokenId uint256 ID of the token being burned */ function _burn(address owner, uint256 tokenId) internal { require(ownerOf(tokenId) == owner); _clearApproval(tokenId); _ownedTokensCount[owner] = _ownedTokensCount[owner].sub(1); _tokenOwner[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Internal function to burn a specific token * Reverts if the token does not exist * @param tokenId uint256 ID of the token being burned */ function _burn(uint256 tokenId) internal { _burn(ownerOf(tokenId), 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); } } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md */
NatSpecMultiLine
_clearApproval
function _clearApproval(uint256 tokenId) private { if (_tokenApprovals[tokenId] != address(0)) { _tokenApprovals[tokenId] = address(0); } }
/** * @dev Private function to clear current approval of a given token ID * @param tokenId uint256 ID of the token to be transferred */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
MIT
bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6
{ "func_code_index": [ 10910, 11085 ] }
5,990
BancorConverter
contracts/token/interfaces/IERC20Token.sol
0x52e37cd16197a9b33529c5c7c7d134a56bd53f71
Solidity
IERC20Token
contract IERC20Token { // these functions aren't abstract since the compiler emits automatically generated getter functions as external function name() public view returns (string) {this;} function symbol() public view returns (string) {this;} function decimals() public view returns (uint8) {this;} function totalSupply() public view returns (uint256) {this;} function balanceOf(address _owner) public view returns (uint256) {_owner; this;} function allowance(address _owner, address _spender) public view returns (uint256) {_owner; _spender; this;} function transfer(address _to, uint256 _value) public returns (bool success); function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); function approve(address _spender, uint256 _value) public returns (bool success); }
/* ERC20 Standard Token interface */
Comment
name
function name() public view returns (string) {this;}
// these functions aren't abstract since the compiler emits automatically generated getter functions as external
LineComment
v0.4.26+commit.4563c3fc
bzzr://a1d5240c498906975038de9bdb52dacf0a95be608af2600ce15c20774b5be07a
{ "func_code_index": [ 140, 196 ] }
5,991
SSC
SSC.sol
0x293cb32ccdbe33c28372b4ebafcb9bb2e293a3ad
Solidity
SSC
contract SSC { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This generates a public event on the blockchain that will notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor( uint256 initialSupply, string memory tokenName, string memory tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } } }
_transfer
function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); }
/** * Internal transfer, only can be called by this contract */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://0e95eabed09004ef760dac8df0a5f5913771d85ea66a677642ec09917c217d4f
{ "func_code_index": [ 1643, 2500 ] }
5,992
SSC
SSC.sol
0x293cb32ccdbe33c28372b4ebafcb9bb2e293a3ad
Solidity
SSC
contract SSC { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This generates a public event on the blockchain that will notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor( uint256 initialSupply, string memory tokenName, string memory tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } } }
transfer
function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; }
/** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://0e95eabed09004ef760dac8df0a5f5913771d85ea66a677642ec09917c217d4f
{ "func_code_index": [ 2706, 2863 ] }
5,993
SSC
SSC.sol
0x293cb32ccdbe33c28372b4ebafcb9bb2e293a3ad
Solidity
SSC
contract SSC { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This generates a public event on the blockchain that will notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor( uint256 initialSupply, string memory tokenName, string memory tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } } }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; }
/** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://0e95eabed09004ef760dac8df0a5f5913771d85ea66a677642ec09917c217d4f
{ "func_code_index": [ 3138, 3439 ] }
5,994
SSC
SSC.sol
0x293cb32ccdbe33c28372b4ebafcb9bb2e293a3ad
Solidity
SSC
contract SSC { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This generates a public event on the blockchain that will notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor( uint256 initialSupply, string memory tokenName, string memory tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } } }
approve
function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; }
/** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://0e95eabed09004ef760dac8df0a5f5913771d85ea66a677642ec09917c217d4f
{ "func_code_index": [ 3703, 4008 ] }
5,995
SSC
SSC.sol
0x293cb32ccdbe33c28372b4ebafcb9bb2e293a3ad
Solidity
SSC
contract SSC { // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // 18 decimals is the strongly suggested default, avoid changing it uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This generates a public event on the blockchain that will notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constructor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor( uint256 initialSupply, string memory tokenName, string memory tokenSymbol ) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != address(0x0)); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { require((_value == 0) || (allowance[msg.sender][_spender] == 0)); allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } } }
approveAndCall
function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, address(this), _extraData); return true; } }
/** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://0e95eabed09004ef760dac8df0a5f5913771d85ea66a677642ec09917c217d4f
{ "func_code_index": [ 4402, 4770 ] }
5,996
TokenERC20
TokenERC20.sol
0xc608342e743ec99b2839aa3bc97f6f78791bd3fb
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; } }
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.4.26+commit.4563c3fc
None
bzzr://9c8eac2a7c7305a20d7019abb8bbb51e4e8952418577898a4d5290bfc6451850
{ "func_code_index": [ 229, 389 ] }
5,997
TokenERC20
TokenERC20.sol
0xc608342e743ec99b2839aa3bc97f6f78791bd3fb
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; } }
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.4.26+commit.4563c3fc
None
bzzr://9c8eac2a7c7305a20d7019abb8bbb51e4e8952418577898a4d5290bfc6451850
{ "func_code_index": [ 637, 766 ] }
5,998
TokenERC20
TokenERC20.sol
0xc608342e743ec99b2839aa3bc97f6f78791bd3fb
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; } }
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.4.26+commit.4563c3fc
None
bzzr://9c8eac2a7c7305a20d7019abb8bbb51e4e8952418577898a4d5290bfc6451850
{ "func_code_index": [ 1034, 1218 ] }
5,999