git.delta.rocks / unique-network / refs/commits / 6edd3f1acfd3

difftreelog

feat implement evm property manipulation

Yaroslav Bolyukin2022-05-17parent: #6020bb0.patch.diff
in: master

12 files changed

modified.maintain/scripts/generate_api.shdiffbeforeafterboth
--- a/.maintain/scripts/generate_api.sh
+++ b/.maintain/scripts/generate_api.sh
@@ -7,6 +7,5 @@
 sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw
 formatted=$(mktemp)
 prettier --use-tabs $raw > $formatted
-solhint --fix $formatted
 
 mv $formatted $OUTPUT
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -21,7 +21,7 @@
 use sp_std::vec::Vec;
 use up_data_structs::Property;
 
-use crate::{Pallet, CollectionHandle, Config};
+use crate::{Pallet, CollectionHandle, Config, CollectionProperties};
 
 /// Does not always represent a full collection, for RFT it is either
 /// collection (Implementing ERC721), or specific collection token (Implementing ERC20)
@@ -33,24 +33,35 @@
 
 #[solidity_interface(name = "CollectionProperties")]
 impl<T: Config> CollectionHandle<T> {
-	fn set_property(&mut self, caller: caller, key: string, value: string) -> Result<()> {
-		<Pallet<T>>::set_collection_property(
-			self,
-			&T::CrossAccountId::from_eth(caller),
-			Property {
-				key: <Vec<u8>>::from(key)
-					.try_into()
-					.map_err(|_| "key too large")?,
-				value: <Vec<u8>>::from(value)
-					.try_into()
-					.map_err(|_| "value too large")?,
-			},
-		)
-		.map_err(dispatch_to_evm::<T>)?;
-		Ok(())
+	fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too large")?;
+		let value = value.try_into().map_err(|_| "value too large")?;
+
+		<Pallet<T>>::set_collection_property(self, &caller, Property { key, value })
+			.map_err(dispatch_to_evm::<T>)
 	}
 
-	fn delete_property(&mut self, caller: caller, key: string) -> Result<()> {
-		self.set_property(caller, key, string::new())
+	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too large")?;
+
+		<Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)
+	}
+
+	/// Throws error if key not found
+	fn collection_property(&self, key: string) -> Result<bytes> {
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too large")?;
+
+		let props = <CollectionProperties<T>>::get(self.id);
+		let prop = props.get(&key).ok_or("key not found")?;
+
+		Ok(prop.to_vec())
 	}
 }
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -31,12 +31,12 @@
 use pallet_evm::GasWeightMapping;
 use up_data_structs::{
 	COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionId, CreateItemData,
-	MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT, TokenId,
-	CollectionStats, MAX_TOKEN_OWNERSHIP, CollectionMode, NFT_SPONSOR_TRANSFER_TIMEOUT,
+	MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT, TokenId, CollectionStats,
+	MAX_TOKEN_OWNERSHIP, CollectionMode, NFT_SPONSOR_TRANSFER_TIMEOUT,
 	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT,
-	CUSTOM_DATA_LIMIT, CollectionLimits, CreateCollectionData, SponsorshipState,
-	CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
-	PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
+	CUSTOM_DATA_LIMIT, CollectionLimits, CreateCollectionData, SponsorshipState, CreateItemExData,
+	SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField, PhantomType,
+	Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
 	PropertiesError, PropertyKeyPermission, TokenData, TrySet,
 };
 pub use pallet::*;
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -8,8 +8,13 @@
 	uint8 dummy;
 	string stub_error = "this contract is implemented in native";
 }
+
 contract ERC165 is Dummy {
-	function supportsInterface(bytes4 interfaceID) external view returns (bool) {
+	function supportsInterface(bytes4 interfaceID)
+		external
+		view
+		returns (bool)
+	{
 		require(false, stub_error);
 		interfaceID;
 		return true;
@@ -19,24 +24,11 @@
 // Inline
 contract ERC20Events {
 	event Transfer(address indexed from, address indexed to, uint256 value);
-	event Approval(address indexed owner, address indexed spender, uint256 value);
-}
-
-// Selector: 56fd500b
-contract CollectionProperties is Dummy, ERC165 {
-	// Selector: setProperty(string,string) 62d9491f
-	function setProperty(string memory key, string memory value) public {
-		require(false, stub_error);
-		key;
-		value;
-		dummy = 0;
-	}
-	// Selector: deleteProperty(string) 34241914
-	function deleteProperty(string memory key) public {
-		require(false, stub_error);
-		key;
-		dummy = 0;
-	}
+	event Approval(
+		address indexed owner,
+		address indexed spender,
+		uint256 value
+	);
 }
 
 // Selector: 79cc6790
@@ -59,24 +51,28 @@
 		dummy;
 		return "";
 	}
+
 	// Selector: symbol() 95d89b41
 	function symbol() public view returns (string memory) {
 		require(false, stub_error);
 		dummy;
 		return "";
 	}
+
 	// Selector: totalSupply() 18160ddd
 	function totalSupply() public view returns (uint256) {
 		require(false, stub_error);
 		dummy;
 		return 0;
 	}
+
 	// Selector: decimals() 313ce567
 	function decimals() public view returns (uint8) {
 		require(false, stub_error);
 		dummy;
 		return 0;
 	}
+
 	// Selector: balanceOf(address) 70a08231
 	function balanceOf(address owner) public view returns (uint256) {
 		require(false, stub_error);
@@ -84,6 +80,7 @@
 		dummy;
 		return 0;
 	}
+
 	// Selector: transfer(address,uint256) a9059cbb
 	function transfer(address to, uint256 amount) public returns (bool) {
 		require(false, stub_error);
@@ -92,8 +89,13 @@
 		dummy = 0;
 		return false;
 	}
+
 	// Selector: transferFrom(address,address,uint256) 23b872dd
-	function transferFrom(address from, address to, uint256 amount) public returns (bool) {
+	function transferFrom(
+		address from,
+		address to,
+		uint256 amount
+	) public returns (bool) {
 		require(false, stub_error);
 		from;
 		to;
@@ -101,6 +103,7 @@
 		dummy = 0;
 		return false;
 	}
+
 	// Selector: approve(address,uint256) 095ea7b3
 	function approve(address spender, uint256 amount) public returns (bool) {
 		require(false, stub_error);
@@ -109,8 +112,13 @@
 		dummy = 0;
 		return false;
 	}
+
 	// Selector: allowance(address,address) dd62ed3e
-	function allowance(address owner, address spender) public view returns (uint256) {
+	function allowance(address owner, address spender)
+		public
+		view
+		returns (uint256)
+	{
 		require(false, stub_error);
 		owner;
 		spender;
@@ -119,6 +127,44 @@
 	}
 }
 
-contract UniqueFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions, CollectionProperties {
+// Selector: 9b5e29c5
+contract CollectionProperties is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
 }
 
+contract UniqueFungible is
+	Dummy,
+	ERC165,
+	ERC20,
+	ERC20UniqueExtensions,
+	CollectionProperties
+{}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -21,7 +21,7 @@
 };
 use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
 use frame_support::BoundedVec;
-use up_data_structs::{TokenId, SchemaVersion};
+use up_data_structs::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property};
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_core::{H160, U256};
 use sp_std::vec::Vec;
@@ -35,9 +35,80 @@
 
 use crate::{
 	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
-	SelfWeightOf, weights::WeightInfo,
+	SelfWeightOf, weights::WeightInfo, TokenProperties,
 };
 
+#[solidity_interface(name = "TokenProperties")]
+impl<T: Config> NonfungibleHandle<T> {
+	fn set_token_property_permission(
+		&mut self,
+		caller: caller,
+		key: string,
+		is_mutable: bool,
+		collection_admin: bool,
+		token_owner: bool,
+	) -> Result<()> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		<Pallet<T>>::set_property_permission(
+			self,
+			&caller,
+			PropertyKeyPermission {
+				key: <Vec<u8>>::from(key)
+					.try_into()
+					.map_err(|_| "too long key")?,
+				permission: PropertyPermission {
+					mutable: is_mutable,
+					collection_admin,
+					token_owner,
+				},
+			},
+		)
+		.map_err(dispatch_to_evm::<T>)
+	}
+
+	fn set_property(
+		&mut self,
+		caller: caller,
+		token_id: uint256,
+		key: string,
+		value: bytes,
+	) -> Result<()> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too long")?;
+		let value = value.try_into().map_err(|_| "value too long")?;
+
+		<Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })
+			.map_err(dispatch_to_evm::<T>)
+	}
+
+	fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too long")?;
+
+		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)
+			.map_err(dispatch_to_evm::<T>)
+	}
+
+	/// Throws error if key not found
+	fn property(&self, token_id: uint256, key: string) -> Result<bytes> {
+		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
+		let key = <Vec<u8>>::from(key)
+			.try_into()
+			.map_err(|_| "key too long")?;
+
+		let props = <TokenProperties<T>>::get((self.id, token_id));
+		let prop = props.get(&key).ok_or("key not found")?;
+
+		Ok(prop.to_vec())
+	}
+}
+
 fn error_unsupported_schema_version() -> Error {
 	alloc::format!(
 		"Unsupported schema version! Support only {:?}",
@@ -470,7 +541,8 @@
 		ERC721UniqueExtensions,
 		ERC721Mintable,
 		ERC721Burnable,
-		via("CollectionHandle<T>", common_mut, CollectionProperties)
+		via("CollectionHandle<T>", common_mut, CollectionProperties),
+		TokenProperties,
 	)
 )]
 impl<T: Config> NonfungibleHandle<T> {}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
before · pallets/nonfungible/src/lib.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#![cfg_attr(not(feature = "std"), no_std)]1819use erc::ERC721Events;20use evm_coder::ToLog;21use frame_support::{BoundedVec, ensure, fail, transactional};22use up_data_structs::{23	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,25	PropertyKey, PropertyKeyPermission, Properties, TrySet,26};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};28use pallet_common::{29	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,30	dispatch::CollectionDispatch, eth::collection_id_to_address,31};32use pallet_structure::Pallet as PalletStructure;33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};34use sp_core::H160;35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};36use sp_std::{vec::Vec, vec};37use core::ops::Deref;38use sp_std::collections::btree_map::BTreeMap;39use codec::{Encode, Decode, MaxEncodedLen};40use scale_info::TypeInfo;4142pub use pallet::*;43#[cfg(feature = "runtime-benchmarks")]44pub mod benchmarking;45pub mod common;46pub mod erc;47pub mod weights;4849pub type CreateItemData<T> = CreateNftExData<<T as pallet_evm::account::Config>::CrossAccountId>;50pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;5152#[struct_versioning::versioned(version = 2, upper)]53#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]54pub struct ItemData<CrossAccountId> {55	pub const_data: BoundedVec<u8, CustomDataLimit>,5657	#[version(..2)]58	pub variable_data: BoundedVec<u8, CustomDataLimit>,5960	pub owner: CrossAccountId,61}6263#[frame_support::pallet]64pub mod pallet {65	use super::*;66	use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};67	use frame_system::pallet_prelude::*;68	use up_data_structs::{CollectionId, TokenId};69	use super::weights::WeightInfo;7071	#[pallet::error]72	pub enum Error<T> {73		/// Not Nonfungible item data used to mint in Nonfungible collection.74		NotNonfungibleDataUsedToMintFungibleCollectionToken,75		/// Used amount > 1 with NFT76		NonfungibleItemsHaveNoAmount,77	}7879	#[pallet::config]80	pub trait Config:81		frame_system::Config + pallet_common::Config + pallet_structure::Config + pallet_evm::Config82	{83		type WeightInfo: WeightInfo;84	}8586	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8788	#[pallet::pallet]89	#[pallet::storage_version(STORAGE_VERSION)]90	#[pallet::generate_store(pub(super) trait Store)]91	pub struct Pallet<T>(_);9293	#[pallet::storage]94	pub type TokensMinted<T: Config> =95		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;96	#[pallet::storage]97	pub type TokensBurnt<T: Config> =98		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;99100	#[pallet::storage]101	pub type TokenData<T: Config> = StorageNMap<102		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),103		Value = ItemData<T::CrossAccountId>,104		QueryKind = OptionQuery,105	>;106107	#[pallet::storage]108	#[pallet::getter(fn token_properties)]109	pub type TokenProperties<T: Config> = StorageNMap<110		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),111		Value = Properties,112		QueryKind = ValueQuery,113		OnEmpty = up_data_structs::TokenProperties,114	>;115116	/// Used to enumerate tokens owned by account117	#[pallet::storage]118	pub type Owned<T: Config> = StorageNMap<119		Key = (120			Key<Twox64Concat, CollectionId>,121			Key<Blake2_128Concat, T::CrossAccountId>,122			Key<Twox64Concat, TokenId>,123		),124		Value = bool,125		QueryKind = ValueQuery,126	>;127128	#[pallet::storage]129	pub type AccountBalance<T: Config> = StorageNMap<130		Key = (131			Key<Twox64Concat, CollectionId>,132			Key<Blake2_128Concat, T::CrossAccountId>,133		),134		Value = u32,135		QueryKind = ValueQuery,136	>;137138	#[pallet::storage]139	pub type Allowance<T: Config> = StorageNMap<140		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),141		Value = T::CrossAccountId,142		QueryKind = OptionQuery,143	>;144145	#[pallet::hooks]146	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {147		fn on_runtime_upgrade() -> Weight {148			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {149				<TokenData<T>>::translate_values::<ItemDataVersion1<T::CrossAccountId>, _>(|v| {150					Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))151				})152			}153154			0155		}156	}157}158159pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);160impl<T: Config> NonfungibleHandle<T> {161	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {162		Self(inner)163	}164	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {165		self.0166	}167	pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {168		&mut self.0169	}170}171impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {172	fn recorder(&self) -> &SubstrateRecorder<T> {173		self.0.recorder()174	}175	fn into_recorder(self) -> SubstrateRecorder<T> {176		self.0.into_recorder()177	}178}179impl<T: Config> Deref for NonfungibleHandle<T> {180	type Target = pallet_common::CollectionHandle<T>;181182	fn deref(&self) -> &Self::Target {183		&self.0184	}185}186187impl<T: Config> Pallet<T> {188	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {189		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)190	}191	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {192		<TokenData<T>>::contains_key((collection.id, token))193	}194}195196// unchecked calls skips any permission checks197impl<T: Config> Pallet<T> {198	pub fn init_collection(199		owner: T::AccountId,200		data: CreateCollectionData<T::AccountId>,201	) -> Result<CollectionId, DispatchError> {202		<PalletCommon<T>>::init_collection(owner, data)203	}204	pub fn destroy_collection(205		collection: NonfungibleHandle<T>,206		sender: &T::CrossAccountId,207	) -> DispatchResult {208		let id = collection.id;209210		// =========211212		PalletCommon::destroy_collection(collection.0, sender)?;213214		<TokenData<T>>::remove_prefix((id,), None);215		<Owned<T>>::remove_prefix((id,), None);216		<TokensMinted<T>>::remove(id);217		<TokensBurnt<T>>::remove(id);218		<Allowance<T>>::remove_prefix((id,), None);219		<AccountBalance<T>>::remove_prefix((id,), None);220		Ok(())221	}222223	pub fn burn(224		collection: &NonfungibleHandle<T>,225		sender: &T::CrossAccountId,226		token: TokenId,227	) -> DispatchResult {228		let token_data =229			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;230		ensure!(231			&token_data.owner == sender232				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),233			<CommonError<T>>::NoPermission234		);235236		if collection.access == AccessMode::AllowList {237			collection.check_allowlist(sender)?;238		}239240		let burnt = <TokensBurnt<T>>::get(collection.id)241			.checked_add(1)242			.ok_or(ArithmeticError::Overflow)?;243244		let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))245			.checked_sub(1)246			.ok_or(ArithmeticError::Overflow)?;247248		if balance == 0 {249			<AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));250		} else {251			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);252		}253		// =========254255		<Owned<T>>::remove((collection.id, &token_data.owner, token));256		<TokensBurnt<T>>::insert(collection.id, burnt);257		<TokenData<T>>::remove((collection.id, token));258		let old_spender = <Allowance<T>>::take((collection.id, token));259260		if let Some(old_spender) = old_spender {261			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(262				collection.id,263				token,264				sender.clone(),265				old_spender,266				0,267			));268		}269270		<PalletEvm<T>>::deposit_log(271			ERC721Events::Transfer {272				from: *token_data.owner.as_eth(),273				to: H160::default(),274				token_id: token.into(),275			}276			.to_log(collection_id_to_address(collection.id)),277		);278		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(279			collection.id,280			token,281			token_data.owner,282			1,283		));284		Ok(())285	}286287	pub fn set_token_property(288		collection: &NonfungibleHandle<T>,289		sender: &T::CrossAccountId,290		token_id: TokenId,291		property: Property,292	) -> DispatchResult {293		Self::check_token_change_permission(collection, sender, token_id, &property.key)?;294295		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {296			let property = property.clone();297			properties.try_set(property.key, property.value)298		})299		.map_err(<CommonError<T>>::from)?;300301		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(302			collection.id,303			token_id,304			property.key,305		));306307		Ok(())308	}309310	#[transactional]311	pub fn set_token_properties(312		collection: &NonfungibleHandle<T>,313		sender: &T::CrossAccountId,314		token_id: TokenId,315		properties: Vec<Property>,316	) -> DispatchResult {317		for property in properties {318			Self::set_token_property(collection, sender, token_id, property)?;319		}320321		Ok(())322	}323324	pub fn delete_token_property(325		collection: &NonfungibleHandle<T>,326		sender: &T::CrossAccountId,327		token_id: TokenId,328		property_key: PropertyKey,329	) -> DispatchResult {330		Self::check_token_change_permission(collection, sender, token_id, &property_key)?;331332		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {333			properties.remove(&property_key)334		})335		.map_err(<CommonError<T>>::from)?;336337		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(338			collection.id,339			token_id,340			property_key,341		));342343		Ok(())344	}345346	fn check_token_change_permission(347		collection: &NonfungibleHandle<T>,348		sender: &T::CrossAccountId,349		token_id: TokenId,350		property_key: &PropertyKey,351	) -> DispatchResult {352		let permission = <PalletCommon<T>>::property_permissions(collection.id)353			.get(property_key)354			.map(|p| p.clone())355			.unwrap_or(PropertyPermission::none());356357		let token_data = <TokenData<T>>::get((collection.id, token_id))358			.ok_or(<CommonError<T>>::TokenNotFound)?;359360		let check_token_owner = || -> DispatchResult {361			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);362			Ok(())363		};364365		let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))366			.get(property_key)367			.is_some();368369		match permission {370			PropertyPermission { mutable: false, .. } if is_property_exists => {371				Err(<CommonError<T>>::NoPermission.into())372			}373374			PropertyPermission {375				collection_admin,376				token_owner,377				..378			} => {379				let mut check_result = Err(<CommonError<T>>::NoPermission.into());380381				if collection_admin {382					check_result = collection.check_is_owner_or_admin(sender);383				}384385				if token_owner {386					check_result.or_else(|_| check_token_owner())387				} else {388					check_result389				}390			}391		}392	}393394	#[transactional]395	pub fn delete_token_properties(396		collection: &NonfungibleHandle<T>,397		sender: &T::CrossAccountId,398		token_id: TokenId,399		property_keys: Vec<PropertyKey>,400	) -> DispatchResult {401		for key in property_keys {402			Self::delete_token_property(collection, sender, token_id, key)?;403		}404405		Ok(())406	}407408	pub fn set_collection_properties(409		collection: &NonfungibleHandle<T>,410		sender: &T::CrossAccountId,411		properties: Vec<Property>,412	) -> DispatchResult {413		<PalletCommon<T>>::set_collection_properties(collection, sender, properties)414	}415416	pub fn delete_collection_properties(417		collection: &CollectionHandle<T>,418		sender: &T::CrossAccountId,419		property_keys: Vec<PropertyKey>,420	) -> DispatchResult {421		<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)422	}423424	pub fn set_property_permissions(425		collection: &CollectionHandle<T>,426		sender: &T::CrossAccountId,427		property_permissions: Vec<PropertyKeyPermission>,428	) -> DispatchResult {429		<PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)430	}431432	pub fn transfer(433		collection: &NonfungibleHandle<T>,434		from: &T::CrossAccountId,435		to: &T::CrossAccountId,436		token: TokenId,437		nesting_budget: &dyn Budget,438	) -> DispatchResult {439		ensure!(440			collection.limits.transfers_enabled(),441			<CommonError<T>>::TransferNotAllowed442		);443444		let token_data =445			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;446		// TODO: require sender to be token, owner, require admins to go through transfer_from447		ensure!(448			&token_data.owner == from449				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),450			<CommonError<T>>::NoPermission451		);452453		if collection.access == AccessMode::AllowList {454			collection.check_allowlist(from)?;455			collection.check_allowlist(to)?;456		}457		<PalletCommon<T>>::ensure_correct_receiver(to)?;458459		let balance_from = <AccountBalance<T>>::get((collection.id, from))460			.checked_sub(1)461			.ok_or(<CommonError<T>>::TokenValueTooLow)?;462		let balance_to = if from != to {463			let balance_to = <AccountBalance<T>>::get((collection.id, to))464				.checked_add(1)465				.ok_or(ArithmeticError::Overflow)?;466467			ensure!(468				balance_to < collection.limits.account_token_ownership_limit(),469				<CommonError<T>>::AccountTokenLimitExceeded,470			);471472			Some(balance_to)473		} else {474			None475		};476477		if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {478			let handle = <CollectionHandle<T>>::try_get(target.0)?;479			let dispatch = T::CollectionDispatch::dispatch(handle);480			let dispatch = dispatch.as_dyn();481482			dispatch.check_nesting(483				from.clone(),484				(collection.id, token),485				target.1,486				nesting_budget,487			)?;488		}489490		// =========491492		<TokenData<T>>::insert(493			(collection.id, token),494			ItemData {495				owner: to.clone(),496				..token_data497			},498		);499500		if let Some(balance_to) = balance_to {501			// from != to502			if balance_from == 0 {503				<AccountBalance<T>>::remove((collection.id, from));504			} else {505				<AccountBalance<T>>::insert((collection.id, from), balance_from);506			}507			<AccountBalance<T>>::insert((collection.id, to), balance_to);508			<Owned<T>>::remove((collection.id, from, token));509			<Owned<T>>::insert((collection.id, to, token), true);510		}511		Self::set_allowance_unchecked(collection, from, token, None, true);512513		<PalletEvm<T>>::deposit_log(514			ERC721Events::Transfer {515				from: *from.as_eth(),516				to: *to.as_eth(),517				token_id: token.into(),518			}519			.to_log(collection_id_to_address(collection.id)),520		);521		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(522			collection.id,523			token,524			from.clone(),525			to.clone(),526			1,527		));528		Ok(())529	}530531	pub fn create_multiple_items(532		collection: &NonfungibleHandle<T>,533		sender: &T::CrossAccountId,534		data: Vec<CreateItemData<T>>,535		nesting_budget: &dyn Budget,536	) -> DispatchResult {537		if !collection.is_owner_or_admin(sender) {538			ensure!(539				collection.mint_mode,540				<CommonError<T>>::PublicMintingNotAllowed541			);542			collection.check_allowlist(sender)?;543544			for item in data.iter() {545				collection.check_allowlist(&item.owner)?;546			}547		}548549		for data in data.iter() {550			<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;551		}552553		let first_token = <TokensMinted<T>>::get(collection.id);554		let tokens_minted = first_token555			.checked_add(data.len() as u32)556			.ok_or(ArithmeticError::Overflow)?;557		ensure!(558			tokens_minted <= collection.limits.token_limit(),559			<CommonError<T>>::CollectionTokenLimitExceeded560		);561562		let mut balances = BTreeMap::new();563		for data in &data {564			let balance = balances565				.entry(&data.owner)566				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));567			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;568569			ensure!(570				*balance <= collection.limits.account_token_ownership_limit(),571				<CommonError<T>>::AccountTokenLimitExceeded,572			);573		}574575		for (i, data) in data.iter().enumerate() {576			let token = TokenId(first_token + i as u32 + 1);577			if let Some(target) = T::CrossTokenAddressMapping::address_to_token(&data.owner) {578				let handle = <CollectionHandle<T>>::try_get(target.0)?;579				let dispatch = T::CollectionDispatch::dispatch(handle);580				let dispatch = dispatch.as_dyn();581				dispatch.check_nesting(582					sender.clone(),583					(collection.id, token),584					target.1,585					nesting_budget,586				)?;587			}588		}589590		// =========591592		<TokensMinted<T>>::insert(collection.id, tokens_minted);593		for (account, balance) in balances {594			<AccountBalance<T>>::insert((collection.id, account), balance);595		}596		for (i, data) in data.into_iter().enumerate() {597			let token = first_token + i as u32 + 1;598599			<TokenData<T>>::insert(600				(collection.id, token),601				ItemData {602					const_data: data.const_data,603					owner: data.owner.clone(),604				},605			);606			<Owned<T>>::insert((collection.id, &data.owner, token), true);607608			Self::set_token_properties(609				collection,610				sender,611				TokenId(token),612				data.properties.into_inner(),613			)?;614615			<PalletEvm<T>>::deposit_log(616				ERC721Events::Transfer {617					from: H160::default(),618					to: *data.owner.as_eth(),619					token_id: token.into(),620				}621				.to_log(collection_id_to_address(collection.id)),622			);623			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(624				collection.id,625				TokenId(token),626				data.owner.clone(),627				1,628			));629		}630		Ok(())631	}632633	pub fn set_allowance_unchecked(634		collection: &NonfungibleHandle<T>,635		sender: &T::CrossAccountId,636		token: TokenId,637		spender: Option<&T::CrossAccountId>,638		assume_implicit_eth: bool,639	) {640		if let Some(spender) = spender {641			let old_spender = <Allowance<T>>::get((collection.id, token));642			<Allowance<T>>::insert((collection.id, token), spender);643			// In ERC721 there is only one possible approved user of token, so we set644			// approved user to spender645			<PalletEvm<T>>::deposit_log(646				ERC721Events::Approval {647					owner: *sender.as_eth(),648					approved: *spender.as_eth(),649					token_id: token.into(),650				}651				.to_log(collection_id_to_address(collection.id)),652			);653			// In Unique chain, any token can have any amount of approved users, so we need to654			// set allowance of old owner to 0, and allowance of new owner to 1655			if old_spender.as_ref() != Some(spender) {656				if let Some(old_owner) = old_spender {657					<PalletCommon<T>>::deposit_event(CommonEvent::Approved(658						collection.id,659						token,660						sender.clone(),661						old_owner,662						0,663					));664				}665				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(666					collection.id,667					token,668					sender.clone(),669					spender.clone(),670					1,671				));672			}673		} else {674			let old_spender = <Allowance<T>>::take((collection.id, token));675			if !assume_implicit_eth {676				// In ERC721 there is only one possible approved user of token, so we set677				// approved user to zero address678				<PalletEvm<T>>::deposit_log(679					ERC721Events::Approval {680						owner: *sender.as_eth(),681						approved: H160::default(),682						token_id: token.into(),683					}684					.to_log(collection_id_to_address(collection.id)),685				);686			}687			// In Unique chain, any token can have any amount of approved users, so we need to688			// set allowance of old owner to 0689			if let Some(old_spender) = old_spender {690				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(691					collection.id,692					token,693					sender.clone(),694					old_spender,695					0,696				));697			}698		}699	}700701	pub fn set_allowance(702		collection: &NonfungibleHandle<T>,703		sender: &T::CrossAccountId,704		token: TokenId,705		spender: Option<&T::CrossAccountId>,706	) -> DispatchResult {707		if collection.access == AccessMode::AllowList {708			collection.check_allowlist(sender)?;709			if let Some(spender) = spender {710				collection.check_allowlist(spender)?;711			}712		}713714		if let Some(spender) = spender {715			<PalletCommon<T>>::ensure_correct_receiver(spender)?;716		}717		let token_data =718			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;719		if &token_data.owner != sender {720			ensure!(721				collection.ignores_owned_amount(sender),722				<CommonError<T>>::CantApproveMoreThanOwned723			);724		}725726		// =========727728		Self::set_allowance_unchecked(collection, sender, token, spender, false);729		Ok(())730	}731732	fn check_allowed(733		collection: &NonfungibleHandle<T>,734		spender: &T::CrossAccountId,735		from: &T::CrossAccountId,736		token: TokenId,737		nesting_budget: &dyn Budget,738	) -> DispatchResult {739		if spender.conv_eq(from) {740			return Ok(());741		}742		if collection.access == AccessMode::AllowList {743			// `from`, `to` checked in [`transfer`]744			collection.check_allowlist(spender)?;745		}746		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {747			// TODO: should collection owner be allowed to perform this transfer?748			ensure!(749				<PalletStructure<T>>::check_indirectly_owned(750					spender.clone(),751					source.0,752					source.1,753					None,754					nesting_budget755				)?,756				<CommonError<T>>::ApprovedValueTooLow,757			);758			return Ok(());759		}760		if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {761			return Ok(());762		}763		ensure!(764			collection.ignores_allowance(spender),765			<CommonError<T>>::ApprovedValueTooLow766		);767		Ok(())768	}769770	pub fn transfer_from(771		collection: &NonfungibleHandle<T>,772		spender: &T::CrossAccountId,773		from: &T::CrossAccountId,774		to: &T::CrossAccountId,775		token: TokenId,776		nesting_budget: &dyn Budget,777	) -> DispatchResult {778		Self::check_allowed(collection, spender, from, token, nesting_budget)?;779780		// =========781782		// Allowance is reset in [`transfer`]783		Self::transfer(collection, from, to, token, nesting_budget)784	}785786	pub fn burn_from(787		collection: &NonfungibleHandle<T>,788		spender: &T::CrossAccountId,789		from: &T::CrossAccountId,790		token: TokenId,791		nesting_budget: &dyn Budget,792	) -> DispatchResult {793		Self::check_allowed(collection, spender, from, token, nesting_budget)?;794795		// =========796797		Self::burn(collection, from, token)798	}799800	pub fn check_nesting(801		handle: &NonfungibleHandle<T>,802		sender: T::CrossAccountId,803		from: (CollectionId, TokenId),804		under: TokenId,805		nesting_budget: &dyn Budget,806	) -> DispatchResult {807		fn ensure_sender_allowed<T: Config>(808			collection: CollectionId,809			token: TokenId,810			for_nest: (CollectionId, TokenId),811			sender: T::CrossAccountId,812			budget: &dyn Budget,813		) -> DispatchResult {814			ensure!(815				<PalletStructure<T>>::check_indirectly_owned(816					sender,817					collection,818					token,819					Some(for_nest),820					budget821				)?,822				<CommonError<T>>::OnlyOwnerAllowedToNest,823			);824			Ok(())825		}826		match handle.limits.nesting_rule() {827			NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),828			NestingRule::Owner => {829				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?830			}831			NestingRule::OwnerRestricted(whitelist) => {832				ensure!(833					whitelist.contains(&from.0),834					<CommonError<T>>::SourceCollectionIsNotAllowedToNest835				);836				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?837			}838		}839		Ok(())840	}841842	/// Delegated to `create_multiple_items`843	pub fn create_item(844		collection: &NonfungibleHandle<T>,845		sender: &T::CrossAccountId,846		data: CreateItemData<T>,847		nesting_budget: &dyn Budget,848	) -> DispatchResult {849		Self::create_multiple_items(collection, sender, vec![data], nesting_budget)850	}851}
after · pallets/nonfungible/src/lib.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#![cfg_attr(not(feature = "std"), no_std)]1819use erc::ERC721Events;20use evm_coder::ToLog;21use frame_support::{BoundedVec, ensure, fail, transactional};22use up_data_structs::{23	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,25	PropertyKey, PropertyKeyPermission, Properties, TrySet,26};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};28use pallet_common::{29	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,30	dispatch::CollectionDispatch, eth::collection_id_to_address,31};32use pallet_structure::Pallet as PalletStructure;33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};34use sp_core::H160;35use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};36use sp_std::{vec::Vec, vec};37use core::ops::Deref;38use sp_std::collections::btree_map::BTreeMap;39use codec::{Encode, Decode, MaxEncodedLen};40use scale_info::TypeInfo;4142pub use pallet::*;43#[cfg(feature = "runtime-benchmarks")]44pub mod benchmarking;45pub mod common;46pub mod erc;47pub mod weights;4849pub type CreateItemData<T> = CreateNftExData<<T as pallet_evm::account::Config>::CrossAccountId>;50pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;5152#[struct_versioning::versioned(version = 2, upper)]53#[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]54pub struct ItemData<CrossAccountId> {55	pub const_data: BoundedVec<u8, CustomDataLimit>,5657	#[version(..2)]58	pub variable_data: BoundedVec<u8, CustomDataLimit>,5960	pub owner: CrossAccountId,61}6263#[frame_support::pallet]64pub mod pallet {65	use super::*;66	use frame_support::{67		Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion,68	};69	use frame_system::pallet_prelude::*;70	use up_data_structs::{CollectionId, TokenId};71	use super::weights::WeightInfo;7273	#[pallet::error]74	pub enum Error<T> {75		/// Not Nonfungible item data used to mint in Nonfungible collection.76		NotNonfungibleDataUsedToMintFungibleCollectionToken,77		/// Used amount > 1 with NFT78		NonfungibleItemsHaveNoAmount,79	}8081	#[pallet::config]82	pub trait Config:83		frame_system::Config + pallet_common::Config + pallet_structure::Config + pallet_evm::Config84	{85		type WeightInfo: WeightInfo;86	}8788	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8990	#[pallet::pallet]91	#[pallet::storage_version(STORAGE_VERSION)]92	#[pallet::generate_store(pub(super) trait Store)]93	pub struct Pallet<T>(_);9495	#[pallet::storage]96	pub type TokensMinted<T: Config> =97		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;98	#[pallet::storage]99	pub type TokensBurnt<T: Config> =100		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;101102	#[pallet::storage]103	pub type TokenData<T: Config> = StorageNMap<104		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),105		Value = ItemData<T::CrossAccountId>,106		QueryKind = OptionQuery,107	>;108109	#[pallet::storage]110	#[pallet::getter(fn token_properties)]111	pub type TokenProperties<T: Config> = StorageNMap<112		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),113		Value = Properties,114		QueryKind = ValueQuery,115		OnEmpty = up_data_structs::TokenProperties,116	>;117118	/// Used to enumerate tokens owned by account119	#[pallet::storage]120	pub type Owned<T: Config> = StorageNMap<121		Key = (122			Key<Twox64Concat, CollectionId>,123			Key<Blake2_128Concat, T::CrossAccountId>,124			Key<Twox64Concat, TokenId>,125		),126		Value = bool,127		QueryKind = ValueQuery,128	>;129130	#[pallet::storage]131	pub type AccountBalance<T: Config> = StorageNMap<132		Key = (133			Key<Twox64Concat, CollectionId>,134			Key<Blake2_128Concat, T::CrossAccountId>,135		),136		Value = u32,137		QueryKind = ValueQuery,138	>;139140	#[pallet::storage]141	pub type Allowance<T: Config> = StorageNMap<142		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),143		Value = T::CrossAccountId,144		QueryKind = OptionQuery,145	>;146147	#[pallet::hooks]148	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {149		fn on_runtime_upgrade() -> Weight {150			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {151				<TokenData<T>>::translate_values::<ItemDataVersion1<T::CrossAccountId>, _>(|v| {152					Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))153				})154			}155156			0157		}158	}159}160161pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);162impl<T: Config> NonfungibleHandle<T> {163	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {164		Self(inner)165	}166	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {167		self.0168	}169	pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {170		&mut self.0171	}172}173impl<T: Config> WithRecorder<T> for NonfungibleHandle<T> {174	fn recorder(&self) -> &SubstrateRecorder<T> {175		self.0.recorder()176	}177	fn into_recorder(self) -> SubstrateRecorder<T> {178		self.0.into_recorder()179	}180}181impl<T: Config> Deref for NonfungibleHandle<T> {182	type Target = pallet_common::CollectionHandle<T>;183184	fn deref(&self) -> &Self::Target {185		&self.0186	}187}188189impl<T: Config> Pallet<T> {190	pub fn total_supply(collection: &NonfungibleHandle<T>) -> u32 {191		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)192	}193	pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {194		<TokenData<T>>::contains_key((collection.id, token))195	}196}197198// unchecked calls skips any permission checks199impl<T: Config> Pallet<T> {200	pub fn init_collection(201		owner: T::AccountId,202		data: CreateCollectionData<T::AccountId>,203	) -> Result<CollectionId, DispatchError> {204		<PalletCommon<T>>::init_collection(owner, data)205	}206	pub fn destroy_collection(207		collection: NonfungibleHandle<T>,208		sender: &T::CrossAccountId,209	) -> DispatchResult {210		let id = collection.id;211212		// =========213214		PalletCommon::destroy_collection(collection.0, sender)?;215216		<TokenData<T>>::remove_prefix((id,), None);217		<Owned<T>>::remove_prefix((id,), None);218		<TokensMinted<T>>::remove(id);219		<TokensBurnt<T>>::remove(id);220		<Allowance<T>>::remove_prefix((id,), None);221		<AccountBalance<T>>::remove_prefix((id,), None);222		Ok(())223	}224225	pub fn burn(226		collection: &NonfungibleHandle<T>,227		sender: &T::CrossAccountId,228		token: TokenId,229	) -> DispatchResult {230		let token_data =231			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;232		ensure!(233			&token_data.owner == sender234				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(sender)),235			<CommonError<T>>::NoPermission236		);237238		if collection.access == AccessMode::AllowList {239			collection.check_allowlist(sender)?;240		}241242		let burnt = <TokensBurnt<T>>::get(collection.id)243			.checked_add(1)244			.ok_or(ArithmeticError::Overflow)?;245246		let balance = <AccountBalance<T>>::get((collection.id, token_data.owner.clone()))247			.checked_sub(1)248			.ok_or(ArithmeticError::Overflow)?;249250		if balance == 0 {251			<AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));252		} else {253			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);254		}255		// =========256257		<Owned<T>>::remove((collection.id, &token_data.owner, token));258		<TokensBurnt<T>>::insert(collection.id, burnt);259		<TokenData<T>>::remove((collection.id, token));260		let old_spender = <Allowance<T>>::take((collection.id, token));261262		if let Some(old_spender) = old_spender {263			<PalletCommon<T>>::deposit_event(CommonEvent::Approved(264				collection.id,265				token,266				sender.clone(),267				old_spender,268				0,269			));270		}271272		<PalletEvm<T>>::deposit_log(273			ERC721Events::Transfer {274				from: *token_data.owner.as_eth(),275				to: H160::default(),276				token_id: token.into(),277			}278			.to_log(collection_id_to_address(collection.id)),279		);280		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(281			collection.id,282			token,283			token_data.owner,284			1,285		));286		Ok(())287	}288289	pub fn set_token_property(290		collection: &NonfungibleHandle<T>,291		sender: &T::CrossAccountId,292		token_id: TokenId,293		property: Property,294	) -> DispatchResult {295		Self::check_token_change_permission(collection, sender, token_id, &property.key)?;296297		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {298			let property = property.clone();299			properties.try_set(property.key, property.value)300		})301		.map_err(<CommonError<T>>::from)?;302303		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(304			collection.id,305			token_id,306			property.key,307		));308309		Ok(())310	}311312	#[transactional]313	pub fn set_token_properties(314		collection: &NonfungibleHandle<T>,315		sender: &T::CrossAccountId,316		token_id: TokenId,317		properties: Vec<Property>,318	) -> DispatchResult {319		for property in properties {320			Self::set_token_property(collection, sender, token_id, property)?;321		}322323		Ok(())324	}325326	pub fn delete_token_property(327		collection: &NonfungibleHandle<T>,328		sender: &T::CrossAccountId,329		token_id: TokenId,330		property_key: PropertyKey,331	) -> DispatchResult {332		Self::check_token_change_permission(collection, sender, token_id, &property_key)?;333334		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {335			properties.remove(&property_key)336		})337		.map_err(<CommonError<T>>::from)?;338339		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(340			collection.id,341			token_id,342			property_key,343		));344345		Ok(())346	}347348	fn check_token_change_permission(349		collection: &NonfungibleHandle<T>,350		sender: &T::CrossAccountId,351		token_id: TokenId,352		property_key: &PropertyKey,353	) -> DispatchResult {354		let permission = <PalletCommon<T>>::property_permissions(collection.id)355			.get(property_key)356			.map(|p| p.clone())357			.unwrap_or(PropertyPermission::none());358359		let token_data = <TokenData<T>>::get((collection.id, token_id))360			.ok_or(<CommonError<T>>::TokenNotFound)?;361362		let check_token_owner = || -> DispatchResult {363			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);364			Ok(())365		};366367		let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))368			.get(property_key)369			.is_some();370371		match permission {372			PropertyPermission { mutable: false, .. } if is_property_exists => {373				Err(<CommonError<T>>::NoPermission.into())374			}375376			PropertyPermission {377				collection_admin,378				token_owner,379				..380			} => {381				let mut check_result = Err(<CommonError<T>>::NoPermission.into());382383				if collection_admin {384					check_result = collection.check_is_owner_or_admin(sender);385				}386387				if token_owner {388					check_result.or_else(|_| check_token_owner())389				} else {390					check_result391				}392			}393		}394	}395396	#[transactional]397	pub fn delete_token_properties(398		collection: &NonfungibleHandle<T>,399		sender: &T::CrossAccountId,400		token_id: TokenId,401		property_keys: Vec<PropertyKey>,402	) -> DispatchResult {403		for key in property_keys {404			Self::delete_token_property(collection, sender, token_id, key)?;405		}406407		Ok(())408	}409410	pub fn set_collection_properties(411		collection: &NonfungibleHandle<T>,412		sender: &T::CrossAccountId,413		properties: Vec<Property>,414	) -> DispatchResult {415		<PalletCommon<T>>::set_collection_properties(collection, sender, properties)416	}417418	pub fn delete_collection_properties(419		collection: &CollectionHandle<T>,420		sender: &T::CrossAccountId,421		property_keys: Vec<PropertyKey>,422	) -> DispatchResult {423		<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)424	}425426	pub fn set_property_permissions(427		collection: &CollectionHandle<T>,428		sender: &T::CrossAccountId,429		property_permissions: Vec<PropertyKeyPermission>,430	) -> DispatchResult {431		<PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)432	}433434	pub fn set_property_permission(435		collection: &CollectionHandle<T>,436		sender: &T::CrossAccountId,437		permission: PropertyKeyPermission,438	) -> DispatchResult {439		<PalletCommon<T>>::set_property_permission(collection, sender, permission)440	}441442	pub fn transfer(443		collection: &NonfungibleHandle<T>,444		from: &T::CrossAccountId,445		to: &T::CrossAccountId,446		token: TokenId,447		nesting_budget: &dyn Budget,448	) -> DispatchResult {449		ensure!(450			collection.limits.transfers_enabled(),451			<CommonError<T>>::TransferNotAllowed452		);453454		let token_data =455			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;456		// TODO: require sender to be token, owner, require admins to go through transfer_from457		ensure!(458			&token_data.owner == from459				|| (collection.limits.owner_can_transfer() && collection.is_owner_or_admin(from)),460			<CommonError<T>>::NoPermission461		);462463		if collection.access == AccessMode::AllowList {464			collection.check_allowlist(from)?;465			collection.check_allowlist(to)?;466		}467		<PalletCommon<T>>::ensure_correct_receiver(to)?;468469		let balance_from = <AccountBalance<T>>::get((collection.id, from))470			.checked_sub(1)471			.ok_or(<CommonError<T>>::TokenValueTooLow)?;472		let balance_to = if from != to {473			let balance_to = <AccountBalance<T>>::get((collection.id, to))474				.checked_add(1)475				.ok_or(ArithmeticError::Overflow)?;476477			ensure!(478				balance_to < collection.limits.account_token_ownership_limit(),479				<CommonError<T>>::AccountTokenLimitExceeded,480			);481482			Some(balance_to)483		} else {484			None485		};486487		if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {488			let handle = <CollectionHandle<T>>::try_get(target.0)?;489			let dispatch = T::CollectionDispatch::dispatch(handle);490			let dispatch = dispatch.as_dyn();491492			dispatch.check_nesting(493				from.clone(),494				(collection.id, token),495				target.1,496				nesting_budget,497			)?;498		}499500		// =========501502		<TokenData<T>>::insert(503			(collection.id, token),504			ItemData {505				owner: to.clone(),506				..token_data507			},508		);509510		if let Some(balance_to) = balance_to {511			// from != to512			if balance_from == 0 {513				<AccountBalance<T>>::remove((collection.id, from));514			} else {515				<AccountBalance<T>>::insert((collection.id, from), balance_from);516			}517			<AccountBalance<T>>::insert((collection.id, to), balance_to);518			<Owned<T>>::remove((collection.id, from, token));519			<Owned<T>>::insert((collection.id, to, token), true);520		}521		Self::set_allowance_unchecked(collection, from, token, None, true);522523		<PalletEvm<T>>::deposit_log(524			ERC721Events::Transfer {525				from: *from.as_eth(),526				to: *to.as_eth(),527				token_id: token.into(),528			}529			.to_log(collection_id_to_address(collection.id)),530		);531		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(532			collection.id,533			token,534			from.clone(),535			to.clone(),536			1,537		));538		Ok(())539	}540541	pub fn create_multiple_items(542		collection: &NonfungibleHandle<T>,543		sender: &T::CrossAccountId,544		data: Vec<CreateItemData<T>>,545		nesting_budget: &dyn Budget,546	) -> DispatchResult {547		if !collection.is_owner_or_admin(sender) {548			ensure!(549				collection.mint_mode,550				<CommonError<T>>::PublicMintingNotAllowed551			);552			collection.check_allowlist(sender)?;553554			for item in data.iter() {555				collection.check_allowlist(&item.owner)?;556			}557		}558559		for data in data.iter() {560			<PalletCommon<T>>::ensure_correct_receiver(&data.owner)?;561		}562563		let first_token = <TokensMinted<T>>::get(collection.id);564		let tokens_minted = first_token565			.checked_add(data.len() as u32)566			.ok_or(ArithmeticError::Overflow)?;567		ensure!(568			tokens_minted <= collection.limits.token_limit(),569			<CommonError<T>>::CollectionTokenLimitExceeded570		);571572		let mut balances = BTreeMap::new();573		for data in &data {574			let balance = balances575				.entry(&data.owner)576				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));577			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;578579			ensure!(580				*balance <= collection.limits.account_token_ownership_limit(),581				<CommonError<T>>::AccountTokenLimitExceeded,582			);583		}584585		for (i, data) in data.iter().enumerate() {586			let token = TokenId(first_token + i as u32 + 1);587			if let Some(target) = T::CrossTokenAddressMapping::address_to_token(&data.owner) {588				let handle = <CollectionHandle<T>>::try_get(target.0)?;589				let dispatch = T::CollectionDispatch::dispatch(handle);590				let dispatch = dispatch.as_dyn();591				dispatch.check_nesting(592					sender.clone(),593					(collection.id, token),594					target.1,595					nesting_budget,596				)?;597			}598		}599600		// =========601602		<TokensMinted<T>>::insert(collection.id, tokens_minted);603		for (account, balance) in balances {604			<AccountBalance<T>>::insert((collection.id, account), balance);605		}606		for (i, data) in data.into_iter().enumerate() {607			let token = first_token + i as u32 + 1;608609			<TokenData<T>>::insert(610				(collection.id, token),611				ItemData {612					const_data: data.const_data,613					owner: data.owner.clone(),614				},615			);616			<Owned<T>>::insert((collection.id, &data.owner, token), true);617618			Self::set_token_properties(619				collection,620				sender,621				TokenId(token),622				data.properties.into_inner(),623			)?;624625			<PalletEvm<T>>::deposit_log(626				ERC721Events::Transfer {627					from: H160::default(),628					to: *data.owner.as_eth(),629					token_id: token.into(),630				}631				.to_log(collection_id_to_address(collection.id)),632			);633			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(634				collection.id,635				TokenId(token),636				data.owner.clone(),637				1,638			));639		}640		Ok(())641	}642643	pub fn set_allowance_unchecked(644		collection: &NonfungibleHandle<T>,645		sender: &T::CrossAccountId,646		token: TokenId,647		spender: Option<&T::CrossAccountId>,648		assume_implicit_eth: bool,649	) {650		if let Some(spender) = spender {651			let old_spender = <Allowance<T>>::get((collection.id, token));652			<Allowance<T>>::insert((collection.id, token), spender);653			// In ERC721 there is only one possible approved user of token, so we set654			// approved user to spender655			<PalletEvm<T>>::deposit_log(656				ERC721Events::Approval {657					owner: *sender.as_eth(),658					approved: *spender.as_eth(),659					token_id: token.into(),660				}661				.to_log(collection_id_to_address(collection.id)),662			);663			// In Unique chain, any token can have any amount of approved users, so we need to664			// set allowance of old owner to 0, and allowance of new owner to 1665			if old_spender.as_ref() != Some(spender) {666				if let Some(old_owner) = old_spender {667					<PalletCommon<T>>::deposit_event(CommonEvent::Approved(668						collection.id,669						token,670						sender.clone(),671						old_owner,672						0,673					));674				}675				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(676					collection.id,677					token,678					sender.clone(),679					spender.clone(),680					1,681				));682			}683		} else {684			let old_spender = <Allowance<T>>::take((collection.id, token));685			if !assume_implicit_eth {686				// In ERC721 there is only one possible approved user of token, so we set687				// approved user to zero address688				<PalletEvm<T>>::deposit_log(689					ERC721Events::Approval {690						owner: *sender.as_eth(),691						approved: H160::default(),692						token_id: token.into(),693					}694					.to_log(collection_id_to_address(collection.id)),695				);696			}697			// In Unique chain, any token can have any amount of approved users, so we need to698			// set allowance of old owner to 0699			if let Some(old_spender) = old_spender {700				<PalletCommon<T>>::deposit_event(CommonEvent::Approved(701					collection.id,702					token,703					sender.clone(),704					old_spender,705					0,706				));707			}708		}709	}710711	pub fn set_allowance(712		collection: &NonfungibleHandle<T>,713		sender: &T::CrossAccountId,714		token: TokenId,715		spender: Option<&T::CrossAccountId>,716	) -> DispatchResult {717		if collection.access == AccessMode::AllowList {718			collection.check_allowlist(sender)?;719			if let Some(spender) = spender {720				collection.check_allowlist(spender)?;721			}722		}723724		if let Some(spender) = spender {725			<PalletCommon<T>>::ensure_correct_receiver(spender)?;726		}727		let token_data =728			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;729		if &token_data.owner != sender {730			ensure!(731				collection.ignores_owned_amount(sender),732				<CommonError<T>>::CantApproveMoreThanOwned733			);734		}735736		// =========737738		Self::set_allowance_unchecked(collection, sender, token, spender, false);739		Ok(())740	}741742	fn check_allowed(743		collection: &NonfungibleHandle<T>,744		spender: &T::CrossAccountId,745		from: &T::CrossAccountId,746		token: TokenId,747		nesting_budget: &dyn Budget,748	) -> DispatchResult {749		if spender.conv_eq(from) {750			return Ok(());751		}752		if collection.access == AccessMode::AllowList {753			// `from`, `to` checked in [`transfer`]754			collection.check_allowlist(spender)?;755		}756		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {757			// TODO: should collection owner be allowed to perform this transfer?758			ensure!(759				<PalletStructure<T>>::check_indirectly_owned(760					spender.clone(),761					source.0,762					source.1,763					None,764					nesting_budget765				)?,766				<CommonError<T>>::ApprovedValueTooLow,767			);768			return Ok(());769		}770		if <Allowance<T>>::get((collection.id, token)).as_ref() == Some(spender) {771			return Ok(());772		}773		ensure!(774			collection.ignores_allowance(spender),775			<CommonError<T>>::ApprovedValueTooLow776		);777		Ok(())778	}779780	pub fn transfer_from(781		collection: &NonfungibleHandle<T>,782		spender: &T::CrossAccountId,783		from: &T::CrossAccountId,784		to: &T::CrossAccountId,785		token: TokenId,786		nesting_budget: &dyn Budget,787	) -> DispatchResult {788		Self::check_allowed(collection, spender, from, token, nesting_budget)?;789790		// =========791792		// Allowance is reset in [`transfer`]793		Self::transfer(collection, from, to, token, nesting_budget)794	}795796	pub fn burn_from(797		collection: &NonfungibleHandle<T>,798		spender: &T::CrossAccountId,799		from: &T::CrossAccountId,800		token: TokenId,801		nesting_budget: &dyn Budget,802	) -> DispatchResult {803		Self::check_allowed(collection, spender, from, token, nesting_budget)?;804805		// =========806807		Self::burn(collection, from, token)808	}809810	pub fn check_nesting(811		handle: &NonfungibleHandle<T>,812		sender: T::CrossAccountId,813		from: (CollectionId, TokenId),814		under: TokenId,815		nesting_budget: &dyn Budget,816	) -> DispatchResult {817		fn ensure_sender_allowed<T: Config>(818			collection: CollectionId,819			token: TokenId,820			for_nest: (CollectionId, TokenId),821			sender: T::CrossAccountId,822			budget: &dyn Budget,823		) -> DispatchResult {824			ensure!(825				<PalletStructure<T>>::check_indirectly_owned(826					sender,827					collection,828					token,829					Some(for_nest),830					budget831				)?,832				<CommonError<T>>::OnlyOwnerAllowedToNest,833			);834			Ok(())835		}836		match handle.limits.nesting_rule() {837			NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),838			NestingRule::Owner => {839				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?840			}841			NestingRule::OwnerRestricted(whitelist) => {842				ensure!(843					whitelist.contains(&from.0),844					<CommonError<T>>::SourceCollectionIsNotAllowedToNest845				);846				ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?847			}848		}849		Ok(())850	}851852	/// Delegated to `create_multiple_items`853	pub fn create_item(854		collection: &NonfungibleHandle<T>,855		sender: &T::CrossAccountId,856		data: CreateItemData<T>,857		nesting_budget: &dyn Budget,858	) -> DispatchResult {859		Self::create_multiple_items(collection, sender, vec![data], nesting_budget)860	}861}
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
@@ -51,32 +51,68 @@
 	event MintingFinished();
 }
 
-// Selector: 42966c68
-contract ERC721Burnable is Dummy, ERC165 {
-	// Selector: burn(uint256) 42966c68
-	function burn(uint256 tokenId) public {
+// Selector: 41369377
+contract TokenProperties is Dummy, ERC165 {
+	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
+	function setTokenPropertyPermission(
+		string memory key,
+		bool isMutable,
+		bool collectionAdmin,
+		bool tokenOwner
+	) public {
 		require(false, stub_error);
-		tokenId;
+		key;
+		isMutable;
+		collectionAdmin;
+		tokenOwner;
 		dummy = 0;
 	}
-}
 
-// Selector: 56fd500b
-contract CollectionProperties is Dummy, ERC165 {
-	// Selector: setProperty(string,string) 62d9491f
-	function setProperty(string memory key, string memory value) public {
+	// Selector: setProperty(uint256,string,bytes) 1752d67b
+	function setProperty(
+		uint256 tokenId,
+		string memory key,
+		bytes memory value
+	) public {
 		require(false, stub_error);
+		tokenId;
 		key;
 		value;
 		dummy = 0;
 	}
 
-	// Selector: deleteProperty(string) 34241914
-	function deleteProperty(string memory key) public {
+	// Selector: deleteProperty(uint256,string) 066111d1
+	function deleteProperty(uint256 tokenId, string memory key) public {
 		require(false, stub_error);
+		tokenId;
 		key;
 		dummy = 0;
 	}
+
+	// Throws error if key not found
+	//
+	// Selector: property(uint256,string) 7228c327
+	function property(uint256 tokenId, string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		tokenId;
+		key;
+		dummy;
+		return hex"";
+	}
+}
+
+// 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
@@ -294,6 +330,40 @@
 	}
 }
 
+// Selector: 9b5e29c5
+contract CollectionProperties is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
+}
+
 // Selector: d74d154f
 contract ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
@@ -353,5 +423,6 @@
 	ERC721UniqueExtensions,
 	ERC721Mintable,
 	ERC721Burnable,
-	CollectionProperties
+	CollectionProperties,
+	TokenProperties
 {}
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -22,15 +22,6 @@
 	);
 }
 
-// Selector: 56fd500b
-interface CollectionProperties is Dummy, ERC165 {
-	// Selector: setProperty(string,string) 62d9491f
-	function setProperty(string memory key, string memory value) external;
-
-	// Selector: deleteProperty(string) 34241914
-	function deleteProperty(string memory key) external;
-}
-
 // Selector: 79cc6790
 interface ERC20UniqueExtensions is Dummy, ERC165 {
 	// Selector: burnFrom(address,uint256) 79cc6790
@@ -74,6 +65,24 @@
 		returns (uint256);
 }
 
+// Selector: 9b5e29c5
+interface CollectionProperties is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+}
+
 interface UniqueFungible is
 	Dummy,
 	ERC165,
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,21 +42,41 @@
 	event MintingFinished();
 }
 
+// Selector: 41369377
+interface TokenProperties is Dummy, ERC165 {
+	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
+	function setTokenPropertyPermission(
+		string memory key,
+		bool isMutable,
+		bool collectionAdmin,
+		bool tokenOwner
+	) external;
+
+	// Selector: setProperty(uint256,string,bytes) 1752d67b
+	function setProperty(
+		uint256 tokenId,
+		string memory key,
+		bytes memory value
+	) external;
+
+	// Selector: deleteProperty(uint256,string) 066111d1
+	function deleteProperty(uint256 tokenId, string memory key) external;
+
+	// Throws error if key not found
+	//
+	// Selector: property(uint256,string) 7228c327
+	function property(uint256 tokenId, string memory key)
+		external
+		view
+		returns (bytes memory);
+}
+
 // Selector: 42966c68
 interface ERC721Burnable is Dummy, ERC165 {
 	// Selector: burn(uint256) 42966c68
 	function burn(uint256 tokenId) external;
 }
 
-// Selector: 56fd500b
-interface CollectionProperties is Dummy, ERC165 {
-	// Selector: setProperty(string,string) 62d9491f
-	function setProperty(string memory key, string memory value) external;
-
-	// Selector: deleteProperty(string) 34241914
-	function deleteProperty(string memory key) external;
-}
-
 // Selector: 58800161
 interface ERC721 is Dummy, ERC165, ERC721Events {
 	// Selector: balanceOf(address) 70a08231
@@ -171,6 +191,24 @@
 	function totalSupply() external view returns (uint256);
 }
 
+// Selector: 9b5e29c5
+interface CollectionProperties is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+}
+
 // Selector: d74d154f
 interface ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
@@ -202,5 +240,6 @@
 	ERC721UniqueExtensions,
 	ERC721Mintable,
 	ERC721Burnable,
-	CollectionProperties
+	CollectionProperties,
+	TokenProperties
 {}