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
df8a0fe8
Commit
df8a0fe8
authored
Apr 29, 2021
by
Francisco Giordano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete documentation of UUPSUpgradeable
parent
50a9b4d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
9 deletions
+35
-9
README.adoc
contracts/access/README.adoc
+1
-1
README.adoc
contracts/proxy/README.adoc
+2
-4
UUPSUpgradeable.sol
contracts/proxy/utils/UUPSUpgradeable.sol
+32
-4
No files found.
contracts/access/README.adoc
View file @
df8a0fe8
= Access
= Access
Control
[.readme-notice]
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/access
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/access
...
...
contracts/proxy/README.adoc
View file @
df8a0fe8
...
@@ -58,10 +58,6 @@ By default, the upgrade functionality included in {UUPSUpgradeable} contains a s
...
@@ -58,10 +58,6 @@ By default, the upgrade functionality included in {UUPSUpgradeable} contains a s
{{ERC1967Upgrade}}
{{ERC1967Upgrade}}
== UUPS
{{UUPSUpgradeable}}
== Transparent Proxy
== Transparent Proxy
{{TransparentUpgradeableProxy}}
{{TransparentUpgradeableProxy}}
...
@@ -83,3 +79,5 @@ By default, the upgrade functionality included in {UUPSUpgradeable} contains a s
...
@@ -83,3 +79,5 @@ By default, the upgrade functionality included in {UUPSUpgradeable} contains a s
== Utils
== Utils
{{Initializable}}
{{Initializable}}
{{UUPSUpgradeable}}
contracts/proxy/utils/UUPSUpgradeable.sol
View file @
df8a0fe8
...
@@ -5,24 +5,52 @@ pragma solidity ^0.8.0;
...
@@ -5,24 +5,52 @@ pragma solidity ^0.8.0;
import "../ERC1967/ERC1967Upgrade.sol";
import "../ERC1967/ERC1967Upgrade.sol";
/**
/**
* @dev Base contract for building openzeppelin-upgrades compatible implementations for the {ERC1967Proxy}. It includes
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* publicly available upgrade functions that are called by the plugin and by the secure upgrade mechanism to verify
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
* continuation of the upgradability.
*
*
* The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism.
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
*
* _Available since v4.1._
* _Available since v4.1._
*/
*/
abstract contract UUPSUpgradeable is ERC1967Upgrade {
abstract contract UUPSUpgradeable is ERC1967Upgrade {
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeTo(address newImplementation) external virtual {
function upgradeTo(address newImplementation) external virtual {
_authorizeUpgrade(newImplementation);
_authorizeUpgrade(newImplementation);
_upgradeToAndCallSecure(newImplementation, bytes(""), false);
_upgradeToAndCallSecure(newImplementation, bytes(""), false);
}
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual {
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual {
_authorizeUpgrade(newImplementation);
_authorizeUpgrade(newImplementation);
_upgradeToAndCallSecure(newImplementation, data, true);
_upgradeToAndCallSecure(newImplementation, data, true);
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
function _authorizeUpgrade(address newImplementation) internal virtual;
}
}
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