git.delta.rocks / unique-network / refs/commits / 1eed41e9dfea

difftreelog

fix restore foreign flag, minor fixes

Daniel Shiposha2023-10-19parent: #56fde60.patch.diff
in: master

11 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -121,7 +121,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<Pallet<T>>::init_collection(owner.clone(), Some(owner), data)
+			<Pallet<T>>::init_collection(owner.clone(), Some(owner), false, data)
 		},
 		|h| h,
 	)
modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -78,6 +78,21 @@
 		sender: T::CrossAccountId,
 		payer: Option<T::CrossAccountId>,
 		data: CreateCollectionData<T::CrossAccountId>,
+	) -> Result<CollectionId, DispatchError> {
+		Self::create_internal(sender, payer, false, data)
+	}
+
+	/// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
+	///
+	/// * `sender` - The user who will become the owner of the collection.
+	/// * `payer` - If set, the user who pays the collection creation deposit.
+	/// * `data` - Description of the created collection.
+	/// * `is_special_collection` -- Whether this collection is a system one, i.e. can have special flags set.
+	fn create_internal(
+		sender: T::CrossAccountId,
+		payer: Option<T::CrossAccountId>,
+		is_special_collection: bool,
+		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError>;
 
 	/// Delete the collection.
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1088,6 +1088,7 @@
 			read_only: flags.external,
 
 			flags: RpcCollectionFlags {
+				foreign: flags.foreign,
 				erc721metadata: flags.erc721metadata,
 			},
 		})
@@ -1129,12 +1130,16 @@
 	/// * `owner` - The owner of the collection.
 	/// * `payer` - If set, the user that will pay a deposit for the collection creation.
 	/// * `data` - Description of the created collection.
+	/// * `is_special_collection` -- Whether this collection is a special one, i.e. can have special flags set.
 	pub fn init_collection(
 		owner: T::CrossAccountId,
 		payer: Option<T::CrossAccountId>,
+		is_special_collection: bool,
 		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError> {
-		ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
+		if !is_special_collection {
+			ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
+		}
 
 		// Take a (non-refundable) deposit of collection creation
 		if let Some(payer) = payer {
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -153,9 +153,11 @@
 				.expect("description length < max description length; qed");
 
 			let payer = None;
-			let collection_id = T::CollectionDispatch::create(
+			let is_special_collection = true;
+			let collection_id = T::CollectionDispatch::create_internal(
 				foreign_collection_owner,
 				payer,
+				is_special_collection,
 				CreateCollectionData {
 					name,
 					description,
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -31,7 +31,7 @@
 		owner,
 		CollectionMode::Fungible(0),
 		|owner: T::CrossAccountId, data| {
-			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), data)
+			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)
 		},
 		FungibleHandle::cast,
 	)
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -58,7 +58,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), data)
+			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)
 		},
 		NonfungibleHandle::cast,
 	)
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -20,6 +20,7 @@
 use pallet_common::{
 	bench_init,
 	benchmarking::{create_collection_raw, property_key, property_value},
+	Pallet as PalletCommon,
 };
 use sp_std::prelude::*;
 use up_data_structs::{
@@ -61,7 +62,9 @@
 	create_collection_raw(
 		owner,
 		CollectionMode::ReFungible,
-		|owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),
+		|owner: T::CrossAccountId, data| {
+			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)
+		},
 		RefungibleHandle::cast,
 	)
 }
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -103,7 +103,7 @@
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
 use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
 use up_data_structs::{
-	budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId, CreateCollectionData,
+	budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId,
 	CreateRefungibleExMultipleOwners, PropertiesPermissionMap, Property, PropertyKey,
 	PropertyKeyPermission, PropertyScope, PropertyValue, TokenId, TokenOwnerError,
 	TokenProperties as TokenPropertiesT, MAX_REFUNGIBLE_PIECES,
@@ -296,19 +296,6 @@
 
 // unchecked calls skips any permission checks
 impl<T: Config> Pallet<T> {
-	/// Create RFT 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,
-		payer: T::CrossAccountId,
-		data: CreateCollectionData<T::CrossAccountId>,
-	) -> Result<CollectionId, DispatchError> {
-		<PalletCommon<T>>::init_collection(owner, Some(payer), data)
-	}
-
 	/// Destroy RFT collection
 	///
 	/// `destroy_collection` will throw error if collection contains any tokens.
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
380pub struct CollectionFlags {380pub struct CollectionFlags {
381 /// Reserved flag381 /// Reserved flag
382 #[bondrewd(bits = "0..1")]382 #[bondrewd(bits = "0..1")]
383 pub reserved_0: bool,383 pub foreign: bool,
384 /// Supports ERC721Metadata384 /// Supports ERC721Metadata
385 #[bondrewd(bits = "1..2")]385 #[bondrewd(bits = "1..2")]
386 pub erc721metadata: bool,386 pub erc721metadata: bool,
395395
396impl CollectionFlags {396impl CollectionFlags {
397 pub fn is_allowed_for_user(self) -> bool {397 pub fn is_allowed_for_user(self) -> bool {
398 !self.reserved_0 && !self.external && self.reserved == 0398 !self.foreign && !self.external && self.reserved == 0
399 }399 }
400}400}
401401
461461
462#[derive(Debug, Encode, Decode, Clone, PartialEq, TypeInfo, Serialize, Deserialize)]462#[derive(Debug, Encode, Decode, Clone, PartialEq, TypeInfo, Serialize, Deserialize)]
463pub struct RpcCollectionFlags {463pub struct RpcCollectionFlags {
464 /// Is collection is foreign.
465 pub foreign: bool,
464 /// Collection supports ERC721Metadata.466 /// Collection supports ERC721Metadata.
465 pub erc721metadata: bool,467 pub erc721metadata: bool,
466}468}
503 pub read_only: bool,505 pub read_only: bool,
504506
505 /// Extra collection flags507 /// Extra collection flags
506 #[version(2.., upper(RpcCollectionFlags {erc721metadata: false}))]508 #[version(2.., upper(RpcCollectionFlags {foreign: false, erc721metadata: false}))]
507 pub flags: RpcCollectionFlags,509 pub flags: RpcCollectionFlags,
508}510}
509511
540 read_only: true,542 read_only: true,
541543
542 flags: RpcCollectionFlags {544 flags: RpcCollectionFlags {
545 foreign: false,
543 erc721metadata: false,546 erc721metadata: false,
544 },547 },
545 }548 }
modifiedruntime/common/config/pallets/foreign_asset.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/foreign_asset.rs
+++ b/runtime/common/config/pallets/foreign_asset.rs
@@ -1,4 +1,6 @@
 use frame_support::{parameter_types, PalletId};
+#[cfg(not(feature = "governance"))]
+use frame_system::EnsureRoot;
 use pallet_evm::account::CrossAccountId;
 use sp_core::H160;
 use staging_xcm::prelude::*;
@@ -6,10 +8,6 @@
 
 #[cfg(feature = "governance")]
 use crate::runtime_common::config::governance;
-
-#[cfg(not(feature = "governance"))]
-use frame_system::EnsureRoot;
-
 use crate::{
 	runtime_common::config::{
 		ethereum::CrossAccountId as ConfigCrossAccountId,
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -66,9 +66,10 @@
 		}
 	}
 
-	fn create(
+	fn create_internal(
 		sender: T::CrossAccountId,
 		payer: Option<T::CrossAccountId>,
+		is_special_collection: bool,
 		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError> {
 		match data.mode {
@@ -86,7 +87,7 @@
 			_ => {}
 		};
 
-		<PalletCommon<T>>::init_collection(sender, payer, data)
+		<PalletCommon<T>>::init_collection(sender, payer, is_special_collection, data)
 	}
 
 	fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {