git.delta.rocks / unique-network / refs/commits / 3d14ec560294

difftreelog

feat generate solidity documentation

Yaroslav Bolyukin2021-11-05parent: #a5e777f.patch.diff
in: master

9 files changed

modifiedcrates/evm-coder-macros/src/solidity_interface.rsdiffbeforeafterboth
--- a/crates/evm-coder-macros/src/solidity_interface.rs
+++ b/crates/evm-coder-macros/src/solidity_interface.rs
@@ -6,7 +6,7 @@
 use std::fmt::Write;
 use syn::{
 	Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,
-	NestedMeta, PatType, Path, PathArguments, ReturnType, Type, spanned::Spanned,
+	MetaNameValue, NestedMeta, PatType, Path, PathArguments, ReturnType, Type, spanned::Spanned,
 };
 
 use crate::{
@@ -362,19 +362,28 @@
 	has_normal_args: bool,
 	mutability: Mutability,
 	result: Type,
+	docs: Vec<String>,
 }
 impl Method {
 	fn try_from(value: &ImplItemMethod) -> syn::Result<Self> {
 		let mut info = MethodInfo {
 			rename_selector: None,
 		};
+		let mut docs = Vec::new();
 		for attr in &value.attrs {
 			let ident = parse_ident_from_path(&attr.path, false)?;
 			if ident == "solidity" {
 				let args = attr.parse_meta().unwrap();
 				info = MethodInfo::from_meta(&args).unwrap();
 			} else if ident == "doc" {
-				// TODO: Add docs to evm interfaces
+				let args = attr.parse_meta().unwrap();
+				let value = match args {
+					Meta::NameValue(MetaNameValue {
+						lit: Lit::Str(str), ..
+					}) => str.value(),
+					_ => unreachable!(),
+				};
+				docs.push(value);
 			}
 		}
 		let ident = &value.sig.ident;
@@ -457,6 +466,7 @@
 			has_normal_args,
 			mutability,
 			result: result.clone(),
+			docs,
 		})
 	}
 	fn expand_call_def(&self) -> proc_macro2::TokenStream {
@@ -570,10 +580,12 @@
 			.iter()
 			.filter(|a| !a.is_special())
 			.map(MethodArg::expand_solidity_argument);
+		let docs = self.docs.iter();
 		let selector = format!("{} {:0>8x}", self.selector_str, self.selector);
 
 		quote! {
 			SolidityFunction {
+				docs: &[#(#docs),*],
 				selector: #selector,
 				name: #camel_name,
 				mutability: #mutability,
@@ -704,6 +716,7 @@
 					use core::fmt::Write;
 					let interface = SolidityInterface {
 						name: #solidity_name,
+						selector: Self::interface_id(),
 						is: &["Dummy", "ERC165", #(
 							#solidity_is,
 						)* #(
modifiedcrates/evm-coder-macros/src/to_log.rsdiffbeforeafterboth
--- a/crates/evm-coder-macros/src/to_log.rs
+++ b/crates/evm-coder-macros/src/to_log.rs
@@ -183,6 +183,7 @@
 					use evm_coder::solidity::*;
 					use core::fmt::Write;
 					let interface = SolidityInterface {
+						selector: 0,
 						name: #solidity_name,
 						is: &[],
 						functions: (#(
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -84,6 +84,7 @@
 solidity_type_name! {
 	uint8 => "uint8" true = "0",
 	uint32 => "uint32" true = "0",
+	uint64 => "uint64" true = "0",
 	uint128 => "uint128" true = "0",
 	uint256 => "uint256" true = "0",
 	address => "address" true = "0x0000000000000000000000000000000000000000",
@@ -376,6 +377,7 @@
 	Mutable,
 }
 pub struct SolidityFunction<A, R> {
+	pub docs: &'static [&'static str],
 	pub selector: &'static str,
 	pub name: &'static str,
 	pub args: A,
@@ -389,6 +391,12 @@
 		writer: &mut impl fmt::Write,
 		tc: &TypeCollector,
 	) -> fmt::Result {
+		for doc in self.docs {
+			writeln!(writer, "\t//{}", doc)?;
+		}
+		if !self.docs.is_empty() {
+			writeln!(writer, "\t//")?;
+		}
 		writeln!(writer, "\t// Selector: {}", self.selector)?;
 		write!(writer, "\tfunction {}(", self.name)?;
 		self.args.solidity_name(writer, tc)?;
@@ -449,6 +457,7 @@
 }
 
 pub struct SolidityInterface<F: SolidityFunctions> {
+	pub selector: u32,
 	pub name: &'static str,
 	pub is: &'static [&'static str],
 	pub functions: F,
@@ -461,6 +470,9 @@
 		out: &mut impl fmt::Write,
 		tc: &TypeCollector,
 	) -> fmt::Result {
+		if self.selector != 0 {
+			writeln!(out, "// Selector: {:0>8x}", self.selector)?;
+		}
 		if is_impl {
 			write!(out, "contract ")?;
 		} else {
modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -31,6 +31,7 @@
 	);
 }
 
+// Selector: 942e8b22
 contract ERC20 is Dummy, ERC165, ERC20Events {
 	// Selector: name() 06fdde03
 	function name() public view returns (string memory) {
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
before · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21	Transfer {22		#[indexed]23		from: address,24		#[indexed]25		to: address,26		#[indexed]27		token_id: uint256,28	},29	Approval {30		#[indexed]31		owner: address,32		#[indexed]33		approved: address,34		#[indexed]35		token_id: uint256,36	},37	#[allow(dead_code)]38	ApprovalForAll {39		#[indexed]40		owner: address,41		#[indexed]42		operator: address,43		approved: bool,44	},45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49	#[allow(dead_code)]50	MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55	fn name(&self) -> Result<string> {56		Ok(decode_utf16(self.name.iter().copied())57			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58			.collect::<string>())59	}60	fn symbol(&self) -> Result<string> {61		Ok(string::from_utf8_lossy(&self.token_prefix).into())62	}6364	#[solidity(rename_selector = "tokenURI")]65	fn token_uri(&self, token_id: uint256) -> Result<string> {66		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;67		Ok(string::from_utf8_lossy(68			&<TokenData<T>>::get((self.id, token_id))69				.ok_or("token not found")?70				.const_data,71		)72		.into())73	}74}7576#[solidity_interface(name = "ERC721Enumerable")]77impl<T: Config> NonfungibleHandle<T> {78	fn token_by_index(&self, index: uint256) -> Result<uint256> {79		Ok(index)80	}8182	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {83		// TODO: Not implemetable84		Err("not implemented".into())85	}8687	fn total_supply(&self) -> Result<uint256> {88		Ok(<Pallet<T>>::total_supply(self).into())89	}90}9192#[solidity_interface(name = "ERC721", events(ERC721Events))]93impl<T: Config> NonfungibleHandle<T> {94	fn balance_of(&self, owner: address) -> Result<uint256> {95		let owner = T::CrossAccountId::from_eth(owner);96		let balance = <AccountBalance<T>>::get((self.id, owner));97		Ok(balance.into())98	}99	fn owner_of(&self, token_id: uint256) -> Result<address> {100		let token: TokenId = token_id.try_into()?;101		Ok(*<TokenData<T>>::get((self.id, token))102			.ok_or("token not found")?103			.owner104			.as_eth())105	}106	fn safe_transfer_from_with_data(107		&mut self,108		_from: address,109		_to: address,110		_token_id: uint256,111		_data: bytes,112		_value: value,113	) -> Result<void> {114		// TODO: Not implemetable115		Err("not implemented".into())116	}117	fn safe_transfer_from(118		&mut self,119		_from: address,120		_to: address,121		_token_id: uint256,122		_value: value,123	) -> Result<void> {124		// TODO: Not implemetable125		Err("not implemented".into())126	}127128	fn transfer_from(129		&mut self,130		caller: caller,131		from: address,132		to: address,133		token_id: uint256,134		_value: value,135	) -> Result<void> {136		let caller = T::CrossAccountId::from_eth(caller);137		let from = T::CrossAccountId::from_eth(from);138		let to = T::CrossAccountId::from_eth(to);139		let token = token_id.try_into()?;140141		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)142			.map_err(dispatch_to_evm::<T>)?;143		Ok(())144	}145146	fn approve(147		&mut self,148		caller: caller,149		approved: address,150		token_id: uint256,151		_value: value,152	) -> Result<void> {153		let caller = T::CrossAccountId::from_eth(caller);154		let approved = T::CrossAccountId::from_eth(approved);155		let token = token_id.try_into()?;156157		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))158			.map_err(dispatch_to_evm::<T>)?;159		Ok(())160	}161162	fn set_approval_for_all(163		&mut self,164		_caller: caller,165		_operator: address,166		_approved: bool,167	) -> Result<void> {168		// TODO: Not implemetable169		Err("not implemented".into())170	}171172	fn get_approved(&self, _token_id: uint256) -> Result<address> {173		// TODO: Not implemetable174		Err("not implemented".into())175	}176177	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {178		// TODO: Not implemetable179		Err("not implemented".into())180	}181}182183#[solidity_interface(name = "ERC721Burnable")]184impl<T: Config> NonfungibleHandle<T> {185	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {186		let caller = T::CrossAccountId::from_eth(caller);187		let token = token_id.try_into()?;188189		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;190		Ok(())191	}192}193194#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]195impl<T: Config> NonfungibleHandle<T> {196	fn minting_finished(&self) -> Result<bool> {197		Ok(false)198	}199200	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {201		let caller = T::CrossAccountId::from_eth(caller);202		let to = T::CrossAccountId::from_eth(to);203		let token_id: u32 = token_id.try_into()?;204		if <TokensMinted<T>>::get(self.id)205			.checked_add(1)206			.ok_or("item id overflow")?207			!= token_id208		{209			return Err("item id should be next".into());210		}211212		<Pallet<T>>::create_item(213			self,214			&caller,215			CreateItemData {216				const_data: BoundedVec::default(),217				variable_data: BoundedVec::default(),218				owner: to,219			},220		)221		.map_err(dispatch_to_evm::<T>)?;222223		Ok(true)224	}225226	#[solidity(rename_selector = "mintWithTokenURI")]227	fn mint_with_token_uri(228		&mut self,229		caller: caller,230		to: address,231		token_id: uint256,232		token_uri: string,233	) -> Result<bool> {234		let caller = T::CrossAccountId::from_eth(caller);235		let to = T::CrossAccountId::from_eth(to);236		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;237		if <TokensMinted<T>>::get(self.id)238			.checked_add(1)239			.ok_or("item id overflow")?240			!= token_id241		{242			return Err("item id should be next".into());243		}244245		<Pallet<T>>::create_item(246			self,247			&caller,248			CreateItemData {249				const_data: Vec::<u8>::from(token_uri)250					.try_into()251					.map_err(|_| "token uri is too long")?,252				variable_data: BoundedVec::default(),253				owner: to,254			},255		)256		.map_err(dispatch_to_evm::<T>)?;257		Ok(true)258	}259260	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {261		Err("not implementable".into())262	}263}264265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {267	fn transfer(268		&mut self,269		caller: caller,270		to: address,271		token_id: uint256,272		_value: value,273	) -> Result<void> {274		let caller = T::CrossAccountId::from_eth(caller);275		let to = T::CrossAccountId::from_eth(to);276		let token = token_id.try_into()?;277278		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;279		Ok(())280	}281282	fn burn_from(283		&mut self,284		caller: caller,285		from: address,286		token_id: uint256,287		_value: value,288	) -> Result<void> {289		let caller = T::CrossAccountId::from_eth(caller);290		let from = T::CrossAccountId::from_eth(from);291		let token = token_id.try_into()?;292293		<Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;294		Ok(())295	}296297	fn next_token_id(&self) -> Result<uint256> {298		Ok(<TokensMinted<T>>::get(self.id)299			.checked_add(1)300			.ok_or("item id overflow")?301			.into())302	}303304	fn set_variable_metadata(305		&mut self,306		caller: caller,307		token_id: uint256,308		data: bytes,309	) -> Result<void> {310		let caller = T::CrossAccountId::from_eth(caller);311		let token = token_id.try_into()?;312313		<Pallet<T>>::set_variable_metadata(self, &caller, token, data)314			.map_err(dispatch_to_evm::<T>)?;315		Ok(())316	}317318	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {319		let token: TokenId = token_id.try_into()?;320321		Ok(<TokenData<T>>::get((self.id, token))322			.ok_or("token not found")?323			.variable_data)324	}325326	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {327		let caller = T::CrossAccountId::from_eth(caller);328		let to = T::CrossAccountId::from_eth(to);329		let mut expected_index = <TokensMinted<T>>::get(self.id)330			.checked_add(1)331			.ok_or("item id overflow")?;332333		let total_tokens = token_ids.len();334		for id in token_ids.into_iter() {335			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;336			if id != expected_index {337				return Err("item id should be next".into());338			}339			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;340		}341		let data = (0..total_tokens)342			.map(|_| CreateItemData {343				const_data: BoundedVec::default(),344				variable_data: BoundedVec::default(),345				owner: to.clone(),346			})347			.collect();348349		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;350		Ok(true)351	}352353	#[solidity(rename_selector = "mintBulkWithTokenURI")]354	fn mint_bulk_with_token_uri(355		&mut self,356		caller: caller,357		to: address,358		tokens: Vec<(uint256, string)>,359	) -> Result<bool> {360		let caller = T::CrossAccountId::from_eth(caller);361		let to = T::CrossAccountId::from_eth(to);362		let mut expected_index = <TokensMinted<T>>::get(self.id)363			.checked_add(1)364			.ok_or("item id overflow")?;365366		let mut data = Vec::with_capacity(tokens.len());367		for (id, token_uri) in tokens {368			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;369			if id != expected_index {370				panic!("item id should be next ({}) but got {}", expected_index, id);371			}372			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;373374			data.push(CreateItemData {375				const_data: Vec::<u8>::from(token_uri)376					.try_into()377					.map_err(|_| "token uri is too long")?,378				variable_data: vec![].try_into().unwrap(),379				owner: to.clone(),380			});381		}382383		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;384		Ok(true)385	}386}387388#[solidity_interface(389	name = "UniqueNFT",390	is(391		ERC721,392		ERC721Metadata,393		ERC721Enumerable,394		ERC721UniqueExtensions,395		ERC721Mintable,396		ERC721Burnable,397	)398)]399impl<T: Config> NonfungibleHandle<T> {}400401// Not a tests, but code generators402generate_stubgen!(gen_impl, UniqueNFTCall, true);403generate_stubgen!(gen_iface, UniqueNFTCall, false);404405pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");406407impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {408	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");409410	fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {411		let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);412		self.0.recorder.evm_to_precompile_output(result)413	}414}
after · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21	Transfer {22		#[indexed]23		from: address,24		#[indexed]25		to: address,26		#[indexed]27		token_id: uint256,28	},29	Approval {30		#[indexed]31		owner: address,32		#[indexed]33		approved: address,34		#[indexed]35		token_id: uint256,36	},37	#[allow(dead_code)]38	ApprovalForAll {39		#[indexed]40		owner: address,41		#[indexed]42		operator: address,43		approved: bool,44	},45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49	#[allow(dead_code)]50	MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55	fn name(&self) -> Result<string> {56		Ok(decode_utf16(self.name.iter().copied())57			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58			.collect::<string>())59	}60	fn symbol(&self) -> Result<string> {61		Ok(string::from_utf8_lossy(&self.token_prefix).into())62	}6364	/// Returns token's const_metadata65	#[solidity(rename_selector = "tokenURI")]66	fn token_uri(&self, token_id: uint256) -> Result<string> {67		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;68		Ok(string::from_utf8_lossy(69			&<TokenData<T>>::get((self.id, token_id))70				.ok_or("token not found")?71				.const_data,72		)73		.into())74	}75}7677#[solidity_interface(name = "ERC721Enumerable")]78impl<T: Config> NonfungibleHandle<T> {79	fn token_by_index(&self, index: uint256) -> Result<uint256> {80		Ok(index)81	}8283	/// Not implemented84	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {85		// TODO: Not implemetable86		Err("not implemented".into())87	}8889	fn total_supply(&self) -> Result<uint256> {90		Ok(<Pallet<T>>::total_supply(self).into())91	}92}9394#[solidity_interface(name = "ERC721", events(ERC721Events))]95impl<T: Config> NonfungibleHandle<T> {96	fn balance_of(&self, owner: address) -> Result<uint256> {97		let owner = T::CrossAccountId::from_eth(owner);98		let balance = <AccountBalance<T>>::get((self.id, owner));99		Ok(balance.into())100	}101	fn owner_of(&self, token_id: uint256) -> Result<address> {102		let token: TokenId = token_id.try_into()?;103		Ok(*<TokenData<T>>::get((self.id, token))104			.ok_or("token not found")?105			.owner106			.as_eth())107	}108	/// Not implemented109	fn safe_transfer_from_with_data(110		&mut self,111		_from: address,112		_to: address,113		_token_id: uint256,114		_data: bytes,115		_value: value,116	) -> Result<void> {117		// TODO: Not implemetable118		Err("not implemented".into())119	}120	/// Not implemented121	fn safe_transfer_from(122		&mut self,123		_from: address,124		_to: address,125		_token_id: uint256,126		_value: value,127	) -> Result<void> {128		// TODO: Not implemetable129		Err("not implemented".into())130	}131132	fn transfer_from(133		&mut self,134		caller: caller,135		from: address,136		to: address,137		token_id: uint256,138		_value: value,139	) -> Result<void> {140		let caller = T::CrossAccountId::from_eth(caller);141		let from = T::CrossAccountId::from_eth(from);142		let to = T::CrossAccountId::from_eth(to);143		let token = token_id.try_into()?;144145		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)146			.map_err(dispatch_to_evm::<T>)?;147		Ok(())148	}149150	fn approve(151		&mut self,152		caller: caller,153		approved: address,154		token_id: uint256,155		_value: value,156	) -> Result<void> {157		let caller = T::CrossAccountId::from_eth(caller);158		let approved = T::CrossAccountId::from_eth(approved);159		let token = token_id.try_into()?;160161		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))162			.map_err(dispatch_to_evm::<T>)?;163		Ok(())164	}165166	/// Not implemented167	fn set_approval_for_all(168		&mut self,169		_caller: caller,170		_operator: address,171		_approved: bool,172	) -> Result<void> {173		// TODO: Not implemetable174		Err("not implemented".into())175	}176177	/// Not implemented178	fn get_approved(&self, _token_id: uint256) -> Result<address> {179		// TODO: Not implemetable180		Err("not implemented".into())181	}182183	/// Not implemented184	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {185		// TODO: Not implemetable186		Err("not implemented".into())187	}188}189190#[solidity_interface(name = "ERC721Burnable")]191impl<T: Config> NonfungibleHandle<T> {192	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {193		let caller = T::CrossAccountId::from_eth(caller);194		let token = token_id.try_into()?;195196		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;197		Ok(())198	}199}200201#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]202impl<T: Config> NonfungibleHandle<T> {203	fn minting_finished(&self) -> Result<bool> {204		Ok(false)205	}206207	/// `token_id` should be obtained with `next_token_id` method,208	/// unlike standard, you can't specify it manually209	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {210		let caller = T::CrossAccountId::from_eth(caller);211		let to = T::CrossAccountId::from_eth(to);212		let token_id: u32 = token_id.try_into()?;213		if <TokensMinted<T>>::get(self.id)214			.checked_add(1)215			.ok_or("item id overflow")?216			!= token_id217		{218			return Err("item id should be next".into());219		}220221		<Pallet<T>>::create_item(222			self,223			&caller,224			CreateItemData {225				const_data: BoundedVec::default(),226				variable_data: BoundedVec::default(),227				owner: to,228			},229		)230		.map_err(dispatch_to_evm::<T>)?;231232		Ok(true)233	}234235	/// `token_id` should be obtained with `next_token_id` method,236	/// unlike standard, you can't specify it manually237	#[solidity(rename_selector = "mintWithTokenURI")]238	fn mint_with_token_uri(239		&mut self,240		caller: caller,241		to: address,242		token_id: uint256,243		token_uri: string,244	) -> Result<bool> {245		let caller = T::CrossAccountId::from_eth(caller);246		let to = T::CrossAccountId::from_eth(to);247		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;248		if <TokensMinted<T>>::get(self.id)249			.checked_add(1)250			.ok_or("item id overflow")?251			!= token_id252		{253			return Err("item id should be next".into());254		}255256		<Pallet<T>>::create_item(257			self,258			&caller,259			CreateItemData {260				const_data: Vec::<u8>::from(token_uri)261					.try_into()262					.map_err(|_| "token uri is too long")?,263				variable_data: BoundedVec::default(),264				owner: to,265			},266		)267		.map_err(dispatch_to_evm::<T>)?;268		Ok(true)269	}270271	/// Not implemented272	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {273		Err("not implementable".into())274	}275}276277#[solidity_interface(name = "ERC721UniqueExtensions")]278impl<T: Config> NonfungibleHandle<T> {279	fn transfer(280		&mut self,281		caller: caller,282		to: address,283		token_id: uint256,284		_value: value,285	) -> Result<void> {286		let caller = T::CrossAccountId::from_eth(caller);287		let to = T::CrossAccountId::from_eth(to);288		let token = token_id.try_into()?;289290		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;291		Ok(())292	}293294	fn burn_from(295		&mut self,296		caller: caller,297		from: address,298		token_id: uint256,299		_value: value,300	) -> Result<void> {301		let caller = T::CrossAccountId::from_eth(caller);302		let from = T::CrossAccountId::from_eth(from);303		let token = token_id.try_into()?;304305		<Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;306		Ok(())307	}308309	fn next_token_id(&self) -> Result<uint256> {310		Ok(<TokensMinted<T>>::get(self.id)311			.checked_add(1)312			.ok_or("item id overflow")?313			.into())314	}315316	fn set_variable_metadata(317		&mut self,318		caller: caller,319		token_id: uint256,320		data: bytes,321	) -> Result<void> {322		let caller = T::CrossAccountId::from_eth(caller);323		let token = token_id.try_into()?;324325		<Pallet<T>>::set_variable_metadata(self, &caller, token, data)326			.map_err(dispatch_to_evm::<T>)?;327		Ok(())328	}329330	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {331		let token: TokenId = token_id.try_into()?;332333		Ok(<TokenData<T>>::get((self.id, token))334			.ok_or("token not found")?335			.variable_data)336	}337338	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {339		let caller = T::CrossAccountId::from_eth(caller);340		let to = T::CrossAccountId::from_eth(to);341		let mut expected_index = <TokensMinted<T>>::get(self.id)342			.checked_add(1)343			.ok_or("item id overflow")?;344345		let total_tokens = token_ids.len();346		for id in token_ids.into_iter() {347			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;348			if id != expected_index {349				return Err("item id should be next".into());350			}351			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;352		}353		let data = (0..total_tokens)354			.map(|_| CreateItemData {355				const_data: BoundedVec::default(),356				variable_data: BoundedVec::default(),357				owner: to.clone(),358			})359			.collect();360361		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;362		Ok(true)363	}364365	#[solidity(rename_selector = "mintBulkWithTokenURI")]366	fn mint_bulk_with_token_uri(367		&mut self,368		caller: caller,369		to: address,370		tokens: Vec<(uint256, string)>,371	) -> Result<bool> {372		let caller = T::CrossAccountId::from_eth(caller);373		let to = T::CrossAccountId::from_eth(to);374		let mut expected_index = <TokensMinted<T>>::get(self.id)375			.checked_add(1)376			.ok_or("item id overflow")?;377378		let mut data = Vec::with_capacity(tokens.len());379		for (id, token_uri) in tokens {380			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;381			if id != expected_index {382				panic!("item id should be next ({}) but got {}", expected_index, id);383			}384			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;385386			data.push(CreateItemData {387				const_data: Vec::<u8>::from(token_uri)388					.try_into()389					.map_err(|_| "token uri is too long")?,390				variable_data: vec![].try_into().unwrap(),391				owner: to.clone(),392			});393		}394395		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;396		Ok(true)397	}398}399400#[solidity_interface(401	name = "UniqueNFT",402	is(403		ERC721,404		ERC721Metadata,405		ERC721Enumerable,406		ERC721UniqueExtensions,407		ERC721Mintable,408		ERC721Burnable,409	)410)]411impl<T: Config> NonfungibleHandle<T> {}412413// Not a tests, but code generators414generate_stubgen!(gen_impl, UniqueNFTCall, true);415generate_stubgen!(gen_iface, UniqueNFTCall, false);416417pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");418419impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {420	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");421422	fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {423		let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);424		self.0.recorder.evm_to_precompile_output(result)425	}426}
modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -51,6 +51,17 @@
 	event MintingFinished();
 }
 
+// Selector: 42966c68
+contract ERC721Burnable is Dummy, ERC165 {
+	// Selector: burn(uint256) 42966c68
+	function burn(uint256 tokenId) public {
+		require(false, stub_error);
+		tokenId;
+		dummy = 0;
+	}
+}
+
+// Selector: 58800161
 contract ERC721 is Dummy, ERC165, ERC721Events {
 	// Selector: balanceOf(address) 70a08231
 	function balanceOf(address owner) public view returns (uint256) {
@@ -68,6 +79,8 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
+	// Not implemented
+	//
 	// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
 	function safeTransferFromWithData(
 		address from,
@@ -83,6 +96,8 @@
 		dummy = 0;
 	}
 
+	// Not implemented
+	//
 	// Selector: safeTransferFrom(address,address,uint256) 42842e0e
 	function safeTransferFrom(
 		address from,
@@ -117,6 +132,8 @@
 		dummy = 0;
 	}
 
+	// Not implemented
+	//
 	// Selector: setApprovalForAll(address,bool) a22cb465
 	function setApprovalForAll(address operator, bool approved) public {
 		require(false, stub_error);
@@ -125,6 +142,8 @@
 		dummy = 0;
 	}
 
+	// Not implemented
+	//
 	// Selector: getApproved(uint256) 081812fc
 	function getApproved(uint256 tokenId) public view returns (address) {
 		require(false, stub_error);
@@ -133,6 +152,8 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
+	// Not implemented
+	//
 	// Selector: isApprovedForAll(address,address) e985e9c5
 	function isApprovedForAll(address owner, address operator)
 		public
@@ -147,45 +168,7 @@
 	}
 }
 
-contract ERC721Burnable is Dummy, ERC165 {
-	// Selector: burn(uint256) 42966c68
-	function burn(uint256 tokenId) public {
-		require(false, stub_error);
-		tokenId;
-		dummy = 0;
-	}
-}
-
-contract ERC721Enumerable is Dummy, ERC165 {
-	// Selector: tokenByIndex(uint256) 4f6ccce7
-	function tokenByIndex(uint256 index) public view returns (uint256) {
-		require(false, stub_error);
-		index;
-		dummy;
-		return 0;
-	}
-
-	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
-	function tokenOfOwnerByIndex(address owner, uint256 index)
-		public
-		view
-		returns (uint256)
-	{
-		require(false, stub_error);
-		owner;
-		index;
-		dummy;
-		return 0;
-	}
-
-	// Selector: totalSupply() 18160ddd
-	function totalSupply() public view returns (uint256) {
-		require(false, stub_error);
-		dummy;
-		return 0;
-	}
-}
-
+// Selector: 5b5e139f
 contract ERC721Metadata is Dummy, ERC165 {
 	// Selector: name() 06fdde03
 	function name() public view returns (string memory) {
@@ -201,6 +184,8 @@
 		return "";
 	}
 
+	// Returns token's const_metadata
+	//
 	// Selector: tokenURI(uint256) c87b56dd
 	function tokenURI(uint256 tokenId) public view returns (string memory) {
 		require(false, stub_error);
@@ -210,6 +195,7 @@
 	}
 }
 
+// Selector: 68ccfe89
 contract ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {
 	// Selector: mintingFinished() 05d2035b
 	function mintingFinished() public view returns (bool) {
@@ -218,6 +204,9 @@
 		return false;
 	}
 
+	// `token_id` should be obtained with `next_token_id` method,
+	// unlike standard, you can't specify it manually
+	//
 	// Selector: mint(address,uint256) 40c10f19
 	function mint(address to, uint256 tokenId) public returns (bool) {
 		require(false, stub_error);
@@ -227,6 +216,9 @@
 		return false;
 	}
 
+	// `token_id` should be obtained with `next_token_id` method,
+	// unlike standard, you can't specify it manually
+	//
 	// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
 	function mintWithTokenURI(
 		address to,
@@ -241,6 +233,8 @@
 		return false;
 	}
 
+	// Not implemented
+	//
 	// Selector: finishMinting() 7d64bcb4
 	function finishMinting() public returns (bool) {
 		require(false, stub_error);
@@ -249,6 +243,40 @@
 	}
 }
 
+// Selector: 780e9d63
+contract ERC721Enumerable is Dummy, ERC165 {
+	// Selector: tokenByIndex(uint256) 4f6ccce7
+	function tokenByIndex(uint256 index) public view returns (uint256) {
+		require(false, stub_error);
+		index;
+		dummy;
+		return 0;
+	}
+
+	// Not implemented
+	//
+	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
+	function tokenOfOwnerByIndex(address owner, uint256 index)
+		public
+		view
+		returns (uint256)
+	{
+		require(false, stub_error);
+		owner;
+		index;
+		dummy;
+		return 0;
+	}
+
+	// Selector: totalSupply() 18160ddd
+	function totalSupply() public view returns (uint256) {
+		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+}
+
+// Selector: e562194d
 contract ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
 	function transfer(address to, uint256 tokenId) public {
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -12,6 +12,7 @@
 	function supportsInterface(bytes4 interfaceID) external view returns (bool);
 }
 
+// Selector: 31acb1fe
 interface ContractHelpers is Dummy, ERC165 {
 	// Selector: contractOwner(address) 5152b14c
 	function contractOwner(address contractAddress)
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -22,6 +22,7 @@
 	);
 }
 
+// Selector: 942e8b22
 interface ERC20 is Dummy, ERC165, ERC20Events {
 	// Selector: name() 06fdde03
 	function name() external view returns (string memory);
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,6 +42,13 @@
 	event MintingFinished();
 }
 
+// Selector: 42966c68
+interface ERC721Burnable is Dummy, ERC165 {
+	// Selector: burn(uint256) 42966c68
+	function burn(uint256 tokenId) external;
+}
+
+// Selector: 58800161
 interface ERC721 is Dummy, ERC165, ERC721Events {
 	// Selector: balanceOf(address) 70a08231
 	function balanceOf(address owner) external view returns (uint256);
@@ -49,6 +56,8 @@
 	// Selector: ownerOf(uint256) 6352211e
 	function ownerOf(uint256 tokenId) external view returns (address);
 
+	// Not implemented
+	//
 	// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
 	function safeTransferFromWithData(
 		address from,
@@ -57,6 +66,8 @@
 		bytes memory data
 	) external;
 
+	// Not implemented
+	//
 	// Selector: safeTransferFrom(address,address,uint256) 42842e0e
 	function safeTransferFrom(
 		address from,
@@ -74,12 +85,18 @@
 	// Selector: approve(address,uint256) 095ea7b3
 	function approve(address approved, uint256 tokenId) external;
 
+	// Not implemented
+	//
 	// Selector: setApprovalForAll(address,bool) a22cb465
 	function setApprovalForAll(address operator, bool approved) external;
 
+	// Not implemented
+	//
 	// Selector: getApproved(uint256) 081812fc
 	function getApproved(uint256 tokenId) external view returns (address);
 
+	// Not implemented
+	//
 	// Selector: isApprovedForAll(address,address) e985e9c5
 	function isApprovedForAll(address owner, address operator)
 		external
@@ -87,25 +104,7 @@
 		returns (address);
 }
 
-interface ERC721Burnable is Dummy, ERC165 {
-	// Selector: burn(uint256) 42966c68
-	function burn(uint256 tokenId) external;
-}
-
-interface ERC721Enumerable is Dummy, ERC165 {
-	// Selector: tokenByIndex(uint256) 4f6ccce7
-	function tokenByIndex(uint256 index) external view returns (uint256);
-
-	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
-	function tokenOfOwnerByIndex(address owner, uint256 index)
-		external
-		view
-		returns (uint256);
-
-	// Selector: totalSupply() 18160ddd
-	function totalSupply() external view returns (uint256);
-}
-
+// Selector: 5b5e139f
 interface ERC721Metadata is Dummy, ERC165 {
 	// Selector: name() 06fdde03
 	function name() external view returns (string memory);
@@ -113,17 +112,26 @@
 	// Selector: symbol() 95d89b41
 	function symbol() external view returns (string memory);
 
+	// Returns token's const_metadata
+	//
 	// Selector: tokenURI(uint256) c87b56dd
 	function tokenURI(uint256 tokenId) external view returns (string memory);
 }
 
+// Selector: 68ccfe89
 interface ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {
 	// Selector: mintingFinished() 05d2035b
 	function mintingFinished() external view returns (bool);
 
+	// `token_id` should be obtained with `next_token_id` method,
+	// unlike standard, you can't specify it manually
+	//
 	// Selector: mint(address,uint256) 40c10f19
 	function mint(address to, uint256 tokenId) external returns (bool);
 
+	// `token_id` should be obtained with `next_token_id` method,
+	// unlike standard, you can't specify it manually
+	//
 	// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
 	function mintWithTokenURI(
 		address to,
@@ -131,10 +139,30 @@
 		string memory tokenUri
 	) external returns (bool);
 
+	// Not implemented
+	//
 	// Selector: finishMinting() 7d64bcb4
 	function finishMinting() external returns (bool);
 }
 
+// Selector: 780e9d63
+interface ERC721Enumerable is Dummy, ERC165 {
+	// Selector: tokenByIndex(uint256) 4f6ccce7
+	function tokenByIndex(uint256 index) external view returns (uint256);
+
+	// Not implemented
+	//
+	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
+	function tokenOfOwnerByIndex(address owner, uint256 index)
+		external
+		view
+		returns (uint256);
+
+	// Selector: totalSupply() 18160ddd
+	function totalSupply() external view returns (uint256);
+}
+
+// Selector: e562194d
 interface ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
 	function transfer(address to, uint256 tokenId) external;