Squashed commit of the following:
commit fcf35eb806100de300bd9803ce3150dde1ecc424
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 17 17:16:04 2019 -0300
remove all docsite dependency
commit eeaee9a9d43d70704f6ab17b5126ddbd52b93a50
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 17 17:15:23 2019 -0300
update solidity-docgen
commit f021ff951829ea0c155186749819403c6b76e803
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 17 17:05:06 2019 -0300
update docsite script for new setup
commit ff887699d381cfbbe3acf1f1c0de8e22b58480f3
Merge: c938aa1d 84f85a41
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 17 16:46:46 2019 -0300
Merge branch 'master' into antora
commit c938aa1d9ed05ac83a34e2cebd8353f8331ad6d6
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jul 16 18:24:29 2019 -0300
make component name shorter
commit 5bbd6931e02cbbd8864c82655ad0f390ceead5f3
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 20:16:17 2019 -0300
add all info to docs templates
commit 39682c4515d7cf0f0368ed557f50d2709174208a
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 20:13:49 2019 -0300
fix npm docsite script
commit 7ae46bd4a0437abf66150d54d05adf46e3de2cab
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 18:48:05 2019 -0300
convert inline docs to asciidoc
commit cfdfd3dee4b4bf582fde22c8cb6e17a603d6e0c8
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 17:34:52 2019 -0300
add missing contract names in readmes
commit 15b6a2f9bfb546cf1d3bf4f104278b118bf1b3f4
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 17:16:47 2019 -0300
fix script path
commit 80d82b909f9460d1450d401f00b3f309da506b29
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 17:13:53 2019 -0300
update version of solidity-docgen
commit a870b6c607b9c2d0012f8a60a4ed1a1c8b7e8ebd
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 17:03:53 2019 -0300
add nav generation of api ref
commit 069cff4a25b83752650b54b86d85608c2f547e5e
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Wed Jul 10 16:32:14 2019 -0300
initial migration to asciidoc and new docgen version
commit 55216eed0a6551da913c8d1da4b2a0d0d3faa1a8
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 20:39:35 2019 -0300
add basic api doc example
commit 0cbe50ce2173b6d1d9a698329d91220f58822a53
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 19:31:31 2019 -0300
add sidebars
commit 256fc942845307258ac9dc25aace48117fa10f79
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 15:22:38 2019 -0300
add page titles
commit f4d0effa70e1fc0662729863e8ee72a8821bc458
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 15:19:41 2019 -0300
add contracts index file
commit b73b06359979f7d933df7f2b283c50cb1c31b2a0
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 15:14:52 2019 -0300
fix header levels
commit fb57d9b820f09a1b7c04eed1a205be0e45866cac
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 15:11:47 2019 -0300
switch format to preferred asciidoctor format
commit 032181d8804137332c71534753929d080a31a71f
Author: Francisco Giordano <frangio.1@gmail.com>
Date: Tue Jun 25 15:05:38 2019 -0300
initialize antora component and convert docs to asciidoc
122 lines
4.9 KiB
Solidity
122 lines
4.9 KiB
Solidity
pragma solidity ^0.5.0;
|
|
|
|
/**
|
|
* @dev Library used to query support of an interface declared via {IERC165}.
|
|
*
|
|
* Note that these functions return the actual result of the query: they do not
|
|
* `revert` if an interface is not supported. It is up to the caller to decide
|
|
* what to do in these cases.
|
|
*/
|
|
library ERC165Checker {
|
|
// As per the EIP-165 spec, no interface should ever match 0xffffffff
|
|
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
|
|
|
|
/*
|
|
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
|
|
*/
|
|
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
|
|
|
|
/**
|
|
* @dev Returns true if `account` supports the {IERC165} interface,
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns true if `account` supports the interface defined by
|
|
* `interfaceId`. Support for {IERC165} itself is queried automatically.
|
|
*
|
|
* See {IERC165-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);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns true if `account` supports all the interfaces defined in
|
|
* `interfaceIds`. Support for {IERC165} itself is queried automatically.
|
|
*
|
|
* Batch-querying can lead to gas savings by skipping repeated checks for
|
|
* {IERC165} support.
|
|
*
|
|
* See {IERC165-supportsInterface}.
|
|
*/
|
|
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
|
|
}
|
|
}
|
|
}
|