git.delta.rocks / unique-network / refs/commits / 7d542e4157ec

difftreelog

refac: rename string -> String

Trubnikov Sergey2023-01-18parent: #a4ecd38.patch.diff
in: master

16 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -999,7 +999,7 @@
 						)*),
 					};
 
-					let mut out = ::evm_coder::types::string::new();
+					let mut out = ::evm_coder::types::String::new();
 					if #solidity_name.starts_with("Inline") {
 						out.push_str("/// @dev inlined interface\n");
 					}
modifiedcrates/evm-coder/procedural/src/to_log.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/to_log.rs
+++ b/crates/evm-coder/procedural/src/to_log.rs
@@ -222,7 +222,7 @@
 							#solidity_functions,
 						)*),
 					};
-					let mut out = string::new();
+					let mut out = ::evm_coder::types::String::new();
 					out.push_str("/// @dev inlined interface\n");
 					let _ = interface.format(is_impl, &mut out, tc);
 					tc.collect(out);
modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -63,7 +63,7 @@
 impl_abi!(u128, uint128, false);
 impl_abi!(U256, uint256, false);
 impl_abi!(H160, address, false);
-impl_abi!(string, string, true);
+impl_abi!(String, string, true);
 
 impl_abi_writeable!(&str, string);
 
modifiedcrates/evm-coder/src/abi/mod.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/mod.rs
+++ b/crates/evm-coder/src/abi/mod.rs
@@ -148,8 +148,8 @@
 	}
 
 	/// Read [`string`] at current position, then advance
-	pub fn string(&mut self) -> Result<string> {
-		string::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))
+	pub fn string(&mut self) -> Result<String> {
+		String::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))
 	}
 
 	/// Read [`u8`] at current position, then advance
modifiedcrates/evm-coder/src/abi/test.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/test.rs
+++ b/crates/evm-coder/src/abi/test.rs
@@ -138,7 +138,7 @@
 
 #[test]
 fn encode_decode_vec_tuple_uint256_string() {
-	test_impl::<Vec<(U256, string)>>(
+	test_impl::<Vec<(U256, String)>>(
         0xdeadbeef,
         vec![
             (1.into(), "Test URI 0".to_string()),
@@ -261,7 +261,7 @@
 	let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();
 	assert_eq!(call, u32::to_be_bytes(decoded_data.0));
 	let address = decoder.address().unwrap();
-	let data = <Vec<(U256, string)>>::abi_read(&mut decoder).unwrap();
+	let data = <Vec<(U256, String)>>::abi_read(&mut decoder).unwrap();
 	assert_eq!(data, decoded_data.1);
 
 	let mut writer = AbiWriter::new_call(decoded_data.0);
@@ -273,7 +273,7 @@
 
 #[test]
 fn encode_decode_vec_tuple_string_bytes() {
-	test_impl::<Vec<(string, bytes)>>(
+	test_impl::<Vec<(String, bytes)>>(
 		0xdeadbeef,
 		vec![
 			(
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -136,9 +136,9 @@
 	pub type Topic = H256;
 
 	#[cfg(not(feature = "std"))]
-	pub type string = ::alloc::string::String;
+	pub type String = ::alloc::string::String;
 	#[cfg(feature = "std")]
-	pub type string = ::std::string::String;
+	pub type String = ::std::string::String;
 
 	#[derive(Default, Debug, PartialEq, Eq, Clone)]
 	pub struct bytes(pub Vec<u8>);
modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity/impls.rs
+++ b/crates/evm-coder/src/solidity/impls.rs
@@ -29,7 +29,7 @@
 	U256 => "uint256" true = "0",
 	Bytes4 => "bytes4" true = "bytes4(0)",
 	H160 => "address" true = "0x0000000000000000000000000000000000000000",
-	string => "string" false = "\"\"",
+	String => "string" false = "\"\"",
 	bytes => "bytes" false = "hex\"\"",
 	bool => "bool" true = "false",
 }
@@ -72,10 +72,10 @@
 macro_rules! impl_tuples {
 	($($ident:ident)+) => {
 		impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {
-			fn fields(tc: &TypeCollector) -> Vec<string> {
+			fn fields(tc: &TypeCollector) -> Vec<String> {
 				let mut collected = Vec::with_capacity(Self::len());
 				$({
-					let mut out = string::new();
+					let mut out = String::new();
 					$ident::solidity_name(&mut out, tc).expect("no fmt error");
 					collected.push(out);
 				})*;
modifiedcrates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity/mod.rs
+++ b/crates/evm-coder/src/solidity/mod.rs
@@ -26,7 +26,7 @@
 mod impls;
 
 #[cfg(not(feature = "std"))]
-use alloc::{string::String, vec::Vec, collections::BTreeMap, format};
+use alloc::{vec::Vec, collections::BTreeMap, format};
 #[cfg(feature = "std")]
 use std::collections::BTreeMap;
 use core::{
@@ -42,16 +42,16 @@
 pub struct TypeCollector {
 	/// Code => id
 	/// id ordering is required to perform topo-sort on the resulting data
-	structs: RefCell<BTreeMap<string, usize>>,
-	anonymous: RefCell<BTreeMap<Vec<string>, usize>>,
-	// generic: RefCell<BTreeMap<string, usize>>,
+	structs: RefCell<BTreeMap<String, usize>>,
+	anonymous: RefCell<BTreeMap<Vec<String>, usize>>,
+	// generic: RefCell<BTreeMap<String, usize>>,
 	id: Cell<usize>,
 }
 impl TypeCollector {
 	pub fn new() -> Self {
 		Self::default()
 	}
-	pub fn collect(&self, item: string) {
+	pub fn collect(&self, item: String) {
 		let id = self.next_id();
 		self.structs.borrow_mut().insert(item, id);
 	}
@@ -84,7 +84,7 @@
 	pub fn collect_enum<T: SolidityEnumTy>(&self) -> String {
 		T::generate_solidity_interface(self)
 	}
-	pub fn finish(self) -> Vec<string> {
+	pub fn finish(self) -> Vec<String> {
 		let mut data = self.structs.into_inner().into_iter().collect::<Vec<_>>();
 		data.sort_by_key(|(_, id)| Reverse(*id));
 		data.into_iter().map(|(code, _)| code).collect()
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -94,7 +94,7 @@
 	/// @param value Propery value.
 	#[solidity(hide)]
 	#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
-	fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
+	fn set_collection_property(&mut self, caller: caller, key: String, value: bytes) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let key = <Vec<u8>>::from(key)
 			.try_into()
@@ -130,7 +130,7 @@
 	/// @param key Property key.
 	#[solidity(hide)]
 	#[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
-	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {
+	fn delete_collection_property(&mut self, caller: caller, key: String) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let key = <Vec<u8>>::from(key)
 			.try_into()
@@ -143,7 +143,7 @@
 	///
 	/// @param keys Properties keys.
 	#[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
-	fn delete_collection_properties(&mut self, caller: caller, keys: Vec<string>) -> Result<()> {
+	fn delete_collection_properties(&mut self, caller: caller, keys: Vec<String>) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let keys = keys
 			.into_iter()
@@ -164,7 +164,7 @@
 	///
 	/// @param key Property key.
 	/// @return bytes The property corresponding to the key.
-	fn collection_property(&self, key: string) -> Result<bytes> {
+	fn collection_property(&self, key: String) -> Result<bytes> {
 		let key = <Vec<u8>>::from(key)
 			.try_into()
 			.map_err(|_| "key too large")?;
@@ -179,7 +179,7 @@
 	///
 	/// @param keys Properties keys. Empty keys for all propertyes.
 	/// @return Vector of properties key/value pairs.
-	fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<eth::Property>> {
+	fn collection_properties(&self, keys: Vec<String>) -> Result<Vec<eth::Property>> {
 		let keys = keys
 			.into_iter()
 			.map(|key| {
@@ -616,7 +616,7 @@
 	/// Returns collection type
 	///
 	/// @return `Fungible` or `NFT` or `ReFungible`
-	fn unique_collection_type(&self) -> Result<string> {
+	fn unique_collection_type(&self) -> Result<String> {
 		let mode = match self.collection.mode {
 			CollectionMode::Fungible(_) => "Fungible",
 			CollectionMode::NFT => "NFT",
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -118,7 +118,7 @@
 /// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 #[derive(Debug, Default, AbiCoder)]
 pub struct Property {
-	key: evm_coder::types::string,
+	key: evm_coder::types::String,
 	value: evm_coder::types::bytes,
 }
 
@@ -126,7 +126,7 @@
 	type Error = evm_coder::execution::Error;
 
 	fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {
-		let key = evm_coder::types::string::from_utf8(from.key.into())
+		let key = evm_coder::types::String::from_utf8(from.key.into())
 			.map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;
 		let value = evm_coder::types::bytes(from.value.to_vec());
 		Ok(Property { key, value })
@@ -342,7 +342,7 @@
 #[derive(Debug, Default, AbiCoder)]
 pub struct TokenPropertyPermission {
 	/// Token property key.
-	key: evm_coder::types::string,
+	key: evm_coder::types::String,
 	/// Token property permissions.
 	permissions: Vec<PropertyPermission>,
 }
@@ -360,7 +360,7 @@
 		),
 	) -> Self {
 		let (key, permission) = value;
-		let key = evm_coder::types::string::from_utf8(key.into_inner())
+		let key = evm_coder::types::String::from_utf8(key.into_inner())
 			.expect("Stored key must be valid");
 		let permissions = PropertyPermission::into_vec(permission);
 		Self { key, permissions }
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -59,13 +59,13 @@
 
 #[solidity_interface(name = ERC20, events(ERC20Events))]
 impl<T: Config> FungibleHandle<T> {
-	fn name(&self) -> Result<string> {
+	fn name(&self) -> Result<String> {
 		Ok(decode_utf16(self.name.iter().copied())
 			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
-			.collect::<string>())
+			.collect::<String>())
 	}
-	fn symbol(&self) -> Result<string> {
-		Ok(string::from_utf8_lossy(&self.token_prefix).into())
+	fn symbol(&self) -> Result<String> {
+		Ok(String::from_utf8_lossy(&self.token_prefix).into())
 	}
 	fn total_supply(&self) -> Result<U256> {
 		self.consume_store_reads(1)?;
@@ -167,10 +167,10 @@
 	T::AccountId: From<[u8; 32]>,
 {
 	/// @notice A description for the collection.
-	fn description(&self) -> Result<string> {
+	fn description(&self) -> Result<String> {
 		Ok(decode_utf16(self.description.iter().copied())
 			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
-			.collect::<string>())
+			.collect::<String>())
 	}
 
 	#[weight(<SelfWeightOf<T>>::create_item())]
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -64,7 +64,7 @@
 	fn set_token_property_permission(
 		&mut self,
 		caller: caller,
-		key: string,
+		key: String,
 		is_mutable: bool,
 		collection_admin: bool,
 		token_owner: bool,
@@ -123,7 +123,7 @@
 		&mut self,
 		caller: caller,
 		token_id: U256,
-		key: string,
+		key: String,
 		value: bytes,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -187,7 +187,7 @@
 	/// @param key Property key.
 	#[solidity(hide)]
 	#[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
-	fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {
+	fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 		let key = <Vec<u8>>::from(key)
@@ -211,7 +211,7 @@
 		&mut self,
 		token_id: U256,
 		caller: caller,
-		keys: Vec<string>,
+		keys: Vec<String>,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -239,7 +239,7 @@
 	/// @param tokenId ID of the token.
 	/// @param key Property key.
 	/// @return Property value bytes
-	fn property(&self, token_id: U256, key: string) -> Result<bytes> {
+	fn property(&self, token_id: U256, key: String) -> Result<bytes> {
 		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 		let key = <Vec<u8>>::from(key)
 			.try_into()
@@ -301,14 +301,14 @@
 	/// @notice A descriptive name for a collection of NFTs in this contract
 	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
 	#[solidity(hide, rename_selector = "name")]
-	fn name_proxy(&self) -> Result<string> {
+	fn name_proxy(&self) -> Result<String> {
 		self.name()
 	}
 
 	/// @notice An abbreviated name for NFTs in this contract
 	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
 	#[solidity(hide, rename_selector = "symbol")]
-	fn symbol_proxy(&self) -> Result<string> {
+	fn symbol_proxy(&self) -> Result<String> {
 		self.symbol()
 	}
 
@@ -322,7 +322,7 @@
 	///
 	/// @return token's const_metadata
 	#[solidity(rename_selector = "tokenURI")]
-	fn token_uri(&self, token_id: U256) -> Result<string> {
+	fn token_uri(&self, token_id: U256) -> Result<String> {
 		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 
 		match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -335,7 +335,7 @@
 		let base_uri =
 			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
 				.map(BoundedVec::into_inner)
-				.map(string::from_utf8)
+				.map(String::from_utf8)
 				.transpose()
 				.map_err(|e| {
 					Error::Revert(alloc::format!(
@@ -595,7 +595,7 @@
 		&mut self,
 		caller: caller,
 		to: Address,
-		token_uri: string,
+		token_uri: String,
 	) -> Result<U256> {
 		let token_id: U256 = <TokensMinted<T>>::get(self.id)
 			.checked_add(1)
@@ -618,7 +618,7 @@
 		caller: caller,
 		to: Address,
 		token_id: U256,
-		token_uri: string,
+		token_uri: String,
 	) -> Result<bool> {
 		let key = key::url();
 		let permission = get_token_permission::<T>(self.id, &key)?;
@@ -670,12 +670,12 @@
 	collection: &CollectionHandle<T>,
 	token_id: u32,
 	key: &up_data_structs::PropertyKey,
-) -> Result<string> {
+) -> Result<String> {
 	collection.consume_store_reads(1)?;
 	let properties = <TokenProperties<T>>::try_get((collection.id, token_id))
 		.map_err(|_| Error::Revert("Token properties not found".into()))?;
 	if let Some(property) = properties.get(key) {
-		return Ok(string::from_utf8_lossy(property).into());
+		return Ok(String::from_utf8_lossy(property).into());
 	}
 
 	Err("Property tokenURI not found".into())
@@ -691,7 +691,7 @@
 		.get(key)
 		.map(Clone::clone)
 		.ok_or_else(|| {
-			let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();
+			let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();
 			Error::Revert(alloc::format!("No permission for key {}", key))
 		})?;
 	Ok(a)
@@ -704,22 +704,22 @@
 	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
 {
 	/// @notice A descriptive name for a collection of NFTs in this contract
-	fn name(&self) -> Result<string> {
+	fn name(&self) -> Result<String> {
 		Ok(decode_utf16(self.name.iter().copied())
 			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
-			.collect::<string>())
+			.collect::<String>())
 	}
 
 	/// @notice An abbreviated name for NFTs in this contract
-	fn symbol(&self) -> Result<string> {
-		Ok(string::from_utf8_lossy(&self.token_prefix).into())
+	fn symbol(&self) -> Result<String> {
+		Ok(String::from_utf8_lossy(&self.token_prefix).into())
 	}
 
 	/// @notice A description for the collection.
-	fn description(&self) -> Result<string> {
+	fn description(&self) -> Result<String> {
 		Ok(decode_utf16(self.description.iter().copied())
 			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
-			.collect::<string>())
+			.collect::<String>())
 	}
 
 	/// Returns the owner (in cross format) of the token.
@@ -736,7 +736,7 @@
 	/// @param tokenId Id for the token.
 	/// @param keys Properties keys. Empty keys for all propertyes.
 	/// @return Vector of properties key/value pairs.
-	fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
+	fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {
 		let keys = keys
 			.into_iter()
 			.map(|key| {
@@ -948,7 +948,7 @@
 		&mut self,
 		caller: caller,
 		to: Address,
-		tokens: Vec<(U256, string)>,
+		tokens: Vec<(U256, String)>,
 	) -> Result<bool> {
 		let key = key::url();
 		let caller = T::CrossAccountId::from_eth(caller);
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
before · pallets/refungible/src/erc.rs
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//! # Refungible Pallet EVM API for tokens18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Refungible Pallet methods.2122extern crate alloc;2324use core::{25	char::{REPLACEMENT_CHARACTER, decode_utf16},26	convert::TryInto,27};28use evm_coder::{29	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30	weight,31};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{34	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35	Error as CommonError,36	erc::{CommonEvmHandler, CollectionCall, static_property::key},37	eth,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};42use sp_core::{H160, U256, Get};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};44use up_data_structs::{45	CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,46	PropertyKeyPermission, PropertyPermission, TokenId,47};4849use crate::{50	AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,51	TokenProperties, TokensMinted, TotalSupply, weights::WeightInfo,52};5354pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);5556/// @title A contract that allows to set and delete token properties and change token property permissions.57#[solidity_interface(name = TokenProperties)]58impl<T: Config> RefungibleHandle<T> {59	/// @notice Set permissions for token property.60	/// @dev Throws error if `msg.sender` is not admin or owner of the collection.61	/// @param key Property key.62	/// @param isMutable Permission to mutate property.63	/// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.64	/// @param tokenOwner Permission to mutate property by token owner if property is mutable.65	#[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]66	#[solidity(hide)]67	fn set_token_property_permission(68		&mut self,69		caller: caller,70		key: string,71		is_mutable: bool,72		collection_admin: bool,73		token_owner: bool,74	) -> Result<()> {75		let caller = T::CrossAccountId::from_eth(caller);76		<Pallet<T>>::set_token_property_permissions(77			self,78			&caller,79			vec![PropertyKeyPermission {80				key: <Vec<u8>>::from(key)81					.try_into()82					.map_err(|_| "too long key")?,83				permission: PropertyPermission {84					mutable: is_mutable,85					collection_admin,86					token_owner,87				},88			}],89		)90		.map_err(dispatch_to_evm::<T>)91	}9293	/// @notice Set permissions for token property.94	/// @dev Throws error if `msg.sender` is not admin or owner of the collection.95	/// @param permissions Permissions for keys.96	#[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]97	fn set_token_property_permissions(98		&mut self,99		caller: caller,100		permissions: Vec<eth::TokenPropertyPermission>,101	) -> Result<()> {102		let caller = T::CrossAccountId::from_eth(caller);103		let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;104105		<Pallet<T>>::set_token_property_permissions(self, &caller, perms)106			.map_err(dispatch_to_evm::<T>)107	}108109	/// @notice Get permissions for token properties.110	fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {111		let perms = <Pallet<T>>::token_property_permission(self.id);112		Ok(perms113			.into_iter()114			.map(eth::TokenPropertyPermission::from)115			.collect())116	}117118	/// @notice Set token property value.119	/// @dev Throws error if `msg.sender` has no permission to edit the property.120	/// @param tokenId ID of the token.121	/// @param key Property key.122	/// @param value Property value.123	#[solidity(hide)]124	#[weight(<SelfWeightOf<T>>::set_token_properties(1))]125	fn set_property(126		&mut self,127		caller: caller,128		token_id: U256,129		key: string,130		value: bytes,131	) -> Result<()> {132		let caller = T::CrossAccountId::from_eth(caller);133		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;134		let key = <Vec<u8>>::from(key)135			.try_into()136			.map_err(|_| "key too long")?;137		let value = value.0.try_into().map_err(|_| "value too long")?;138139		let nesting_budget = self140			.recorder141			.weight_calls_budget(<StructureWeight<T>>::find_parent());142143		<Pallet<T>>::set_token_property(144			self,145			&caller,146			TokenId(token_id),147			Property { key, value },148			&nesting_budget,149		)150		.map_err(dispatch_to_evm::<T>)151	}152153	/// @notice Set token properties value.154	/// @dev Throws error if `msg.sender` has no permission to edit the property.155	/// @param tokenId ID of the token.156	/// @param properties settable properties157	#[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]158	fn set_properties(159		&mut self,160		caller: caller,161		token_id: U256,162		properties: Vec<eth::Property>,163	) -> Result<()> {164		let caller = T::CrossAccountId::from_eth(caller);165		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;166167		let nesting_budget = self168			.recorder169			.weight_calls_budget(<StructureWeight<T>>::find_parent());170171		let properties = properties172			.into_iter()173			.map(eth::Property::try_into)174			.collect::<Result<Vec<_>>>()?;175176		<Pallet<T>>::set_token_properties(177			self,178			&caller,179			TokenId(token_id),180			properties.into_iter(),181			false,182			&nesting_budget,183		)184		.map_err(dispatch_to_evm::<T>)185	}186187	/// @notice Delete token property value.188	/// @dev Throws error if `msg.sender` has no permission to edit the property.189	/// @param tokenId ID of the token.190	/// @param key Property key.191	#[solidity(hide)]192	#[weight(<SelfWeightOf<T>>::delete_token_properties(1))]193	fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {194		let caller = T::CrossAccountId::from_eth(caller);195		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;196		let key = <Vec<u8>>::from(key)197			.try_into()198			.map_err(|_| "key too long")?;199200		let nesting_budget = self201			.recorder202			.weight_calls_budget(<StructureWeight<T>>::find_parent());203204		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)205			.map_err(dispatch_to_evm::<T>)206	}207208	/// @notice Delete token properties value.209	/// @dev Throws error if `msg.sender` has no permission to edit the property.210	/// @param tokenId ID of the token.211	/// @param keys Properties key.212	#[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]213	fn delete_properties(214		&mut self,215		token_id: U256,216		caller: caller,217		keys: Vec<string>,218	) -> Result<()> {219		let caller = T::CrossAccountId::from_eth(caller);220		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221		let keys = keys222			.into_iter()223			.map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))224			.collect::<Result<Vec<_>>>()?;225226		let nesting_budget = self227			.recorder228			.weight_calls_budget(<StructureWeight<T>>::find_parent());229230		<Pallet<T>>::delete_token_properties(231			self,232			&caller,233			TokenId(token_id),234			keys.into_iter(),235			&nesting_budget,236		)237		.map_err(dispatch_to_evm::<T>)238	}239240	/// @notice Get token property value.241	/// @dev Throws error if key not found242	/// @param tokenId ID of the token.243	/// @param key Property key.244	/// @return Property value bytes245	fn property(&self, token_id: U256, key: string) -> Result<bytes> {246		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;247		let key = <Vec<u8>>::from(key)248			.try_into()249			.map_err(|_| "key too long")?;250251		let props = <TokenProperties<T>>::get((self.id, token_id));252		let prop = props.get(&key).ok_or("key not found")?;253254		Ok(prop.to_vec().into())255	}256}257258#[derive(ToLog)]259pub enum ERC721Events {260	/// @dev This event emits when NFTs are created (`from` == 0) and destroyed261	///  (`to` == 0). Exception: during contract creation, any number of RFTs262	///  may be created and assigned without emitting Transfer.263	Transfer {264		#[indexed]265		from: Address,266		#[indexed]267		to: Address,268		#[indexed]269		token_id: U256,270	},271	/// @dev Not supported272	Approval {273		#[indexed]274		owner: Address,275		#[indexed]276		approved: Address,277		#[indexed]278		token_id: U256,279	},280	/// @dev Not supported281	#[allow(dead_code)]282	ApprovalForAll {283		#[indexed]284		owner: Address,285		#[indexed]286		operator: Address,287		approved: bool,288	},289}290291/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension292/// @dev See https://eips.ethereum.org/EIPS/eip-721293#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]294impl<T: Config> RefungibleHandle<T>295where296	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,297{298	/// @notice A descriptive name for a collection of NFTs in this contract299	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`300	#[solidity(hide, rename_selector = "name")]301	fn name_proxy(&self) -> Result<string> {302		self.name()303	}304305	/// @notice An abbreviated name for NFTs in this contract306	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`307	#[solidity(hide, rename_selector = "symbol")]308	fn symbol_proxy(&self) -> Result<string> {309		self.symbol()310	}311312	/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.313	///314	/// @dev If the token has a `url` property and it is not empty, it is returned.315	///  Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.316	///  If the collection property `baseURI` is empty or absent, return "" (empty string)317	///  otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix318	///  otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).319	///320	/// @return token's const_metadata321	#[solidity(rename_selector = "tokenURI")]322	fn token_uri(&self, token_id: U256) -> Result<string> {323		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;324325		match get_token_property(self, token_id_u32, &key::url()).as_deref() {326			Err(_) | Ok("") => (),327			Ok(url) => {328				return Ok(url.into());329			}330		};331332		let base_uri =333			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())334				.map(BoundedVec::into_inner)335				.map(string::from_utf8)336				.transpose()337				.map_err(|e| {338					Error::Revert(alloc::format!(339						"Can not convert value \"baseURI\" to string with error \"{}\"",340						e341					))342				})?;343344		let base_uri = match base_uri.as_deref() {345			None | Some("") => {346				return Ok("".into());347			}348			Some(base_uri) => base_uri.into(),349		};350351		Ok(352			match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {353				Err(_) | Ok("") => base_uri,354				Ok(suffix) => base_uri + suffix,355			},356		)357	}358}359360/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension361/// @dev See https://eips.ethereum.org/EIPS/eip-721362#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63)]363impl<T: Config> RefungibleHandle<T> {364	/// @notice Enumerate valid RFTs365	/// @param index A counter less than `totalSupply()`366	/// @return The token identifier for the `index`th NFT,367	///  (sort order not specified)368	fn token_by_index(&self, index: U256) -> Result<U256> {369		Ok(index)370	}371372	/// Not implemented373	fn token_of_owner_by_index(&self, _owner: Address, _index: U256) -> Result<U256> {374		// TODO: Not implemetable375		Err("not implemented".into())376	}377378	/// @notice Count RFTs tracked by this contract379	/// @return A count of valid RFTs tracked by this contract, where each one of380	///  them has an assigned and queryable owner not equal to the zero address381	fn total_supply(&self) -> Result<U256> {382		self.consume_store_reads(1)?;383		Ok(<Pallet<T>>::total_supply(self).into())384	}385}386387/// @title ERC-721 Non-Fungible Token Standard388/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md389#[solidity_interface(name = ERC721, events(ERC721Events), expect_selector = 0x80ac58cd)]390impl<T: Config> RefungibleHandle<T> {391	/// @notice Count all RFTs assigned to an owner392	/// @dev RFTs assigned to the zero address are considered invalid, and this393	///  function throws for queries about the zero address.394	/// @param owner An address for whom to query the balance395	/// @return The number of RFTs owned by `owner`, possibly zero396	fn balance_of(&self, owner: Address) -> Result<U256> {397		self.consume_store_reads(1)?;398		let owner = T::CrossAccountId::from_eth(owner);399		let balance = <AccountBalance<T>>::get((self.id, owner));400		Ok(balance.into())401	}402403	/// @notice Find the owner of an RFT404	/// @dev RFTs assigned to zero address are considered invalid, and queries405	///  about them do throw.406	///  Returns special 0xffffffffffffffffffffffffffffffffffffffff address for407	///  the tokens that are partially owned.408	/// @param tokenId The identifier for an RFT409	/// @return The address of the owner of the RFT410	fn owner_of(&self, token_id: U256) -> Result<Address> {411		self.consume_store_reads(2)?;412		let token = token_id.try_into()?;413		let owner = <Pallet<T>>::token_owner(self.id, token);414		Ok(owner415			.map(|address| *address.as_eth())416			.unwrap_or_else(|| ADDRESS_FOR_PARTIALLY_OWNED_TOKENS))417	}418419	/// @dev Not implemented420	#[solidity(rename_selector = "safeTransferFrom")]421	fn safe_transfer_from_with_data(422		&mut self,423		_from: Address,424		_to: Address,425		_token_id: U256,426		_data: bytes,427	) -> Result<()> {428		// TODO: Not implemetable429		Err("not implemented".into())430	}431432	/// @dev Not implemented433	#[solidity(rename_selector = "safeTransferFrom")]434	fn safe_transfer_from(&mut self, _from: Address, _to: Address, _token_id: U256) -> Result<()> {435		// TODO: Not implemetable436		Err("not implemented".into())437	}438439	/// @notice Transfer ownership of an RFT -- THE CALLER IS RESPONSIBLE440	///  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE441	///  THEY MAY BE PERMANENTLY LOST442	/// @dev Throws unless `msg.sender` is the current owner or an authorized443	///  operator for this RFT. Throws if `from` is not the current owner. Throws444	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.445	///  Throws if RFT pieces have multiple owners.446	/// @param from The current owner of the NFT447	/// @param to The new owner448	/// @param tokenId The NFT to transfer449	#[weight(<SelfWeightOf<T>>::transfer_from_creating_removing())]450	fn transfer_from(451		&mut self,452		caller: caller,453		from: Address,454		to: Address,455		token_id: U256,456	) -> Result<()> {457		let caller = T::CrossAccountId::from_eth(caller);458		let from = T::CrossAccountId::from_eth(from);459		let to = T::CrossAccountId::from_eth(to);460		let token = token_id.try_into()?;461		let budget = self462			.recorder463			.weight_calls_budget(<StructureWeight<T>>::find_parent());464465		let balance = balance(&self, token, &from)?;466		ensure_single_owner(&self, token, balance)?;467468		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, balance, &budget)469			.map_err(dispatch_to_evm::<T>)?;470471		Ok(())472	}473474	/// @dev Not implemented475	fn approve(&mut self, _caller: caller, _approved: Address, _token_id: U256) -> Result<()> {476		Err("not implemented".into())477	}478479	/// @notice Sets or unsets the approval of a given operator.480	///  The `operator` is allowed to transfer all token pieces of the `caller` on their behalf.481	/// @param operator Operator482	/// @param approved Should operator status be granted or revoked?483	#[weight(<SelfWeightOf<T>>::set_allowance_for_all())]484	fn set_approval_for_all(485		&mut self,486		caller: caller,487		operator: Address,488		approved: bool,489	) -> Result<()> {490		let caller = T::CrossAccountId::from_eth(caller);491		let operator = T::CrossAccountId::from_eth(operator);492493		<Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)494			.map_err(dispatch_to_evm::<T>)?;495		Ok(())496	}497498	/// @dev Not implemented499	fn get_approved(&self, _token_id: U256) -> Result<Address> {500		// TODO: Not implemetable501		Err("not implemented".into())502	}503504	/// @notice Tells whether the given `owner` approves the `operator`.505	#[weight(<SelfWeightOf<T>>::allowance_for_all())]506	fn is_approved_for_all(&self, owner: Address, operator: Address) -> Result<bool> {507		let owner = T::CrossAccountId::from_eth(owner);508		let operator = T::CrossAccountId::from_eth(operator);509510		Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))511	}512}513514/// Returns amount of pieces of `token` that `owner` have515pub fn balance<T: Config>(516	collection: &RefungibleHandle<T>,517	token: TokenId,518	owner: &T::CrossAccountId,519) -> Result<u128> {520	collection.consume_store_reads(1)?;521	let balance = <Balance<T>>::get((collection.id, token, &owner));522	Ok(balance)523}524525/// Throws if `owner_balance` is lower than total amount of `token` pieces526pub fn ensure_single_owner<T: Config>(527	collection: &RefungibleHandle<T>,528	token: TokenId,529	owner_balance: u128,530) -> Result<()> {531	collection.consume_store_reads(1)?;532	let total_supply = <TotalSupply<T>>::get((collection.id, token));533534	if owner_balance == 0 {535		return Err(dispatch_to_evm::<T>(536			<CommonError<T>>::MustBeTokenOwner.into(),537		));538	}539540	if total_supply != owner_balance {541		return Err("token has multiple owners".into());542	}543	Ok(())544}545546/// @title ERC721 Token that can be irreversibly burned (destroyed).547#[solidity_interface(name = ERC721Burnable)]548impl<T: Config> RefungibleHandle<T> {549	/// @notice Burns a specific ERC721 token.550	/// @dev Throws unless `msg.sender` is the current RFT owner, or an authorized551	///  operator of the current owner.552	/// @param tokenId The RFT to approve553	#[weight(<SelfWeightOf<T>>::burn_item_fully())]554	fn burn(&mut self, caller: caller, token_id: U256) -> Result<()> {555		let caller = T::CrossAccountId::from_eth(caller);556		let token = token_id.try_into()?;557558		let balance = balance(&self, token, &caller)?;559		ensure_single_owner(&self, token, balance)?;560561		<Pallet<T>>::burn(self, &caller, token, balance).map_err(dispatch_to_evm::<T>)?;562		Ok(())563	}564}565566/// @title ERC721 minting logic.567#[solidity_interface(name = ERC721UniqueMintable)]568impl<T: Config> RefungibleHandle<T> {569	/// @notice Function to mint a token.570	/// @param to The new owner571	/// @return uint256 The id of the newly minted token572	#[weight(<SelfWeightOf<T>>::create_item())]573	fn mint(&mut self, caller: caller, to: Address) -> Result<U256> {574		let token_id: U256 = <TokensMinted<T>>::get(self.id)575			.checked_add(1)576			.ok_or("item id overflow")?577			.into();578		self.mint_check_id(caller, to, token_id)?;579		Ok(token_id)580	}581582	/// @notice Function to mint a token.583	/// @dev `tokenId` should be obtained with `nextTokenId` method,584	///  unlike standard, you can't specify it manually585	/// @param to The new owner586	/// @param tokenId ID of the minted RFT587	#[solidity(hide, rename_selector = "mint")]588	#[weight(<SelfWeightOf<T>>::create_item())]589	fn mint_check_id(&mut self, caller: caller, to: Address, token_id: U256) -> Result<bool> {590		let caller = T::CrossAccountId::from_eth(caller);591		let to = T::CrossAccountId::from_eth(to);592		let token_id: u32 = token_id.try_into()?;593		let budget = self594			.recorder595			.weight_calls_budget(<StructureWeight<T>>::find_parent());596597		if <TokensMinted<T>>::get(self.id)598			.checked_add(1)599			.ok_or("item id overflow")?600			!= token_id601		{602			return Err("item id should be next".into());603		}604605		let users = [(to.clone(), 1)]606			.into_iter()607			.collect::<BTreeMap<_, _>>()608			.try_into()609			.unwrap();610		<Pallet<T>>::create_item(611			self,612			&caller,613			CreateItemData::<T> {614				users,615				properties: CollectionPropertiesVec::default(),616			},617			&budget,618		)619		.map_err(dispatch_to_evm::<T>)?;620621		Ok(true)622	}623624	/// @notice Function to mint token with the given tokenUri.625	/// @param to The new owner626	/// @param tokenUri Token URI that would be stored in the NFT properties627	/// @return uint256 The id of the newly minted token628	#[solidity(rename_selector = "mintWithTokenURI")]629	#[weight(<SelfWeightOf<T>>::create_item())]630	fn mint_with_token_uri(631		&mut self,632		caller: caller,633		to: Address,634		token_uri: string,635	) -> Result<U256> {636		let token_id: U256 = <TokensMinted<T>>::get(self.id)637			.checked_add(1)638			.ok_or("item id overflow")?639			.into();640		self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;641		Ok(token_id)642	}643644	/// @notice Function to mint token with the given tokenUri.645	/// @dev `tokenId` should be obtained with `nextTokenId` method,646	///  unlike standard, you can't specify it manually647	/// @param to The new owner648	/// @param tokenId ID of the minted RFT649	/// @param tokenUri Token URI that would be stored in the RFT properties650	#[solidity(hide, rename_selector = "mintWithTokenURI")]651	#[weight(<SelfWeightOf<T>>::create_item())]652	fn mint_with_token_uri_check_id(653		&mut self,654		caller: caller,655		to: Address,656		token_id: U256,657		token_uri: string,658	) -> Result<bool> {659		let key = key::url();660		let permission = get_token_permission::<T>(self.id, &key)?;661		if !permission.collection_admin {662			return Err("Operation is not allowed".into());663		}664665		let caller = T::CrossAccountId::from_eth(caller);666		let to = T::CrossAccountId::from_eth(to);667		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;668		let budget = self669			.recorder670			.weight_calls_budget(<StructureWeight<T>>::find_parent());671672		if <TokensMinted<T>>::get(self.id)673			.checked_add(1)674			.ok_or("item id overflow")?675			!= token_id676		{677			return Err("item id should be next".into());678		}679680		let mut properties = CollectionPropertiesVec::default();681		properties682			.try_push(Property {683				key,684				value: token_uri685					.into_bytes()686					.try_into()687					.map_err(|_| "token uri is too long")?,688			})689			.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;690691		let users = [(to.clone(), 1)]692			.into_iter()693			.collect::<BTreeMap<_, _>>()694			.try_into()695			.unwrap();696		<Pallet<T>>::create_item(697			self,698			&caller,699			CreateItemData::<T> { users, properties },700			&budget,701		)702		.map_err(dispatch_to_evm::<T>)?;703		Ok(true)704	}705}706707fn get_token_property<T: Config>(708	collection: &CollectionHandle<T>,709	token_id: u32,710	key: &up_data_structs::PropertyKey,711) -> Result<string> {712	collection.consume_store_reads(1)?;713	let properties = <TokenProperties<T>>::try_get((collection.id, token_id))714		.map_err(|_| Error::Revert("Token properties not found".into()))?;715	if let Some(property) = properties.get(key) {716		return Ok(string::from_utf8_lossy(property).into());717	}718719	Err("Property tokenURI not found".into())720}721722fn get_token_permission<T: Config>(723	collection_id: CollectionId,724	key: &PropertyKey,725) -> Result<PropertyPermission> {726	let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)727		.map_err(|_| Error::Revert("No permissions for collection".into()))?;728	let a = token_property_permissions729		.get(key)730		.map(Clone::clone)731		.ok_or_else(|| {732			let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();733			Error::Revert(alloc::format!("No permission for key {}", key))734		})?;735	Ok(a)736}737738/// @title Unique extensions for ERC721.739#[solidity_interface(name = ERC721UniqueExtensions)]740impl<T: Config> RefungibleHandle<T>741where742	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,743{744	/// @notice A descriptive name for a collection of NFTs in this contract745	fn name(&self) -> Result<string> {746		Ok(decode_utf16(self.name.iter().copied())747			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))748			.collect::<string>())749	}750751	/// @notice An abbreviated name for NFTs in this contract752	fn symbol(&self) -> Result<string> {753		Ok(string::from_utf8_lossy(&self.token_prefix).into())754	}755756	/// @notice A description for the collection.757	fn description(&self) -> Result<string> {758		Ok(decode_utf16(self.description.iter().copied())759			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))760			.collect::<string>())761	}762763	/// Returns the owner (in cross format) of the token.764	///765	/// @param tokenId Id for the token.766	fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {767		Self::token_owner(&self, token_id.try_into()?)768			.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))769			.ok_or(Error::Revert("key too large".into()))770	}771772	/// Returns the token properties.773	///774	/// @param tokenId Id for the token.775	/// @param keys Properties keys. Empty keys for all propertyes.776	/// @return Vector of properties key/value pairs.777	fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {778		let keys = keys779			.into_iter()780			.map(|key| {781				<Vec<u8>>::from(key)782					.try_into()783					.map_err(|_| Error::Revert("key too large".into()))784			})785			.collect::<Result<Vec<_>>>()?;786787		<Self as CommonCollectionOperations<T>>::token_properties(788			&self,789			token_id.try_into()?,790			if keys.is_empty() { None } else { Some(keys) },791		)792		.into_iter()793		.map(eth::Property::try_from)794		.collect::<Result<Vec<_>>>()795	}796	/// @notice Transfer ownership of an RFT797	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`798	///  is the zero address. Throws if `tokenId` is not a valid RFT.799	///  Throws if RFT pieces have multiple owners.800	/// @param to The new owner801	/// @param tokenId The RFT to transfer802	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]803	fn transfer(&mut self, caller: caller, to: Address, token_id: U256) -> Result<()> {804		let caller = T::CrossAccountId::from_eth(caller);805		let to = T::CrossAccountId::from_eth(to);806		let token = token_id.try_into()?;807		let budget = self808			.recorder809			.weight_calls_budget(<StructureWeight<T>>::find_parent());810811		let balance = balance(self, token, &caller)?;812		ensure_single_owner(self, token, balance)?;813814		<Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)815			.map_err(dispatch_to_evm::<T>)?;816		Ok(())817	}818819	/// @notice Transfer ownership of an RFT820	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`821	///  is the zero address. Throws if `tokenId` is not a valid RFT.822	///  Throws if RFT pieces have multiple owners.823	/// @param to The new owner824	/// @param tokenId The RFT to transfer825	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]826	fn transfer_cross(827		&mut self,828		caller: caller,829		to: eth::CrossAddress,830		token_id: U256,831	) -> Result<()> {832		let caller = T::CrossAccountId::from_eth(caller);833		let to = to.into_sub_cross_account::<T>()?;834		let token = token_id.try_into()?;835		let budget = self836			.recorder837			.weight_calls_budget(<StructureWeight<T>>::find_parent());838839		let balance = balance(self, token, &caller)?;840		ensure_single_owner(self, token, balance)?;841842		<Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)843			.map_err(dispatch_to_evm::<T>)?;844		Ok(())845	}846847	/// @notice Transfer ownership of an RFT848	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`849	///  is the zero address. Throws if `tokenId` is not a valid RFT.850	///  Throws if RFT pieces have multiple owners.851	/// @param to The new owner852	/// @param tokenId The RFT to transfer853	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]854	fn transfer_from_cross(855		&mut self,856		caller: caller,857		from: eth::CrossAddress,858		to: eth::CrossAddress,859		token_id: U256,860	) -> Result<()> {861		let caller = T::CrossAccountId::from_eth(caller);862		let from = from.into_sub_cross_account::<T>()?;863		let to = to.into_sub_cross_account::<T>()?;864		let token_id = token_id.try_into()?;865		let budget = self866			.recorder867			.weight_calls_budget(<StructureWeight<T>>::find_parent());868869		let balance = balance(self, token_id, &from)?;870		ensure_single_owner(self, token_id, balance)?;871872		Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)873			.map_err(dispatch_to_evm::<T>)?;874		Ok(())875	}876877	/// @notice Burns a specific ERC721 token.878	/// @dev Throws unless `msg.sender` is the current owner or an authorized879	///  operator for this RFT. Throws if `from` is not the current owner. Throws880	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.881	///  Throws if RFT pieces have multiple owners.882	/// @param from The current owner of the RFT883	/// @param tokenId The RFT to transfer884	#[solidity(hide)]885	#[weight(<SelfWeightOf<T>>::burn_from())]886	fn burn_from(&mut self, caller: caller, from: Address, token_id: U256) -> Result<()> {887		let caller = T::CrossAccountId::from_eth(caller);888		let from = T::CrossAccountId::from_eth(from);889		let token = token_id.try_into()?;890		let budget = self891			.recorder892			.weight_calls_budget(<StructureWeight<T>>::find_parent());893894		let balance = balance(self, token, &from)?;895		ensure_single_owner(self, token, balance)?;896897		<Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)898			.map_err(dispatch_to_evm::<T>)?;899		Ok(())900	}901902	/// @notice Burns a specific ERC721 token.903	/// @dev Throws unless `msg.sender` is the current owner or an authorized904	///  operator for this RFT. Throws if `from` is not the current owner. Throws905	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.906	///  Throws if RFT pieces have multiple owners.907	/// @param from The current owner of the RFT908	/// @param tokenId The RFT to transfer909	#[weight(<SelfWeightOf<T>>::burn_from())]910	fn burn_from_cross(911		&mut self,912		caller: caller,913		from: eth::CrossAddress,914		token_id: U256,915	) -> Result<()> {916		let caller = T::CrossAccountId::from_eth(caller);917		let from = from.into_sub_cross_account::<T>()?;918		let token = token_id.try_into()?;919		let budget = self920			.recorder921			.weight_calls_budget(<StructureWeight<T>>::find_parent());922923		let balance = balance(self, token, &from)?;924		ensure_single_owner(self, token, balance)?;925926		<Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)927			.map_err(dispatch_to_evm::<T>)?;928		Ok(())929	}930931	/// @notice Returns next free RFT ID.932	fn next_token_id(&self) -> Result<U256> {933		self.consume_store_reads(1)?;934		Ok(<TokensMinted<T>>::get(self.id)935			.checked_add(1)936			.ok_or("item id overflow")?937			.into())938	}939940	/// @notice Function to mint multiple tokens.941	/// @dev `tokenIds` should be an array of consecutive numbers and first number942	///  should be obtained with `nextTokenId` method943	/// @param to The new owner944	/// @param tokenIds IDs of the minted RFTs945	#[solidity(hide)]946	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]947	fn mint_bulk(&mut self, caller: caller, to: Address, token_ids: Vec<U256>) -> Result<bool> {948		let caller = T::CrossAccountId::from_eth(caller);949		let to = T::CrossAccountId::from_eth(to);950		let mut expected_index = <TokensMinted<T>>::get(self.id)951			.checked_add(1)952			.ok_or("item id overflow")?;953		let budget = self954			.recorder955			.weight_calls_budget(<StructureWeight<T>>::find_parent());956957		let total_tokens = token_ids.len();958		for id in token_ids.into_iter() {959			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;960			if id != expected_index {961				return Err("item id should be next".into());962			}963			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;964		}965		let users = [(to.clone(), 1)]966			.into_iter()967			.collect::<BTreeMap<_, _>>()968			.try_into()969			.unwrap();970		let create_item_data = CreateItemData::<T> {971			users,972			properties: CollectionPropertiesVec::default(),973		};974		let data = (0..total_tokens)975			.map(|_| create_item_data.clone())976			.collect();977978		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)979			.map_err(dispatch_to_evm::<T>)?;980		Ok(true)981	}982983	/// @notice Function to mint multiple tokens with the given tokenUris.984	/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive985	///  numbers and first number should be obtained with `nextTokenId` method986	/// @param to The new owner987	/// @param tokens array of pairs of token ID and token URI for minted tokens988	#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]989	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]990	fn mint_bulk_with_token_uri(991		&mut self,992		caller: caller,993		to: Address,994		tokens: Vec<(U256, string)>,995	) -> Result<bool> {996		let key = key::url();997		let caller = T::CrossAccountId::from_eth(caller);998		let to = T::CrossAccountId::from_eth(to);999		let mut expected_index = <TokensMinted<T>>::get(self.id)1000			.checked_add(1)1001			.ok_or("item id overflow")?;1002		let budget = self1003			.recorder1004			.weight_calls_budget(<StructureWeight<T>>::find_parent());10051006		let mut data = Vec::with_capacity(tokens.len());1007		let users: BoundedBTreeMap<_, _, _> = [(to.clone(), 1)]1008			.into_iter()1009			.collect::<BTreeMap<_, _>>()1010			.try_into()1011			.unwrap();1012		for (id, token_uri) in tokens {1013			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;1014			if id != expected_index {1015				return Err("item id should be next".into());1016			}1017			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;10181019			let mut properties = CollectionPropertiesVec::default();1020			properties1021				.try_push(Property {1022					key: key.clone(),1023					value: token_uri1024						.into_bytes()1025						.try_into()1026						.map_err(|_| "token uri is too long")?,1027				})1028				.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;10291030			let create_item_data = CreateItemData::<T> {1031				users: users.clone(),1032				properties,1033			};1034			data.push(create_item_data);1035		}10361037		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1038			.map_err(dispatch_to_evm::<T>)?;1039		Ok(true)1040	}10411042	/// @notice Function to mint a token.1043	/// @param to The new owner crossAccountId1044	/// @param properties Properties of minted token1045	/// @return uint256 The id of the newly minted token1046	#[weight(<SelfWeightOf<T>>::create_item())]1047	fn mint_cross(1048		&mut self,1049		caller: caller,1050		to: eth::CrossAddress,1051		properties: Vec<eth::Property>,1052	) -> Result<U256> {1053		let token_id = <TokensMinted<T>>::get(self.id)1054			.checked_add(1)1055			.ok_or("item id overflow")?;10561057		let to = to.into_sub_cross_account::<T>()?;10581059		let properties = properties1060			.into_iter()1061			.map(eth::Property::try_into)1062			.collect::<Result<Vec<_>>>()?1063			.try_into()1064			.map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10651066		let caller = T::CrossAccountId::from_eth(caller);10671068		let budget = self1069			.recorder1070			.weight_calls_budget(<StructureWeight<T>>::find_parent());10711072		let users = [(to, 1)]1073			.into_iter()1074			.collect::<BTreeMap<_, _>>()1075			.try_into()1076			.unwrap();1077		<Pallet<T>>::create_item(1078			self,1079			&caller,1080			CreateItemData::<T> { users, properties },1081			&budget,1082		)1083		.map_err(dispatch_to_evm::<T>)?;10841085		Ok(token_id.into())1086	}10871088	/// Returns EVM address for refungible token1089	///1090	/// @param token ID of the token1091	fn token_contract_address(&self, token: U256) -> Result<Address> {1092		Ok(T::EvmTokenAddressMapping::token_to_address(1093			self.id,1094			token.try_into().map_err(|_| "token id overflow")?,1095		))1096	}10971098	/// @notice Returns collection helper contract address1099	fn collection_helper_address(&self) -> Result<Address> {1100		Ok(T::ContractAddress::get())1101	}1102}11031104#[solidity_interface(1105	name = UniqueRefungible,1106	is(1107		ERC721,1108		ERC721Enumerable,1109		ERC721UniqueExtensions,1110		ERC721UniqueMintable,1111		ERC721Burnable,1112		ERC721Metadata(if(this.flags.erc721metadata)),1113		Collection(via(common_mut returns CollectionHandle<T>)),1114		TokenProperties,1115	)1116)]1117impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}11181119// Not a tests, but code generators1120generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);1121generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);11221123impl<T: Config> CommonEvmHandler for RefungibleHandle<T>1124where1125	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1126{1127	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");1128	fn call(1129		self,1130		handle: &mut impl PrecompileHandle,1131	) -> Option<pallet_common::erc::PrecompileResult> {1132		call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)1133	}1134}
after · pallets/refungible/src/erc.rs
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//! # Refungible Pallet EVM API for tokens18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Refungible Pallet methods.2122extern crate alloc;2324use core::{25	char::{REPLACEMENT_CHARACTER, decode_utf16},26	convert::TryInto,27};28use evm_coder::{29	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30	weight,31};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{34	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35	Error as CommonError,36	erc::{CommonEvmHandler, CollectionCall, static_property::key},37	eth,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};42use sp_core::{H160, U256, Get};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};44use up_data_structs::{45	CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,46	PropertyKeyPermission, PropertyPermission, TokenId,47};4849use crate::{50	AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,51	TokenProperties, TokensMinted, TotalSupply, weights::WeightInfo,52};5354pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);5556/// @title A contract that allows to set and delete token properties and change token property permissions.57#[solidity_interface(name = TokenProperties)]58impl<T: Config> RefungibleHandle<T> {59	/// @notice Set permissions for token property.60	/// @dev Throws error if `msg.sender` is not admin or owner of the collection.61	/// @param key Property key.62	/// @param isMutable Permission to mutate property.63	/// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.64	/// @param tokenOwner Permission to mutate property by token owner if property is mutable.65	#[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]66	#[solidity(hide)]67	fn set_token_property_permission(68		&mut self,69		caller: caller,70		key: String,71		is_mutable: bool,72		collection_admin: bool,73		token_owner: bool,74	) -> Result<()> {75		let caller = T::CrossAccountId::from_eth(caller);76		<Pallet<T>>::set_token_property_permissions(77			self,78			&caller,79			vec![PropertyKeyPermission {80				key: <Vec<u8>>::from(key)81					.try_into()82					.map_err(|_| "too long key")?,83				permission: PropertyPermission {84					mutable: is_mutable,85					collection_admin,86					token_owner,87				},88			}],89		)90		.map_err(dispatch_to_evm::<T>)91	}9293	/// @notice Set permissions for token property.94	/// @dev Throws error if `msg.sender` is not admin or owner of the collection.95	/// @param permissions Permissions for keys.96	#[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]97	fn set_token_property_permissions(98		&mut self,99		caller: caller,100		permissions: Vec<eth::TokenPropertyPermission>,101	) -> Result<()> {102		let caller = T::CrossAccountId::from_eth(caller);103		let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;104105		<Pallet<T>>::set_token_property_permissions(self, &caller, perms)106			.map_err(dispatch_to_evm::<T>)107	}108109	/// @notice Get permissions for token properties.110	fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {111		let perms = <Pallet<T>>::token_property_permission(self.id);112		Ok(perms113			.into_iter()114			.map(eth::TokenPropertyPermission::from)115			.collect())116	}117118	/// @notice Set token property value.119	/// @dev Throws error if `msg.sender` has no permission to edit the property.120	/// @param tokenId ID of the token.121	/// @param key Property key.122	/// @param value Property value.123	#[solidity(hide)]124	#[weight(<SelfWeightOf<T>>::set_token_properties(1))]125	fn set_property(126		&mut self,127		caller: caller,128		token_id: U256,129		key: String,130		value: bytes,131	) -> Result<()> {132		let caller = T::CrossAccountId::from_eth(caller);133		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;134		let key = <Vec<u8>>::from(key)135			.try_into()136			.map_err(|_| "key too long")?;137		let value = value.0.try_into().map_err(|_| "value too long")?;138139		let nesting_budget = self140			.recorder141			.weight_calls_budget(<StructureWeight<T>>::find_parent());142143		<Pallet<T>>::set_token_property(144			self,145			&caller,146			TokenId(token_id),147			Property { key, value },148			&nesting_budget,149		)150		.map_err(dispatch_to_evm::<T>)151	}152153	/// @notice Set token properties value.154	/// @dev Throws error if `msg.sender` has no permission to edit the property.155	/// @param tokenId ID of the token.156	/// @param properties settable properties157	#[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]158	fn set_properties(159		&mut self,160		caller: caller,161		token_id: U256,162		properties: Vec<eth::Property>,163	) -> Result<()> {164		let caller = T::CrossAccountId::from_eth(caller);165		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;166167		let nesting_budget = self168			.recorder169			.weight_calls_budget(<StructureWeight<T>>::find_parent());170171		let properties = properties172			.into_iter()173			.map(eth::Property::try_into)174			.collect::<Result<Vec<_>>>()?;175176		<Pallet<T>>::set_token_properties(177			self,178			&caller,179			TokenId(token_id),180			properties.into_iter(),181			false,182			&nesting_budget,183		)184		.map_err(dispatch_to_evm::<T>)185	}186187	/// @notice Delete token property value.188	/// @dev Throws error if `msg.sender` has no permission to edit the property.189	/// @param tokenId ID of the token.190	/// @param key Property key.191	#[solidity(hide)]192	#[weight(<SelfWeightOf<T>>::delete_token_properties(1))]193	fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {194		let caller = T::CrossAccountId::from_eth(caller);195		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;196		let key = <Vec<u8>>::from(key)197			.try_into()198			.map_err(|_| "key too long")?;199200		let nesting_budget = self201			.recorder202			.weight_calls_budget(<StructureWeight<T>>::find_parent());203204		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)205			.map_err(dispatch_to_evm::<T>)206	}207208	/// @notice Delete token properties value.209	/// @dev Throws error if `msg.sender` has no permission to edit the property.210	/// @param tokenId ID of the token.211	/// @param keys Properties key.212	#[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]213	fn delete_properties(214		&mut self,215		token_id: U256,216		caller: caller,217		keys: Vec<String>,218	) -> Result<()> {219		let caller = T::CrossAccountId::from_eth(caller);220		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221		let keys = keys222			.into_iter()223			.map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))224			.collect::<Result<Vec<_>>>()?;225226		let nesting_budget = self227			.recorder228			.weight_calls_budget(<StructureWeight<T>>::find_parent());229230		<Pallet<T>>::delete_token_properties(231			self,232			&caller,233			TokenId(token_id),234			keys.into_iter(),235			&nesting_budget,236		)237		.map_err(dispatch_to_evm::<T>)238	}239240	/// @notice Get token property value.241	/// @dev Throws error if key not found242	/// @param tokenId ID of the token.243	/// @param key Property key.244	/// @return Property value bytes245	fn property(&self, token_id: U256, key: String) -> Result<bytes> {246		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;247		let key = <Vec<u8>>::from(key)248			.try_into()249			.map_err(|_| "key too long")?;250251		let props = <TokenProperties<T>>::get((self.id, token_id));252		let prop = props.get(&key).ok_or("key not found")?;253254		Ok(prop.to_vec().into())255	}256}257258#[derive(ToLog)]259pub enum ERC721Events {260	/// @dev This event emits when NFTs are created (`from` == 0) and destroyed261	///  (`to` == 0). Exception: during contract creation, any number of RFTs262	///  may be created and assigned without emitting Transfer.263	Transfer {264		#[indexed]265		from: Address,266		#[indexed]267		to: Address,268		#[indexed]269		token_id: U256,270	},271	/// @dev Not supported272	Approval {273		#[indexed]274		owner: Address,275		#[indexed]276		approved: Address,277		#[indexed]278		token_id: U256,279	},280	/// @dev Not supported281	#[allow(dead_code)]282	ApprovalForAll {283		#[indexed]284		owner: Address,285		#[indexed]286		operator: Address,287		approved: bool,288	},289}290291/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension292/// @dev See https://eips.ethereum.org/EIPS/eip-721293#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]294impl<T: Config> RefungibleHandle<T>295where296	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,297{298	/// @notice A descriptive name for a collection of NFTs in this contract299	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`300	#[solidity(hide, rename_selector = "name")]301	fn name_proxy(&self) -> Result<String> {302		self.name()303	}304305	/// @notice An abbreviated name for NFTs in this contract306	/// @dev real implementation of this function lies in `ERC721UniqueExtensions`307	#[solidity(hide, rename_selector = "symbol")]308	fn symbol_proxy(&self) -> Result<String> {309		self.symbol()310	}311312	/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.313	///314	/// @dev If the token has a `url` property and it is not empty, it is returned.315	///  Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.316	///  If the collection property `baseURI` is empty or absent, return "" (empty string)317	///  otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix318	///  otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).319	///320	/// @return token's const_metadata321	#[solidity(rename_selector = "tokenURI")]322	fn token_uri(&self, token_id: U256) -> Result<String> {323		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;324325		match get_token_property(self, token_id_u32, &key::url()).as_deref() {326			Err(_) | Ok("") => (),327			Ok(url) => {328				return Ok(url.into());329			}330		};331332		let base_uri =333			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())334				.map(BoundedVec::into_inner)335				.map(String::from_utf8)336				.transpose()337				.map_err(|e| {338					Error::Revert(alloc::format!(339						"Can not convert value \"baseURI\" to string with error \"{}\"",340						e341					))342				})?;343344		let base_uri = match base_uri.as_deref() {345			None | Some("") => {346				return Ok("".into());347			}348			Some(base_uri) => base_uri.into(),349		};350351		Ok(352			match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {353				Err(_) | Ok("") => base_uri,354				Ok(suffix) => base_uri + suffix,355			},356		)357	}358}359360/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension361/// @dev See https://eips.ethereum.org/EIPS/eip-721362#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63)]363impl<T: Config> RefungibleHandle<T> {364	/// @notice Enumerate valid RFTs365	/// @param index A counter less than `totalSupply()`366	/// @return The token identifier for the `index`th NFT,367	///  (sort order not specified)368	fn token_by_index(&self, index: U256) -> Result<U256> {369		Ok(index)370	}371372	/// Not implemented373	fn token_of_owner_by_index(&self, _owner: Address, _index: U256) -> Result<U256> {374		// TODO: Not implemetable375		Err("not implemented".into())376	}377378	/// @notice Count RFTs tracked by this contract379	/// @return A count of valid RFTs tracked by this contract, where each one of380	///  them has an assigned and queryable owner not equal to the zero address381	fn total_supply(&self) -> Result<U256> {382		self.consume_store_reads(1)?;383		Ok(<Pallet<T>>::total_supply(self).into())384	}385}386387/// @title ERC-721 Non-Fungible Token Standard388/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md389#[solidity_interface(name = ERC721, events(ERC721Events), expect_selector = 0x80ac58cd)]390impl<T: Config> RefungibleHandle<T> {391	/// @notice Count all RFTs assigned to an owner392	/// @dev RFTs assigned to the zero address are considered invalid, and this393	///  function throws for queries about the zero address.394	/// @param owner An address for whom to query the balance395	/// @return The number of RFTs owned by `owner`, possibly zero396	fn balance_of(&self, owner: Address) -> Result<U256> {397		self.consume_store_reads(1)?;398		let owner = T::CrossAccountId::from_eth(owner);399		let balance = <AccountBalance<T>>::get((self.id, owner));400		Ok(balance.into())401	}402403	/// @notice Find the owner of an RFT404	/// @dev RFTs assigned to zero address are considered invalid, and queries405	///  about them do throw.406	///  Returns special 0xffffffffffffffffffffffffffffffffffffffff address for407	///  the tokens that are partially owned.408	/// @param tokenId The identifier for an RFT409	/// @return The address of the owner of the RFT410	fn owner_of(&self, token_id: U256) -> Result<Address> {411		self.consume_store_reads(2)?;412		let token = token_id.try_into()?;413		let owner = <Pallet<T>>::token_owner(self.id, token);414		Ok(owner415			.map(|address| *address.as_eth())416			.unwrap_or_else(|| ADDRESS_FOR_PARTIALLY_OWNED_TOKENS))417	}418419	/// @dev Not implemented420	#[solidity(rename_selector = "safeTransferFrom")]421	fn safe_transfer_from_with_data(422		&mut self,423		_from: Address,424		_to: Address,425		_token_id: U256,426		_data: bytes,427	) -> Result<()> {428		// TODO: Not implemetable429		Err("not implemented".into())430	}431432	/// @dev Not implemented433	#[solidity(rename_selector = "safeTransferFrom")]434	fn safe_transfer_from(&mut self, _from: Address, _to: Address, _token_id: U256) -> Result<()> {435		// TODO: Not implemetable436		Err("not implemented".into())437	}438439	/// @notice Transfer ownership of an RFT -- THE CALLER IS RESPONSIBLE440	///  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE441	///  THEY MAY BE PERMANENTLY LOST442	/// @dev Throws unless `msg.sender` is the current owner or an authorized443	///  operator for this RFT. Throws if `from` is not the current owner. Throws444	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.445	///  Throws if RFT pieces have multiple owners.446	/// @param from The current owner of the NFT447	/// @param to The new owner448	/// @param tokenId The NFT to transfer449	#[weight(<SelfWeightOf<T>>::transfer_from_creating_removing())]450	fn transfer_from(451		&mut self,452		caller: caller,453		from: Address,454		to: Address,455		token_id: U256,456	) -> Result<()> {457		let caller = T::CrossAccountId::from_eth(caller);458		let from = T::CrossAccountId::from_eth(from);459		let to = T::CrossAccountId::from_eth(to);460		let token = token_id.try_into()?;461		let budget = self462			.recorder463			.weight_calls_budget(<StructureWeight<T>>::find_parent());464465		let balance = balance(&self, token, &from)?;466		ensure_single_owner(&self, token, balance)?;467468		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, balance, &budget)469			.map_err(dispatch_to_evm::<T>)?;470471		Ok(())472	}473474	/// @dev Not implemented475	fn approve(&mut self, _caller: caller, _approved: Address, _token_id: U256) -> Result<()> {476		Err("not implemented".into())477	}478479	/// @notice Sets or unsets the approval of a given operator.480	///  The `operator` is allowed to transfer all token pieces of the `caller` on their behalf.481	/// @param operator Operator482	/// @param approved Should operator status be granted or revoked?483	#[weight(<SelfWeightOf<T>>::set_allowance_for_all())]484	fn set_approval_for_all(485		&mut self,486		caller: caller,487		operator: Address,488		approved: bool,489	) -> Result<()> {490		let caller = T::CrossAccountId::from_eth(caller);491		let operator = T::CrossAccountId::from_eth(operator);492493		<Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)494			.map_err(dispatch_to_evm::<T>)?;495		Ok(())496	}497498	/// @dev Not implemented499	fn get_approved(&self, _token_id: U256) -> Result<Address> {500		// TODO: Not implemetable501		Err("not implemented".into())502	}503504	/// @notice Tells whether the given `owner` approves the `operator`.505	#[weight(<SelfWeightOf<T>>::allowance_for_all())]506	fn is_approved_for_all(&self, owner: Address, operator: Address) -> Result<bool> {507		let owner = T::CrossAccountId::from_eth(owner);508		let operator = T::CrossAccountId::from_eth(operator);509510		Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))511	}512}513514/// Returns amount of pieces of `token` that `owner` have515pub fn balance<T: Config>(516	collection: &RefungibleHandle<T>,517	token: TokenId,518	owner: &T::CrossAccountId,519) -> Result<u128> {520	collection.consume_store_reads(1)?;521	let balance = <Balance<T>>::get((collection.id, token, &owner));522	Ok(balance)523}524525/// Throws if `owner_balance` is lower than total amount of `token` pieces526pub fn ensure_single_owner<T: Config>(527	collection: &RefungibleHandle<T>,528	token: TokenId,529	owner_balance: u128,530) -> Result<()> {531	collection.consume_store_reads(1)?;532	let total_supply = <TotalSupply<T>>::get((collection.id, token));533534	if owner_balance == 0 {535		return Err(dispatch_to_evm::<T>(536			<CommonError<T>>::MustBeTokenOwner.into(),537		));538	}539540	if total_supply != owner_balance {541		return Err("token has multiple owners".into());542	}543	Ok(())544}545546/// @title ERC721 Token that can be irreversibly burned (destroyed).547#[solidity_interface(name = ERC721Burnable)]548impl<T: Config> RefungibleHandle<T> {549	/// @notice Burns a specific ERC721 token.550	/// @dev Throws unless `msg.sender` is the current RFT owner, or an authorized551	///  operator of the current owner.552	/// @param tokenId The RFT to approve553	#[weight(<SelfWeightOf<T>>::burn_item_fully())]554	fn burn(&mut self, caller: caller, token_id: U256) -> Result<()> {555		let caller = T::CrossAccountId::from_eth(caller);556		let token = token_id.try_into()?;557558		let balance = balance(&self, token, &caller)?;559		ensure_single_owner(&self, token, balance)?;560561		<Pallet<T>>::burn(self, &caller, token, balance).map_err(dispatch_to_evm::<T>)?;562		Ok(())563	}564}565566/// @title ERC721 minting logic.567#[solidity_interface(name = ERC721UniqueMintable)]568impl<T: Config> RefungibleHandle<T> {569	/// @notice Function to mint a token.570	/// @param to The new owner571	/// @return uint256 The id of the newly minted token572	#[weight(<SelfWeightOf<T>>::create_item())]573	fn mint(&mut self, caller: caller, to: Address) -> Result<U256> {574		let token_id: U256 = <TokensMinted<T>>::get(self.id)575			.checked_add(1)576			.ok_or("item id overflow")?577			.into();578		self.mint_check_id(caller, to, token_id)?;579		Ok(token_id)580	}581582	/// @notice Function to mint a token.583	/// @dev `tokenId` should be obtained with `nextTokenId` method,584	///  unlike standard, you can't specify it manually585	/// @param to The new owner586	/// @param tokenId ID of the minted RFT587	#[solidity(hide, rename_selector = "mint")]588	#[weight(<SelfWeightOf<T>>::create_item())]589	fn mint_check_id(&mut self, caller: caller, to: Address, token_id: U256) -> Result<bool> {590		let caller = T::CrossAccountId::from_eth(caller);591		let to = T::CrossAccountId::from_eth(to);592		let token_id: u32 = token_id.try_into()?;593		let budget = self594			.recorder595			.weight_calls_budget(<StructureWeight<T>>::find_parent());596597		if <TokensMinted<T>>::get(self.id)598			.checked_add(1)599			.ok_or("item id overflow")?600			!= token_id601		{602			return Err("item id should be next".into());603		}604605		let users = [(to.clone(), 1)]606			.into_iter()607			.collect::<BTreeMap<_, _>>()608			.try_into()609			.unwrap();610		<Pallet<T>>::create_item(611			self,612			&caller,613			CreateItemData::<T> {614				users,615				properties: CollectionPropertiesVec::default(),616			},617			&budget,618		)619		.map_err(dispatch_to_evm::<T>)?;620621		Ok(true)622	}623624	/// @notice Function to mint token with the given tokenUri.625	/// @param to The new owner626	/// @param tokenUri Token URI that would be stored in the NFT properties627	/// @return uint256 The id of the newly minted token628	#[solidity(rename_selector = "mintWithTokenURI")]629	#[weight(<SelfWeightOf<T>>::create_item())]630	fn mint_with_token_uri(631		&mut self,632		caller: caller,633		to: Address,634		token_uri: String,635	) -> Result<U256> {636		let token_id: U256 = <TokensMinted<T>>::get(self.id)637			.checked_add(1)638			.ok_or("item id overflow")?639			.into();640		self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;641		Ok(token_id)642	}643644	/// @notice Function to mint token with the given tokenUri.645	/// @dev `tokenId` should be obtained with `nextTokenId` method,646	///  unlike standard, you can't specify it manually647	/// @param to The new owner648	/// @param tokenId ID of the minted RFT649	/// @param tokenUri Token URI that would be stored in the RFT properties650	#[solidity(hide, rename_selector = "mintWithTokenURI")]651	#[weight(<SelfWeightOf<T>>::create_item())]652	fn mint_with_token_uri_check_id(653		&mut self,654		caller: caller,655		to: Address,656		token_id: U256,657		token_uri: String,658	) -> Result<bool> {659		let key = key::url();660		let permission = get_token_permission::<T>(self.id, &key)?;661		if !permission.collection_admin {662			return Err("Operation is not allowed".into());663		}664665		let caller = T::CrossAccountId::from_eth(caller);666		let to = T::CrossAccountId::from_eth(to);667		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;668		let budget = self669			.recorder670			.weight_calls_budget(<StructureWeight<T>>::find_parent());671672		if <TokensMinted<T>>::get(self.id)673			.checked_add(1)674			.ok_or("item id overflow")?675			!= token_id676		{677			return Err("item id should be next".into());678		}679680		let mut properties = CollectionPropertiesVec::default();681		properties682			.try_push(Property {683				key,684				value: token_uri685					.into_bytes()686					.try_into()687					.map_err(|_| "token uri is too long")?,688			})689			.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;690691		let users = [(to.clone(), 1)]692			.into_iter()693			.collect::<BTreeMap<_, _>>()694			.try_into()695			.unwrap();696		<Pallet<T>>::create_item(697			self,698			&caller,699			CreateItemData::<T> { users, properties },700			&budget,701		)702		.map_err(dispatch_to_evm::<T>)?;703		Ok(true)704	}705}706707fn get_token_property<T: Config>(708	collection: &CollectionHandle<T>,709	token_id: u32,710	key: &up_data_structs::PropertyKey,711) -> Result<String> {712	collection.consume_store_reads(1)?;713	let properties = <TokenProperties<T>>::try_get((collection.id, token_id))714		.map_err(|_| Error::Revert("Token properties not found".into()))?;715	if let Some(property) = properties.get(key) {716		return Ok(String::from_utf8_lossy(property).into());717	}718719	Err("Property tokenURI not found".into())720}721722fn get_token_permission<T: Config>(723	collection_id: CollectionId,724	key: &PropertyKey,725) -> Result<PropertyPermission> {726	let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)727		.map_err(|_| Error::Revert("No permissions for collection".into()))?;728	let a = token_property_permissions729		.get(key)730		.map(Clone::clone)731		.ok_or_else(|| {732			let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();733			Error::Revert(alloc::format!("No permission for key {}", key))734		})?;735	Ok(a)736}737738/// @title Unique extensions for ERC721.739#[solidity_interface(name = ERC721UniqueExtensions)]740impl<T: Config> RefungibleHandle<T>741where742	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,743{744	/// @notice A descriptive name for a collection of NFTs in this contract745	fn name(&self) -> Result<String> {746		Ok(decode_utf16(self.name.iter().copied())747			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))748			.collect::<String>())749	}750751	/// @notice An abbreviated name for NFTs in this contract752	fn symbol(&self) -> Result<String> {753		Ok(String::from_utf8_lossy(&self.token_prefix).into())754	}755756	/// @notice A description for the collection.757	fn description(&self) -> Result<String> {758		Ok(decode_utf16(self.description.iter().copied())759			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))760			.collect::<String>())761	}762763	/// Returns the owner (in cross format) of the token.764	///765	/// @param tokenId Id for the token.766	fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {767		Self::token_owner(&self, token_id.try_into()?)768			.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))769			.ok_or(Error::Revert("key too large".into()))770	}771772	/// Returns the token properties.773	///774	/// @param tokenId Id for the token.775	/// @param keys Properties keys. Empty keys for all propertyes.776	/// @return Vector of properties key/value pairs.777	fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {778		let keys = keys779			.into_iter()780			.map(|key| {781				<Vec<u8>>::from(key)782					.try_into()783					.map_err(|_| Error::Revert("key too large".into()))784			})785			.collect::<Result<Vec<_>>>()?;786787		<Self as CommonCollectionOperations<T>>::token_properties(788			&self,789			token_id.try_into()?,790			if keys.is_empty() { None } else { Some(keys) },791		)792		.into_iter()793		.map(eth::Property::try_from)794		.collect::<Result<Vec<_>>>()795	}796	/// @notice Transfer ownership of an RFT797	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`798	///  is the zero address. Throws if `tokenId` is not a valid RFT.799	///  Throws if RFT pieces have multiple owners.800	/// @param to The new owner801	/// @param tokenId The RFT to transfer802	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]803	fn transfer(&mut self, caller: caller, to: Address, token_id: U256) -> Result<()> {804		let caller = T::CrossAccountId::from_eth(caller);805		let to = T::CrossAccountId::from_eth(to);806		let token = token_id.try_into()?;807		let budget = self808			.recorder809			.weight_calls_budget(<StructureWeight<T>>::find_parent());810811		let balance = balance(self, token, &caller)?;812		ensure_single_owner(self, token, balance)?;813814		<Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)815			.map_err(dispatch_to_evm::<T>)?;816		Ok(())817	}818819	/// @notice Transfer ownership of an RFT820	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`821	///  is the zero address. Throws if `tokenId` is not a valid RFT.822	///  Throws if RFT pieces have multiple owners.823	/// @param to The new owner824	/// @param tokenId The RFT to transfer825	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]826	fn transfer_cross(827		&mut self,828		caller: caller,829		to: eth::CrossAddress,830		token_id: U256,831	) -> Result<()> {832		let caller = T::CrossAccountId::from_eth(caller);833		let to = to.into_sub_cross_account::<T>()?;834		let token = token_id.try_into()?;835		let budget = self836			.recorder837			.weight_calls_budget(<StructureWeight<T>>::find_parent());838839		let balance = balance(self, token, &caller)?;840		ensure_single_owner(self, token, balance)?;841842		<Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)843			.map_err(dispatch_to_evm::<T>)?;844		Ok(())845	}846847	/// @notice Transfer ownership of an RFT848	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`849	///  is the zero address. Throws if `tokenId` is not a valid RFT.850	///  Throws if RFT pieces have multiple owners.851	/// @param to The new owner852	/// @param tokenId The RFT to transfer853	#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]854	fn transfer_from_cross(855		&mut self,856		caller: caller,857		from: eth::CrossAddress,858		to: eth::CrossAddress,859		token_id: U256,860	) -> Result<()> {861		let caller = T::CrossAccountId::from_eth(caller);862		let from = from.into_sub_cross_account::<T>()?;863		let to = to.into_sub_cross_account::<T>()?;864		let token_id = token_id.try_into()?;865		let budget = self866			.recorder867			.weight_calls_budget(<StructureWeight<T>>::find_parent());868869		let balance = balance(self, token_id, &from)?;870		ensure_single_owner(self, token_id, balance)?;871872		Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)873			.map_err(dispatch_to_evm::<T>)?;874		Ok(())875	}876877	/// @notice Burns a specific ERC721 token.878	/// @dev Throws unless `msg.sender` is the current owner or an authorized879	///  operator for this RFT. Throws if `from` is not the current owner. Throws880	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.881	///  Throws if RFT pieces have multiple owners.882	/// @param from The current owner of the RFT883	/// @param tokenId The RFT to transfer884	#[solidity(hide)]885	#[weight(<SelfWeightOf<T>>::burn_from())]886	fn burn_from(&mut self, caller: caller, from: Address, token_id: U256) -> Result<()> {887		let caller = T::CrossAccountId::from_eth(caller);888		let from = T::CrossAccountId::from_eth(from);889		let token = token_id.try_into()?;890		let budget = self891			.recorder892			.weight_calls_budget(<StructureWeight<T>>::find_parent());893894		let balance = balance(self, token, &from)?;895		ensure_single_owner(self, token, balance)?;896897		<Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)898			.map_err(dispatch_to_evm::<T>)?;899		Ok(())900	}901902	/// @notice Burns a specific ERC721 token.903	/// @dev Throws unless `msg.sender` is the current owner or an authorized904	///  operator for this RFT. Throws if `from` is not the current owner. Throws905	///  if `to` is the zero address. Throws if `tokenId` is not a valid RFT.906	///  Throws if RFT pieces have multiple owners.907	/// @param from The current owner of the RFT908	/// @param tokenId The RFT to transfer909	#[weight(<SelfWeightOf<T>>::burn_from())]910	fn burn_from_cross(911		&mut self,912		caller: caller,913		from: eth::CrossAddress,914		token_id: U256,915	) -> Result<()> {916		let caller = T::CrossAccountId::from_eth(caller);917		let from = from.into_sub_cross_account::<T>()?;918		let token = token_id.try_into()?;919		let budget = self920			.recorder921			.weight_calls_budget(<StructureWeight<T>>::find_parent());922923		let balance = balance(self, token, &from)?;924		ensure_single_owner(self, token, balance)?;925926		<Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)927			.map_err(dispatch_to_evm::<T>)?;928		Ok(())929	}930931	/// @notice Returns next free RFT ID.932	fn next_token_id(&self) -> Result<U256> {933		self.consume_store_reads(1)?;934		Ok(<TokensMinted<T>>::get(self.id)935			.checked_add(1)936			.ok_or("item id overflow")?937			.into())938	}939940	/// @notice Function to mint multiple tokens.941	/// @dev `tokenIds` should be an array of consecutive numbers and first number942	///  should be obtained with `nextTokenId` method943	/// @param to The new owner944	/// @param tokenIds IDs of the minted RFTs945	#[solidity(hide)]946	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]947	fn mint_bulk(&mut self, caller: caller, to: Address, token_ids: Vec<U256>) -> Result<bool> {948		let caller = T::CrossAccountId::from_eth(caller);949		let to = T::CrossAccountId::from_eth(to);950		let mut expected_index = <TokensMinted<T>>::get(self.id)951			.checked_add(1)952			.ok_or("item id overflow")?;953		let budget = self954			.recorder955			.weight_calls_budget(<StructureWeight<T>>::find_parent());956957		let total_tokens = token_ids.len();958		for id in token_ids.into_iter() {959			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;960			if id != expected_index {961				return Err("item id should be next".into());962			}963			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;964		}965		let users = [(to.clone(), 1)]966			.into_iter()967			.collect::<BTreeMap<_, _>>()968			.try_into()969			.unwrap();970		let create_item_data = CreateItemData::<T> {971			users,972			properties: CollectionPropertiesVec::default(),973		};974		let data = (0..total_tokens)975			.map(|_| create_item_data.clone())976			.collect();977978		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)979			.map_err(dispatch_to_evm::<T>)?;980		Ok(true)981	}982983	/// @notice Function to mint multiple tokens with the given tokenUris.984	/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive985	///  numbers and first number should be obtained with `nextTokenId` method986	/// @param to The new owner987	/// @param tokens array of pairs of token ID and token URI for minted tokens988	#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]989	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]990	fn mint_bulk_with_token_uri(991		&mut self,992		caller: caller,993		to: Address,994		tokens: Vec<(U256, String)>,995	) -> Result<bool> {996		let key = key::url();997		let caller = T::CrossAccountId::from_eth(caller);998		let to = T::CrossAccountId::from_eth(to);999		let mut expected_index = <TokensMinted<T>>::get(self.id)1000			.checked_add(1)1001			.ok_or("item id overflow")?;1002		let budget = self1003			.recorder1004			.weight_calls_budget(<StructureWeight<T>>::find_parent());10051006		let mut data = Vec::with_capacity(tokens.len());1007		let users: BoundedBTreeMap<_, _, _> = [(to.clone(), 1)]1008			.into_iter()1009			.collect::<BTreeMap<_, _>>()1010			.try_into()1011			.unwrap();1012		for (id, token_uri) in tokens {1013			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;1014			if id != expected_index {1015				return Err("item id should be next".into());1016			}1017			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;10181019			let mut properties = CollectionPropertiesVec::default();1020			properties1021				.try_push(Property {1022					key: key.clone(),1023					value: token_uri1024						.into_bytes()1025						.try_into()1026						.map_err(|_| "token uri is too long")?,1027				})1028				.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;10291030			let create_item_data = CreateItemData::<T> {1031				users: users.clone(),1032				properties,1033			};1034			data.push(create_item_data);1035		}10361037		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1038			.map_err(dispatch_to_evm::<T>)?;1039		Ok(true)1040	}10411042	/// @notice Function to mint a token.1043	/// @param to The new owner crossAccountId1044	/// @param properties Properties of minted token1045	/// @return uint256 The id of the newly minted token1046	#[weight(<SelfWeightOf<T>>::create_item())]1047	fn mint_cross(1048		&mut self,1049		caller: caller,1050		to: eth::CrossAddress,1051		properties: Vec<eth::Property>,1052	) -> Result<U256> {1053		let token_id = <TokensMinted<T>>::get(self.id)1054			.checked_add(1)1055			.ok_or("item id overflow")?;10561057		let to = to.into_sub_cross_account::<T>()?;10581059		let properties = properties1060			.into_iter()1061			.map(eth::Property::try_into)1062			.collect::<Result<Vec<_>>>()?1063			.try_into()1064			.map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10651066		let caller = T::CrossAccountId::from_eth(caller);10671068		let budget = self1069			.recorder1070			.weight_calls_budget(<StructureWeight<T>>::find_parent());10711072		let users = [(to, 1)]1073			.into_iter()1074			.collect::<BTreeMap<_, _>>()1075			.try_into()1076			.unwrap();1077		<Pallet<T>>::create_item(1078			self,1079			&caller,1080			CreateItemData::<T> { users, properties },1081			&budget,1082		)1083		.map_err(dispatch_to_evm::<T>)?;10841085		Ok(token_id.into())1086	}10871088	/// Returns EVM address for refungible token1089	///1090	/// @param token ID of the token1091	fn token_contract_address(&self, token: U256) -> Result<Address> {1092		Ok(T::EvmTokenAddressMapping::token_to_address(1093			self.id,1094			token.try_into().map_err(|_| "token id overflow")?,1095		))1096	}10971098	/// @notice Returns collection helper contract address1099	fn collection_helper_address(&self) -> Result<Address> {1100		Ok(T::ContractAddress::get())1101	}1102}11031104#[solidity_interface(1105	name = UniqueRefungible,1106	is(1107		ERC721,1108		ERC721Enumerable,1109		ERC721UniqueExtensions,1110		ERC721UniqueMintable,1111		ERC721Burnable,1112		ERC721Metadata(if(this.flags.erc721metadata)),1113		Collection(via(common_mut returns CollectionHandle<T>)),1114		TokenProperties,1115	)1116)]1117impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}11181119// Not a tests, but code generators1120generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);1121generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);11221123impl<T: Config> CommonEvmHandler for RefungibleHandle<T>1124where1125	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1126{1127	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");1128	fn call(1129		self,1130		handle: &mut impl PrecompileHandle,1131	) -> Option<pallet_common::erc::PrecompileResult> {1132		call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)1133	}1134}
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -92,15 +92,15 @@
 #[solidity_interface(name = ERC20, events(ERC20Events))]
 impl<T: Config> RefungibleTokenHandle<T> {
 	/// @return the name of the token.
-	fn name(&self) -> Result<string> {
+	fn name(&self) -> Result<String> {
 		Ok(decode_utf16(self.name.iter().copied())
 			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
-			.collect::<string>())
+			.collect::<String>())
 	}
 
 	/// @return the symbol of the token.
-	fn symbol(&self) -> Result<string> {
-		Ok(string::from_utf8_lossy(&self.token_prefix).into())
+	fn symbol(&self) -> Result<String> {
+		Ok(String::from_utf8_lossy(&self.token_prefix).into())
 	}
 
 	/// @dev Total number of tokens in existence
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -57,9 +57,9 @@
 
 fn convert_data<T: Config>(
 	caller: caller,
-	name: string,
-	description: string,
-	token_prefix: string,
+	name: String,
+	description: String,
+	token_prefix: String,
 ) -> Result<(
 	T::CrossAccountId,
 	CollectionName,
@@ -89,10 +89,10 @@
 fn create_collection_internal<T: Config>(
 	caller: caller,
 	value: value,
-	name: string,
+	name: String,
 	collection_mode: CollectionMode,
-	description: string,
-	token_prefix: string,
+	description: String,
+	token_prefix: String,
 ) -> Result<Address> {
 	let (caller, name, description, token_prefix) =
 		convert_data::<T>(caller, name, description, token_prefix)?;
@@ -151,9 +151,9 @@
 		&mut self,
 		caller: caller,
 		value: value,
-		name: string,
-		description: string,
-		token_prefix: string,
+		name: String,
+		description: String,
+		token_prefix: String,
 	) -> Result<Address> {
 		let (caller, name, description, token_prefix) =
 			convert_data::<T>(caller, name, description, token_prefix)?;
@@ -190,9 +190,9 @@
 		&mut self,
 		caller: caller,
 		value: value,
-		name: string,
-		description: string,
-		token_prefix: string,
+		name: String,
+		description: String,
+		token_prefix: String,
 	) -> Result<Address> {
 		create_collection_internal::<T>(
 			caller,
@@ -210,9 +210,9 @@
 		&mut self,
 		caller: caller,
 		value: value,
-		name: string,
-		description: string,
-		token_prefix: string,
+		name: String,
+		description: String,
+		token_prefix: String,
 	) -> Result<Address> {
 		create_collection_internal::<T>(
 			caller,
@@ -230,10 +230,10 @@
 		&mut self,
 		caller: caller,
 		value: value,
-		name: string,
+		name: String,
 		decimals: u8,
-		description: string,
-		token_prefix: string,
+		description: String,
+		token_prefix: String,
 	) -> Result<Address> {
 		create_collection_internal::<T>(
 			caller,
@@ -250,7 +250,7 @@
 		&mut self,
 		caller: caller,
 		collection: Address,
-		base_uri: string,
+		base_uri: String,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let collection =
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
--- a/runtime/tests/src/tests.rs
+++ b/runtime/tests/src/tests.rs
@@ -323,7 +323,7 @@
 				.map(|d| { d.into() })
 				.collect()
 		));
-		for (index, data) in items_data.into_iter().enumerate() {
+		for (index, _data) in items_data.into_iter().enumerate() {
 			let balance = <pallet_refungible::Balance<Test>>::get((
 				CollectionId(1),
 				TokenId((index + 1) as u32),