difftreelog
fix Add weights to common collection eth methods.
in: master
2 files changed
pallets/common/src/erc.rsdiffbeforeafterboth78 key: string,78 key: string,79 value: bytes,79 value: bytes,80 ) -> Result<void> {80 ) -> Result<void> {81 self.consume_store_reads_and_writes(1, 1)?;8281 let caller = T::CrossAccountId::from_eth(caller);83 let caller = T::CrossAccountId::from_eth(caller);82 let key = <Vec<u8>>::from(key)84 let key = <Vec<u8>>::from(key)92 ///94 ///93 /// @param key Property key.95 /// @param key Property key.94 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {96 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {97 self.consume_store_reads_and_writes(1, 1)?;9895 let caller = T::CrossAccountId::from_eth(caller);99 let caller = T::CrossAccountId::from_eth(caller);96 let key = <Vec<u8>>::from(key)100 let key = <Vec<u8>>::from(key)123 ///127 ///124 /// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.128 /// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.125 fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {129 fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {130 self.consume_store_reads_and_writes(1, 1)?;131126 check_is_owner_or_admin(caller, self)?;132 check_is_owner_or_admin(caller, self)?;127133141 caller: caller,147 caller: caller,142 sponsor: uint256,148 sponsor: uint256,143 ) -> Result<void> {149 ) -> Result<void> {150 self.consume_store_reads_and_writes(1, 1)?;151144 check_is_owner_or_admin(caller, self)?;152 check_is_owner_or_admin(caller, self)?;145153161 ///169 ///162 /// @dev After setting the sponsor for the collection, it must be confirmed with this function.170 /// @dev After setting the sponsor for the collection, it must be confirmed with this function.163 fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {171 fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {172 self.consume_store_writes(1)?;173164 let caller = T::CrossAccountId::from_eth(caller);174 let caller = T::CrossAccountId::from_eth(caller);165 if !self175 if !self173183174 /// Remove collection sponsor.184 /// Remove collection sponsor.175 fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {185 fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {186 self.consume_store_reads_and_writes(1, 1)?;176 check_is_owner_or_admin(caller, self)?;187 check_is_owner_or_admin(caller, self)?;177 self.remove_sponsor().map_err(dispatch_to_evm::<T>)?;188 self.remove_sponsor().map_err(dispatch_to_evm::<T>)?;178 save(self)189 save(self)209 /// @param value Value of the limit.220 /// @param value Value of the limit.210 #[solidity(rename_selector = "setCollectionLimit")]221 #[solidity(rename_selector = "setCollectionLimit")]211 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {222 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {223 self.consume_store_reads_and_writes(1, 1)?;224212 check_is_owner_or_admin(caller, self)?;225 check_is_owner_or_admin(caller, self)?;213 let mut limits = self.limits.clone();226 let mut limits = self.limits.clone();252 /// @param value Value of the limit.265 /// @param value Value of the limit.253 #[solidity(rename_selector = "setCollectionLimit")]266 #[solidity(rename_selector = "setCollectionLimit")]254 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {267 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {268 self.consume_store_reads_and_writes(1, 1)?;269255 check_is_owner_or_admin(caller, self)?;270 check_is_owner_or_admin(caller, self)?;256 let mut limits = self.limits.clone();271 let mut limits = self.limits.clone();289 caller: caller,304 caller: caller,290 new_admin: uint256,305 new_admin: uint256,291 ) -> Result<void> {306 ) -> Result<void> {307 self.consume_store_writes(2)?;308292 let caller = T::CrossAccountId::from_eth(caller);309 let caller = T::CrossAccountId::from_eth(caller);293 let new_admin = convert_uint256_to_cross_account::<T>(new_admin);310 let new_admin = convert_uint256_to_cross_account::<T>(new_admin);302 caller: caller,319 caller: caller,303 admin: uint256,320 admin: uint256,304 ) -> Result<void> {321 ) -> Result<void> {322 self.consume_store_writes(2)?;323305 let caller = T::CrossAccountId::from_eth(caller);324 let caller = T::CrossAccountId::from_eth(caller);306 let admin = convert_uint256_to_cross_account::<T>(admin);325 let admin = convert_uint256_to_cross_account::<T>(admin);311 /// Add collection admin.330 /// Add collection admin.312 /// @param newAdmin Address of the added administrator.331 /// @param newAdmin Address of the added administrator.313 fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {332 fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {333 self.consume_store_writes(2)?;334314 let caller = T::CrossAccountId::from_eth(caller);335 let caller = T::CrossAccountId::from_eth(caller);315 let new_admin = T::CrossAccountId::from_eth(new_admin);336 let new_admin = T::CrossAccountId::from_eth(new_admin);321 ///342 ///322 /// @param admin Address of the removed administrator.343 /// @param admin Address of the removed administrator.323 fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {344 fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {345 self.consume_store_writes(2)?;346324 let caller = T::CrossAccountId::from_eth(caller);347 let caller = T::CrossAccountId::from_eth(caller);325 let admin = T::CrossAccountId::from_eth(admin);348 let admin = T::CrossAccountId::from_eth(admin);332 /// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'355 /// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'333 #[solidity(rename_selector = "setCollectionNesting")]356 #[solidity(rename_selector = "setCollectionNesting")]334 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {357 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {358 self.consume_store_reads_and_writes(1, 1)?;359335 check_is_owner_or_admin(caller, self)?;360 check_is_owner_or_admin(caller, self)?;336361361 enable: bool,386 enable: bool,362 collections: Vec<address>,387 collections: Vec<address>,363 ) -> Result<void> {388 ) -> Result<void> {389 self.consume_store_reads_and_writes(1, 1)?;390364 if collections.is_empty() {391 if collections.is_empty() {365 return Err("no addresses provided".into());392 return Err("no addresses provided".into());404 /// 0 for Normal431 /// 0 for Normal405 /// 1 for AllowList432 /// 1 for AllowList406 fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {433 fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {434 self.consume_store_reads_and_writes(1, 1)?;435407 check_is_owner_or_admin(caller, self)?;436 check_is_owner_or_admin(caller, self)?;408 let permissions = CollectionPermissions {437 let permissions = CollectionPermissions {437 ///466 ///438 /// @param user Address of a trusted user.467 /// @param user Address of a trusted user.439 fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {468 fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {469 self.consume_store_writes(1)?;470440 let caller = T::CrossAccountId::from_eth(caller);471 let caller = T::CrossAccountId::from_eth(caller);441 let user = T::CrossAccountId::from_eth(user);472 let user = T::CrossAccountId::from_eth(user);451 caller: caller,482 caller: caller,452 user: uint256,483 user: uint256,453 ) -> Result<void> {484 ) -> Result<void> {485 self.consume_store_writes(1)?;486454 let caller = T::CrossAccountId::from_eth(caller);487 let caller = T::CrossAccountId::from_eth(caller);455 let user = convert_uint256_to_cross_account::<T>(user);488 let user = convert_uint256_to_cross_account::<T>(user);461 ///494 ///462 /// @param user Address of a removed user.495 /// @param user Address of a removed user.463 fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {496 fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {497 self.consume_store_writes(1)?;498464 let caller = T::CrossAccountId::from_eth(caller);499 let caller = T::CrossAccountId::from_eth(caller);465 let user = T::CrossAccountId::from_eth(user);500 let user = T::CrossAccountId::from_eth(user);475 caller: caller,510 caller: caller,476 user: uint256,511 user: uint256,477 ) -> Result<void> {512 ) -> Result<void> {513 self.consume_store_writes(1)?;514478 let caller = T::CrossAccountId::from_eth(caller);515 let caller = T::CrossAccountId::from_eth(caller);479 let user = convert_uint256_to_cross_account::<T>(user);516 let user = convert_uint256_to_cross_account::<T>(user);485 ///522 ///486 /// @param mode Enable if "true".523 /// @param mode Enable if "true".487 fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {524 fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {525 self.consume_store_reads_and_writes(1, 1)?;526488 check_is_owner_or_admin(caller, self)?;527 check_is_owner_or_admin(caller, self)?;489 let permissions = CollectionPermissions {528 let permissions = CollectionPermissions {546 /// @dev Owner can be changed only by current owner585 /// @dev Owner can be changed only by current owner547 /// @param newOwner new owner account586 /// @param newOwner new owner account548 fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {587 fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {588 self.consume_store_writes(1)?;589549 let caller = T::CrossAccountId::from_eth(caller);590 let caller = T::CrossAccountId::from_eth(caller);550 let new_owner = T::CrossAccountId::from_eth(new_owner);591 let new_owner = T::CrossAccountId::from_eth(new_owner);557 /// @dev Owner can be changed only by current owner598 /// @dev Owner can be changed only by current owner558 /// @param newOwner new owner substrate account599 /// @param newOwner new owner substrate account559 fn set_owner_substrate(&mut self, caller: caller, new_owner: uint256) -> Result<void> {600 fn set_owner_substrate(&mut self, caller: caller, new_owner: uint256) -> Result<void> {601 self.consume_store_writes(1)?;602560 let caller = T::CrossAccountId::from_eth(caller);603 let caller = T::CrossAccountId::from_eth(caller);561 let new_owner = convert_uint256_to_cross_account::<T>(new_owner);604 let new_owner = convert_uint256_to_cross_account::<T>(new_owner);572 // }615 // }573}616}574617618/// ### Note619/// Do not forget to add: `self.consume_store_reads(1)?;`575fn check_is_owner_or_admin<T: Config>(620fn check_is_owner_or_admin<T: Config>(576 caller: caller,621 caller: caller,577 collection: &CollectionHandle<T>,622 collection: &CollectionHandle<T>,583 Ok(caller)628 Ok(caller)584}629}585630631/// ### Note632/// Do not forget to add: `self.consume_store_writes(1)?;`586fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {633fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {587 // TODO possibly delete for the lack of transaction588 collection.consume_store_writes(1)?;589 collection634 collection590 .check_is_internal()635 .check_is_internal()591 .map_err(dispatch_to_evm::<T>)?;636 .map_err(dispatch_to_evm::<T>)?;pallets/common/src/lib.rsdiffbeforeafterboth112 RmrkBoundedTheme,112 RmrkBoundedTheme,113 RmrkNftChild,113 RmrkNftChild,114 CollectionPermissions,114 CollectionPermissions,115 SchemaVersion,116};115};117116118pub use pallet::*;117pub use pallet::*;202 ))201 ))203 }202 }203204 /// Consume gas for reading and writing.205 pub fn consume_store_reads_and_writes(206 &self,207 reads: u64,208 writes: u64,209 ) -> evm_coder::execution::Result<()> {210 let weight = <T as frame_system::Config>::DbWeight::get();211 let reads = weight.read.saturating_mul(reads);212 let writes = weight.read.saturating_mul(writes);213 self.recorder214 .consume_gas(T::GasWeightMapping::weight_to_gas(215 reads.saturating_add(writes),216 ))217 }204218205 /// Save collection to storage.219 /// Save collection to storage.206 pub fn save(&self) -> DispatchResult {220 pub fn save(&self) -> DispatchResult {310 }324 }311325312 /// Changes collection owner to another account326 /// Changes collection owner to another account327 /// #### Store read/writes328 /// 1 writes313 fn set_owner_internal(329 fn set_owner_internal(314 &mut self,330 &mut self,315 caller: T::CrossAccountId,331 caller: T::CrossAccountId,1292 }1308 }129313091294 /// Toggle `user` participation in the `collection`'s allow list.1310 /// Toggle `user` participation in the `collection`'s allow list.1311 /// #### Store read/writes1312 /// 1 writes1295 pub fn toggle_allowlist(1313 pub fn toggle_allowlist(1296 collection: &CollectionHandle<T>,1314 collection: &CollectionHandle<T>,1297 sender: &T::CrossAccountId,1315 sender: &T::CrossAccountId,1312 }1330 }131313311314 /// Toggle `user` participation in the `collection`'s admin list.1332 /// Toggle `user` participation in the `collection`'s admin list.1333 /// #### Store read/writes1334 /// 2 writes1315 pub fn toggle_admin(1335 pub fn toggle_admin(1316 collection: &CollectionHandle<T>,1336 collection: &CollectionHandle<T>,1317 sender: &T::CrossAccountId,1337 sender: &T::CrossAccountId,