Skip to content

Commit

Permalink
change the mapping for permission storage
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Aug 27, 2024
1 parent d380f43 commit 1a8d1a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/components/permissionable/permissionable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod PermissionableComponent {

#[storage]
pub struct Storage {
permissions: Map<ContractAddress, (ContractAddress, bool)> // <owner => <caller, bool>>
permissions: Map<(ContractAddress, ContractAddress), bool> // <<caller, owner>, bool>
}

// *************************************************************************
Expand Down Expand Up @@ -76,7 +76,7 @@ pub mod PermissionableComponent {
while index < length {
self
.permissions
.write(owner, (*permissioned_addresses[index], *permissions[index]));
.write((owner, *permissioned_addresses[index]), *permissions[index]);
// emit event
self
.emit(
Expand All @@ -93,11 +93,9 @@ pub mod PermissionableComponent {
fn has_permission(
self: @ComponentState<TContractState>,
owner: ContractAddress,
permission_address: ContractAddress
permissioned_address: ContractAddress
) -> bool {
let (caller, permission): (ContractAddress, bool) = self.permissions.read(owner);

assert(caller != permission_address, Errors::NOT_PERMITTED);
let permission = self.permissions.read((owner, permissioned_address));
permission
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/presets/account_preset.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ pub mod AccountPreset {
self.permissionable.set_permission(permissioned_addresses, permissions)
}
fn has_permission(
self: @ContractState, owner: ContractAddress, permission_address: ContractAddress
self: @ContractState, owner: ContractAddress, permissioned_address: ContractAddress
) -> bool {
self.permissionable.has_permission(owner, permission_address)
self.permissionable.has_permission(owner, permissioned_address)
}
}
}
2 changes: 1 addition & 1 deletion src/interfaces/IPermissionable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub trait IPermissionable<TContractState> {
permissions: Array<bool>
);
fn has_permission(
self: @TContractState, owner: ContractAddress, permission_address: ContractAddress
self: @TContractState, owner: ContractAddress, permissioned_address: ContractAddress
) -> bool;
}

0 comments on commit 1a8d1a6

Please sign in to comment.