difftreelog
added `destroyCollection`method to `CollectionHelpers`
in: master
1 file changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use ethereum as _;21use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};22use frame_support::traits::Get;2324use crate::Pallet;2526use pallet_common::{27 CollectionById,28 dispatch::CollectionDispatch,29 erc::{static_property::key, CollectionHelpersEvents},30 Pallet as PalletCommon,31};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};33use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};34use sp_std::vec;35use up_data_structs::{36 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,37 CreateCollectionData,38};3940use crate::{weights::WeightInfo, Config, SelfWeightOf};4142use alloc::format;43use sp_std::vec::Vec;4445/// See [`CollectionHelpersCall`]46pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);47impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {48 fn recorder(&self) -> &SubstrateRecorder<T> {49 &self.050 }5152 fn into_recorder(self) -> SubstrateRecorder<T> {53 self.054 }55}5657fn convert_data<T: Config>(58 caller: caller,59 name: string,60 description: string,61 token_prefix: string,62) -> Result<(63 T::CrossAccountId,64 CollectionName,65 CollectionDescription,66 CollectionTokenPrefix,67)> {68 let caller = T::CrossAccountId::from_eth(caller);69 let name = name70 .encode_utf16()71 .collect::<Vec<u16>>()72 .try_into()73 .map_err(|_| error_field_too_long(stringify!(name), CollectionName::bound()))?;74 let description = description75 .encode_utf16()76 .collect::<Vec<u16>>()77 .try_into()78 .map_err(|_| {79 error_field_too_long(stringify!(description), CollectionDescription::bound())80 })?;81 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {82 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())83 })?;84 Ok((caller, name, description, token_prefix))85}8687#[inline(always)]88fn create_collection_internal<T: Config>(89 caller: caller,90 value: value,91 name: string,92 collection_mode: CollectionMode,93 description: string,94 token_prefix: string,95) -> Result<address> {96 let (caller, name, description, token_prefix) =97 convert_data::<T>(caller, name, description, token_prefix)?;98 let data = CreateCollectionData {99 name,100 mode: collection_mode,101 description,102 token_prefix,103 ..Default::default()104 };105 check_sent_amount_equals_collection_creation_price::<T>(value)?;106 let collection_helpers_address =107 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());108109 let collection_id = T::CollectionDispatch::create(110 caller.clone(),111 collection_helpers_address,112 data,113 Default::default(),114 )115 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;116 let address = pallet_common::eth::collection_id_to_address(collection_id);117 Ok(address)118}119120fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {121 let value = value.as_u128();122 let creation_price: u128 = T::CollectionCreationPrice::get()123 .try_into()124 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait125 .expect("Collection creation price should be convertible to u128");126 if value != creation_price {127 return Err(format!(128 "Sent amount not equals to collection creation price ({0})",129 creation_price130 )131 .into());132 }133 Ok(())134}135136/// @title Contract, which allows users to operate with collections137#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]138impl<T> EvmCollectionHelpers<T>139where140 T: Config + pallet_common::Config + pallet_nonfungible::Config + pallet_refungible::Config,141{142 /// Create an NFT collection143 /// @param name Name of the collection144 /// @param description Informative description of the collection145 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications146 /// @return address Address of the newly created collection147 #[weight(<SelfWeightOf<T>>::create_collection())]148 #[solidity(rename_selector = "createNFTCollection")]149 fn create_nft_collection(150 &mut self,151 caller: caller,152 value: value,153 name: string,154 description: string,155 token_prefix: string,156 ) -> Result<address> {157 let (caller, name, description, token_prefix) =158 convert_data::<T>(caller, name, description, token_prefix)?;159 let data = CreateCollectionData {160 name,161 mode: CollectionMode::NFT,162 description,163 token_prefix,164 ..Default::default()165 };166 check_sent_amount_equals_collection_creation_price::<T>(value)?;167 let collection_helpers_address =168 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());169 let collection_id = T::CollectionDispatch::create(170 caller,171 collection_helpers_address,172 data,173 Default::default(),174 )175 .map_err(dispatch_to_evm::<T>)?;176177 let address = pallet_common::eth::collection_id_to_address(collection_id);178 Ok(address)179 }180 /// Create an NFT collection181 /// @param name Name of the collection182 /// @param description Informative description of the collection183 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications184 /// @return address Address of the newly created collection185 #[weight(<SelfWeightOf<T>>::create_collection())]186 #[deprecated(note = "mathod was renamed to `create_nft_collection`, prefer it instead")]187 #[solidity(hide)]188 fn create_nonfungible_collection(189 &mut self,190 caller: caller,191 value: value,192 name: string,193 description: string,194 token_prefix: string,195 ) -> Result<address> {196 create_collection_internal::<T>(197 caller,198 value,199 name,200 CollectionMode::NFT,201 description,202 token_prefix,203 )204 }205206 #[weight(<SelfWeightOf<T>>::create_collection())]207 #[solidity(rename_selector = "createRFTCollection")]208 fn create_rft_collection(209 &mut self,210 caller: caller,211 value: value,212 name: string,213 description: string,214 token_prefix: string,215 ) -> Result<address> {216 create_collection_internal::<T>(217 caller,218 value,219 name,220 CollectionMode::ReFungible,221 description,222 token_prefix,223 )224 }225226 #[weight(<SelfWeightOf<T>>::create_collection())]227 #[solidity(rename_selector = "createFTCollection")]228 fn create_fungible_collection(229 &mut self,230 caller: caller,231 value: value,232 name: string,233 decimals: uint8,234 description: string,235 token_prefix: string,236 ) -> Result<address> {237 create_collection_internal::<T>(238 caller,239 value,240 name,241 CollectionMode::Fungible(decimals),242 description,243 token_prefix,244 )245 }246247 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]248 fn make_collection_metadata_compatible(249 &mut self,250 caller: caller,251 collection: address,252 base_uri: string,253 ) -> Result<()> {254 let caller = T::CrossAccountId::from_eth(caller);255 let collection =256 pallet_common::eth::map_eth_to_id(&collection).ok_or("not a collection address")?;257 let mut collection =258 <crate::CollectionHandle<T>>::new(collection).ok_or("collection not found")?;259260 if !matches!(261 collection.mode,262 CollectionMode::NFT | CollectionMode::ReFungible263 ) {264 return Err("target collection should be either NFT or Refungible".into());265 }266267 self.recorder().consume_sstore()?;268 collection269 .check_is_owner_or_admin(&caller)270 .map_err(dispatch_to_evm::<T>)?;271272 if collection.flags.erc721metadata {273 return Err("target collection is already Erc721Metadata compatible".into());274 }275 collection.flags.erc721metadata = true;276277 let all_permissions = <pallet_common::CollectionPropertyPermissions<T>>::get(collection.id);278 if all_permissions.get(&key::url()).is_none() {279 self.recorder().consume_sstore()?;280 <PalletCommon<T>>::set_property_permission(281 &collection,282 &caller,283 up_data_structs::PropertyKeyPermission {284 key: key::url(),285 permission: up_data_structs::PropertyPermission {286 mutable: true,287 collection_admin: true,288 token_owner: false,289 },290 },291 )292 .map_err(dispatch_to_evm::<T>)?;293 }294 if all_permissions.get(&key::suffix()).is_none() {295 self.recorder().consume_sstore()?;296 <PalletCommon<T>>::set_property_permission(297 &collection,298 &caller,299 up_data_structs::PropertyKeyPermission {300 key: key::suffix(),301 permission: up_data_structs::PropertyPermission {302 mutable: true,303 collection_admin: true,304 token_owner: false,305 },306 },307 )308 .map_err(dispatch_to_evm::<T>)?;309 }310311 let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);312 if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {313 self.recorder().consume_sstore()?;314 <PalletCommon<T>>::set_collection_properties(315 &collection,316 &caller,317 vec![up_data_structs::Property {318 key: key::base_uri(),319 value: base_uri320 .into_bytes()321 .try_into()322 .map_err(|_| "base uri is too large")?,323 }],324 )325 .map_err(dispatch_to_evm::<T>)?;326 }327328 self.recorder().consume_sstore()?;329 collection.save().map_err(dispatch_to_evm::<T>)?;330331 Ok(())332 }333334 #[weight(<SelfWeightOf<T>>::destroy_collection())]335 fn destroy_collection(&mut self, caller: caller, collection_address: address) -> Result<void> {336 let caller = T::CrossAccountId::from_eth(caller);337338 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)339 .ok_or("Invalid collection address format")?;340 <Pallet<T>>::destroy_collection_internal(caller, collection_id)341 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)342 }343344 /// Check if a collection exists345 /// @param collectionAddress Address of the collection in question346 /// @return bool Does the collection exist?347 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {348 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {349 let collection_id = id;350 return Ok(<CollectionById<T>>::contains_key(collection_id));351 }352353 Ok(false)354 }355356 fn collection_creation_fee(&self) -> Result<value> {357 let price: u128 = T::CollectionCreationPrice::get()358 .try_into()359 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait360 .expect("Collection creation price should be convertible to u128");361 Ok(price.into())362 }363}364365/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]366pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);367impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>368 for CollectionHelpersOnMethodCall<T>369{370 fn is_reserved(contract: &sp_core::H160) -> bool {371 contract == &T::ContractAddress::get()372 }373374 fn is_used(contract: &sp_core::H160) -> bool {375 contract == &T::ContractAddress::get()376 }377378 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {379 if handle.code_address() != T::ContractAddress::get() {380 return None;381 }382383 let helpers =384 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));385 pallet_evm_coder_substrate::call(handle, helpers)386 }387388 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {389 (contract == &T::ContractAddress::get())390 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())391 }392}393394generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);395generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);396397fn error_field_too_long(feild: &str, bound: usize) -> Error {398 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))399}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use ethereum as _;21use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};22use frame_support::{traits::Get, storage::StorageNMap};23use crate::sp_api_hidden_includes_decl_storage::hidden_include::StorageDoubleMap;24use crate::Pallet;2526use pallet_common::{27 CollectionById,28 dispatch::CollectionDispatch,29 erc::{static_property::key, CollectionHelpersEvents},30 Pallet as PalletCommon,31};32use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};33use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};34use sp_std::vec;35use up_data_structs::{36 CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,37 CreateCollectionData,38};3940use crate::{41 weights::WeightInfo, Config, SelfWeightOf, NftTransferBasket, FungibleTransferBasket,42 ReFungibleTransferBasket, NftApproveBasket, FungibleApproveBasket, RefungibleApproveBasket,43};4445use alloc::format;46use sp_std::vec::Vec;4748/// See [`CollectionHelpersCall`]49pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);50impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {51 fn recorder(&self) -> &SubstrateRecorder<T> {52 &self.053 }5455 fn into_recorder(self) -> SubstrateRecorder<T> {56 self.057 }58}5960fn convert_data<T: Config>(61 caller: caller,62 name: string,63 description: string,64 token_prefix: string,65) -> Result<(66 T::CrossAccountId,67 CollectionName,68 CollectionDescription,69 CollectionTokenPrefix,70)> {71 let caller = T::CrossAccountId::from_eth(caller);72 let name = name73 .encode_utf16()74 .collect::<Vec<u16>>()75 .try_into()76 .map_err(|_| error_field_too_long(stringify!(name), CollectionName::bound()))?;77 let description = description78 .encode_utf16()79 .collect::<Vec<u16>>()80 .try_into()81 .map_err(|_| {82 error_field_too_long(stringify!(description), CollectionDescription::bound())83 })?;84 let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {85 error_field_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())86 })?;87 Ok((caller, name, description, token_prefix))88}8990#[inline(always)]91fn create_collection_internal<T: Config>(92 caller: caller,93 value: value,94 name: string,95 collection_mode: CollectionMode,96 description: string,97 token_prefix: string,98) -> Result<address> {99 let (caller, name, description, token_prefix) =100 convert_data::<T>(caller, name, description, token_prefix)?;101 let data = CreateCollectionData {102 name,103 mode: collection_mode,104 description,105 token_prefix,106 ..Default::default()107 };108 check_sent_amount_equals_collection_creation_price::<T>(value)?;109 let collection_helpers_address =110 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());111112 let collection_id = T::CollectionDispatch::create(113 caller.clone(),114 collection_helpers_address,115 data,116 Default::default(),117 )118 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;119 let address = pallet_common::eth::collection_id_to_address(collection_id);120 Ok(address)121}122123fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {124 let value = value.as_u128();125 let creation_price: u128 = T::CollectionCreationPrice::get()126 .try_into()127 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait128 .expect("Collection creation price should be convertible to u128");129 if value != creation_price {130 return Err(format!(131 "Sent amount not equals to collection creation price ({0})",132 creation_price133 )134 .into());135 }136 Ok(())137}138139/// @title Contract, which allows users to operate with collections140#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]141impl<T> EvmCollectionHelpers<T>142where143 T: Config + pallet_common::Config + pallet_nonfungible::Config + pallet_refungible::Config,144{145 /// Create an NFT collection146 /// @param name Name of the collection147 /// @param description Informative description of the collection148 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications149 /// @return address Address of the newly created collection150 #[weight(<SelfWeightOf<T>>::create_collection())]151 #[solidity(rename_selector = "createNFTCollection")]152 fn create_nft_collection(153 &mut self,154 caller: caller,155 value: value,156 name: string,157 description: string,158 token_prefix: string,159 ) -> Result<address> {160 let (caller, name, description, token_prefix) =161 convert_data::<T>(caller, name, description, token_prefix)?;162 let data = CreateCollectionData {163 name,164 mode: CollectionMode::NFT,165 description,166 token_prefix,167 ..Default::default()168 };169 check_sent_amount_equals_collection_creation_price::<T>(value)?;170 let collection_helpers_address =171 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());172 let collection_id = T::CollectionDispatch::create(173 caller,174 collection_helpers_address,175 data,176 Default::default(),177 )178 .map_err(dispatch_to_evm::<T>)?;179180 let address = pallet_common::eth::collection_id_to_address(collection_id);181 Ok(address)182 }183 /// Create an NFT collection184 /// @param name Name of the collection185 /// @param description Informative description of the collection186 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications187 /// @return address Address of the newly created collection188 #[weight(<SelfWeightOf<T>>::create_collection())]189 #[deprecated(note = "mathod was renamed to `create_nft_collection`, prefer it instead")]190 #[solidity(hide)]191 fn create_nonfungible_collection(192 &mut self,193 caller: caller,194 value: value,195 name: string,196 description: string,197 token_prefix: string,198 ) -> Result<address> {199 create_collection_internal::<T>(200 caller,201 value,202 name,203 CollectionMode::NFT,204 description,205 token_prefix,206 )207 }208209 #[weight(<SelfWeightOf<T>>::create_collection())]210 #[solidity(rename_selector = "createRFTCollection")]211 fn create_rft_collection(212 &mut self,213 caller: caller,214 value: value,215 name: string,216 description: string,217 token_prefix: string,218 ) -> Result<address> {219 create_collection_internal::<T>(220 caller,221 value,222 name,223 CollectionMode::ReFungible,224 description,225 token_prefix,226 )227 }228229 #[weight(<SelfWeightOf<T>>::create_collection())]230 #[solidity(rename_selector = "createFTCollection")]231 fn create_fungible_collection(232 &mut self,233 caller: caller,234 value: value,235 name: string,236 decimals: uint8,237 description: string,238 token_prefix: string,239 ) -> Result<address> {240 create_collection_internal::<T>(241 caller,242 value,243 name,244 CollectionMode::Fungible(decimals),245 description,246 token_prefix,247 )248 }249250 #[solidity(rename_selector = "makeCollectionERC721MetadataCompatible")]251 fn make_collection_metadata_compatible(252 &mut self,253 caller: caller,254 collection: address,255 base_uri: string,256 ) -> Result<()> {257 let caller = T::CrossAccountId::from_eth(caller);258 let collection =259 pallet_common::eth::map_eth_to_id(&collection).ok_or("not a collection address")?;260 let mut collection =261 <crate::CollectionHandle<T>>::new(collection).ok_or("collection not found")?;262263 if !matches!(264 collection.mode,265 CollectionMode::NFT | CollectionMode::ReFungible266 ) {267 return Err("target collection should be either NFT or Refungible".into());268 }269270 self.recorder().consume_sstore()?;271 collection272 .check_is_owner_or_admin(&caller)273 .map_err(dispatch_to_evm::<T>)?;274275 if collection.flags.erc721metadata {276 return Err("target collection is already Erc721Metadata compatible".into());277 }278 collection.flags.erc721metadata = true;279280 let all_permissions = <pallet_common::CollectionPropertyPermissions<T>>::get(collection.id);281 if all_permissions.get(&key::url()).is_none() {282 self.recorder().consume_sstore()?;283 <PalletCommon<T>>::set_property_permission(284 &collection,285 &caller,286 up_data_structs::PropertyKeyPermission {287 key: key::url(),288 permission: up_data_structs::PropertyPermission {289 mutable: true,290 collection_admin: true,291 token_owner: false,292 },293 },294 )295 .map_err(dispatch_to_evm::<T>)?;296 }297 if all_permissions.get(&key::suffix()).is_none() {298 self.recorder().consume_sstore()?;299 <PalletCommon<T>>::set_property_permission(300 &collection,301 &caller,302 up_data_structs::PropertyKeyPermission {303 key: key::suffix(),304 permission: up_data_structs::PropertyPermission {305 mutable: true,306 collection_admin: true,307 token_owner: false,308 },309 },310 )311 .map_err(dispatch_to_evm::<T>)?;312 }313314 let all_properties = <pallet_common::CollectionProperties<T>>::get(collection.id);315 if all_properties.get(&key::base_uri()).is_none() && !base_uri.is_empty() {316 self.recorder().consume_sstore()?;317 <PalletCommon<T>>::set_collection_properties(318 &collection,319 &caller,320 vec![up_data_structs::Property {321 key: key::base_uri(),322 value: base_uri323 .into_bytes()324 .try_into()325 .map_err(|_| "base uri is too large")?,326 }],327 )328 .map_err(dispatch_to_evm::<T>)?;329 }330331 self.recorder().consume_sstore()?;332 collection.save().map_err(dispatch_to_evm::<T>)?;333334 Ok(())335 }336337 #[weight(<SelfWeightOf<T>>::destroy_collection())]338 fn destroy_collection(&mut self, caller: caller, collection_address: address) -> Result<void> {339 let caller = T::CrossAccountId::from_eth(caller);340341 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)342 .ok_or("Invalid collection address format")?;343 <Pallet<T>>::destroy_collection_internal(caller, collection_id)344 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)345 }346347 /// Check if a collection exists348 /// @param collectionAddress Address of the collection in question349 /// @return bool Does the collection exist?350 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {351 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {352 let collection_id = id;353 return Ok(<CollectionById<T>>::contains_key(collection_id));354 }355356 Ok(false)357 }358359 fn collection_creation_fee(&self) -> Result<value> {360 let price: u128 = T::CollectionCreationPrice::get()361 .try_into()362 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait363 .expect("Collection creation price should be convertible to u128");364 Ok(price.into())365 }366}367368/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]369pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);370impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>371 for CollectionHelpersOnMethodCall<T>372{373 fn is_reserved(contract: &sp_core::H160) -> bool {374 contract == &T::ContractAddress::get()375 }376377 fn is_used(contract: &sp_core::H160) -> bool {378 contract == &T::ContractAddress::get()379 }380381 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {382 if handle.code_address() != T::ContractAddress::get() {383 return None;384 }385386 let helpers =387 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));388 pallet_evm_coder_substrate::call(handle, helpers)389 }390391 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {392 (contract == &T::ContractAddress::get())393 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())394 }395}396397generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);398generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);399400fn error_field_too_long(feild: &str, bound: usize) -> Error {401 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))402}