git.delta.rocks / unique-network / refs/commits / 61b47c80db35

difftreelog

source

pallets/common/src/erc.rs23.1 KiBsourcehistory
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//! This module contains the implementation of pallet methods for evm.1819use evm_coder::{20	solidity_interface, solidity, ToLog,21	types::*,22	execution::{Result, Error},23	weight,24};25pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};26use pallet_evm_coder_substrate::dispatch_to_evm;27use sp_std::vec::Vec;28use up_data_structs::{29	AccessMode, CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property,30	SponsoringRateLimit, SponsorshipState,31};32use alloc::format;3334use crate::{35	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,36	eth::convert_cross_account_to_uint256, weights::WeightInfo,37};3839/// Events for ethereum collection helper.40#[derive(ToLog)]41pub enum CollectionHelpersEvents {42	/// The collection has been created.43	CollectionCreated {44		/// Collection owner.45		#[indexed]46		owner: address,4748		/// Collection ID.49		#[indexed]50		collection_id: address,51	},52	/// The collection has been destroyed.53	CollectionDestroyed {54		/// Collection ID.55		#[indexed]56		collection_id: address,57	},58}5960/// Does not always represent a full collection, for RFT it is either61/// collection (Implementing ERC721), or specific collection token (Implementing ERC20).62pub trait CommonEvmHandler {63	/// Raw compiled binary code of the contract stub64	const CODE: &'static [u8];6566	/// Call precompiled handle.67	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;68}6970/// @title A contract that allows you to work with collections.71#[solidity_interface(name = Collection)]72impl<T: Config> CollectionHandle<T>73where74	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,75{76	/// Set collection property.77	///78	/// @param key Property key.79	/// @param value Propery value.80	#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]81	fn set_collection_property(82		&mut self,83		caller: caller,84		key: string,85		value: bytes,86	) -> Result<void> {87		let caller = T::CrossAccountId::from_eth(caller);88		let key = <Vec<u8>>::from(key)89			.try_into()90			.map_err(|_| "key too large")?;91		let value = value.0.try_into().map_err(|_| "value too large")?;9293		<Pallet<T>>::set_collection_property(self, &caller, Property { key, value })94			.map_err(dispatch_to_evm::<T>)95	}9697	/// Set collection properties.98	///99	/// @param properties Vector of properties key/value pair.100	#[weight(<SelfWeightOf<T>>::set_collection_properties(properties.len() as u32))]101	fn set_collection_properties(102		&mut self,103		caller: caller,104		properties: Vec<(string, bytes)>,105	) -> Result<void> {106		let caller = T::CrossAccountId::from_eth(caller);107108		let properties = properties109			.into_iter()110			.map(|(key, value)| {111				let key = <Vec<u8>>::from(key)112					.try_into()113					.map_err(|_| "key too large")?;114115				let value = value.0.try_into().map_err(|_| "value too large")?;116117				Ok(Property { key, value })118			})119			.collect::<Result<Vec<_>>>()?;120121		<Pallet<T>>::set_collection_properties(self, &caller, properties)122			.map_err(dispatch_to_evm::<T>)123	}124125	/// Delete collection property.126	///127	/// @param key Property key.128	#[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]129	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {130		let caller = T::CrossAccountId::from_eth(caller);131		let key = <Vec<u8>>::from(key)132			.try_into()133			.map_err(|_| "key too large")?;134135		<Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)136	}137138	/// Delete collection properties.139	///140	/// @param keys Properties keys.141	#[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]142	fn delete_collection_properties(&mut self, caller: caller, keys: Vec<string>) -> Result<()> {143		let caller = T::CrossAccountId::from_eth(caller);144		let keys = keys145			.into_iter()146			.map(|key| {147				<Vec<u8>>::from(key)148					.try_into()149					.map_err(|_| Error::Revert("key too large".into()))150			})151			.collect::<Result<Vec<_>>>()?;152153		<Pallet<T>>::delete_collection_properties(self, &caller, keys).map_err(dispatch_to_evm::<T>)154	}155156	/// Get collection property.157	///158	/// @dev Throws error if key not found.159	///160	/// @param key Property key.161	/// @return bytes The property corresponding to the key.162	fn collection_property(&self, key: string) -> Result<bytes> {163		let key = <Vec<u8>>::from(key)164			.try_into()165			.map_err(|_| "key too large")?;166167		let props = CollectionProperties::<T>::get(self.id);168		let prop = props.get(&key).ok_or("key not found")?;169170		Ok(bytes(prop.to_vec()))171	}172173	/// Get collection properties.174	///175	/// @param keys Properties keys. Empty keys for all propertyes.176	/// @return Vector of properties key/value pairs.177	fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<(string, bytes)>> {178		let keys = keys179			.into_iter()180			.map(|key| {181				<Vec<u8>>::from(key)182					.try_into()183					.map_err(|_| Error::Revert("key too large".into()))184			})185			.collect::<Result<Vec<_>>>()?;186187		let properties = Pallet::<T>::filter_collection_properties(188			self.id,189			if keys.is_empty() { None } else { Some(keys) },190		)191		.map_err(dispatch_to_evm::<T>)?;192193		let properties = properties194			.into_iter()195			.map(|p| {196				let key =197					string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;198				let value = bytes(p.value.to_vec());199				Ok((key, value))200			})201			.collect::<Result<Vec<_>>>()?;202		Ok(properties)203	}204205	/// Set the sponsor of the collection.206	///207	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.208	///209	/// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.210	fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {211		self.consume_store_reads_and_writes(1, 1)?;212213		check_is_owner_or_admin(caller, self)?;214215		let sponsor = T::CrossAccountId::from_eth(sponsor);216		self.set_sponsor(sponsor.as_sub().clone())217			.map_err(dispatch_to_evm::<T>)?;218		save(self)219	}220221	/// Set the sponsor of the collection.222	///223	/// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.224	///225	/// @param sponsor Cross account address of the sponsor from whose account funds will be debited for operations with the contract.226	fn set_collection_sponsor_cross(227		&mut self,228		caller: caller,229		sponsor: EthCrossAccount,230	) -> Result<void> {231		self.consume_store_reads_and_writes(1, 1)?;232233		check_is_owner_or_admin(caller, self)?;234235		let sponsor = sponsor.into_sub_cross_account::<T>()?;236		self.set_sponsor(sponsor.as_sub().clone())237			.map_err(dispatch_to_evm::<T>)?;238		save(self)239	}240241	/// Whether there is a pending sponsor.242	fn has_collection_pending_sponsor(&self) -> Result<bool> {243		Ok(matches!(244			self.collection.sponsorship,245			SponsorshipState::Unconfirmed(_)246		))247	}248249	/// Collection sponsorship confirmation.250	///251	/// @dev After setting the sponsor for the collection, it must be confirmed with this function.252	fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {253		self.consume_store_writes(1)?;254255		let caller = T::CrossAccountId::from_eth(caller);256		if !self257			.confirm_sponsorship(caller.as_sub())258			.map_err(dispatch_to_evm::<T>)?259		{260			return Err("caller is not set as sponsor".into());261		}262		save(self)263	}264265	/// Remove collection sponsor.266	fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {267		self.consume_store_reads_and_writes(1, 1)?;268		check_is_owner_or_admin(caller, self)?;269		self.remove_sponsor().map_err(dispatch_to_evm::<T>)?;270		save(self)271	}272273	/// Get current sponsor.274	///275	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.276	fn collection_sponsor(&self) -> Result<(address, uint256)> {277		let sponsor = match self.collection.sponsorship.sponsor() {278			Some(sponsor) => sponsor,279			None => return Ok(Default::default()),280		};281		let sponsor = T::CrossAccountId::from_sub(sponsor.clone());282		let result: (address, uint256) = if sponsor.is_canonical_substrate() {283			let sponsor = convert_cross_account_to_uint256::<T>(&sponsor);284			(Default::default(), sponsor)285		} else {286			let sponsor = *sponsor.as_eth();287			(sponsor, Default::default())288		};289		Ok(result)290	}291292	/// Set limits for the collection.293	/// @dev Throws error if limit not found.294	/// @param limit Name of the limit. Valid names:295	/// 	"accountTokenOwnershipLimit",296	/// 	"sponsoredDataSize",297	/// 	"sponsoredDataRateLimit",298	/// 	"tokenLimit",299	/// 	"sponsorTransferTimeout",300	/// 	"sponsorApproveTimeout"301	/// @param value Value of the limit.302	#[solidity(rename_selector = "setCollectionLimit")]303	fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {304		self.consume_store_reads_and_writes(1, 1)?;305306		check_is_owner_or_admin(caller, self)?;307		let mut limits = self.limits.clone();308309		match limit.as_str() {310			"accountTokenOwnershipLimit" => {311				limits.account_token_ownership_limit = Some(value);312			}313			"sponsoredDataSize" => {314				limits.sponsored_data_size = Some(value);315			}316			"sponsoredDataRateLimit" => {317				limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));318			}319			"tokenLimit" => {320				limits.token_limit = Some(value);321			}322			"sponsorTransferTimeout" => {323				limits.sponsor_transfer_timeout = Some(value);324			}325			"sponsorApproveTimeout" => {326				limits.sponsor_approve_timeout = Some(value);327			}328			_ => {329				return Err(Error::Revert(format!(330					"unknown integer limit \"{}\"",331					limit332				)))333			}334		}335		self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)336			.map_err(dispatch_to_evm::<T>)?;337		save(self)338	}339340	/// Set limits for the collection.341	/// @dev Throws error if limit not found.342	/// @param limit Name of the limit. Valid names:343	/// 	"ownerCanTransfer",344	/// 	"ownerCanDestroy",345	/// 	"transfersEnabled"346	/// @param value Value of the limit.347	#[solidity(rename_selector = "setCollectionLimit")]348	fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {349		self.consume_store_reads_and_writes(1, 1)?;350351		check_is_owner_or_admin(caller, self)?;352		let mut limits = self.limits.clone();353354		match limit.as_str() {355			"ownerCanTransfer" => {356				limits.owner_can_transfer = Some(value);357			}358			"ownerCanDestroy" => {359				limits.owner_can_destroy = Some(value);360			}361			"transfersEnabled" => {362				limits.transfers_enabled = Some(value);363			}364			_ => {365				return Err(Error::Revert(format!(366					"unknown boolean limit \"{}\"",367					limit368				)))369			}370		}371		self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)372			.map_err(dispatch_to_evm::<T>)?;373		save(self)374	}375376	/// Get contract address.377	fn contract_address(&self) -> Result<address> {378		Ok(crate::eth::collection_id_to_address(self.id))379	}380381	/// Add collection admin.382	/// @param newAdmin Cross account administrator address.383	fn add_collection_admin_cross(384		&mut self,385		caller: caller,386		new_admin: EthCrossAccount,387	) -> Result<void> {388		self.consume_store_writes(2)?;389390		let caller = T::CrossAccountId::from_eth(caller);391		let new_admin = new_admin.into_sub_cross_account::<T>()?;392		<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;393		Ok(())394	}395396	/// Remove collection admin.397	/// @param admin Cross account administrator address.398	fn remove_collection_admin_cross(399		&mut self,400		caller: caller,401		admin: EthCrossAccount,402	) -> Result<void> {403		self.consume_store_writes(2)?;404405		let caller = T::CrossAccountId::from_eth(caller);406		let admin = admin.into_sub_cross_account::<T>()?;407		<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;408		Ok(())409	}410411	/// Add collection admin.412	/// @param newAdmin Address of the added administrator.413	fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {414		self.consume_store_writes(2)?;415416		let caller = T::CrossAccountId::from_eth(caller);417		let new_admin = T::CrossAccountId::from_eth(new_admin);418		<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;419		Ok(())420	}421422	/// Remove collection admin.423	///424	/// @param admin Address of the removed administrator.425	fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {426		self.consume_store_writes(2)?;427428		let caller = T::CrossAccountId::from_eth(caller);429		let admin = T::CrossAccountId::from_eth(admin);430		<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;431		Ok(())432	}433434	/// Toggle accessibility of collection nesting.435	///436	/// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'437	#[solidity(rename_selector = "setCollectionNesting")]438	fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {439		self.consume_store_reads_and_writes(1, 1)?;440441		check_is_owner_or_admin(caller, self)?;442443		let mut permissions = self.collection.permissions.clone();444		let mut nesting = permissions.nesting().clone();445		nesting.token_owner = enable;446		nesting.restricted = None;447		permissions.nesting = Some(nesting);448449		self.collection.permissions = <Pallet<T>>::clamp_permissions(450			self.collection.mode.clone(),451			&self.collection.permissions,452			permissions,453		)454		.map_err(dispatch_to_evm::<T>)?;455456		save(self)457	}458459	/// Toggle accessibility of collection nesting.460	///461	/// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'462	/// @param collections Addresses of collections that will be available for nesting.463	#[solidity(rename_selector = "setCollectionNesting")]464	fn set_nesting(465		&mut self,466		caller: caller,467		enable: bool,468		collections: Vec<address>,469	) -> Result<void> {470		self.consume_store_reads_and_writes(1, 1)?;471472		if collections.is_empty() {473			return Err("no addresses provided".into());474		}475		check_is_owner_or_admin(caller, self)?;476477		let mut permissions = self.collection.permissions.clone();478		match enable {479			false => {480				let mut nesting = permissions.nesting().clone();481				nesting.token_owner = false;482				nesting.restricted = None;483				permissions.nesting = Some(nesting);484			}485			true => {486				let mut bv = OwnerRestrictedSet::new();487				for i in collections {488					bv.try_insert(crate::eth::map_eth_to_id(&i).ok_or_else(|| {489						Error::Revert("Can't convert address into collection id".into())490					})?)491					.map_err(|_| "too many collections")?;492				}493				let mut nesting = permissions.nesting().clone();494				nesting.token_owner = true;495				nesting.restricted = Some(bv);496				permissions.nesting = Some(nesting);497			}498		};499500		self.collection.permissions = <Pallet<T>>::clamp_permissions(501			self.collection.mode.clone(),502			&self.collection.permissions,503			permissions,504		)505		.map_err(dispatch_to_evm::<T>)?;506507		save(self)508	}509510	/// Set the collection access method.511	/// @param mode Access mode512	/// 	0 for Normal513	/// 	1 for AllowList514	fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {515		self.consume_store_reads_and_writes(1, 1)?;516517		check_is_owner_or_admin(caller, self)?;518		let permissions = CollectionPermissions {519			access: Some(match mode {520				0 => AccessMode::Normal,521				1 => AccessMode::AllowList,522				_ => return Err("not supported access mode".into()),523			}),524			..Default::default()525		};526		self.collection.permissions = <Pallet<T>>::clamp_permissions(527			self.collection.mode.clone(),528			&self.collection.permissions,529			permissions,530		)531		.map_err(dispatch_to_evm::<T>)?;532533		save(self)534	}535536	/// Checks that user allowed to operate with collection.537	///538	/// @param user User address to check.539	fn allowed(&self, user: address) -> Result<bool> {540		Ok(Pallet::<T>::allowed(541			self.id,542			T::CrossAccountId::from_eth(user),543		))544	}545546	/// Add the user to the allowed list.547	///548	/// @param user Address of a trusted user.549	fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {550		self.consume_store_writes(1)?;551552		let caller = T::CrossAccountId::from_eth(caller);553		let user = T::CrossAccountId::from_eth(user);554		<Pallet<T>>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;555		Ok(())556	}557558	/// Add user to allowed list.559	///560	/// @param user User cross account address.561	fn add_to_collection_allow_list_cross(562		&mut self,563		caller: caller,564		user: EthCrossAccount,565	) -> Result<void> {566		self.consume_store_writes(1)?;567568		let caller = T::CrossAccountId::from_eth(caller);569		let user = user.into_sub_cross_account::<T>()?;570		Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;571		Ok(())572	}573574	/// Remove the user from the allowed list.575	///576	/// @param user Address of a removed user.577	fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {578		self.consume_store_writes(1)?;579580		let caller = T::CrossAccountId::from_eth(caller);581		let user = T::CrossAccountId::from_eth(user);582		<Pallet<T>>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;583		Ok(())584	}585586	/// Remove user from allowed list.587	///588	/// @param user User cross account address.589	fn remove_from_collection_allow_list_cross(590		&mut self,591		caller: caller,592		user: EthCrossAccount,593	) -> Result<void> {594		self.consume_store_writes(1)?;595596		let caller = T::CrossAccountId::from_eth(caller);597		let user = user.into_sub_cross_account::<T>()?;598		Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;599		Ok(())600	}601602	/// Switch permission for minting.603	///604	/// @param mode Enable if "true".605	fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {606		self.consume_store_reads_and_writes(1, 1)?;607608		check_is_owner_or_admin(caller, self)?;609		let permissions = CollectionPermissions {610			mint_mode: Some(mode),611			..Default::default()612		};613		self.collection.permissions = <Pallet<T>>::clamp_permissions(614			self.collection.mode.clone(),615			&self.collection.permissions,616			permissions,617		)618		.map_err(dispatch_to_evm::<T>)?;619620		save(self)621	}622623	/// Check that account is the owner or admin of the collection624	///625	/// @param user account to verify626	/// @return "true" if account is the owner or admin627	#[solidity(rename_selector = "isOwnerOrAdmin")]628	fn is_owner_or_admin_eth(&self, user: address) -> Result<bool> {629		let user = T::CrossAccountId::from_eth(user);630		Ok(self.is_owner_or_admin(&user))631	}632633	/// Check that account is the owner or admin of the collection634	///635	/// @param user User cross account to verify636	/// @return "true" if account is the owner or admin637	fn is_owner_or_admin_cross(&self, user: EthCrossAccount) -> Result<bool> {638		let user = user.into_sub_cross_account::<T>()?;639		Ok(self.is_owner_or_admin(&user))640	}641642	/// Returns collection type643	///644	/// @return `Fungible` or `NFT` or `ReFungible`645	fn unique_collection_type(&self) -> Result<string> {646		let mode = match self.collection.mode {647			CollectionMode::Fungible(_) => "Fungible",648			CollectionMode::NFT => "NFT",649			CollectionMode::ReFungible => "ReFungible",650		};651		Ok(mode.into())652	}653654	/// Get collection owner.655	///656	/// @return Tuble with sponsor address and his substrate mirror.657	/// If address is canonical then substrate mirror is zero and vice versa.658	fn collection_owner(&self) -> Result<EthCrossAccount> {659		Ok(EthCrossAccount::from_sub_cross_account::<T>(660			&T::CrossAccountId::from_sub(self.owner.clone()),661		))662	}663664	/// Changes collection owner to another account665	///666	/// @dev Owner can be changed only by current owner667	/// @param newOwner new owner account668	#[solidity(rename_selector = "changeCollectionOwner")]669	fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {670		self.consume_store_writes(1)?;671672		let caller = T::CrossAccountId::from_eth(caller);673		let new_owner = T::CrossAccountId::from_eth(new_owner);674		self.set_owner_internal(caller, new_owner)675			.map_err(dispatch_to_evm::<T>)676	}677678	/// Get collection administrators679	///680	/// @return Vector of tuples with admins address and his substrate mirror.681	/// If address is canonical then substrate mirror is zero and vice versa.682	fn collection_admins(&self) -> Result<Vec<EthCrossAccount>> {683		let result = crate::IsAdmin::<T>::iter_prefix((self.id,))684			.map(|(admin, _)| EthCrossAccount::from_sub_cross_account::<T>(&admin))685			.collect();686		Ok(result)687	}688689	/// Changes collection owner to another account690	///691	/// @dev Owner can be changed only by current owner692	/// @param newOwner new owner cross account693	fn set_owner_cross(&mut self, caller: caller, new_owner: EthCrossAccount) -> Result<void> {694		self.consume_store_writes(1)?;695696		let caller = T::CrossAccountId::from_eth(caller);697		let new_owner = new_owner.into_sub_cross_account::<T>()?;698		self.set_owner_internal(caller, new_owner)699			.map_err(dispatch_to_evm::<T>)700	}701}702703/// ### Note704/// Do not forget to add: `self.consume_store_reads(1)?;`705fn check_is_owner_or_admin<T: Config>(706	caller: caller,707	collection: &CollectionHandle<T>,708) -> Result<T::CrossAccountId> {709	let caller = T::CrossAccountId::from_eth(caller);710	collection711		.check_is_owner_or_admin(&caller)712		.map_err(dispatch_to_evm::<T>)?;713	Ok(caller)714}715716/// ### Note717/// Do not forget to add: `self.consume_store_writes(1)?;`718fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {719	collection720		.check_is_internal()721		.map_err(dispatch_to_evm::<T>)?;722	collection.save().map_err(dispatch_to_evm::<T>)?;723	Ok(())724}725726/// Contains static property keys and values.727pub mod static_property {728	use evm_coder::{729		execution::{Result, Error},730	};731	use alloc::format;732733	const EXPECT_CONVERT_ERROR: &str = "length < limit";734735	/// Keys.736	pub mod key {737		use super::*;738739		/// Key "baseURI".740		pub fn base_uri() -> up_data_structs::PropertyKey {741			property_key_from_bytes(b"baseURI").expect(EXPECT_CONVERT_ERROR)742		}743744		/// Key "url".745		pub fn url() -> up_data_structs::PropertyKey {746			property_key_from_bytes(b"URI").expect(EXPECT_CONVERT_ERROR)747		}748749		/// Key "suffix".750		pub fn suffix() -> up_data_structs::PropertyKey {751			property_key_from_bytes(b"URISuffix").expect(EXPECT_CONVERT_ERROR)752		}753754		/// Key "parentNft".755		pub fn parent_nft() -> up_data_structs::PropertyKey {756			property_key_from_bytes(b"parentNft").expect(EXPECT_CONVERT_ERROR)757		}758	}759760	/// Convert `byte` to [`PropertyKey`].761	pub fn property_key_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyKey> {762		bytes.to_vec().try_into().map_err(|_| {763			Error::Revert(format!(764				"Property key is too long. Max length is {}.",765				up_data_structs::PropertyKey::bound()766			))767		})768	}769770	/// Convert `bytes` to [`PropertyValue`].771	pub fn property_value_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyValue> {772		bytes.to_vec().try_into().map_err(|_| {773			Error::Revert(format!(774				"Property key is too long. Max length is {}.",775				up_data_structs::PropertyKey::bound()776			))777		})778	}779}