git.delta.rocks / unique-network / refs/commits / c4af3bbf1360

difftreelog

Merge pull request #442 from UniqueNetwork/doc/nonfungible-pallet

Yaroslav Bolyukin2022-07-21parents: #3750ef0 #4bd95ca.patch.diff
in: master

6 files changed

modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -133,6 +133,8 @@
 	}
 }
 
+/// Implementation of `CommonCollectionOperations` for `NonfungibleHandle`. It wraps Nonfungible Pallete
+/// methods and adds weight info.
 impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {
 	fn create_item(
 		&self,
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
before · pallets/nonfungible/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/>.1617extern crate alloc;18use core::{19	char::{REPLACEMENT_CHARACTER, decode_utf16},20	convert::TryInto,21};22use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};23use frame_support::BoundedVec;24use up_data_structs::{25	TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,26	CollectionPropertiesVec,27};28use pallet_evm_coder_substrate::dispatch_to_evm;29use sp_std::vec::Vec;30use pallet_common::{31	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, token_uri_key},32	CollectionHandle, CollectionPropertyPermissions,33};34use pallet_evm::{account::CrossAccountId, PrecompileHandle};35use pallet_evm_coder_substrate::call;36use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};3738use crate::{39	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,40	SelfWeightOf, weights::WeightInfo, TokenProperties,41};4243#[solidity_interface(name = "TokenProperties")]44impl<T: Config> NonfungibleHandle<T> {45	fn set_token_property_permission(46		&mut self,47		caller: caller,48		key: string,49		is_mutable: bool,50		collection_admin: bool,51		token_owner: bool,52	) -> Result<()> {53		let caller = T::CrossAccountId::from_eth(caller);54		<Pallet<T>>::set_property_permission(55			self,56			&caller,57			PropertyKeyPermission {58				key: <Vec<u8>>::from(key)59					.try_into()60					.map_err(|_| "too long key")?,61				permission: PropertyPermission {62					mutable: is_mutable,63					collection_admin,64					token_owner,65				},66			},67		)68		.map_err(dispatch_to_evm::<T>)69	}7071	fn set_property(72		&mut self,73		caller: caller,74		token_id: uint256,75		key: string,76		value: bytes,77	) -> Result<()> {78		let caller = T::CrossAccountId::from_eth(caller);79		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;80		let key = <Vec<u8>>::from(key)81			.try_into()82			.map_err(|_| "key too long")?;83		let value = value.try_into().map_err(|_| "value too long")?;8485		let nesting_budget = self86			.recorder87			.weight_calls_budget(<StructureWeight<T>>::find_parent());8889		<Pallet<T>>::set_token_property(90			self,91			&caller,92			TokenId(token_id),93			Property { key, value },94			&nesting_budget,95		)96		.map_err(dispatch_to_evm::<T>)97	}9899	fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {100		let caller = T::CrossAccountId::from_eth(caller);101		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;102		let key = <Vec<u8>>::from(key)103			.try_into()104			.map_err(|_| "key too long")?;105106		let nesting_budget = self107			.recorder108			.weight_calls_budget(<StructureWeight<T>>::find_parent());109110		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)111			.map_err(dispatch_to_evm::<T>)112	}113114	/// Throws error if key not found115	fn property(&self, token_id: uint256, key: string) -> Result<bytes> {116		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;117		let key = <Vec<u8>>::from(key)118			.try_into()119			.map_err(|_| "key too long")?;120121		let props = <TokenProperties<T>>::get((self.id, token_id));122		let prop = props.get(&key).ok_or("key not found")?;123124		Ok(prop.to_vec())125	}126}127128#[derive(ToLog)]129pub enum ERC721Events {130	Transfer {131		#[indexed]132		from: address,133		#[indexed]134		to: address,135		#[indexed]136		token_id: uint256,137	},138	Approval {139		#[indexed]140		owner: address,141		#[indexed]142		approved: address,143		#[indexed]144		token_id: uint256,145	},146	#[allow(dead_code)]147	ApprovalForAll {148		#[indexed]149		owner: address,150		#[indexed]151		operator: address,152		approved: bool,153	},154}155156#[derive(ToLog)]157pub enum ERC721MintableEvents {158	#[allow(dead_code)]159	MintingFinished {},160}161162#[solidity_interface(name = "ERC721Metadata")]163impl<T: Config> NonfungibleHandle<T> {164	fn name(&self) -> Result<string> {165		Ok(decode_utf16(self.name.iter().copied())166			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))167			.collect::<string>())168	}169170	fn symbol(&self) -> Result<string> {171		Ok(string::from_utf8_lossy(&self.token_prefix).into())172	}173174	/// Returns token's const_metadata175	#[solidity(rename_selector = "tokenURI")]176	fn token_uri(&self, token_id: uint256) -> Result<string> {177		let key = token_uri_key();178		if !has_token_permission::<T>(self.id, &key) {179			return Err("No tokenURI permission".into());180		}181182		self.consume_store_reads(1)?;183		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;184185		let properties = <TokenProperties<T>>::try_get((self.id, token_id))186			.map_err(|_| Error::Revert("Token properties not found".into()))?;187		if let Some(property) = properties.get(&key) {188			return Ok(string::from_utf8_lossy(property).into());189		}190191		Err("Property tokenURI not found".into())192	}193}194195#[solidity_interface(name = "ERC721Enumerable")]196impl<T: Config> NonfungibleHandle<T> {197	fn token_by_index(&self, index: uint256) -> Result<uint256> {198		Ok(index)199	}200201	/// Not implemented202	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {203		// TODO: Not implemetable204		Err("not implemented".into())205	}206207	fn total_supply(&self) -> Result<uint256> {208		self.consume_store_reads(1)?;209		Ok(<Pallet<T>>::total_supply(self).into())210	}211}212213#[solidity_interface(name = "ERC721", events(ERC721Events))]214impl<T: Config> NonfungibleHandle<T> {215	fn balance_of(&self, owner: address) -> Result<uint256> {216		self.consume_store_reads(1)?;217		let owner = T::CrossAccountId::from_eth(owner);218		let balance = <AccountBalance<T>>::get((self.id, owner));219		Ok(balance.into())220	}221	fn owner_of(&self, token_id: uint256) -> Result<address> {222		self.consume_store_reads(1)?;223		let token: TokenId = token_id.try_into()?;224		Ok(*<TokenData<T>>::get((self.id, token))225			.ok_or("token not found")?226			.owner227			.as_eth())228	}229	/// Not implemented230	fn safe_transfer_from_with_data(231		&mut self,232		_from: address,233		_to: address,234		_token_id: uint256,235		_data: bytes,236		_value: value,237	) -> Result<void> {238		// TODO: Not implemetable239		Err("not implemented".into())240	}241	/// Not implemented242	fn safe_transfer_from(243		&mut self,244		_from: address,245		_to: address,246		_token_id: uint256,247		_value: value,248	) -> Result<void> {249		// TODO: Not implemetable250		Err("not implemented".into())251	}252253	#[weight(<SelfWeightOf<T>>::transfer_from())]254	fn transfer_from(255		&mut self,256		caller: caller,257		from: address,258		to: address,259		token_id: uint256,260		_value: value,261	) -> Result<void> {262		let caller = T::CrossAccountId::from_eth(caller);263		let from = T::CrossAccountId::from_eth(from);264		let to = T::CrossAccountId::from_eth(to);265		let token = token_id.try_into()?;266		let budget = self267			.recorder268			.weight_calls_budget(<StructureWeight<T>>::find_parent());269270		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)271			.map_err(dispatch_to_evm::<T>)?;272		Ok(())273	}274275	#[weight(<SelfWeightOf<T>>::approve())]276	fn approve(277		&mut self,278		caller: caller,279		approved: address,280		token_id: uint256,281		_value: value,282	) -> Result<void> {283		let caller = T::CrossAccountId::from_eth(caller);284		let approved = T::CrossAccountId::from_eth(approved);285		let token = token_id.try_into()?;286287		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))288			.map_err(dispatch_to_evm::<T>)?;289		Ok(())290	}291292	/// Not implemented293	fn set_approval_for_all(294		&mut self,295		_caller: caller,296		_operator: address,297		_approved: bool,298	) -> Result<void> {299		// TODO: Not implemetable300		Err("not implemented".into())301	}302303	/// Not implemented304	fn get_approved(&self, _token_id: uint256) -> Result<address> {305		// TODO: Not implemetable306		Err("not implemented".into())307	}308309	/// Not implemented310	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {311		// TODO: Not implemetable312		Err("not implemented".into())313	}314}315316#[solidity_interface(name = "ERC721Burnable")]317impl<T: Config> NonfungibleHandle<T> {318	#[weight(<SelfWeightOf<T>>::burn_item())]319	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {320		let caller = T::CrossAccountId::from_eth(caller);321		let token = token_id.try_into()?;322323		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;324		Ok(())325	}326}327328#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]329impl<T: Config> NonfungibleHandle<T> {330	fn minting_finished(&self) -> Result<bool> {331		Ok(false)332	}333334	/// `token_id` should be obtained with `next_token_id` method,335	/// unlike standard, you can't specify it manually336	#[weight(<SelfWeightOf<T>>::create_item())]337	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {338		let caller = T::CrossAccountId::from_eth(caller);339		let to = T::CrossAccountId::from_eth(to);340		let token_id: u32 = token_id.try_into()?;341		let budget = self342			.recorder343			.weight_calls_budget(<StructureWeight<T>>::find_parent());344345		if <TokensMinted<T>>::get(self.id)346			.checked_add(1)347			.ok_or("item id overflow")?348			!= token_id349		{350			return Err("item id should be next".into());351		}352353		<Pallet<T>>::create_item(354			self,355			&caller,356			CreateItemData::<T> {357				properties: BoundedVec::default(),358				owner: to,359			},360			&budget,361		)362		.map_err(dispatch_to_evm::<T>)?;363364		Ok(true)365	}366367	/// `token_id` should be obtained with `next_token_id` method,368	/// unlike standard, you can't specify it manually369	#[solidity(rename_selector = "mintWithTokenURI")]370	#[weight(<SelfWeightOf<T>>::create_item())]371	fn mint_with_token_uri(372		&mut self,373		caller: caller,374		to: address,375		token_id: uint256,376		token_uri: string,377	) -> Result<bool> {378		let key = token_uri_key();379		let permission = get_token_permission::<T>(self.id, &key)?;380		if !permission.collection_admin {381			return Err("Operation is not allowed".into());382		}383384		let caller = T::CrossAccountId::from_eth(caller);385		let to = T::CrossAccountId::from_eth(to);386		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;387		let budget = self388			.recorder389			.weight_calls_budget(<StructureWeight<T>>::find_parent());390391		if <TokensMinted<T>>::get(self.id)392			.checked_add(1)393			.ok_or("item id overflow")?394			!= token_id395		{396			return Err("item id should be next".into());397		}398399		let mut properties = CollectionPropertiesVec::default();400		properties401			.try_push(Property {402				key,403				value: token_uri404					.into_bytes()405					.try_into()406					.map_err(|_| "token uri is too long")?,407			})408			.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;409410		<Pallet<T>>::create_item(411			self,412			&caller,413			CreateItemData::<T> {414				properties,415				owner: to,416			},417			&budget,418		)419		.map_err(dispatch_to_evm::<T>)?;420		Ok(true)421	}422423	/// Not implemented424	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {425		Err("not implementable".into())426	}427}428429fn get_token_permission<T: Config>(430	collection_id: CollectionId,431	key: &PropertyKey,432) -> Result<PropertyPermission> {433	let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)434		.map_err(|_| Error::Revert("No permissions for collection".into()))?;435	let a = token_property_permissions436		.get(key)437		.map(|p| p.clone())438		.ok_or_else(|| Error::Revert("No permission".into()))?;439	Ok(a)440}441442fn has_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> bool {443	if let Ok(token_property_permissions) =444		CollectionPropertyPermissions::<T>::try_get(collection_id)445	{446		return token_property_permissions.contains_key(key);447	}448449	false450}451452#[solidity_interface(name = "ERC721UniqueExtensions")]453impl<T: Config> NonfungibleHandle<T> {454	#[weight(<SelfWeightOf<T>>::transfer())]455	fn transfer(456		&mut self,457		caller: caller,458		to: address,459		token_id: uint256,460		_value: value,461	) -> Result<void> {462		let caller = T::CrossAccountId::from_eth(caller);463		let to = T::CrossAccountId::from_eth(to);464		let token = token_id.try_into()?;465		let budget = self466			.recorder467			.weight_calls_budget(<StructureWeight<T>>::find_parent());468469		<Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;470		Ok(())471	}472473	#[weight(<SelfWeightOf<T>>::burn_from())]474	fn burn_from(475		&mut self,476		caller: caller,477		from: address,478		token_id: uint256,479		_value: value,480	) -> Result<void> {481		let caller = T::CrossAccountId::from_eth(caller);482		let from = T::CrossAccountId::from_eth(from);483		let token = token_id.try_into()?;484		let budget = self485			.recorder486			.weight_calls_budget(<StructureWeight<T>>::find_parent());487488		<Pallet<T>>::burn_from(self, &caller, &from, token, &budget)489			.map_err(dispatch_to_evm::<T>)?;490		Ok(())491	}492493	fn next_token_id(&self) -> Result<uint256> {494		self.consume_store_reads(1)?;495		Ok(<TokensMinted<T>>::get(self.id)496			.checked_add(1)497			.ok_or("item id overflow")?498			.into())499	}500501	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]502	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {503		let caller = T::CrossAccountId::from_eth(caller);504		let to = T::CrossAccountId::from_eth(to);505		let mut expected_index = <TokensMinted<T>>::get(self.id)506			.checked_add(1)507			.ok_or("item id overflow")?;508		let budget = self509			.recorder510			.weight_calls_budget(<StructureWeight<T>>::find_parent());511512		let total_tokens = token_ids.len();513		for id in token_ids.into_iter() {514			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;515			if id != expected_index {516				return Err("item id should be next".into());517			}518			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;519		}520		let data = (0..total_tokens)521			.map(|_| CreateItemData::<T> {522				properties: BoundedVec::default(),523				owner: to.clone(),524			})525			.collect();526527		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)528			.map_err(dispatch_to_evm::<T>)?;529		Ok(true)530	}531532	#[solidity(rename_selector = "mintBulkWithTokenURI")]533	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]534	fn mint_bulk_with_token_uri(535		&mut self,536		caller: caller,537		to: address,538		tokens: Vec<(uint256, string)>,539	) -> Result<bool> {540		let key = token_uri_key();541		let caller = T::CrossAccountId::from_eth(caller);542		let to = T::CrossAccountId::from_eth(to);543		let mut expected_index = <TokensMinted<T>>::get(self.id)544			.checked_add(1)545			.ok_or("item id overflow")?;546		let budget = self547			.recorder548			.weight_calls_budget(<StructureWeight<T>>::find_parent());549550		let mut data = Vec::with_capacity(tokens.len());551		for (id, token_uri) in tokens {552			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;553			if id != expected_index {554				return Err("item id should be next".into());555			}556			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;557558			let mut properties = CollectionPropertiesVec::default();559			properties560				.try_push(Property {561					key: key.clone(),562					value: token_uri563						.into_bytes()564						.try_into()565						.map_err(|_| "token uri is too long")?,566				})567				.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;568569			data.push(CreateItemData::<T> {570				properties,571				owner: to.clone(),572			});573		}574575		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)576			.map_err(dispatch_to_evm::<T>)?;577		Ok(true)578	}579}580581#[solidity_interface(582	name = "UniqueNFT",583	is(584		ERC721,585		ERC721Metadata,586		ERC721Enumerable,587		ERC721UniqueExtensions,588		ERC721Mintable,589		ERC721Burnable,590		via("CollectionHandle<T>", common_mut, Collection),591		TokenProperties,592	)593)]594impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> {}595596// Not a tests, but code generators597generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);598generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);599600impl<T: Config> CommonEvmHandler for NonfungibleHandle<T>601where602	T::AccountId: From<[u8; 32]>,603{604	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");605606	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {607		call::<T, UniqueNFTCall<T>, _, _>(handle, self)608	}609}
after · pallets/nonfungible/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//! # Nonfungible Pallet EVM API18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Nonfungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122extern crate alloc;23use core::{24	char::{REPLACEMENT_CHARACTER, decode_utf16},25	convert::TryInto,26};27use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};28use frame_support::BoundedVec;29use up_data_structs::{30	TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,31	CollectionPropertiesVec,32};33use pallet_evm_coder_substrate::dispatch_to_evm;34use sp_std::vec::Vec;35use pallet_common::{36	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, token_uri_key},37	CollectionHandle, CollectionPropertyPermissions,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::call;41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};4243use crate::{44	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,45	SelfWeightOf, weights::WeightInfo, TokenProperties,46};4748/// @title A contract that allows to set and delete token properties and change token property permissions.49#[solidity_interface(name = "TokenProperties")]50impl<T: Config> NonfungibleHandle<T> {51	/// @notice Set permissions for token property.52	/// @dev Throws error if `msg.sender` is not admin or owner of the collection.53	/// @param key Property key.54	/// @param is_mutable Permission to mutate property.55	/// @param collection_admin Permission to mutate property by collection admin if property is mutable.56	/// @param token_owner Permission to mutate property by token owner if property is mutable.57	fn set_token_property_permission(58		&mut self,59		caller: caller,60		key: string,61		is_mutable: bool,62		collection_admin: bool,63		token_owner: bool,64	) -> Result<()> {65		let caller = T::CrossAccountId::from_eth(caller);66		<Pallet<T>>::set_property_permission(67			self,68			&caller,69			PropertyKeyPermission {70				key: <Vec<u8>>::from(key)71					.try_into()72					.map_err(|_| "too long key")?,73				permission: PropertyPermission {74					mutable: is_mutable,75					collection_admin,76					token_owner,77				},78			},79		)80		.map_err(dispatch_to_evm::<T>)81	}8283	/// @notice Set token property value.84	/// @dev Throws error if `msg.sender` has no permission to edit the property.85	/// @param tokenId ID of the token.86	/// @param key Property key.87	/// @param value Property value.88	fn set_property(89		&mut self,90		caller: caller,91		token_id: uint256,92		key: string,93		value: bytes,94	) -> Result<()> {95		let caller = T::CrossAccountId::from_eth(caller);96		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;97		let key = <Vec<u8>>::from(key)98			.try_into()99			.map_err(|_| "key too long")?;100		let value = value.try_into().map_err(|_| "value too long")?;101102		let nesting_budget = self103			.recorder104			.weight_calls_budget(<StructureWeight<T>>::find_parent());105106		<Pallet<T>>::set_token_property(107			self,108			&caller,109			TokenId(token_id),110			Property { key, value },111			&nesting_budget,112		)113		.map_err(dispatch_to_evm::<T>)114	}115116	/// @notice Delete token property value.117	/// @dev Throws error if `msg.sender` has no permission to edit the property.118	/// @param tokenId ID of the token.119	/// @param key Property key.120	fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {121		let caller = T::CrossAccountId::from_eth(caller);122		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;123		let key = <Vec<u8>>::from(key)124			.try_into()125			.map_err(|_| "key too long")?;126127		let nesting_budget = self128			.recorder129			.weight_calls_budget(<StructureWeight<T>>::find_parent());130131		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)132			.map_err(dispatch_to_evm::<T>)133	}134135	/// @notice Get token property value.136	/// @dev Throws error if key not found137	/// @param tokenId ID of the token.138	/// @param key Property key.139	/// @return Property value bytes140	fn property(&self, token_id: uint256, key: string) -> Result<bytes> {141		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;142		let key = <Vec<u8>>::from(key)143			.try_into()144			.map_err(|_| "key too long")?;145146		let props = <TokenProperties<T>>::get((self.id, token_id));147		let prop = props.get(&key).ok_or("key not found")?;148149		Ok(prop.to_vec())150	}151}152153#[derive(ToLog)]154pub enum ERC721Events {155	/// @dev This emits when ownership of any NFT changes by any mechanism.156	///  This event emits when NFTs are created (`from` == 0) and destroyed157	///  (`to` == 0). Exception: during contract creation, any number of NFTs158	///  may be created and assigned without emitting Transfer. At the time of159	///  any transfer, the approved address for that NFT (if any) is reset to none.160	Transfer {161		#[indexed]162		from: address,163		#[indexed]164		to: address,165		#[indexed]166		token_id: uint256,167	},168	/// @dev This emits when the approved address for an NFT is changed or169	///  reaffirmed. The zero address indicates there is no approved address.170	///  When a Transfer event emits, this also indicates that the approved171	///  address for that NFT (if any) is reset to none.172	Approval {173		#[indexed]174		owner: address,175		#[indexed]176		approved: address,177		#[indexed]178		token_id: uint256,179	},180	/// @dev This emits when an operator is enabled or disabled for an owner.181	///  The operator can manage all NFTs of the owner.182	#[allow(dead_code)]183	ApprovalForAll {184		#[indexed]185		owner: address,186		#[indexed]187		operator: address,188		approved: bool,189	},190}191192#[derive(ToLog)]193pub enum ERC721MintableEvents {194	#[allow(dead_code)]195	MintingFinished {},196}197198/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension199/// @dev See https://eips.ethereum.org/EIPS/eip-721200#[solidity_interface(name = "ERC721Metadata")]201impl<T: Config> NonfungibleHandle<T> {202	/// @notice A descriptive name for a collection of NFTs in this contract203	fn name(&self) -> Result<string> {204		Ok(decode_utf16(self.name.iter().copied())205			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))206			.collect::<string>())207	}208209	/// @notice An abbreviated name for NFTs in this contract210	fn symbol(&self) -> Result<string> {211		Ok(string::from_utf8_lossy(&self.token_prefix).into())212	}213214	/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.215	/// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC216	///  3986. The URI may point to a JSON file that conforms to the "ERC721217	///  Metadata JSON Schema".218	/// @return token's const_metadata219	#[solidity(rename_selector = "tokenURI")]220	fn token_uri(&self, token_id: uint256) -> Result<string> {221		let key = token_uri_key();222		if !has_token_permission::<T>(self.id, &key) {223			return Err("No tokenURI permission".into());224		}225226		self.consume_store_reads(1)?;227		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;228229		let properties = <TokenProperties<T>>::try_get((self.id, token_id))230			.map_err(|_| Error::Revert("Token properties not found".into()))?;231		if let Some(property) = properties.get(&key) {232			return Ok(string::from_utf8_lossy(property).into());233		}234235		Err("Property tokenURI not found".into())236	}237}238239/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension240/// @dev See https://eips.ethereum.org/EIPS/eip-721241#[solidity_interface(name = "ERC721Enumerable")]242impl<T: Config> NonfungibleHandle<T> {243	/// @notice Enumerate valid NFTs244	/// @param index A counter less than `totalSupply()`245	/// @return The token identifier for the `index`th NFT,246	///  (sort order not specified)247	fn token_by_index(&self, index: uint256) -> Result<uint256> {248		Ok(index)249	}250251	/// @dev Not implemented252	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {253		// TODO: Not implemetable254		Err("not implemented".into())255	}256257	/// @notice Count NFTs tracked by this contract258	/// @return A count of valid NFTs tracked by this contract, where each one of259	///  them has an assigned and queryable owner not equal to the zero address260	fn total_supply(&self) -> Result<uint256> {261		self.consume_store_reads(1)?;262		Ok(<Pallet<T>>::total_supply(self).into())263	}264}265266/// @title ERC-721 Non-Fungible Token Standard267/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md268#[solidity_interface(name = "ERC721", events(ERC721Events))]269impl<T: Config> NonfungibleHandle<T> {270	/// @notice Count all NFTs assigned to an owner271	/// @dev NFTs assigned to the zero address are considered invalid, and this272	///  function throws for queries about the zero address.273	/// @param owner An address for whom to query the balance274	/// @return The number of NFTs owned by `owner`, possibly zero275	fn balance_of(&self, owner: address) -> Result<uint256> {276		self.consume_store_reads(1)?;277		let owner = T::CrossAccountId::from_eth(owner);278		let balance = <AccountBalance<T>>::get((self.id, owner));279		Ok(balance.into())280	}281	/// @notice Find the owner of an NFT282	/// @dev NFTs assigned to zero address are considered invalid, and queries283	///  about them do throw.284	/// @param tokenId The identifier for an NFT285	/// @return The address of the owner of the NFT286	fn owner_of(&self, token_id: uint256) -> Result<address> {287		self.consume_store_reads(1)?;288		let token: TokenId = token_id.try_into()?;289		Ok(*<TokenData<T>>::get((self.id, token))290			.ok_or("token not found")?291			.owner292			.as_eth())293	}294	/// @dev Not implemented295	fn safe_transfer_from_with_data(296		&mut self,297		_from: address,298		_to: address,299		_token_id: uint256,300		_data: bytes,301		_value: value,302	) -> Result<void> {303		// TODO: Not implemetable304		Err("not implemented".into())305	}306	/// @dev Not implemented307	fn safe_transfer_from(308		&mut self,309		_from: address,310		_to: address,311		_token_id: uint256,312		_value: value,313	) -> Result<void> {314		// TODO: Not implemetable315		Err("not implemented".into())316	}317318	/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE319	///  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE320	///  THEY MAY BE PERMANENTLY LOST321	/// @dev Throws unless `msg.sender` is the current owner or an authorized322	///  operator for this NFT. Throws if `from` is not the current owner. Throws323	///  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.324	/// @param from The current owner of the NFT325	/// @param to The new owner326	/// @param tokenId The NFT to transfer327	/// @param _value Not used for an NFT328	#[weight(<SelfWeightOf<T>>::transfer_from())]329	fn transfer_from(330		&mut self,331		caller: caller,332		from: address,333		to: address,334		token_id: uint256,335		_value: value,336	) -> Result<void> {337		let caller = T::CrossAccountId::from_eth(caller);338		let from = T::CrossAccountId::from_eth(from);339		let to = T::CrossAccountId::from_eth(to);340		let token = token_id.try_into()?;341		let budget = self342			.recorder343			.weight_calls_budget(<StructureWeight<T>>::find_parent());344345		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)346			.map_err(dispatch_to_evm::<T>)?;347		Ok(())348	}349350	/// @notice Set or reaffirm the approved address for an NFT351	/// @dev The zero address indicates there is no approved address.352	/// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized353	///  operator of the current owner.354	/// @param approved The new approved NFT controller355	/// @param tokenId The NFT to approve356	#[weight(<SelfWeightOf<T>>::approve())]357	fn approve(358		&mut self,359		caller: caller,360		approved: address,361		token_id: uint256,362		_value: value,363	) -> Result<void> {364		let caller = T::CrossAccountId::from_eth(caller);365		let approved = T::CrossAccountId::from_eth(approved);366		let token = token_id.try_into()?;367368		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))369			.map_err(dispatch_to_evm::<T>)?;370		Ok(())371	}372373	/// @dev Not implemented374	fn set_approval_for_all(375		&mut self,376		_caller: caller,377		_operator: address,378		_approved: bool,379	) -> Result<void> {380		// TODO: Not implemetable381		Err("not implemented".into())382	}383384	/// @dev Not implemented385	fn get_approved(&self, _token_id: uint256) -> Result<address> {386		// TODO: Not implemetable387		Err("not implemented".into())388	}389390	/// @dev Not implemented391	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {392		// TODO: Not implemetable393		Err("not implemented".into())394	}395}396397/// @title ERC721 Token that can be irreversibly burned (destroyed).398#[solidity_interface(name = "ERC721Burnable")]399impl<T: Config> NonfungibleHandle<T> {400	/// @notice Burns a specific ERC721 token.401	/// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized402	///  operator of the current owner.403	/// @param tokenId The NFT to approve404	#[weight(<SelfWeightOf<T>>::burn_item())]405	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {406		let caller = T::CrossAccountId::from_eth(caller);407		let token = token_id.try_into()?;408409		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;410		Ok(())411	}412}413414/// @title ERC721 minting logic.415#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]416impl<T: Config> NonfungibleHandle<T> {417	fn minting_finished(&self) -> Result<bool> {418		Ok(false)419	}420421	/// @notice Function to mint token.422	/// @dev `tokenId` should be obtained with `nextTokenId` method,423	///  unlike standard, you can't specify it manually424	/// @param to The new owner425	/// @param tokenId ID of the minted NFT426	#[weight(<SelfWeightOf<T>>::create_item())]427	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {428		let caller = T::CrossAccountId::from_eth(caller);429		let to = T::CrossAccountId::from_eth(to);430		let token_id: u32 = token_id.try_into()?;431		let budget = self432			.recorder433			.weight_calls_budget(<StructureWeight<T>>::find_parent());434435		if <TokensMinted<T>>::get(self.id)436			.checked_add(1)437			.ok_or("item id overflow")?438			!= token_id439		{440			return Err("item id should be next".into());441		}442443		<Pallet<T>>::create_item(444			self,445			&caller,446			CreateItemData::<T> {447				properties: BoundedVec::default(),448				owner: to,449			},450			&budget,451		)452		.map_err(dispatch_to_evm::<T>)?;453454		Ok(true)455	}456457	/// @notice Function to mint token with the given tokenUri.458	/// @dev `tokenId` should be obtained with `nextTokenId` method,459	///  unlike standard, you can't specify it manually460	/// @param to The new owner461	/// @param tokenId ID of the minted NFT462	/// @param tokenUri Token URI that would be stored in the NFT properties463	#[solidity(rename_selector = "mintWithTokenURI")]464	#[weight(<SelfWeightOf<T>>::create_item())]465	fn mint_with_token_uri(466		&mut self,467		caller: caller,468		to: address,469		token_id: uint256,470		token_uri: string,471	) -> Result<bool> {472		let key = token_uri_key();473		let permission = get_token_permission::<T>(self.id, &key)?;474		if !permission.collection_admin {475			return Err("Operation is not allowed".into());476		}477478		let caller = T::CrossAccountId::from_eth(caller);479		let to = T::CrossAccountId::from_eth(to);480		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;481		let budget = self482			.recorder483			.weight_calls_budget(<StructureWeight<T>>::find_parent());484485		if <TokensMinted<T>>::get(self.id)486			.checked_add(1)487			.ok_or("item id overflow")?488			!= token_id489		{490			return Err("item id should be next".into());491		}492493		let mut properties = CollectionPropertiesVec::default();494		properties495			.try_push(Property {496				key,497				value: token_uri498					.into_bytes()499					.try_into()500					.map_err(|_| "token uri is too long")?,501			})502			.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;503504		<Pallet<T>>::create_item(505			self,506			&caller,507			CreateItemData::<T> {508				properties,509				owner: to,510			},511			&budget,512		)513		.map_err(dispatch_to_evm::<T>)?;514		Ok(true)515	}516517	/// @dev Not implemented518	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {519		Err("not implementable".into())520	}521}522523fn get_token_permission<T: Config>(524	collection_id: CollectionId,525	key: &PropertyKey,526) -> Result<PropertyPermission> {527	let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)528		.map_err(|_| Error::Revert("No permissions for collection".into()))?;529	let a = token_property_permissions530		.get(key)531		.map(|p| p.clone())532		.ok_or_else(|| Error::Revert("No permission".into()))?;533	Ok(a)534}535536fn has_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> bool {537	if let Ok(token_property_permissions) =538		CollectionPropertyPermissions::<T>::try_get(collection_id)539	{540		return token_property_permissions.contains_key(key);541	}542543	false544}545546/// @title Unique extensions for ERC721.547#[solidity_interface(name = "ERC721UniqueExtensions")]548impl<T: Config> NonfungibleHandle<T> {549	/// @notice Transfer ownership of an NFT550	/// @dev Throws unless `msg.sender` is the current owner. Throws if `to`551	///  is the zero address. Throws if `tokenId` is not a valid NFT.552	/// @param to The new owner553	/// @param tokenId The NFT to transfer554	/// @param _value Not used for an NFT555	#[weight(<SelfWeightOf<T>>::transfer())]556	fn transfer(557		&mut self,558		caller: caller,559		to: address,560		token_id: uint256,561		_value: value,562	) -> Result<void> {563		let caller = T::CrossAccountId::from_eth(caller);564		let to = T::CrossAccountId::from_eth(to);565		let token = token_id.try_into()?;566		let budget = self567			.recorder568			.weight_calls_budget(<StructureWeight<T>>::find_parent());569570		<Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;571		Ok(())572	}573574	/// @notice Burns a specific ERC721 token.575	/// @dev Throws unless `msg.sender` is the current owner or an authorized576	///  operator for this NFT. Throws if `from` is not the current owner. Throws577	///  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.578	/// @param from The current owner of the NFT579	/// @param tokenId The NFT to transfer580	/// @param _value Not used for an NFT581	#[weight(<SelfWeightOf<T>>::burn_from())]582	fn burn_from(583		&mut self,584		caller: caller,585		from: address,586		token_id: uint256,587		_value: value,588	) -> Result<void> {589		let caller = T::CrossAccountId::from_eth(caller);590		let from = T::CrossAccountId::from_eth(from);591		let token = token_id.try_into()?;592		let budget = self593			.recorder594			.weight_calls_budget(<StructureWeight<T>>::find_parent());595596		<Pallet<T>>::burn_from(self, &caller, &from, token, &budget)597			.map_err(dispatch_to_evm::<T>)?;598		Ok(())599	}600601	/// @notice Returns next free NFT ID.602	fn next_token_id(&self) -> Result<uint256> {603		self.consume_store_reads(1)?;604		Ok(<TokensMinted<T>>::get(self.id)605			.checked_add(1)606			.ok_or("item id overflow")?607			.into())608	}609610	/// @notice Function to mint multiple tokens.611	/// @dev `tokenIds` should be an array of consecutive numbers and first number612	///  should be obtained with `nextTokenId` method613	/// @param to The new owner614	/// @param tokenIds IDs of the minted NFTs615	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]616	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {617		let caller = T::CrossAccountId::from_eth(caller);618		let to = T::CrossAccountId::from_eth(to);619		let mut expected_index = <TokensMinted<T>>::get(self.id)620			.checked_add(1)621			.ok_or("item id overflow")?;622		let budget = self623			.recorder624			.weight_calls_budget(<StructureWeight<T>>::find_parent());625626		let total_tokens = token_ids.len();627		for id in token_ids.into_iter() {628			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;629			if id != expected_index {630				return Err("item id should be next".into());631			}632			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;633		}634		let data = (0..total_tokens)635			.map(|_| CreateItemData::<T> {636				properties: BoundedVec::default(),637				owner: to.clone(),638			})639			.collect();640641		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)642			.map_err(dispatch_to_evm::<T>)?;643		Ok(true)644	}645646	/// @notice Function to mint multiple tokens with the given tokenUris.647	/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive648	///  numbers and first number should be obtained with `nextTokenId` method649	/// @param to The new owner650	/// @param tokens array of pairs of token ID and token URI for minted tokens651	#[solidity(rename_selector = "mintBulkWithTokenURI")]652	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]653	fn mint_bulk_with_token_uri(654		&mut self,655		caller: caller,656		to: address,657		tokens: Vec<(uint256, string)>,658	) -> Result<bool> {659		let key = token_uri_key();660		let caller = T::CrossAccountId::from_eth(caller);661		let to = T::CrossAccountId::from_eth(to);662		let mut expected_index = <TokensMinted<T>>::get(self.id)663			.checked_add(1)664			.ok_or("item id overflow")?;665		let budget = self666			.recorder667			.weight_calls_budget(<StructureWeight<T>>::find_parent());668669		let mut data = Vec::with_capacity(tokens.len());670		for (id, token_uri) in tokens {671			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;672			if id != expected_index {673				return Err("item id should be next".into());674			}675			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;676677			let mut properties = CollectionPropertiesVec::default();678			properties679				.try_push(Property {680					key: key.clone(),681					value: token_uri682						.into_bytes()683						.try_into()684						.map_err(|_| "token uri is too long")?,685				})686				.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;687688			data.push(CreateItemData::<T> {689				properties,690				owner: to.clone(),691			});692		}693694		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)695			.map_err(dispatch_to_evm::<T>)?;696		Ok(true)697	}698}699700#[solidity_interface(701	name = "UniqueNFT",702	is(703		ERC721,704		ERC721Metadata,705		ERC721Enumerable,706		ERC721UniqueExtensions,707		ERC721Mintable,708		ERC721Burnable,709		via("CollectionHandle<T>", common_mut, Collection),710		TokenProperties,711	)712)]713impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> {}714715// Not a tests, but code generators716generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);717generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);718719impl<T: Config> CommonEvmHandler for NonfungibleHandle<T>720where721	T::AccountId: From<[u8; 32]>,722{723	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");724725	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {726		call::<T, UniqueNFTCall<T>, _, _>(handle, self)727	}728}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -14,6 +14,80 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+//! # Nonfungible Pallet
+//!
+//! The Nonfungible pallet provides functionality for handling nonfungible collections and tokens.
+//!
+//! - [`Config`]
+//! - [`NonfungibleHandle`]
+//! - [`Pallet`]
+//! - [`CommonWeights`]
+//!
+//! ## Overview
+//!
+//! The Nonfungible pallet provides functions for:
+//!
+//! - NFT collection creation and removal
+//! - Minting and burning of NFT tokens
+//! - Retrieving account balances
+//! - Transfering NFT tokens
+//! - Setting and checking allowance for NFT tokens
+//! - Setting properties and permissions for NFT collections and tokens
+//! - Nesting and unnesting tokens
+//!
+//! ### Terminology
+//!
+//! - **NFT token:** Non fungible token.
+//!
+//! - **NFT Collection:** A collection of NFT tokens. All NFT tokens are part of a collection.
+//!   Each collection can define it's own properties, properties for it's tokens and set of permissions.
+//!
+//! - **Balance:** Number of NFT tokens owned by an account
+//!
+//! - **Allowance:** NFT tokens owned by one account that another account is allowed to make operations on
+//!
+//! - **Burning:** The process of “deleting” a token from a collection and from
+//!   an account balance of the owner.
+//!
+//! - **Nesting:** Setting up parent-child relationship between tokens. Nested tokens are inhereting
+//!   owner from their parent. There could be multiple levels of nesting. Token couldn't be nested in
+//!   it's child token i.e. parent-child relationship graph shouldn't have cycles.
+//!
+//! - **Properties:** Key-Values pairs. Token properties are attached to a token. Collection properties are
+//!   attached to a collection. Set of permissions could be defined for each property.
+//!
+//! ### Implementations
+//!
+//! The Nonfungible pallet provides implementations for the following traits. If these traits provide
+//! the functionality that you need, then you can avoid coupling with the Nonfungible pallet.
+//!
+//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight
+//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing
+//!   with collections
+//!
+//! ## Interface
+//!
+//! ### Dispatchable Functions
+//!
+//! - `init_collection` - Create NFT collection. NFT collection can be configured to allow or deny access for
+//!   some accounts.
+//! - `destroy_collection` - Destroy exising NFT collection. There should be no tokens in the collection.
+//! - `burn` - Burn NFT token owned by account.
+//! - `transfer` - Transfer NFT token. Transfers should be enabled for NFT collection.
+//!   Nests the NFT token if it is sent to another token.
+//! - `create_item` - Mint NFT token in collection. Sender should have permission to mint tokens.
+//! - `set_allowance` - Set allowance for another account.
+//! - `set_token_property` - Set token property value.
+//! - `delete_token_property` - Remove property from the token.
+//! - `set_collection_properties` - Set collection properties.
+//! - `delete_collection_properties` - Remove properties from the collection.
+//! - `set_property_permission` - Set collection property permission.
+//! - `set_token_property_permissions` - Set token property permissions.
+//!
+//! ## Assumptions
+//!
+//! * To perform operations on tokens sender should be in collection's allow list if collection access mode is `AllowList`.
+
 #![cfg_attr(not(feature = "std"), no_std)]
 
 use erc::ERC721Events;
@@ -102,13 +176,17 @@
 	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
 
+	/// Amount of tokens minted for collection.
 	#[pallet::storage]
 	pub type TokensMinted<T: Config> =
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
+
+	/// Amount of burnt tokens for collection.
 	#[pallet::storage]
 	pub type TokensBurnt<T: Config> =
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
 
+	/// Custom data serialized to bytes for token.
 	#[pallet::storage]
 	pub type TokenData<T: Config> = StorageNMap<
 		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
@@ -116,6 +194,7 @@
 		QueryKind = OptionQuery,
 	>;
 
+	/// Key-Value map stored for token.
 	#[pallet::storage]
 	#[pallet::getter(fn token_properties)]
 	pub type TokenProperties<T: Config> = StorageNMap<
@@ -125,6 +204,8 @@
 		OnEmpty = up_data_structs::TokenProperties,
 	>;
 
+	/// Custom data that is serialized to bytes and attached to a token property.
+	/// Currently used to store RMRK data.
 	#[pallet::storage]
 	#[pallet::getter(fn token_aux_property)]
 	pub type TokenAuxProperties<T: Config> = StorageNMap<
@@ -138,7 +219,7 @@
 		QueryKind = OptionQuery,
 	>;
 
-	/// Used to enumerate tokens owned by account
+	/// Used to enumerate tokens owned by account.
 	#[pallet::storage]
 	pub type Owned<T: Config> = StorageNMap<
 		Key = (
@@ -150,7 +231,7 @@
 		QueryKind = ValueQuery,
 	>;
 
-	/// Used to enumerate token's children
+	/// Used to enumerate token's children.
 	#[pallet::storage]
 	#[pallet::getter(fn token_children)]
 	pub type TokenChildren<T: Config> = StorageNMap<
@@ -163,6 +244,7 @@
 		QueryKind = ValueQuery,
 	>;
 
+	/// Amount of tokens owned by account.
 	#[pallet::storage]
 	pub type AccountBalance<T: Config> = StorageNMap<
 		Key = (
@@ -173,6 +255,7 @@
 		QueryKind = ValueQuery,
 	>;
 
+	/// Allowance set by an owner for a spender for a token.
 	#[pallet::storage]
 	pub type Allowance<T: Config> = StorageNMap<
 		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
@@ -273,13 +356,21 @@
 }
 
 impl<T: Config> Pallet<T> {
+	/// Get number of NFT tokens in collection.
 	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {
 		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)
 	}
+
+	/// Check that NFT token exists.
+	///
+	/// - `token`: Token ID.
 	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {
 		<TokenData<T>>::contains_key((collection.id, token))
 	}
 
+	/// Set the token property with the scope.
+	///
+	/// - `property`: Contains key-value pair.
 	pub fn set_scoped_token_property(
 		collection_id: CollectionId,
 		token_id: TokenId,
@@ -294,6 +385,7 @@
 		Ok(())
 	}
 
+	/// Batch operation to set multiple properties with the same scope.
 	pub fn set_scoped_token_properties(
 		collection_id: CollectionId,
 		token_id: TokenId,
@@ -308,6 +400,9 @@
 		Ok(())
 	}
 
+	/// Add or edit auxiliary data for the property.
+	///
+	/// - `f`: function that adds or edits auxiliary data.
 	pub fn try_mutate_token_aux_property<R, E>(
 		collection_id: CollectionId,
 		token_id: TokenId,
@@ -318,6 +413,7 @@
 		<TokenAuxProperties<T>>::try_mutate((collection_id, token_id, scope, key), f)
 	}
 
+	/// Remove auxiliary data for the property.
 	pub fn remove_token_aux_property(
 		collection_id: CollectionId,
 		token_id: TokenId,
@@ -327,6 +423,9 @@
 		<TokenAuxProperties<T>>::remove((collection_id, token_id, scope, key));
 	}
 
+	/// Get all auxiliary data in a given scope.
+	///
+	/// Returns iterator over Property Key - Data pairs.
 	pub fn iterate_token_aux_properties(
 		collection_id: CollectionId,
 		token_id: TokenId,
@@ -335,6 +434,7 @@
 		<TokenAuxProperties<T>>::iter_prefix((collection_id, token_id, scope))
 	}
 
+	/// Get ID of the last minted token
 	pub fn current_token_id(collection_id: CollectionId) -> TokenId {
 		TokenId(<TokensMinted<T>>::get(collection_id))
 	}
@@ -342,6 +442,11 @@
 
 // unchecked calls skips any permission checks
 impl<T: Config> Pallet<T> {
+	/// Create NFT collection
+	///
+	/// `init_collection` will take non-refundable deposit for collection creation.
+	///
+	/// - `data`: Contains settings for collection limits and permissions.
 	pub fn init_collection(
 		owner: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
@@ -349,6 +454,11 @@
 	) -> Result<CollectionId, DispatchError> {
 		<PalletCommon<T>>::init_collection(owner, data, is_external)
 	}
+
+	/// Destroy NFT collection
+	///
+	/// `destroy_collection` will throw error if collection contains any tokens.
+	/// Only owner can destroy collection.
 	pub fn destroy_collection(
 		collection: NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -373,6 +483,15 @@
 		Ok(())
 	}
 
+	/// Burn NFT token
+	///
+	/// `burn` removes `token` from the `collection`, from it's owner and from the parent token
+	/// if the token is nested.
+	/// Only the owner can `burn` the token. The `token` shouldn't have any nested tokens.
+	/// Also removes all corresponding properties and auxiliary properties.
+	///
+	/// - `token`: Token that should be burned
+	/// - `collection`: Collection that contains the token
 	pub fn burn(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -442,6 +561,12 @@
 		Ok(())
 	}
 
+	/// Same as [`burn`] but burns all the tokens that are nested in the token first
+	///
+	/// - `self_budget`: Limit for searching children in depth.
+	/// - `breadth_budget`: Limit of breadth of searching children.
+	///
+	/// [`burn`]: struct.Pallet.html#method.burn
 	#[transactional]
 	pub fn burn_recursively(
 		collection: &NonfungibleHandle<T>,
@@ -481,6 +606,14 @@
 		})
 	}
 
+	/// Batch operation to add, edit or remove properties for the token
+	///
+	/// All affected properties should have mutable permission and sender should have
+	/// permission to edit those properties.
+	///
+	/// - `nesting_budget`: Limit for searching parents in depth to check ownership.
+	/// - `is_token_create`: Indicates that method is called during token initialization.
+	///   Allows to bypass ownership check.
 	#[transactional]
 	fn modify_token_properties(
 		collection: &NonfungibleHandle<T>,
@@ -574,6 +707,11 @@
 		Ok(())
 	}
 
+	/// Batch operation to add or edit properties for the token
+	///
+	/// Same as [`modify_token_properties`] but doesn't allow to remove properties
+	///
+	/// [`modify_token_properties`]: struct.Pallet.html#method.modify_token_properties
 	pub fn set_token_properties(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -592,6 +730,11 @@
 		)
 	}
 
+	/// Add or edit single property for the token
+	///
+	/// Calls [`set_token_properties`] internally
+	///
+	/// [`set_token_properties`]: struct.Pallet.html#method.set_token_properties
 	pub fn set_token_property(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -611,6 +754,11 @@
 		)
 	}
 
+	/// Batch operation to remove properties from the token
+	///
+	/// Same as [`modify_token_properties`] but doesn't allow to add or edit properties
+	///
+	/// [`modify_token_properties`]: struct.Pallet.html#method.modify_token_properties
 	pub fn delete_token_properties(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -630,6 +778,11 @@
 		)
 	}
 
+	/// Remove single property from the token
+	///
+	/// Calls [`delete_token_properties`] internally
+	///
+	/// [`delete_token_properties`]: struct.Pallet.html#method.delete_token_properties
 	pub fn delete_token_property(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -646,6 +799,7 @@
 		)
 	}
 
+	/// Add or edit properties for the collection
 	pub fn set_collection_properties(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -654,6 +808,7 @@
 		<PalletCommon<T>>::set_collection_properties(collection, sender, properties)
 	}
 
+	/// Remove properties from the collection
 	pub fn delete_collection_properties(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
@@ -662,6 +817,9 @@
 		<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
 	}
 
+	/// Set property permissions for the token.
+	///
+	/// Sender should be the owner or admin of token's collection.
 	pub fn set_token_property_permissions(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
@@ -670,6 +828,9 @@
 		<PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)
 	}
 
+	/// Set property permissions for the collection.
+	///
+	/// Sender should be the owner or admin of the collection.
 	pub fn set_property_permission(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
@@ -678,6 +839,15 @@
 		<PalletCommon<T>>::set_property_permission(collection, sender, permission)
 	}
 
+	/// Transfer NFT token from one account to another.
+	///
+	/// `from` account stops being the owner and `to` account becomes the owner of the token.
+	/// If `to` is token than `to` becomes owner of the token and the token become nested.
+	/// Unnests token from previous parent if it was nested before.
+	/// Removes allowance for the token if there was any.
+	/// Throws if transfers aren't allowed for collection or if receiver reached token ownership limit.
+	///
+	/// - `nesting_budget`: Limit for token nesting depth
 	pub fn transfer(
 		collection: &NonfungibleHandle<T>,
 		from: &T::CrossAccountId,
@@ -769,6 +939,16 @@
 		Ok(())
 	}
 
+	/// Batch operation to mint multiple NFT tokens.
+	///
+	/// The sender should be the owner/admin of the collection or collection should be configured
+	/// to allow public minting.
+	/// Throws if amount of tokens reached it's limit for the collection or if caller reached
+	/// token ownership limit.
+	///
+	/// - `data`: Contains list of token properties and users who will become the owners of the
+	///   corresponging tokens.
+	/// - `nesting_budget`: Limit for token nesting depth
 	pub fn create_multiple_items(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -953,6 +1133,9 @@
 		}
 	}
 
+	/// Set allowance for the spender to `transfer` or `burn` sender's token.
+	///
+	/// - `token`: Token the spender is allowed to `transfer` or `burn`.
 	pub fn set_allowance(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
@@ -985,6 +1168,7 @@
 		Ok(())
 	}
 
+	/// Checks allowance for the spender to use the token.
 	fn check_allowed(
 		collection: &NonfungibleHandle<T>,
 		spender: &T::CrossAccountId,
@@ -1027,6 +1211,12 @@
 		Ok(())
 	}
 
+	/// Transfer NFT token from one account to another.
+	///
+	/// Same as the [`transfer`] but spender doesn't needs to be the owner of the token.
+	/// The owner should set allowance for the spender to transfer token.
+	///
+	/// [`transfer`]: struct.Pallet.html#method.transfer
 	pub fn transfer_from(
 		collection: &NonfungibleHandle<T>,
 		spender: &T::CrossAccountId,
@@ -1043,6 +1233,12 @@
 		Self::transfer(collection, from, to, token, nesting_budget)
 	}
 
+	/// Burn NFT token for `from` account.
+	///
+	/// Same as the [`burn`] but spender doesn't need to be an owner of the token. The owner should
+	/// set allowance for the spender to burn token.
+	///
+	/// [`burn`]: struct.Pallet.html#method.burn
 	pub fn burn_from(
 		collection: &NonfungibleHandle<T>,
 		spender: &T::CrossAccountId,
@@ -1057,6 +1253,8 @@
 		Self::burn(collection, from, token)
 	}
 
+	/// Check that `from` token could be nested in `under` token.
+	///
 	pub fn check_nesting(
 		handle: &NonfungibleHandle<T>,
 		sender: T::CrossAccountId,
@@ -1126,7 +1324,11 @@
 			.collect()
 	}
 
-	/// Delegated to `create_multiple_items`
+	/// Mint single NFT token.
+	///
+	/// Delegated to [`create_multiple_items`]
+	///
+	/// [`create_multiple_items`]: struct.Pallet.html#method.create_multiple_items
 	pub fn create_item(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -53,6 +53,13 @@
 
 // Selector: 41369377
 contract TokenProperties is Dummy, ERC165 {
+	// @notice Set permissions for token property.
+	// @dev Throws error if `msg.sender` is not admin or owner of the collection.
+	// @param key Property key.
+	// @param is_mutable Permission to mutate property.
+	// @param collection_admin Permission to mutate property by collection admin if property is mutable.
+	// @param token_owner Permission to mutate property by token owner if property is mutable.
+	//
 	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
 	function setTokenPropertyPermission(
 		string memory key,
@@ -68,6 +75,12 @@
 		dummy = 0;
 	}
 
+	// @notice Set token property value.
+	// @dev Throws error if `msg.sender` has no permission to edit the property.
+	// @param token_id ID of the token.
+	// @param key Property key.
+	// @param value Property value.
+	//
 	// Selector: setProperty(uint256,string,bytes) 1752d67b
 	function setProperty(
 		uint256 tokenId,
@@ -81,6 +94,11 @@
 		dummy = 0;
 	}
 
+	// @notice Delete token property value.
+	// @dev Throws error if `msg.sender` has no permission to edit the property.
+	// @param token_id ID of the token.
+	// @param key Property key.
+	//
 	// Selector: deleteProperty(uint256,string) 066111d1
 	function deleteProperty(uint256 tokenId, string memory key) public {
 		require(false, stub_error);
@@ -89,7 +107,10 @@
 		dummy = 0;
 	}
 
-	// Throws error if key not found
+	// @notice Get token property value.
+	// @dev Throws error if key not found
+	// @param token_id ID of the token.
+	// @param key Property key.
 	//
 	// Selector: property(uint256,string) 7228c327
 	function property(uint256 tokenId, string memory key)
@@ -107,6 +128,11 @@
 
 // Selector: 42966c68
 contract ERC721Burnable is Dummy, ERC165 {
+	// @notice Burns a specific ERC721 token.
+	// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+	//  operator of the current owner.
+	// @param tokenId The NFT to approve
+	//
 	// Selector: burn(uint256) 42966c68
 	function burn(uint256 tokenId) public {
 		require(false, stub_error);
@@ -117,6 +143,12 @@
 
 // Selector: 58800161
 contract ERC721 is Dummy, ERC165, ERC721Events {
+	// @notice Count all NFTs assigned to an owner
+	// @dev NFTs assigned to the zero address are considered invalid, and this
+	//  function throws for queries about the zero address.
+	// @param _owner An address for whom to query the balance
+	// @return The number of NFTs owned by `_owner`, possibly zero
+	//
 	// Selector: balanceOf(address) 70a08231
 	function balanceOf(address owner) public view returns (uint256) {
 		require(false, stub_error);
@@ -125,6 +157,12 @@
 		return 0;
 	}
 
+	// @notice Find the owner of an NFT
+	// @dev NFTs assigned to zero address are considered invalid, and queries
+	//  about them do throw.
+	// @param _tokenId The identifier for an NFT
+	// @return The address of the owner of the NFT
+	//
 	// Selector: ownerOf(uint256) 6352211e
 	function ownerOf(uint256 tokenId) public view returns (address) {
 		require(false, stub_error);
@@ -133,7 +171,7 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
 	function safeTransferFromWithData(
@@ -150,7 +188,7 @@
 		dummy = 0;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: safeTransferFrom(address,address,uint256) 42842e0e
 	function safeTransferFrom(
@@ -165,6 +203,17 @@
 		dummy = 0;
 	}
 
+	// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+	//  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+	//  THEY MAY BE PERMANENTLY LOST
+	// @dev Throws unless `msg.sender` is the current owner or an authorized
+	//  operator for this NFT. Throws if `from` is not the current owner. Throws
+	//  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param from The current owner of the NFT
+	// @param to The new owner
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: transferFrom(address,address,uint256) 23b872dd
 	function transferFrom(
 		address from,
@@ -178,6 +227,13 @@
 		dummy = 0;
 	}
 
+	// @notice Set or reaffirm the approved address for an NFT
+	// @dev The zero address indicates there is no approved address.
+	// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+	//  operator of the current owner.
+	// @param approved The new approved NFT controller
+	// @param tokenId The NFT to approve
+	//
 	// Selector: approve(address,uint256) 095ea7b3
 	function approve(address approved, uint256 tokenId) public {
 		require(false, stub_error);
@@ -186,7 +242,7 @@
 		dummy = 0;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: setApprovalForAll(address,bool) a22cb465
 	function setApprovalForAll(address operator, bool approved) public {
@@ -196,7 +252,7 @@
 		dummy = 0;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: getApproved(uint256) 081812fc
 	function getApproved(uint256 tokenId) public view returns (address) {
@@ -206,7 +262,7 @@
 		return 0x0000000000000000000000000000000000000000;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: isApprovedForAll(address,address) e985e9c5
 	function isApprovedForAll(address owner, address operator)
@@ -224,6 +280,8 @@
 
 // Selector: 5b5e139f
 contract ERC721Metadata is Dummy, ERC165 {
+	// @notice A descriptive name for a collection of NFTs in this contract
+	//
 	// Selector: name() 06fdde03
 	function name() public view returns (string memory) {
 		require(false, stub_error);
@@ -231,6 +289,8 @@
 		return "";
 	}
 
+	// @notice An abbreviated name for NFTs in this contract
+	//
 	// Selector: symbol() 95d89b41
 	function symbol() public view returns (string memory) {
 		require(false, stub_error);
@@ -238,7 +298,11 @@
 		return "";
 	}
 
-	// Returns token's const_metadata
+	// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+	// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC
+	//  3986. The URI may point to a JSON file that conforms to the "ERC721
+	//  Metadata JSON Schema".
+	// @return token's const_metadata
 	//
 	// Selector: tokenURI(uint256) c87b56dd
 	function tokenURI(uint256 tokenId) public view returns (string memory) {
@@ -258,8 +322,11 @@
 		return false;
 	}
 
-	// `token_id` should be obtained with `next_token_id` method,
-	// unlike standard, you can't specify it manually
+	// @notice Function to mint token.
+	// @dev `tokenId` should be obtained with `nextTokenId` method,
+	//  unlike standard, you can't specify it manually
+	// @param to The new owner
+	// @param tokenId ID of the minted NFT
 	//
 	// Selector: mint(address,uint256) 40c10f19
 	function mint(address to, uint256 tokenId) public returns (bool) {
@@ -270,8 +337,12 @@
 		return false;
 	}
 
-	// `token_id` should be obtained with `next_token_id` method,
-	// unlike standard, you can't specify it manually
+	// @notice Function to mint token with the given tokenUri.
+	// @dev `tokenId` should be obtained with `nextTokenId` method,
+	//  unlike standard, you can't specify it manually
+	// @param to The new owner
+	// @param tokenId ID of the minted NFT
+	// @param tokenUri Token URI that would be stored in the NFT properties
 	//
 	// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
 	function mintWithTokenURI(
@@ -287,7 +358,7 @@
 		return false;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: finishMinting() 7d64bcb4
 	function finishMinting() public returns (bool) {
@@ -299,6 +370,12 @@
 
 // Selector: 780e9d63
 contract ERC721Enumerable is Dummy, ERC165 {
+	// @notice Enumerate valid NFTs
+	// @dev Throws if `index` >= `totalSupply()`.
+	// @param index A counter less than `totalSupply()`
+	// @return The token identifier for the `index`th NFT,
+	//  (sort order not specified)
+	//
 	// Selector: tokenByIndex(uint256) 4f6ccce7
 	function tokenByIndex(uint256 index) public view returns (uint256) {
 		require(false, stub_error);
@@ -307,7 +384,7 @@
 		return 0;
 	}
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
 	function tokenOfOwnerByIndex(address owner, uint256 index)
@@ -322,6 +399,10 @@
 		return 0;
 	}
 
+	// @notice Count NFTs tracked by this contract
+	// @return A count of valid NFTs tracked by this contract, where each one of
+	//  them has an assigned and queryable owner not equal to the zero address
+	//
 	// Selector: totalSupply() 18160ddd
 	function totalSupply() public view returns (uint256) {
 		require(false, stub_error);
@@ -475,6 +556,15 @@
 
 // Selector: d74d154f
 contract ERC721UniqueExtensions is Dummy, ERC165 {
+	// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+	//  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+	//  THEY MAY BE PERMANENTLY LOST
+	// @dev Throws unless `msg.sender` is the current owner. Throws if `to`
+	//  is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param to The new owner
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: transfer(address,uint256) a9059cbb
 	function transfer(address to, uint256 tokenId) public {
 		require(false, stub_error);
@@ -483,6 +573,14 @@
 		dummy = 0;
 	}
 
+	// @notice Burns a specific ERC721 token.
+	// @dev Throws unless `msg.sender` is the current owner or an authorized
+	//  operator for this NFT. Throws if `from` is not the current owner. Throws
+	//  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param from The current owner of the NFT
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: burnFrom(address,uint256) 79cc6790
 	function burnFrom(address from, uint256 tokenId) public {
 		require(false, stub_error);
@@ -491,6 +589,8 @@
 		dummy = 0;
 	}
 
+	// @notice Returns next free NFT ID.
+	//
 	// Selector: nextTokenId() 75794a3c
 	function nextTokenId() public view returns (uint256) {
 		require(false, stub_error);
@@ -498,6 +598,12 @@
 		return 0;
 	}
 
+	// @notice Function to mint multiple tokens.
+	// @dev `tokenIds` should be an array of consecutive numbers and first number
+	//  should be obtained with `nextTokenId` method
+	// @param to The new owner
+	// @param tokenIds IDs of the minted NFTs
+	//
 	// Selector: mintBulk(address,uint256[]) 44a9945e
 	function mintBulk(address to, uint256[] memory tokenIds)
 		public
@@ -510,6 +616,12 @@
 		return false;
 	}
 
+	// @notice Function to mint multiple tokens with the given tokenUris.
+	// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
+	//  numbers and first number should be obtained with `nextTokenId` method
+	// @param to The new owner
+	// @param tokens array of pairs of token ID and token URI for minted tokens
+	//
 	// Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
 	function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
 		public
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -44,6 +44,13 @@
 
 // Selector: 41369377
 interface TokenProperties is Dummy, ERC165 {
+	// @notice Set permissions for token property.
+	// @dev Throws error if `msg.sender` is not admin or owner of the collection.
+	// @param key Property key.
+	// @param is_mutable Permission to mutate property.
+	// @param collection_admin Permission to mutate property by collection admin if property is mutable.
+	// @param token_owner Permission to mutate property by token owner if property is mutable.
+	//
 	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
 	function setTokenPropertyPermission(
 		string memory key,
@@ -52,6 +59,12 @@
 		bool tokenOwner
 	) external;
 
+	// @notice Set token property value.
+	// @dev Throws error if `msg.sender` has no permission to edit the property.
+	// @param token_id ID of the token.
+	// @param key Property key.
+	// @param value Property value.
+	//
 	// Selector: setProperty(uint256,string,bytes) 1752d67b
 	function setProperty(
 		uint256 tokenId,
@@ -59,10 +72,18 @@
 		bytes memory value
 	) external;
 
+	// @notice Delete token property value.
+	// @dev Throws error if `msg.sender` has no permission to edit the property.
+	// @param token_id ID of the token.
+	// @param key Property key.
+	//
 	// Selector: deleteProperty(uint256,string) 066111d1
 	function deleteProperty(uint256 tokenId, string memory key) external;
 
-	// Throws error if key not found
+	// @notice Get token property value.
+	// @dev Throws error if key not found
+	// @param token_id ID of the token.
+	// @param key Property key.
 	//
 	// Selector: property(uint256,string) 7228c327
 	function property(uint256 tokenId, string memory key)
@@ -73,19 +94,36 @@
 
 // Selector: 42966c68
 interface ERC721Burnable is Dummy, ERC165 {
+	// @notice Burns a specific ERC721 token.
+	// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+	//  operator of the current owner.
+	// @param tokenId The NFT to approve
+	//
 	// Selector: burn(uint256) 42966c68
 	function burn(uint256 tokenId) external;
 }
 
 // Selector: 58800161
 interface ERC721 is Dummy, ERC165, ERC721Events {
+	// @notice Count all NFTs assigned to an owner
+	// @dev NFTs assigned to the zero address are considered invalid, and this
+	//  function throws for queries about the zero address.
+	// @param _owner An address for whom to query the balance
+	// @return The number of NFTs owned by `_owner`, possibly zero
+	//
 	// Selector: balanceOf(address) 70a08231
 	function balanceOf(address owner) external view returns (uint256);
 
+	// @notice Find the owner of an NFT
+	// @dev NFTs assigned to zero address are considered invalid, and queries
+	//  about them do throw.
+	// @param _tokenId The identifier for an NFT
+	// @return The address of the owner of the NFT
+	//
 	// Selector: ownerOf(uint256) 6352211e
 	function ownerOf(uint256 tokenId) external view returns (address);
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
 	function safeTransferFromWithData(
@@ -95,7 +133,7 @@
 		bytes memory data
 	) external;
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: safeTransferFrom(address,address,uint256) 42842e0e
 	function safeTransferFrom(
@@ -104,6 +142,17 @@
 		uint256 tokenId
 	) external;
 
+	// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+	//  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+	//  THEY MAY BE PERMANENTLY LOST
+	// @dev Throws unless `msg.sender` is the current owner or an authorized
+	//  operator for this NFT. Throws if `from` is not the current owner. Throws
+	//  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param from The current owner of the NFT
+	// @param to The new owner
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: transferFrom(address,address,uint256) 23b872dd
 	function transferFrom(
 		address from,
@@ -111,20 +160,27 @@
 		uint256 tokenId
 	) external;
 
+	// @notice Set or reaffirm the approved address for an NFT
+	// @dev The zero address indicates there is no approved address.
+	// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+	//  operator of the current owner.
+	// @param approved The new approved NFT controller
+	// @param tokenId The NFT to approve
+	//
 	// Selector: approve(address,uint256) 095ea7b3
 	function approve(address approved, uint256 tokenId) external;
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: setApprovalForAll(address,bool) a22cb465
 	function setApprovalForAll(address operator, bool approved) external;
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: getApproved(uint256) 081812fc
 	function getApproved(uint256 tokenId) external view returns (address);
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: isApprovedForAll(address,address) e985e9c5
 	function isApprovedForAll(address owner, address operator)
@@ -135,13 +191,21 @@
 
 // Selector: 5b5e139f
 interface ERC721Metadata is Dummy, ERC165 {
+	// @notice A descriptive name for a collection of NFTs in this contract
+	//
 	// Selector: name() 06fdde03
 	function name() external view returns (string memory);
 
+	// @notice An abbreviated name for NFTs in this contract
+	//
 	// Selector: symbol() 95d89b41
 	function symbol() external view returns (string memory);
 
-	// Returns token's const_metadata
+	// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+	// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC
+	//  3986. The URI may point to a JSON file that conforms to the "ERC721
+	//  Metadata JSON Schema".
+	// @return token's const_metadata
 	//
 	// Selector: tokenURI(uint256) c87b56dd
 	function tokenURI(uint256 tokenId) external view returns (string memory);
@@ -152,14 +216,21 @@
 	// 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
+	// @notice Function to mint token.
+	// @dev `tokenId` should be obtained with `nextTokenId` method,
+	//  unlike standard, you can't specify it manually
+	// @param to The new owner
+	// @param tokenId ID of the minted NFT
 	//
 	// 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
+	// @notice Function to mint token with the given tokenUri.
+	// @dev `tokenId` should be obtained with `nextTokenId` method,
+	//  unlike standard, you can't specify it manually
+	// @param to The new owner
+	// @param tokenId ID of the minted NFT
+	// @param tokenUri Token URI that would be stored in the NFT properties
 	//
 	// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
 	function mintWithTokenURI(
@@ -168,7 +239,7 @@
 		string memory tokenUri
 	) external returns (bool);
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: finishMinting() 7d64bcb4
 	function finishMinting() external returns (bool);
@@ -176,10 +247,16 @@
 
 // Selector: 780e9d63
 interface ERC721Enumerable is Dummy, ERC165 {
+	// @notice Enumerate valid NFTs
+	// @dev Throws if `index` >= `totalSupply()`.
+	// @param index A counter less than `totalSupply()`
+	// @return The token identifier for the `index`th NFT,
+	//  (sort order not specified)
+	//
 	// Selector: tokenByIndex(uint256) 4f6ccce7
 	function tokenByIndex(uint256 index) external view returns (uint256);
 
-	// Not implemented
+	// @dev Not implemented
 	//
 	// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
 	function tokenOfOwnerByIndex(address owner, uint256 index)
@@ -187,6 +264,10 @@
 		view
 		returns (uint256);
 
+	// @notice Count NFTs tracked by this contract
+	// @return A count of valid NFTs tracked by this contract, where each one of
+	//  them has an assigned and queryable owner not equal to the zero address
+	//
 	// Selector: totalSupply() 18160ddd
 	function totalSupply() external view returns (uint256);
 }
@@ -257,20 +338,51 @@
 
 // Selector: d74d154f
 interface ERC721UniqueExtensions is Dummy, ERC165 {
+	// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+	//  TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+	//  THEY MAY BE PERMANENTLY LOST
+	// @dev Throws unless `msg.sender` is the current owner. Throws if `to`
+	//  is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param to The new owner
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: transfer(address,uint256) a9059cbb
 	function transfer(address to, uint256 tokenId) external;
 
+	// @notice Burns a specific ERC721 token.
+	// @dev Throws unless `msg.sender` is the current owner or an authorized
+	//  operator for this NFT. Throws if `from` is not the current owner. Throws
+	//  if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+	// @param from The current owner of the NFT
+	// @param tokenId The NFT to transfer
+	// @param _value Not used for an NFT
+	//
 	// Selector: burnFrom(address,uint256) 79cc6790
 	function burnFrom(address from, uint256 tokenId) external;
 
+	// @notice Returns next free NFT ID.
+	//
 	// Selector: nextTokenId() 75794a3c
 	function nextTokenId() external view returns (uint256);
 
+	// @notice Function to mint multiple tokens.
+	// @dev `tokenIds` should be an array of consecutive numbers and first number
+	//  should be obtained with `nextTokenId` method
+	// @param to The new owner
+	// @param tokenIds IDs of the minted NFTs
+	//
 	// Selector: mintBulk(address,uint256[]) 44a9945e
 	function mintBulk(address to, uint256[] memory tokenIds)
 		external
 		returns (bool);
 
+	// @notice Function to mint multiple tokens with the given tokenUris.
+	// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
+	//  numbers and first number should be obtained with `nextTokenId` method
+	// @param to The new owner
+	// @param tokens array of pairs of token ID and token URI for minted tokens
+	//
 	// Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
 	function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
 		external