-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Make
AccessControl
Module-Friendly (#216)
### 🕓 Changelog This PR refactors the `AccessControl` contract to make it module-friendly and ready for the breaking `0.4.0` release. --------- Signed-off-by: Pascal Marco Caversaccio <[email protected]>
- Loading branch information
1 parent
19ed1e5
commit b8d0b53
Showing
8 changed files
with
748 additions
and
696 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# pragma version ~=0.4.0b5 | ||
""" | ||
@title AccessControl Module Reference Implementation | ||
@custom:contract-name AccessControlMock | ||
@license GNU Affero General Public License v3.0 only | ||
@author pcaversaccio | ||
""" | ||
|
||
|
||
# @dev We import and implement the `IERC165` interface, | ||
# which is a built-in interface of the Vyper compiler. | ||
from ethereum.ercs import IERC165 | ||
implements: IERC165 | ||
|
||
|
||
# @dev We import and implement the `IAccessControl` | ||
# interface, which is written using standard Vyper | ||
# syntax. | ||
from ..interfaces import IAccessControl | ||
implements: IAccessControl | ||
|
||
|
||
# @dev We import and initialise the `AccessControl` module. | ||
from .. import AccessControl as ac | ||
initializes: ac | ||
|
||
|
||
# @dev The 32-byte minter role. | ||
MINTER_ROLE: public(constant(bytes32)) = keccak256("MINTER_ROLE") | ||
|
||
|
||
# @dev The 32-byte pauser role. | ||
PAUSER_ROLE: public(constant(bytes32)) = keccak256("PAUSER_ROLE") | ||
|
||
|
||
# @dev We export (i.e. the runtime bytecode exposes these | ||
# functions externally, allowing them to be called using | ||
# the ABI encoding specification) all `external` functions | ||
# from the `AccessControl` module. | ||
# @notice Please note that you must always also export (if | ||
# required by the contract logic) `public` declared `constant`, | ||
# `immutable`, and state variables, for which Vyper automatically | ||
# generates an `external` getter function for the variable. | ||
exports: ( | ||
ac.supportsInterface, | ||
ac.DEFAULT_ADMIN_ROLE, | ||
ac.hasRole, | ||
ac.getRoleAdmin, | ||
ac.grantRole, | ||
ac.revokeRole, | ||
ac.renounceRole, | ||
ac.set_role_admin, | ||
) | ||
|
||
|
||
@deploy | ||
@payable | ||
def __init__(): | ||
""" | ||
@dev To omit the opcodes for checking the `msg.value` | ||
in the creation-time EVM bytecode, the constructor | ||
is declared as `payable`. | ||
@notice All predefined roles will be assigned to | ||
the `msg.sender`. | ||
""" | ||
# The following line assigns the `DEFAULT_ADMIN_ROLE` | ||
# to the `msg.sender`. | ||
ac.__init__() | ||
ac._grant_role(MINTER_ROLE, msg.sender) | ||
ac._grant_role(PAUSER_ROLE, msg.sender) |
Oops, something went wrong.