更新合约文档,翻译为中文以增强可读性,包括 AccessControl、Ownable、ERC20 和 IERC20 的相关说明。修正了一些注释以确保准确性和一致性。
Some checks failed
transpile upgradeable / transpile (push) Has been cancelled
Some checks failed
transpile upgradeable / transpile (push) Has been cancelled
This commit is contained in:
@ -8,22 +8,18 @@ import {Context} from "../utils/Context.sol";
|
||||
import {IERC165, ERC165} from "../utils/introspection/ERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Contract module that allows children to implement role-based access
|
||||
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
|
||||
* members except through off-chain means by accessing the contract event logs. Some
|
||||
* applications may benefit from on-chain enumerability, for those cases see
|
||||
* {AccessControlEnumerable}.
|
||||
* @dev 合约模块,允许子合约实现基于角色的访问控制机制。这是一个轻量级版本,
|
||||
* 不允许枚举角色成员,除非通过链下方式访问合约事件日志。某些应用可能会受益于链上可枚举性,
|
||||
* 对于这些情况,请参见 {AccessControlEnumerable}。
|
||||
*
|
||||
* Roles are referred to by their `bytes32` identifier. These should be exposed
|
||||
* in the external API and be unique. The best way to achieve this is by
|
||||
* using `public constant` hash digests:
|
||||
* 角色通过其 `bytes32` 标识符来引用。这些应该在外部 API 中公开并且是唯一的。
|
||||
* 实现这一点的最佳方法是使用 `public constant` 哈希摘要:
|
||||
*
|
||||
* ```solidity
|
||||
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
|
||||
* ```
|
||||
*
|
||||
* Roles can be used to represent a set of permissions. To restrict access to a
|
||||
* function call, use {hasRole}:
|
||||
* 角色可以用来表示一组权限。要限制对函数调用的访问,请使用 {hasRole}:
|
||||
*
|
||||
* ```solidity
|
||||
* function foo() public {
|
||||
@ -32,19 +28,15 @@ import {IERC165, ERC165} from "../utils/introspection/ERC165.sol";
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Roles can be granted and revoked dynamically via the {grantRole} and
|
||||
* {revokeRole} functions. Each role has an associated admin role, and only
|
||||
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
|
||||
* 角色可以通过 {grantRole} 和 {revokeRole} 函数动态授予和撤销。每个角色都有一个关联的管理员角色,
|
||||
* 只有具有角色管理员角色的账户才能调用 {grantRole} 和 {revokeRole}。
|
||||
*
|
||||
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
|
||||
* that only accounts with this role will be able to grant or revoke other
|
||||
* roles. More complex role relationships can be created by using
|
||||
* {_setRoleAdmin}.
|
||||
* 默认情况下,所有角色的管理员角色是 `DEFAULT_ADMIN_ROLE`,这意味着只有具有此角色的账户
|
||||
* 才能授予或撤销其他角色。可以使用 {_setRoleAdmin} 创建更复杂的角色关系。
|
||||
*
|
||||
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
|
||||
* grant and revoke this role. Extra precautions should be taken to secure
|
||||
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
|
||||
* to enforce additional security measures for this role.
|
||||
* 警告:`DEFAULT_ADMIN_ROLE` 也是其自身的管理员:它有权限授予和撤销这个角色。
|
||||
* 应该采取额外的预防措施来保护已被授予此角色的账户。我们建议使用 {AccessControlDefaultAdminRules}
|
||||
* 来为此角色强制执行额外的安全措施。
|
||||
*/
|
||||
abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
struct RoleData {
|
||||
@ -57,8 +49,8 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
|
||||
|
||||
/**
|
||||
* @dev Modifier that checks that an account has a specific role. Reverts
|
||||
* with an {AccessControlUnauthorizedAccount} error including the required role.
|
||||
* @dev 检查账户是否具有特定角色的修饰符。如果没有,则使用 {AccessControlUnauthorizedAccount} 错误
|
||||
* 回退,包括所需的角色。
|
||||
*/
|
||||
modifier onlyRole(bytes32 role) {
|
||||
_checkRole(role);
|
||||
@ -71,23 +63,22 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns `true` if `account` has been granted `role`.
|
||||
* @dev 如果 `account` 已被授予 `role`,则返回 `true`。
|
||||
*/
|
||||
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
|
||||
return _roles[role].hasRole[account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
|
||||
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
|
||||
* @dev 如果 `_msgSender()` 缺少 `role`,则使用 {AccessControlUnauthorizedAccount} 错误回退。
|
||||
* 重写此函数会改变 {onlyRole} 修饰符的行为。
|
||||
*/
|
||||
function _checkRole(bytes32 role) internal view virtual {
|
||||
_checkRole(role, _msgSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
|
||||
* is missing `role`.
|
||||
* @dev 如果 `account` 缺少 `role`,则使用 {AccessControlUnauthorizedAccount} 错误回退。
|
||||
*/
|
||||
function _checkRole(bytes32 role, address account) internal view virtual {
|
||||
if (!hasRole(role, account)) {
|
||||
@ -96,61 +87,57 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the admin role that controls `role`. See {grantRole} and
|
||||
* {revokeRole}.
|
||||
* @dev 返回控制 `role` 的管理员角色。请参见 {grantRole} 和 {revokeRole}。
|
||||
*
|
||||
* To change a role's admin, use {_setRoleAdmin}.
|
||||
* 要更改角色的管理员,请使用 {_setRoleAdmin}。
|
||||
*/
|
||||
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
|
||||
return _roles[role].adminRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Grants `role` to `account`.
|
||||
* @dev 将 `role` 授予给 `account`。
|
||||
*
|
||||
* If `account` had not been already granted `role`, emits a {RoleGranted}
|
||||
* event.
|
||||
* 如果 `account` 尚未被授予 `role`,则发出 {RoleGranted} 事件。
|
||||
*
|
||||
* Requirements:
|
||||
* 要求:
|
||||
*
|
||||
* - the caller must have ``role``'s admin role.
|
||||
* - 调用者必须具有 `role` 的管理员角色。
|
||||
*
|
||||
* May emit a {RoleGranted} event.
|
||||
* 可能发出 {RoleGranted} 事件。
|
||||
*/
|
||||
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
|
||||
_grantRole(role, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Revokes `role` from `account`.
|
||||
* @dev 从 `account` 撤销 `role`。
|
||||
*
|
||||
* If `account` had been granted `role`, emits a {RoleRevoked} event.
|
||||
* 如果 `account` 已被授予 `role`,则发出 {RoleRevoked} 事件。
|
||||
*
|
||||
* Requirements:
|
||||
* 要求:
|
||||
*
|
||||
* - the caller must have ``role``'s admin role.
|
||||
* - 调用者必须具有 `role` 的管理员角色。
|
||||
*
|
||||
* May emit a {RoleRevoked} event.
|
||||
* 可能发出 {RoleRevoked} 事件。
|
||||
*/
|
||||
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
|
||||
_revokeRole(role, account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Revokes `role` from the calling account.
|
||||
* @dev 从调用账户撤销 `role`。
|
||||
*
|
||||
* Roles are often managed via {grantRole} and {revokeRole}: this function's
|
||||
* purpose is to provide a mechanism for accounts to lose their privileges
|
||||
* if they are compromised (such as when a trusted device is misplaced).
|
||||
* 角色通常通过 {grantRole} 和 {revokeRole} 进行管理:此函数的目的是为账户提供一种机制,
|
||||
* 在它们受到损害时(例如当受信任的设备丢失时)失去其特权。
|
||||
*
|
||||
* If the calling account had been revoked `role`, emits a {RoleRevoked}
|
||||
* event.
|
||||
* 如果调用账户的 `role` 已被撤销,则发出 {RoleRevoked} 事件。
|
||||
*
|
||||
* Requirements:
|
||||
* 要求:
|
||||
*
|
||||
* - the caller must be `callerConfirmation`.
|
||||
* - 调用者必须是 `callerConfirmation`。
|
||||
*
|
||||
* May emit a {RoleRevoked} event.
|
||||
* 可能发出 {RoleRevoked} 事件。
|
||||
*/
|
||||
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
|
||||
if (callerConfirmation != _msgSender()) {
|
||||
@ -161,9 +148,9 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets `adminRole` as ``role``'s admin role.
|
||||
* @dev 将 `adminRole` 设置为 `role` 的管理员角色。
|
||||
*
|
||||
* Emits a {RoleAdminChanged} event.
|
||||
* 发出 {RoleAdminChanged} 事件。
|
||||
*/
|
||||
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
|
||||
bytes32 previousAdminRole = getRoleAdmin(role);
|
||||
@ -172,11 +159,11 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
|
||||
* @dev 尝试将 `role` 授予给 `account` 并返回一个布尔值,指示是否授予了 `role`。
|
||||
*
|
||||
* Internal function without access restriction.
|
||||
* 内部函数,无访问限制。
|
||||
*
|
||||
* May emit a {RoleGranted} event.
|
||||
* 可能发出 {RoleGranted} 事件。
|
||||
*/
|
||||
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
|
||||
if (!hasRole(role, account)) {
|
||||
@ -189,11 +176,11 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
|
||||
* @dev 尝试从 `account` 撤销 `role` 并返回一个布尔值,指示是否撤销了 `role`。
|
||||
*
|
||||
* Internal function without access restriction.
|
||||
* 内部函数,无访问限制。
|
||||
*
|
||||
* May emit a {RoleRevoked} event.
|
||||
* 可能发出 {RoleRevoked} 事件。
|
||||
*/
|
||||
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
|
||||
if (hasRole(role, account)) {
|
||||
|
||||
Reference in New Issue
Block a user