Skip to content

Commit

Permalink
move only_owner to internal impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ggonzalez94 committed Oct 16, 2024
1 parent 2786a78 commit 02b8ba2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
34 changes: 17 additions & 17 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ impl Ownable {
self._owner.get()
}

/// Checks if the [`msg::sender`] is set as the owner.
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
pub fn only_owner(&self) -> Result<(), Error> {
let account = msg::sender();
if self.owner() != account {
return Err(Error::UnauthorizedAccount(
OwnableUnauthorizedAccount { account },
));
}

Ok(())
}

/// Transfers ownership of the contract to a new account (`new_owner`). Can
/// only be called by the current owner.
///
Expand Down Expand Up @@ -131,6 +114,23 @@ impl Ownable {
}

impl Ownable {
/// Checks if the [`msg::sender`] is set as the owner.
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
pub fn only_owner(&self) -> Result<(), Error> {
let account = msg::sender();
if self.owner() != account {
return Err(Error::UnauthorizedAccount(
OwnableUnauthorizedAccount { account },
));
}

Ok(())
}

/// Transfers ownership of the contract to a new account (`new_owner`).
/// Internal function without access restriction.
///
Expand Down
11 changes: 0 additions & 11 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ impl Ownable2Step {
self._pending_owner.get()
}

/// Checks if the [`msg::sender`] is set as the owner.
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
pub fn only_owner(&self) -> Result<(), OwnableError> {
self._ownable.only_owner()?;
Ok(())
}

/// Initiates the transfer of ownership to a new account (`new_owner`).
/// Can only be called by the current owner.
///
Expand Down

0 comments on commit 02b8ba2

Please sign in to comment.