difftreelog
fix restore foreign flag, minor fixes
in: master
11 files changed
pallets/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,
)
pallets/common/src/dispatch.rsdiffbeforeafterboth1//! Module with interfaces for dispatching collections.23use frame_support::{4 dispatch::{5 DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, Pays,6 PostDispatchInfo,7 },8 traits::Get,9};10use sp_runtime::DispatchError;11use sp_weights::Weight;12use up_data_structs::{CollectionId, CreateCollectionData};1314use crate::{pallet::Config, CommonCollectionOperations};1516// TODO: move to benchmarking17/// Price of [`dispatch_tx`] call with noop `call` argument18pub fn dispatch_weight<T: Config>() -> Weight {19 // Read collection20 <T as frame_system::Config>::DbWeight::get().reads(1)21 // Dynamic dispatch?22 + Weight::from_parts(6_000_000, 0)23 // submit_logs is measured as part of collection pallets24}2526/// Helper function to implement substrate calls for common collection methods.27///28/// * `collection` - The collection on which to call the method.29/// * `call` - The function in which to call the corresponding method from [`CommonCollectionOperations`].30pub fn dispatch_tx<31 T: Config,32 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,33>(34 collection: CollectionId,35 call: C,36) -> DispatchResultWithPostInfo {37 let dispatched = T::CollectionDispatch::dispatch(collection)38 .and_then(|dispatched| {39 dispatched.check_is_internal()?;40 Ok(dispatched)41 })42 .map_err(|error| DispatchErrorWithPostInfo {43 post_info: PostDispatchInfo {44 actual_weight: Some(dispatch_weight::<T>()),45 pays_fee: Pays::Yes,46 },47 error,48 })?;49 let mut result = call(dispatched.as_dyn());50 match &mut result {51 Ok(PostDispatchInfo {52 actual_weight: Some(weight),53 ..54 })55 | Err(DispatchErrorWithPostInfo {56 post_info: PostDispatchInfo {57 actual_weight: Some(weight),58 ..59 },60 ..61 }) => *weight += dispatch_weight::<T>(),62 _ => {}63 }64 result65}6667/// Interface for working with different collections through the dispatcher.68pub trait CollectionDispatch<T: Config> {69 /// Check if the collection is internal.70 fn check_is_internal(&self) -> DispatchResult;7172 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).73 ///74 /// * `sender` - The user who will become the owner of the collection.75 /// * `payer` - If set, the user who pays the collection creation deposit.76 /// * `data` - Description of the created collection.77 fn create(78 sender: T::CrossAccountId,79 payer: Option<T::CrossAccountId>,80 data: CreateCollectionData<T::CrossAccountId>,81 ) -> Result<CollectionId, DispatchError> {82 Self::create_internal(sender, payer, false, data)83 }8485 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).86 ///87 /// * `sender` - The user who will become the owner of the collection.88 /// * `payer` - If set, the user who pays the collection creation deposit.89 /// * `data` - Description of the created collection.90 /// * `is_special_collection` -- Whether this collection is a system one, i.e. can have special flags set.91 fn create_internal(92 sender: T::CrossAccountId,93 payer: Option<T::CrossAccountId>,94 is_special_collection: bool,95 data: CreateCollectionData<T::CrossAccountId>,96 ) -> Result<CollectionId, DispatchError>;9798 /// Delete the collection.99 ///100 /// * `sender` - The owner of the collection.101 /// * `handle` - Collection handle.102 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult;103104 /// Get a specialized collection from the handle.105 ///106 /// * `handle` - Collection handle.107 fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError>108 where109 Self: Sized;110111 /// Get the implementation of [`CommonCollectionOperations`].112 fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;113}pallets/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 {
pallets/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,
pallets/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,
)
pallets/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,
)
pallets/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,
)
}
pallets/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.
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -380,7 +380,7 @@
pub struct CollectionFlags {
/// Reserved flag
#[bondrewd(bits = "0..1")]
- pub reserved_0: bool,
+ pub foreign: bool,
/// Supports ERC721Metadata
#[bondrewd(bits = "1..2")]
pub erc721metadata: bool,
@@ -395,7 +395,7 @@
impl CollectionFlags {
pub fn is_allowed_for_user(self) -> bool {
- !self.reserved_0 && !self.external && self.reserved == 0
+ !self.foreign && !self.external && self.reserved == 0
}
}
@@ -461,6 +461,8 @@
#[derive(Debug, Encode, Decode, Clone, PartialEq, TypeInfo, Serialize, Deserialize)]
pub struct RpcCollectionFlags {
+ /// Is collection is foreign.
+ pub foreign: bool,
/// Collection supports ERC721Metadata.
pub erc721metadata: bool,
}
@@ -503,7 +505,7 @@
pub read_only: bool,
/// Extra collection flags
- #[version(2.., upper(RpcCollectionFlags {erc721metadata: false}))]
+ #[version(2.., upper(RpcCollectionFlags {foreign: false, erc721metadata: false}))]
pub flags: RpcCollectionFlags,
}
@@ -540,6 +542,7 @@
read_only: true,
flags: RpcCollectionFlags {
+ foreign: false,
erc721metadata: false,
},
}
runtime/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,
runtime/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 {