Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make Rust docs consistent #497

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions contracts/src/access/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
pub fn only_role(&self, role: B256) -> Result<(), Error> {
self._check_role(role, msg::sender())
}
Expand All @@ -170,7 +170,7 @@ impl AccessControl {
/// If `account` had not been already granted `role`, emits a
/// [`RoleGranted`] event.
///
/// # Requirements:
/// # Requirements
///
/// * The caller must have `role`'s admin role.
///
Expand All @@ -182,12 +182,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
///
/// # Events
///
/// May emit a [`RoleGranted`] event.
/// * [`RoleGranted`].
DarkLord017 marked this conversation as resolved.
Show resolved Hide resolved
pub fn grant_role(
&mut self,
role: B256,
Expand All @@ -203,7 +203,7 @@ impl AccessControl {
///
/// If `account` had been granted `role`, emits a [`RoleRevoked`] event.
///
/// # Requirements:
/// # Requirements
///
/// * The caller must have `role`'s admin role.
///
Expand All @@ -215,12 +215,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
///
/// # Events
///
/// May emit a [`RoleRevoked`] event.
/// * [`RoleRevoked`].
pub fn revoke_role(
&mut self,
role: B256,
Expand All @@ -239,7 +239,7 @@ impl AccessControl {
/// for accounts to lose their privileges if they are compromised (such as
/// when a trusted device is misplaced).
///
/// # Requirements:
/// # Requirements
///
/// * The caller must be `confirmation`.
///
Expand All @@ -251,13 +251,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] is not the `confirmation` address, then the error
/// [`Error::BadConfirmation`] is returned.
/// * [`Error::BadConfirmation`] - If [`msg::sender`] is not the
/// `confirmation` address.
///
/// # Events
///
/// If the calling account has its `role` revoked, emits a [`RoleRevoked`]
/// event.
/// * [`RoleRevoked`] - If the calling account has its `role` revoked.
pub fn renounce_role(
&mut self,
role: B256,
Expand Down Expand Up @@ -288,7 +287,7 @@ impl AccessControl {
///
/// # Events
///
/// Emits a [`RoleAdminChanged`] event.
/// * [`RoleAdminChanged`].
pub fn _set_role_admin(&mut self, role: B256, new_admin_role: B256) {
let previous_admin_role = self.get_role_admin(role);
self._roles.setter(role).admin_role.set(new_admin_role);
Expand All @@ -309,8 +308,8 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
pub fn _check_role(
&self,
role: B256,
Expand Down Expand Up @@ -338,7 +337,7 @@ impl AccessControl {
///
/// # Events
///
/// May emit a [`RoleGranted`] event.
/// * [`RoleGranted`].
pub fn _grant_role(&mut self, role: B256, account: Address) -> bool {
if self.has_role(role, account) {
false
Expand All @@ -362,7 +361,7 @@ impl AccessControl {
///
/// # Events
///
/// May emit a [`RoleRevoked`] event.
/// * [`RoleRevoked`].
pub fn _revoke_role(&mut self, role: B256, account: Address) -> bool {
if self.has_role(role, account) {
self._roles.setter(role).has_role.insert(account, false);
Expand Down
16 changes: 7 additions & 9 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ pub trait IOwnable {
///
/// # Errors
///
/// If `new_owner` is the zero address, then the error
/// [`OwnableInvalidOwner`] is returned.
/// * [`OwnableInvalidOwner`] - If `new_owner` is the `Address::ZERO`.
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -120,12 +119,11 @@ pub trait IOwnable {
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

Expand Down Expand Up @@ -170,8 +168,8 @@ impl Ownable {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If called by any account other than
/// the owner.
pub fn only_owner(&self) -> Result<(), Error> {
let account = msg::sender();
if self.owner() != account {
Expand All @@ -193,7 +191,7 @@ impl Ownable {
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
pub fn _transfer_ownership(&mut self, new_owner: Address) {
let previous_owner = self._owner.get();
self._owner.set(new_owner);
Expand Down
22 changes: 12 additions & 10 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ pub trait IOwnable2Step {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If called by any account other
/// than the owner.
///
/// # Events
///
/// Emits a [`OwnershipTransferStarted`] event.
/// * [`OwnershipTransferStarted`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -123,12 +123,12 @@ pub trait IOwnable2Step {
///
/// # Errors
///
/// If called by any account other than the pending owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If called by any account other
/// than the pending owner.
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn accept_ownership(&mut self) -> Result<(), Self::Error>;

/// Leaves the contract without owner. It will not be possible to call
Expand All @@ -139,14 +139,16 @@ pub trait IOwnable2Step {
/// thereby disabling any functionality that is only available to the owner.
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

Expand Down Expand Up @@ -212,7 +214,7 @@ impl Ownable2Step {
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn _transfer_ownership(&mut self, new_owner: Address) {
self._pending_owner.set(Address::ZERO);
self._ownable._transfer_ownership(new_owner);
Expand Down
61 changes: 28 additions & 33 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`ownable::Error::UnauthorizedAccount`] is returned.
/// If `new_owner` is the `Address::ZERO`, then the error
/// [`ownable::Error::InvalidOwner`] is returned.
/// * [`ownable::Error::UnauthorizedAccount`] - If called by any account
/// other than the owner.
/// * [`ownable::Error::InvalidOwner`] - If `new_owner` is the
/// `Address::ZERO`.
///
/// # Events
///
/// Emits an [`ownable::OwnershipTransferred`] event.
/// * [`ownable::OwnershipTransferred`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -190,12 +190,11 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`ownable::Error::UnauthorizedAccount`] is returned.
/// * [`ownable::Error::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits an [`ownable::OwnershipTransferred`] event.
/// * [`ownable::OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;

/// The contract should be able to receive Ether.
Expand Down Expand Up @@ -251,8 +250,8 @@ pub trait IVestingWallet {
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "releasable")]
fn releasable_eth(&self) -> U256;

Expand All @@ -266,13 +265,12 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "releasable")]
fn releasable_erc20(&mut self, token: Address)
-> Result<U256, Self::Error>;
Expand All @@ -285,17 +283,16 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If Ether transfer fails, then the error [`Error::ReleaseEtherFailed`] is
/// returned.
/// * [`Error::ReleaseEtherFailed`] - If Ether transfer fails.
///
/// # Events
///
/// Emits an [`EtherReleased`] event.
/// * [`EtherReleased`].
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "release")]
fn release_eth(&mut self) -> Result<(), Self::Error>;

Expand All @@ -308,19 +305,18 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// If the contract fails to execute the call, then the error
/// [`safe_erc20::Error::SafeErc20FailedOperation`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
/// * [`safe_erc20::Error::SafeErc20FailedOperation`] - If the contract
/// fails to execute the call.
///
/// # Events
///
/// Emits an [`ERC20Released`] event.
/// * [`ERC20Released`].
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "release")]
fn release_erc20(&mut self, token: Address) -> Result<(), Self::Error>;

Expand All @@ -334,8 +330,8 @@ pub trait IVestingWallet {
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "vestedAmount")]
fn vested_amount_eth(&self, timestamp: u64) -> U256;

Expand All @@ -350,13 +346,12 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "vestedAmount")]
fn vested_amount_erc20(
&mut self,
Expand Down Expand Up @@ -505,7 +500,7 @@ impl VestingWallet {
///
/// # Panics
///
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
fn vesting_schedule(&self, total_allocation: U256, timestamp: U64) -> U256 {
let timestamp = U256::from(timestamp);

Expand Down
Loading
Loading