From 29403f7c8253b1f8213973d3c8677963f29f0b88 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 19 Sep 2023 15:17:08 +0200 Subject: [PATCH 1/2] feat: add prefixes --- src/access/accesscontrol/accesscontrol.cairo | 14 ++--- src/access/ownable/ownable.cairo | 10 ++-- src/account/account.cairo | 12 ++-- src/introspection/src5.cairo | 8 +-- src/security/initializable.cairo | 6 +- src/security/pausable.cairo | 12 ++-- src/security/reentrancyguard.cairo | 8 +-- src/tests/access/test_ownable.cairo | 8 +-- src/tests/security/test_reentrancyguard.cairo | 10 ++-- src/tests/token/test_erc721.cairo | 14 ++--- src/token/erc20/erc20.cairo | 49 ++++++++------- src/token/erc721/erc721.cairo | 60 +++++++++---------- 12 files changed, 108 insertions(+), 103 deletions(-) diff --git a/src/access/accesscontrol/accesscontrol.cairo b/src/access/accesscontrol/accesscontrol.cairo index 90dfe421c..74440480c 100644 --- a/src/access/accesscontrol/accesscontrol.cairo +++ b/src/access/accesscontrol/accesscontrol.cairo @@ -12,8 +12,8 @@ mod AccessControl { #[storage] struct Storage { - role_admin: LegacyMap, - role_members: LegacyMap<(felt252, ContractAddress), bool>, + AccessControl_role_admin: LegacyMap, + AccessControl_role_members: LegacyMap<(felt252, ContractAddress), bool>, } #[event] @@ -82,11 +82,11 @@ mod AccessControl { #[external(v0)] impl AccessControlImpl of interface::IAccessControl { fn has_role(self: @ContractState, role: felt252, account: ContractAddress) -> bool { - self.role_members.read((role, account)) + self.AccessControl_role_members.read((role, account)) } fn get_role_admin(self: @ContractState, role: felt252) -> felt252 { - self.role_admin.read(role) + self.AccessControl_role_admin.read(role) } fn grant_role(ref self: ContractState, role: felt252, account: ContractAddress) { @@ -151,7 +151,7 @@ mod AccessControl { fn _grant_role(ref self: ContractState, role: felt252, account: ContractAddress) { if !AccessControlImpl::has_role(@self, role, account) { let caller: ContractAddress = get_caller_address(); - self.role_members.write((role, account), true); + self.AccessControl_role_members.write((role, account), true); self.emit(RoleGranted { role, account, sender: caller }); } } @@ -159,14 +159,14 @@ mod AccessControl { fn _revoke_role(ref self: ContractState, role: felt252, account: ContractAddress) { if AccessControlImpl::has_role(@self, role, account) { let caller: ContractAddress = get_caller_address(); - self.role_members.write((role, account), false); + self.AccessControl_role_members.write((role, account), false); self.emit(RoleRevoked { role, account, sender: caller }); } } fn _set_role_admin(ref self: ContractState, role: felt252, admin_role: felt252) { let previous_admin_role: felt252 = AccessControlImpl::get_role_admin(@self, role); - self.role_admin.write(role, admin_role); + self.AccessControl_role_admin.write(role, admin_role); self.emit(RoleAdminChanged { role, previous_admin_role, new_admin_role: admin_role }); } } diff --git a/src/access/ownable/ownable.cairo b/src/access/ownable/ownable.cairo index ee621afa4..856de8190 100644 --- a/src/access/ownable/ownable.cairo +++ b/src/access/ownable/ownable.cairo @@ -10,7 +10,7 @@ mod Ownable { #[storage] struct Storage { - _owner: ContractAddress + Ownable_owner: ContractAddress } #[event] @@ -38,15 +38,15 @@ mod Ownable { } fn assert_only_owner(self: @ContractState) { - let owner: ContractAddress = self._owner.read(); + let owner: ContractAddress = self.Ownable_owner.read(); let caller: ContractAddress = get_caller_address(); assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); assert(caller == owner, Errors::NOT_OWNER); } fn _transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { - let previous_owner: ContractAddress = self._owner.read(); - self._owner.write(new_owner); + let previous_owner: ContractAddress = self.Ownable_owner.read(); + self.Ownable_owner.write(new_owner); self .emit( OwnershipTransferred { previous_owner: previous_owner, new_owner: new_owner } @@ -57,7 +57,7 @@ mod Ownable { #[external(v0)] impl OwnableImpl of interface::IOwnable { fn owner(self: @ContractState) -> ContractAddress { - self._owner.read() + self.Ownable_owner.read() } fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { diff --git a/src/account/account.cairo b/src/account/account.cairo index 13b7e8d0e..90408a30f 100644 --- a/src/account/account.cairo +++ b/src/account/account.cairo @@ -46,7 +46,7 @@ mod Account { #[storage] struct Storage { - public_key: felt252 + Account_public_key: felt252 } #[event] @@ -150,12 +150,12 @@ mod Account { #[external(v0)] impl PublicKeyImpl of super::PublicKeyTrait { fn get_public_key(self: @ContractState) -> felt252 { - self.public_key.read() + self.Account_public_key.read() } fn set_public_key(ref self: ContractState, new_public_key: felt252) { assert_only_self(); - self.emit(OwnerRemoved { removed_owner_guid: self.public_key.read() }); + self.emit(OwnerRemoved { removed_owner_guid: self.Account_public_key.read() }); self._set_public_key(new_public_key); } } @@ -163,7 +163,7 @@ mod Account { #[external(v0)] impl PublicKeyCamelImpl of super::PublicKeyCamelTrait { fn getPublicKey(self: @ContractState) -> felt252 { - self.public_key.read() + self.Account_public_key.read() } fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { @@ -202,7 +202,7 @@ mod Account { } fn _set_public_key(ref self: ContractState, new_public_key: felt252) { - self.public_key.write(new_public_key); + self.Account_public_key.write(new_public_key); self.emit(OwnerAdded { new_owner_guid: new_public_key }); } @@ -213,7 +213,7 @@ mod Account { if valid_length { check_ecdsa_signature( - hash, self.public_key.read(), *signature.at(0_u32), *signature.at(1_u32) + hash, self.Account_public_key.read(), *signature.at(0_u32), *signature.at(1_u32) ) } else { false diff --git a/src/introspection/src5.cairo b/src/introspection/src5.cairo index 51a4e6720..3b94f4218 100644 --- a/src/introspection/src5.cairo +++ b/src/introspection/src5.cairo @@ -7,7 +7,7 @@ mod SRC5 { #[storage] struct Storage { - supported_interfaces: LegacyMap + SRC5_supported_interfaces: LegacyMap } mod Errors { @@ -20,7 +20,7 @@ mod SRC5 { if interface_id == interface::ISRC5_ID { return true; } - self.supported_interfaces.read(interface_id) + self.SRC5_supported_interfaces.read(interface_id) } } @@ -34,12 +34,12 @@ mod SRC5 { #[generate_trait] impl InternalImpl of InternalTrait { fn register_interface(ref self: ContractState, interface_id: felt252) { - self.supported_interfaces.write(interface_id, true); + self.SRC5_supported_interfaces.write(interface_id, true); } fn deregister_interface(ref self: ContractState, interface_id: felt252) { assert(interface_id != interface::ISRC5_ID, Errors::INVALID_ID); - self.supported_interfaces.write(interface_id, false); + self.SRC5_supported_interfaces.write(interface_id, false); } } } diff --git a/src/security/initializable.cairo b/src/security/initializable.cairo index 934813276..3ab4cda1f 100644 --- a/src/security/initializable.cairo +++ b/src/security/initializable.cairo @@ -5,7 +5,7 @@ mod Initializable { #[storage] struct Storage { - initialized: bool + Initializable_initialized: bool } mod Errors { @@ -15,12 +15,12 @@ mod Initializable { #[generate_trait] impl InternalImpl of InternalTrait { fn is_initialized(self: @ContractState) -> bool { - self.initialized.read() + self.Initializable_initialized.read() } fn initialize(ref self: ContractState) { assert(!self.is_initialized(), Errors::INITIALIZED); - self.initialized.write(true); + self.Initializable_initialized.write(true); } } } diff --git a/src/security/pausable.cairo b/src/security/pausable.cairo index 7441891a8..b29bbf19d 100644 --- a/src/security/pausable.cairo +++ b/src/security/pausable.cairo @@ -13,7 +13,7 @@ mod Pausable { #[storage] struct Storage { - paused: bool + Pausable_paused: bool } #[event] @@ -41,29 +41,29 @@ mod Pausable { #[external(v0)] impl PausableImpl of super::IPausable { fn is_paused(self: @ContractState) -> bool { - self.paused.read() + self.Pausable_paused.read() } } #[generate_trait] impl InternalImpl of InternalTrait { fn assert_not_paused(self: @ContractState) { - assert(!self.paused.read(), Errors::PAUSED); + assert(!self.Pausable_paused.read(), Errors::PAUSED); } fn assert_paused(self: @ContractState) { - assert(self.paused.read(), Errors::NOT_PAUSED); + assert(self.Pausable_paused.read(), Errors::NOT_PAUSED); } fn _pause(ref self: ContractState) { self.assert_not_paused(); - self.paused.write(true); + self.Pausable_paused.write(true); self.emit(Paused { account: get_caller_address() }); } fn _unpause(ref self: ContractState) { self.assert_paused(); - self.paused.write(false); + self.Pausable_paused.write(false); self.emit(Unpaused { account: get_caller_address() }); } } diff --git a/src/security/reentrancyguard.cairo b/src/security/reentrancyguard.cairo index d6a218c62..cabc96049 100644 --- a/src/security/reentrancyguard.cairo +++ b/src/security/reentrancyguard.cairo @@ -7,7 +7,7 @@ mod ReentrancyGuard { #[storage] struct Storage { - entered: bool + ReentrancyGuard_entered: bool } mod Errors { @@ -17,12 +17,12 @@ mod ReentrancyGuard { #[generate_trait] impl InternalImpl of InternalTrait { fn start(ref self: ContractState) { - assert(!self.entered.read(), Errors::REENTRANT_CALL); - self.entered.write(true); + assert(!self.ReentrancyGuard_entered.read(), Errors::REENTRANT_CALL); + self.ReentrancyGuard_entered.write(true); } fn end(ref self: ContractState) { - self.entered.write(false); + self.ReentrancyGuard_entered.write(false); } } } diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index 04b9033a2..5c68a490a 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -2,7 +2,7 @@ use openzeppelin::access::ownable::Ownable::InternalImpl; use openzeppelin::access::ownable::Ownable::OwnableCamelOnlyImpl; use openzeppelin::access::ownable::Ownable::OwnableImpl; use openzeppelin::access::ownable::Ownable::OwnershipTransferred; -use openzeppelin::access::ownable::Ownable::_owner::InternalContractMemberStateTrait; +use openzeppelin::access::ownable::Ownable::Ownable_owner::InternalContractMemberStateTrait; use openzeppelin::access::ownable::Ownable; use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER}; use openzeppelin::tests::utils; @@ -35,12 +35,12 @@ fn setup() -> Ownable::ContractState { #[available_gas(2000000)] fn test_initializer() { let mut state = STATE(); - assert(state._owner.read().is_zero(), 'Should be zero'); + assert(state.Ownable_owner.read().is_zero(), 'Should be zero'); InternalImpl::initializer(ref state, OWNER()); assert_event_ownership_transferred(ZERO(), OWNER()); - assert(state._owner.read() == OWNER(), 'Owner should be set'); + assert(state.Ownable_owner.read() == OWNER(), 'Owner should be set'); } // @@ -84,7 +84,7 @@ fn test__transfer_ownership() { assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state._owner.read() == OTHER(), 'Owner should be OTHER'); + assert(state.Ownable_owner.read() == OTHER(), 'Owner should be OTHER'); } // diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index b5aa84056..231a693b6 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -1,5 +1,5 @@ use openzeppelin::security::reentrancyguard::ReentrancyGuard::InternalImpl; -use openzeppelin::security::reentrancyguard::ReentrancyGuard::entered::InternalContractMemberStateTrait; +use openzeppelin::security::reentrancyguard::ReentrancyGuard::ReentrancyGuard_entered::InternalContractMemberStateTrait; use openzeppelin::security::reentrancyguard::ReentrancyGuard; use openzeppelin::tests::mocks::reentrancy_attacker_mock::Attacker; use openzeppelin::tests::mocks::reentrancy_mock::IReentrancyMockDispatcher; @@ -26,9 +26,9 @@ fn deploy_mock() -> IReentrancyMockDispatcher { fn test_reentrancy_guard_start() { let mut state = STATE(); - assert(!state.entered.read(), 'Should not be entered'); + assert(!state.ReentrancyGuard_entered.read(), 'Should not be entered'); InternalImpl::start(ref state); - assert(state.entered.read(), 'Should be entered'); + assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); } #[test] @@ -47,9 +47,9 @@ fn test_reentrancy_guard_end() { let mut state = STATE(); InternalImpl::start(ref state); - assert(state.entered.read(), 'Should be entered'); + assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); InternalImpl::end(ref state); - assert(!state.entered.read(), 'Should no longer be entered'); + assert(!state.ReentrancyGuard_entered.read(), 'Should no longer be entered'); } // diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index 1351e0385..25265d7e4 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -1,5 +1,5 @@ -use ERC721::_owners::InternalContractMemberStateTrait as OwnersTrait; -use ERC721::_token_approvals::InternalContractMemberStateTrait as TokenApprovalsTrait; +use ERC721::ERC721_owners::InternalContractMemberStateTrait as OwnersTrait; +use ERC721::ERC721_token_approvals::InternalContractMemberStateTrait as TokenApprovalsTrait; use array::ArrayTrait; use integer::u256; @@ -191,17 +191,17 @@ fn test__exists() { let token_id = TOKEN_ID; assert(!InternalImpl::_exists(@state, token_id), 'Token should not exist'); - assert(state._owners.read(token_id) == zero, 'Invalid owner'); + assert(state.ERC721_owners.read(token_id) == zero, 'Invalid owner'); InternalImpl::_mint(ref state, RECIPIENT(), token_id); assert(InternalImpl::_exists(@state, token_id), 'Token should exist'); - assert(state._owners.read(token_id) == RECIPIENT(), 'Invalid owner'); + assert(state.ERC721_owners.read(token_id) == RECIPIENT(), 'Invalid owner'); InternalImpl::_burn(ref state, token_id); assert(!InternalImpl::_exists(@state, token_id), 'Token should not exist'); - assert(state._owners.read(token_id) == zero, 'Invalid owner'); + assert(state.ERC721_owners.read(token_id) == zero, 'Invalid owner'); } // @@ -1329,9 +1329,9 @@ fn test__burn() { InternalImpl::_burn(ref state, TOKEN_ID); assert_event_transfer(OWNER(), ZERO(), TOKEN_ID); - assert(state._owners.read(TOKEN_ID) == ZERO(), 'Ownership after'); + assert(state.ERC721_owners.read(TOKEN_ID) == ZERO(), 'Ownership after'); assert(ERC721Impl::balance_of(@state, OWNER()) == 0, 'Balance of owner after'); - assert(state._token_approvals.read(TOKEN_ID) == ZERO(), 'Approval after'); + assert(state.ERC721_token_approvals.read(TOKEN_ID) == ZERO(), 'Approval after'); } #[test] diff --git a/src/token/erc20/erc20.cairo b/src/token/erc20/erc20.cairo index df5d1fd25..6f5241ff1 100644 --- a/src/token/erc20/erc20.cairo +++ b/src/token/erc20/erc20.cairo @@ -12,11 +12,11 @@ mod ERC20 { #[storage] struct Storage { - _name: felt252, - _symbol: felt252, - _total_supply: u256, - _balances: LegacyMap, - _allowances: LegacyMap<(ContractAddress, ContractAddress), u256>, + ERC20_name: felt252, + ERC20_symbol: felt252, + ERC20_total_supply: u256, + ERC20_balances: LegacyMap, + ERC20_allowances: LegacyMap<(ContractAddress, ContractAddress), u256>, } #[event] @@ -68,11 +68,11 @@ mod ERC20 { #[external(v0)] impl ERC20Impl of IERC20 { fn name(self: @ContractState) -> felt252 { - self._name.read() + self.ERC20_name.read() } fn symbol(self: @ContractState) -> felt252 { - self._symbol.read() + self.ERC20_symbol.read() } fn decimals(self: @ContractState) -> u8 { @@ -80,17 +80,17 @@ mod ERC20 { } fn total_supply(self: @ContractState) -> u256 { - self._total_supply.read() + self.ERC20_total_supply.read() } fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - self._balances.read(account) + self.ERC20_balances.read(account) } fn allowance( self: @ContractState, owner: ContractAddress, spender: ContractAddress ) -> u256 { - self._allowances.read((owner, spender)) + self.ERC20_allowances.read((owner, spender)) } fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool { @@ -173,15 +173,18 @@ mod ERC20 { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer(ref self: ContractState, name_: felt252, symbol_: felt252) { - self._name.write(name_); - self._symbol.write(symbol_); + self.ERC20_name.write(name_); + self.ERC20_symbol.write(symbol_); } fn _increase_allowance( ref self: ContractState, spender: ContractAddress, added_value: u256 ) -> bool { let caller = get_caller_address(); - self._approve(caller, spender, self._allowances.read((caller, spender)) + added_value); + self + ._approve( + caller, spender, self.ERC20_allowances.read((caller, spender)) + added_value + ); true } @@ -191,22 +194,24 @@ mod ERC20 { let caller = get_caller_address(); self ._approve( - caller, spender, self._allowances.read((caller, spender)) - subtracted_value + caller, + spender, + self.ERC20_allowances.read((caller, spender)) - subtracted_value ); true } fn _mint(ref self: ContractState, recipient: ContractAddress, amount: u256) { assert(!recipient.is_zero(), Errors::MINT_TO_ZERO); - self._total_supply.write(self._total_supply.read() + amount); - self._balances.write(recipient, self._balances.read(recipient) + amount); + self.ERC20_total_supply.write(self.ERC20_total_supply.read() + amount); + self.ERC20_balances.write(recipient, self.ERC20_balances.read(recipient) + amount); self.emit(Transfer { from: Zeroable::zero(), to: recipient, value: amount }); } fn _burn(ref self: ContractState, account: ContractAddress, amount: u256) { assert(!account.is_zero(), Errors::BURN_FROM_ZERO); - self._total_supply.write(self._total_supply.read() - amount); - self._balances.write(account, self._balances.read(account) - amount); + self.ERC20_total_supply.write(self.ERC20_total_supply.read() - amount); + self.ERC20_balances.write(account, self.ERC20_balances.read(account) - amount); self.emit(Transfer { from: account, to: Zeroable::zero(), value: amount }); } @@ -215,7 +220,7 @@ mod ERC20 { ) { assert(!owner.is_zero(), Errors::APPROVE_FROM_ZERO); assert(!spender.is_zero(), Errors::APPROVE_TO_ZERO); - self._allowances.write((owner, spender), amount); + self.ERC20_allowances.write((owner, spender), amount); self.emit(Approval { owner, spender, value: amount }); } @@ -227,15 +232,15 @@ mod ERC20 { ) { assert(!sender.is_zero(), Errors::TRANSFER_FROM_ZERO); assert(!recipient.is_zero(), Errors::TRANSFER_TO_ZERO); - self._balances.write(sender, self._balances.read(sender) - amount); - self._balances.write(recipient, self._balances.read(recipient) + amount); + self.ERC20_balances.write(sender, self.ERC20_balances.read(sender) - amount); + self.ERC20_balances.write(recipient, self.ERC20_balances.read(recipient) + amount); self.emit(Transfer { from: sender, to: recipient, value: amount }); } fn _spend_allowance( ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 ) { - let current_allowance = self._allowances.read((owner, spender)); + let current_allowance = self.ERC20_allowances.read((owner, spender)); if current_allowance != BoundedInt::max() { self._approve(owner, spender, current_allowance - amount); } diff --git a/src/token/erc721/erc721.cairo b/src/token/erc721/erc721.cairo index 559b57c9c..cc49bae3e 100644 --- a/src/token/erc721/erc721.cairo +++ b/src/token/erc721/erc721.cairo @@ -22,13 +22,13 @@ mod ERC721 { #[storage] struct Storage { - _name: felt252, - _symbol: felt252, - _owners: LegacyMap, - _balances: LegacyMap, - _token_approvals: LegacyMap, - _operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, - _token_uri: LegacyMap, + ERC721_name: felt252, + ERC721_symbol: felt252, + ERC721_owners: LegacyMap, + ERC721_balances: LegacyMap, + ERC721_token_approvals: LegacyMap, + ERC721_operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, + ERC721_token_uri: LegacyMap, } #[event] @@ -108,16 +108,16 @@ mod ERC721 { #[external(v0)] impl ERC721MetadataImpl of interface::IERC721Metadata { fn name(self: @ContractState) -> felt252 { - self._name.read() + self.ERC721_name.read() } fn symbol(self: @ContractState) -> felt252 { - self._symbol.read() + self.ERC721_symbol.read() } fn token_uri(self: @ContractState, token_id: u256) -> felt252 { assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); - self._token_uri.read(token_id) + self.ERC721_token_uri.read(token_id) } } @@ -125,7 +125,7 @@ mod ERC721 { impl ERC721MetadataCamelOnlyImpl of interface::IERC721MetadataCamelOnly { fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { assert(self._exists(tokenId), Errors::INVALID_TOKEN_ID); - self._token_uri.read(tokenId) + self.ERC721_token_uri.read(tokenId) } } @@ -133,7 +133,7 @@ mod ERC721 { impl ERC721Impl of interface::IERC721 { fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { assert(!account.is_zero(), Errors::INVALID_ACCOUNT); - self._balances.read(account) + self.ERC721_balances.read(account) } fn owner_of(self: @ContractState, token_id: u256) -> ContractAddress { @@ -142,13 +142,13 @@ mod ERC721 { fn get_approved(self: @ContractState, token_id: u256) -> ContractAddress { assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); - self._token_approvals.read(token_id) + self.ERC721_token_approvals.read(token_id) } fn is_approved_for_all( self: @ContractState, owner: ContractAddress, operator: ContractAddress ) -> bool { - self._operator_approvals.read((owner, operator)) + self.ERC721_operator_approvals.read((owner, operator)) } fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) { @@ -239,8 +239,8 @@ mod ERC721 { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer(ref self: ContractState, name_: felt252, symbol_: felt252) { - self._name.write(name_); - self._symbol.write(symbol_); + self.ERC721_name.write(name_); + self.ERC721_symbol.write(symbol_); let mut unsafe_state = src5::SRC5::unsafe_new_contract_state(); src5::SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IERC721_ID); @@ -250,7 +250,7 @@ mod ERC721 { } fn _owner_of(self: @ContractState, token_id: u256) -> ContractAddress { - let owner = self._owners.read(token_id); + let owner = self.ERC721_owners.read(token_id); match owner.is_zero() { bool::False(()) => owner, bool::True(()) => panic_with_felt252(Errors::INVALID_TOKEN_ID) @@ -258,7 +258,7 @@ mod ERC721 { } fn _exists(self: @ContractState, token_id: u256) -> bool { - !self._owners.read(token_id).is_zero() + !self.ERC721_owners.read(token_id).is_zero() } fn _is_approved_or_owner( @@ -275,7 +275,7 @@ mod ERC721 { let owner = self._owner_of(token_id); assert(owner != to, Errors::APPROVAL_TO_OWNER); - self._token_approvals.write(token_id, to); + self.ERC721_token_approvals.write(token_id, to); self.emit(Approval { owner, approved: to, token_id }); } @@ -286,7 +286,7 @@ mod ERC721 { approved: bool ) { assert(owner != operator, Errors::SELF_APPROVAL); - self._operator_approvals.write((owner, operator), approved); + self.ERC721_operator_approvals.write((owner, operator), approved); self.emit(ApprovalForAll { owner, operator, approved }); } @@ -294,8 +294,8 @@ mod ERC721 { assert(!to.is_zero(), Errors::INVALID_RECEIVER); assert(!self._exists(token_id), Errors::ALREADY_MINTED); - self._balances.write(to, self._balances.read(to) + 1); - self._owners.write(token_id, to); + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); self.emit(Transfer { from: Zeroable::zero(), to, token_id }); } @@ -308,11 +308,11 @@ mod ERC721 { assert(from == owner, Errors::WRONG_SENDER); // Implicit clear approvals, no need to emit an event - self._token_approvals.write(token_id, Zeroable::zero()); + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); - self._balances.write(from, self._balances.read(from) - 1); - self._balances.write(to, self._balances.read(to) + 1); - self._owners.write(token_id, to); + self.ERC721_balances.write(from, self.ERC721_balances.read(from) - 1); + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); self.emit(Transfer { from, to, token_id }); } @@ -321,10 +321,10 @@ mod ERC721 { let owner = self._owner_of(token_id); // Implicit clear approvals, no need to emit an event - self._token_approvals.write(token_id, Zeroable::zero()); + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); - self._balances.write(owner, self._balances.read(owner) - 1); - self._owners.write(token_id, Zeroable::zero()); + self.ERC721_balances.write(owner, self.ERC721_balances.read(owner) - 1); + self.ERC721_owners.write(token_id, Zeroable::zero()); self.emit(Transfer { from: owner, to: Zeroable::zero(), token_id }); } @@ -354,7 +354,7 @@ mod ERC721 { fn _set_token_uri(ref self: ContractState, token_id: u256, token_uri: felt252) { assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); - self._token_uri.write(token_id, token_uri) + self.ERC721_token_uri.write(token_id, token_uri) } } From e3bd06c636b3333c3b78263c17a0e4498866db59 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Sat, 23 Sep 2023 19:19:51 +0200 Subject: [PATCH 2/2] Update src/access/accesscontrol/accesscontrol.cairo Co-authored-by: Andrew Fleming --- src/access/accesscontrol/accesscontrol.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/access/accesscontrol/accesscontrol.cairo b/src/access/accesscontrol/accesscontrol.cairo index 74440480c..e7fd23542 100644 --- a/src/access/accesscontrol/accesscontrol.cairo +++ b/src/access/accesscontrol/accesscontrol.cairo @@ -13,7 +13,7 @@ mod AccessControl { #[storage] struct Storage { AccessControl_role_admin: LegacyMap, - AccessControl_role_members: LegacyMap<(felt252, ContractAddress), bool>, + AccessControl_role_member: LegacyMap<(felt252, ContractAddress), bool>, } #[event]