git.delta.rocks / unique-network / refs/commits / 9d5e6bdc297d

difftreelog

fix forward collection flags

Yaroslav Bolyukin2022-10-13parent: #f27580f.patch.diff
in: master

10 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -9,7 +9,7 @@
 	traits::Get,
 };
 use sp_runtime::DispatchError;
-use up_data_structs::{CollectionId, CreateCollectionData};
+use up_data_structs::{CollectionId, CreateCollectionData, CollectionFlags};
 
 use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
 
@@ -80,6 +80,7 @@
 		sender: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError>;
 
 	/// Delete the collection.
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -212,8 +212,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(owner, payer, data, CollectionFlags::default())
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -55,7 +55,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<Pallet<T>>::init_collection(owner.clone(), owner, data, true)
+			<Pallet<T>>::init_collection(owner.clone(), owner, data, Default::default())
 		},
 		NonfungibleHandle::cast,
 	)
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -408,17 +408,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
-		is_external: bool,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(
-			owner,
-			payer,
-			data,
-			CollectionFlags {
-				external: is_external,
-				..Default::default()
-			},
-		)
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Destroy NFT collection
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -1448,7 +1448,15 @@
 		data: CreateCollectionData<T::AccountId>,
 		properties: impl Iterator<Item = Property>,
 	) -> Result<CollectionId, DispatchError> {
-		let collection_id = <PalletNft<T>>::init_collection(sender.clone(), sender, data, true);
+		let collection_id = <PalletNft<T>>::init_collection(
+			sender.clone(),
+			sender,
+			data,
+			up_data_structs::CollectionFlags {
+				external: true,
+				..Default::default()
+			},
+		);
 
 		if let Err(DispatchError::Arithmetic(_)) = &collection_id {
 			return Err(<Error<T>>::NoAvailableCollectionId.into());
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -254,7 +254,10 @@
 				cross_sender.clone(),
 				cross_sender.clone(),
 				data,
-				true,
+				up_data_structs::CollectionFlags {
+					external: true,
+					..Default::default()
+				},
 			);
 
 			if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -371,8 +371,9 @@
 		owner: T::CrossAccountId,
 		payer: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
+		flags: CollectionFlags,
 	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(owner, payer, data, CollectionFlags::default())
+		<PalletCommon<T>>::init_collection(owner, payer, data, flags)
 	}
 
 	/// Destroy RFT collection
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -34,7 +34,7 @@
 use sp_std::vec;
 use up_data_structs::{
 	CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
-	CollectionMode, PropertyValue,
+	CollectionMode, PropertyValue, CollectionFlags,
 };
 
 use crate::{Config, SelfWeightOf, weights::WeightInfo};
@@ -186,9 +186,16 @@
 	let collection_helpers_address =
 		T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-	let collection_id =
-		T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+	let collection_id = T::CollectionDispatch::create(
+		caller.clone(),
+		collection_helpers_address,
+		data,
+		CollectionFlags {
+			erc721metadata: add_properties,
+			..Default::default()
+		},
+	)
+	.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 	let address = pallet_common::eth::collection_id_to_address(collection_id);
 	Ok(address)
 }
@@ -243,8 +250,13 @@
 		check_sent_amount_equals_collection_creation_price::<T>(value)?;
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
-		let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-			.map_err(dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			collection_helpers_address,
+			data,
+			Default::default(),
+		)
+		.map_err(dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -291,8 +303,16 @@
 		check_sent_amount_equals_collection_creation_price::<T>(value)?;
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
-		let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			collection_helpers_address,
+			data,
+			CollectionFlags {
+				erc721metadata: true,
+				..Default::default()
+			},
+		)
+		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -345,7 +345,7 @@
 
 			// =========
 			let sender = T::CrossAccountId::from_sub(sender);
-			let _id = T::CollectionDispatch::create(sender.clone(), sender, data)?;
+			let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;
 
 			Ok(())
 		}
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
before · runtime/common/dispatch.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/>.1617use frame_support::{dispatch::DispatchResult, ensure};18use pallet_evm::{PrecompileHandle, PrecompileResult};19use sp_core::H160;20use sp_runtime::DispatchError;21use sp_std::{borrow::ToOwned, vec::Vec};22use pallet_common::{23	CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,24	eth::map_eth_to_id,25};26pub use pallet_common::dispatch::CollectionDispatch;27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};28use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};29use pallet_refungible::{30	Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,31};32use up_data_structs::{33	CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,34	CollectionId,35};3637#[cfg(not(feature = "refungible"))]38use pallet_common::unsupported;3940pub enum CollectionDispatchT<T>41where42	T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,43{44	Fungible(FungibleHandle<T>),45	Nonfungible(NonfungibleHandle<T>),46	Refungible(RefungibleHandle<T>),47}48impl<T> CollectionDispatch<T> for CollectionDispatchT<T>49where50	T: pallet_common::Config51		+ pallet_unique::Config52		+ pallet_fungible::Config53		+ pallet_nonfungible::Config54		+ pallet_refungible::Config,55{56	fn create(57		sender: T::CrossAccountId,58		payer: T::CrossAccountId,59		data: CreateCollectionData<T::AccountId>,60	) -> Result<CollectionId, DispatchError> {61		let id = match data.mode {62			CollectionMode::NFT => {63				<PalletNonfungible<T>>::init_collection(sender, payer, data, false)?64			}65			CollectionMode::Fungible(decimal_points) => {66				// check params67				ensure!(68					decimal_points <= MAX_DECIMAL_POINTS,69					pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded70				);71				<PalletFungible<T>>::init_collection(sender, payer, data)?72			}7374			#[cfg(feature = "refungible")]75			CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, payer, data)?,7677			#[cfg(not(feature = "refungible"))]78			CollectionMode::ReFungible => return unsupported!(T),79		};80		Ok(id)81	}8283	fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {84		match collection.mode {85			CollectionMode::ReFungible => {86				PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?87			}88			CollectionMode::Fungible(_) => {89				PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?90			}91			CollectionMode::NFT => {92				PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?93			}94		}95		Ok(())96	}9798	fn dispatch(handle: CollectionHandle<T>) -> Self {99		match handle.mode {100			CollectionMode::Fungible(_) => Self::Fungible(FungibleHandle::cast(handle)),101			CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),102			CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),103		}104	}105106	fn into_inner(self) -> CollectionHandle<T> {107		match self {108			Self::Fungible(f) => f.into_inner(),109			Self::Nonfungible(f) => f.into_inner(),110			Self::Refungible(f) => f.into_inner(),111		}112	}113114	fn as_dyn(&self) -> &dyn CommonCollectionOperations<T> {115		match self {116			Self::Fungible(h) => h,117			Self::Nonfungible(h) => h,118			Self::Refungible(h) => h,119		}120	}121}122123impl<T> pallet_evm::OnMethodCall<T> for CollectionDispatchT<T>124where125	T: pallet_common::Config126		+ pallet_unique::Config127		+ pallet_fungible::Config128		+ pallet_nonfungible::Config129		+ pallet_refungible::Config,130	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,131{132	fn is_reserved(target: &H160) -> bool {133		map_eth_to_id(target).is_some()134	}135	fn is_used(target: &H160) -> bool {136		map_eth_to_id(target)137			.map(<CollectionById<T>>::contains_key)138			.unwrap_or(false)139	}140	fn get_code(target: &H160) -> Option<Vec<u8>> {141		if let Some(collection_id) = map_eth_to_id(target) {142			let collection = <CollectionById<T>>::get(collection_id)?;143			Some(144				match collection.mode {145					CollectionMode::NFT => <NonfungibleHandle<T>>::CODE,146					CollectionMode::Fungible(_) => <FungibleHandle<T>>::CODE,147					CollectionMode::ReFungible => <RefungibleHandle<T>>::CODE,148				}149				.to_owned(),150			)151		} else if let Some((collection_id, _token_id)) =152			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(target)153		{154			let collection = <CollectionById<T>>::get(collection_id)?;155			if collection.mode != CollectionMode::ReFungible {156				return None;157			}158			// TODO: check token existence159			Some(<RefungibleTokenHandle<T>>::CODE.to_owned())160		} else {161			None162		}163	}164	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {165		if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {166			let collection =167				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;168			let dispatched = Self::dispatch(collection);169170			match dispatched {171				Self::Fungible(h) => h.call(handle),172				Self::Nonfungible(h) => h.call(handle),173				Self::Refungible(h) => h.call(handle),174			}175		} else if let Some((collection_id, token_id)) =176			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(177				&handle.code_address(),178			) {179			let collection =180				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;181			if collection.mode != CollectionMode::ReFungible {182				return None;183			}184185			let h = RefungibleHandle::cast(collection);186			// TODO: check token existence187			RefungibleTokenHandle(h, token_id).call(handle)188		} else {189			None190		}191	}192}