Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaplas committed Dec 12, 2023
1 parent a05b541 commit 3005d9a
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 337 deletions.
8 changes: 4 additions & 4 deletions modules/Odra.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fqn = "odra_modules::Erc20"
name = "WrappedNativeToken"
fqn = "odra_modules::wrapped_native::WrappedNativeToken"

#[[contracts]]
#name = "ownable"
#fqn = "odra_modules::access::Ownable"
#
[[contracts]]
name = "ownable"
fqn = "odra_modules::access::Ownable"

#[[contracts]]
#name = "ownable2_step"
#fqn = "odra_modules::access::Ownable2Step"
Expand Down
10 changes: 5 additions & 5 deletions modules/src/access/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl AccessControl {
///
/// The caller must have `role`'s admin role.
pub fn grant_role(&mut self, role: &Role, address: &Address) {
self.check_role(&self.get_role_admin(role), &contract_env::caller());
self.check_role(&self.get_role_admin(role), self.env().caller());
self.unchecked_grant_role(role, address);
}

Expand All @@ -72,7 +72,7 @@ impl AccessControl {
///
/// The caller must have `role`'s admin role.
pub fn revoke_role(&mut self, role: &Role, address: &Address) {
self.check_role(&self.get_role_admin(role), &contract_env::caller());
self.check_role(&self.get_role_admin(role), self.env().caller());
self.unchecked_revoke_role(role, address);
}

Expand All @@ -87,8 +87,8 @@ impl AccessControl {
///
/// Note that only `address` is authorized to call this function.
pub fn renounce_role(&mut self, role: &Role, address: &Address) {
if address != &contract_env::caller() {
contract_env::revert(Error::RoleRenounceForAnotherAddress);
if address != self.env().caller() {
self.env().revert(RoleRenounceForAnotherAddress);
}
self.unchecked_revoke_role(role, address);
}
Expand All @@ -98,7 +98,7 @@ impl AccessControl {
/// Ensures `address` has `role`. If not, reverts with [Error::MissingRole].
pub fn check_role(&self, role: &Role, address: &Address) {
if !self.has_role(role, address) {
contract_env::revert(Error::MissingRole);
self.env().revert(MissingRole);
}
}

Expand Down
23 changes: 14 additions & 9 deletions modules/src/access/errors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use odra::execution_error;
use odra::OdraError;

execution_error! {
pub enum Error {
OwnerNotSet => 20_000,
CallerNotTheOwner => 20_001,
CallerNotTheNewOwner => 20_002,
MissingRole => 20_003,
RoleRenounceForAnotherAddress => 20_004,
pub enum Error {
OwnerNotSet = 20_000,
CallerNotTheOwner = 20_001,
CallerNotTheNewOwner = 20_002,
MissingRole = 20_003,
RoleRenounceForAnotherAddress = 20_004,
}
}

impl From<Error> for OdraError {
fn from(error: Error) -> Self {
OdraError::user(error as u16)
}
}

4 changes: 2 additions & 2 deletions modules/src/access/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use odra::{types::Address, Event};

use casper_event_standard::Event;
use odra::Address;
use super::access_control::Role;

#[derive(Event, PartialEq, Eq, Debug)]
Expand Down
Loading

0 comments on commit 3005d9a

Please sign in to comment.