From 1a8d1a6991c57f1b6a809de1f97ff660283c4e30 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 27 Aug 2024 13:01:27 +0100 Subject: [PATCH] change the mapping for permission storage --- src/components/permissionable/permissionable.cairo | 10 ++++------ src/components/presets/account_preset.cairo | 4 ++-- src/interfaces/IPermissionable.cairo | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/permissionable/permissionable.cairo b/src/components/permissionable/permissionable.cairo index 5a55cd8..b4c4e97 100644 --- a/src/components/permissionable/permissionable.cairo +++ b/src/components/permissionable/permissionable.cairo @@ -20,7 +20,7 @@ pub mod PermissionableComponent { #[storage] pub struct Storage { - permissions: Map // > + permissions: Map<(ContractAddress, ContractAddress), bool> // <, bool> } // ************************************************************************* @@ -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( @@ -93,11 +93,9 @@ pub mod PermissionableComponent { fn has_permission( self: @ComponentState, 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 } } diff --git a/src/components/presets/account_preset.cairo b/src/components/presets/account_preset.cairo index f8cb60b..89fde03 100644 --- a/src/components/presets/account_preset.cairo +++ b/src/components/presets/account_preset.cairo @@ -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) } } } diff --git a/src/interfaces/IPermissionable.cairo b/src/interfaces/IPermissionable.cairo index ac07f96..0e636ef 100644 --- a/src/interfaces/IPermissionable.cairo +++ b/src/interfaces/IPermissionable.cairo @@ -8,7 +8,7 @@ pub trait IPermissionable { permissions: Array ); fn has_permission( - self: @TContractState, owner: ContractAddress, permission_address: ContractAddress + self: @TContractState, owner: ContractAddress, permissioned_address: ContractAddress ) -> bool; }