Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
faec973e
Unverified
Commit
faec973e
authored
Jan 13, 2021
by
Hadrien Croubois
Committed by
GitHub
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make non-view functions virtual (#2468)
parent
65b7e515
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
44 additions
and
45 deletions
+44
-45
Escrow.sol
contracts/payment/escrow/Escrow.sol
+1
-1
BeaconProxy.sol
contracts/proxy/BeaconProxy.sol
+1
-1
Initializable.sol
contracts/proxy/Initializable.sol
+2
-10
Proxy.sol
contracts/proxy/Proxy.sol
+4
-4
ProxyAdmin.sol
contracts/proxy/ProxyAdmin.sol
+3
-3
TransparentUpgradeableProxy.sol
contracts/proxy/TransparentUpgradeableProxy.sol
+4
-4
UpgradeableBeacon.sol
contracts/proxy/UpgradeableBeacon.sol
+1
-1
UpgradeableProxy.sol
contracts/proxy/UpgradeableProxy.sol
+2
-2
ERC1155.sol
contracts/token/ERC1155/ERC1155.sol
+2
-1
ERC1155Pausable.sol
contracts/token/ERC1155/ERC1155Pausable.sol
+3
-1
ERC20.sol
contracts/token/ERC20/ERC20.sol
+1
-1
ERC777.sol
contracts/token/ERC777/ERC777.sol
+20
-16
No files found.
contracts/payment/escrow/Escrow.sol
View file @
faec973e
...
...
@@ -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);
...
...
contracts/proxy/BeaconProxy.sol
View file @
faec973e
...
...
@@ -63,7 +63,7 @@ contract BeaconProxy is Proxy {
* - `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"
...
...
contracts/proxy/Initializable.sol
View file @
faec973e
...
...
@@ -3,6 +3,7 @@
// 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
...
...
@@ -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));
}
}
contracts/proxy/Proxy.sol
View file @
faec973e
...
...
@@ -18,7 +18,7 @@ abstract contract Proxy {
*
* 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
...
...
@@ -51,7 +51,7 @@ abstract contract Proxy {
*
* 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());
}
...
...
@@ -60,7 +60,7 @@ 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();
}
...
...
@@ -68,7 +68,7 @@ abstract contract Proxy {
* @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();
}
...
...
contracts/proxy/ProxyAdmin.sol
View file @
faec973e
...
...
@@ -48,7 +48,7 @@ contract ProxyAdmin is Ownable {
*
* - 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);
}
...
...
@@ -59,7 +59,7 @@ contract ProxyAdmin is Ownable {
*
* - 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);
}
...
...
@@ -71,7 +71,7 @@ contract ProxyAdmin is Ownable {
*
* - 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);
}
}
contracts/proxy/TransparentUpgradeableProxy.sol
View file @
faec973e
...
...
@@ -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);
...
...
@@ -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);
}
...
...
@@ -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);
}
...
...
@@ -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();
}
...
...
contracts/proxy/UpgradeableBeacon.sol
View file @
faec973e
...
...
@@ -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);
}
...
...
contracts/proxy/UpgradeableProxy.sol
View file @
faec973e
...
...
@@ -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 {
...
...
@@ -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);
}
...
...
contracts/token/ERC1155/ERC1155.sol
View file @
faec973e
...
...
@@ -355,7 +355,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory amounts,
bytes memory data
)
internal virtual
internal
virtual
{ }
function _doSafeTransferAcceptanceCheck(
...
...
contracts/token/ERC1155/ERC1155Pausable.sol
View file @
faec973e
...
...
@@ -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);
...
...
contracts/token/ERC20/ERC20.sol
View file @
faec973e
...
...
@@ -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_;
}
...
...
contracts/token/ERC777/ERC777.sol
View file @
faec973e
...
...
@@ -70,7 +70,9 @@ contract ERC777 is Context, IERC777, IERC20 {
string memory name_,
string memory symbol_,
address[] memory defaultOperators_
) public {
)
public
{
_name = name_;
_symbol = symbol_;
...
...
@@ -136,7 +138,7 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Also emits a {IERC20-Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes memory data) public override {
function send(address recipient, uint256 amount, bytes memory data) public
virtual
override {
_send(_msgSender(), recipient, amount, data, "", true);
}
...
...
@@ -148,7 +150,7 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) public override returns (bool) {
function transfer(address recipient, uint256 amount) public
virtual
override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
...
...
@@ -167,17 +169,14 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Also emits a {IERC20-Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes memory data) public override {
function burn(uint256 amount, bytes memory data) public
virtual
override {
_burn(_msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view override returns (bool) {
function isOperatorFor(address operator, address tokenHolder) public view override returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
...
...
@@ -186,7 +185,7 @@ contract ERC777 is Context, IERC777, IERC20 {
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) public override {
function authorizeOperator(address operator) public
virtual
override {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
...
...
@@ -201,7 +200,7 @@ contract ERC777 is Context, IERC777, IERC20 {
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) public override {
function revokeOperator(address operator) public
virtual
override {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
...
...
@@ -232,7 +231,9 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory data,
bytes memory operatorData
)
public override
public
virtual
override
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(sender, recipient, amount, data, operatorData, true);
...
...
@@ -243,7 +244,7 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Emits {Burned} and {IERC20-Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public override {
function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public
virtual
override {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(account, amount, data, operatorData);
}
...
...
@@ -264,7 +265,7 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) public override returns (bool) {
function approve(address spender, uint256 value) public
virtual
override returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
...
...
@@ -279,7 +280,7 @@ contract ERC777 is Context, IERC777, IERC20 {
*
* Emits {Sent}, {IERC20-Transfer} and {IERC20-Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) public override returns (bool) {
function transferFrom(address holder, address recipient, uint256 amount) public
virtual
override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
...
...
@@ -318,7 +319,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory userData,
bytes memory operatorData
)
internal virtual
internal
virtual
{
require(account != address(0), "ERC777: mint to the zero address");
...
...
@@ -354,6 +356,7 @@ contract ERC777 is Context, IERC777, IERC20 {
bool requireReceptionAck
)
internal
virtual
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
...
...
@@ -380,7 +383,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory data,
bytes memory operatorData
)
internal virtual
internal
virtual
{
require(from != address(0), "ERC777: burn from the zero address");
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment