Skip to content

Commit

Permalink
Make non-view functions virtual (#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jan 13, 2021
1 parent 65b7e51 commit faec973
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion contracts/payment/escrow/Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract Escrow is Ownable {
* @dev Stores the sent amount as credit to be withdrawn.
* @param payee The destination address of the funds.
*/
function deposit(address payee) public virtual payable onlyOwner {
function deposit(address payee) public payable virtual onlyOwner {
uint256 amount = msg.value;
_deposits[payee] = _deposits[payee].add(amount);

Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/BeaconProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ contract BeaconProxy is Proxy {
/**
* @dev Changes the proxy to use a new beacon.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
*
* Requirements:
*
* - `beacon` must be a contract.
* - The implementation returned by `beacon` must be a contract.
*/
function _setBeacon(address beacon, bytes memory data) internal {
function _setBeacon(address beacon, bytes memory data) internal virtual {
require(
Address.isContract(beacon),
"BeaconProxy: beacon is not a contract"
Expand Down
16 changes: 4 additions & 12 deletions contracts/proxy/Initializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

import "../utils/Address.sol";

/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
*
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
Expand Down Expand Up @@ -49,15 +50,6 @@ abstract contract Initializable {

/// @dev Returns true if and only if the function is running in the constructor
function _isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
// solhint-disable-next-line no-inline-assembly
assembly { cs := extcodesize(self) }
return cs == 0;
return !Address.isContract(address(this));
}
}
18 changes: 9 additions & 9 deletions contracts/proxy/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pragma solidity >=0.6.0 <0.8.0;
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal {
function _delegate(address implementation) internal virtual {
// solhint-disable-next-line no-inline-assembly
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
Expand Down Expand Up @@ -48,10 +48,10 @@ abstract contract Proxy {

/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
*
* This function does not return to its internall call site, it will return directly to the external caller.
*/
function _fallback() internal {
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
Expand All @@ -60,22 +60,22 @@ abstract contract Proxy {
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback () external payable {
fallback () external payable virtual {
_fallback();
}

/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive () external payable {
receive () external payable virtual {
_fallback();
}

/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
*
* If overriden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {
Expand Down
26 changes: 13 additions & 13 deletions contracts/proxy/ProxyAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ contract ProxyAdmin is Ownable {

/**
* @dev Returns the current implementation of `proxy`.
*
*
* Requirements:
*
*
* - This contract must be the admin of `proxy`.
*/
function getProxyImplementation(TransparentUpgradeableProxy proxy) public view returns (address) {
Expand All @@ -28,9 +28,9 @@ contract ProxyAdmin is Ownable {

/**
* @dev Returns the current admin of `proxy`.
*
*
* Requirements:
*
*
* - This contract must be the admin of `proxy`.
*/
function getProxyAdmin(TransparentUpgradeableProxy proxy) public view returns (address) {
Expand All @@ -43,35 +43,35 @@ contract ProxyAdmin is Ownable {

/**
* @dev Changes the admin of `proxy` to `newAdmin`.
*
*
* Requirements:
*
*
* - This contract must be the current admin of `proxy`.
*/
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public onlyOwner {
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
proxy.changeAdmin(newAdmin);
}

/**
* @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
*
*
* Requirements:
*
*
* - This contract must be the admin of `proxy`.
*/
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public onlyOwner {
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
proxy.upgradeTo(implementation);
}

/**
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
* {TransparentUpgradeableProxy-upgradeToAndCall}.
*
*
* Requirements:
*
*
* - This contract must be the admin of `proxy`.
*/
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable onlyOwner {
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
}
}
8 changes: 4 additions & 4 deletions contracts/proxy/TransparentUpgradeableProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
*/
function changeAdmin(address newAdmin) external ifAdmin {
function changeAdmin(address newAdmin) external virtual ifAdmin {
require(newAdmin != address(0), "TransparentUpgradeableProxy: new admin is the zero address");
emit AdminChanged(_admin(), newAdmin);
_setAdmin(newAdmin);
Expand All @@ -102,7 +102,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
*/
function upgradeTo(address newImplementation) external ifAdmin {
function upgradeTo(address newImplementation) external virtual ifAdmin {
_upgradeTo(newImplementation);
}

Expand All @@ -113,7 +113,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
*/
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable virtual ifAdmin {
_upgradeTo(newImplementation);
Address.functionDelegateCall(newImplementation, data);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
/**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/
function _beforeFallback() internal override virtual {
function _beforeFallback() internal virtual override {
require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._beforeFallback();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/proxy/UpgradeableBeacon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract UpgradeableBeacon is IBeacon, Ownable {
* - msg.sender must be the owner of the contract.
* - `newImplementation` must be a contract.
*/
function upgradeTo(address newImplementation) public onlyOwner {
function upgradeTo(address newImplementation) public virtual onlyOwner {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/UpgradeableProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract UpgradeableProxy is Proxy {
/**
* @dev Returns the current implementation address.
*/
function _implementation() internal override view returns (address impl) {
function _implementation() internal view override returns (address impl) {
bytes32 slot = _IMPLEMENTATION_SLOT;
// solhint-disable-next-line no-inline-assembly
assembly {
Expand All @@ -57,7 +57,7 @@ contract UpgradeableProxy is Proxy {
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
function _upgradeTo(address newImplementation) internal virtual {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory amounts,
bytes memory data
)
internal virtual
internal
virtual
{ }

function _doSafeTransferAcceptanceCheck(
Expand Down
4 changes: 3 additions & 1 deletion contracts/token/ERC1155/ERC1155Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ abstract contract ERC1155Pausable is ERC1155, Pausable {
uint256[] memory amounts,
bytes memory data
)
internal virtual override
internal
virtual
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ contract ERC20 is Context, IERC20 {
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_;
}

Expand Down
Loading

0 comments on commit faec973

Please sign in to comment.