difftreelog
fix use CollectionIssuer enum for collection creation
in: master
6 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -11,7 +11,7 @@
use sp_weights::Weight;
use up_data_structs::{CollectionId, CreateCollectionData};
-use crate::{pallet::Config, CommonCollectionOperations};
+use crate::{pallet::Config, CollectionIssuer, CommonCollectionOperations};
// TODO: move to benchmarking
/// Price of [`dispatch_tx`] call with noop `call` argument
@@ -72,26 +72,11 @@
/// Create a regular 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.
+ /// * `issuer` - An entity that creates the collection.
/// * `data` - Description of the created collection.
fn create(
sender: T::CrossAccountId,
- payer: Option<T::CrossAccountId>,
- data: CreateCollectionData<T::CrossAccountId>,
- ) -> Result<CollectionId, DispatchError> {
- Self::create_raw(sender, payer, false, data)
- }
-
- /// Function for creating regular and special collections.
- ///
- /// * `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 special one, i.e. can have special flags set.
- fn create_raw(
- sender: T::CrossAccountId,
- payer: Option<T::CrossAccountId>,
- is_special_collection: bool,
+ issuer: CollectionIssuer<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError>;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -944,6 +944,15 @@
}
}
+/// An issuer of a collection.
+pub enum CollectionIssuer<CrossAccountId> {
+ /// A user who creates the collection.
+ User(CrossAccountId),
+
+ /// The internal mechanisms are creating the collection.
+ Internals,
+}
+
fn check_token_permissions<T: Config>(
collection_admin_permitted: bool,
token_owner_permitted: bool,
@@ -1128,32 +1137,34 @@
/// Create new collection.
///
/// * `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.
+ /// * `issuer` - An entity that creates the 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,
+ issuer: CollectionIssuer<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError> {
- if !is_special_collection {
- ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
- }
+ match issuer {
+ CollectionIssuer::User(payer) => {
+ ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
- // Take a (non-refundable) deposit of collection creation
- if let Some(payer) = payer {
- let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
- imbalance.subsume(<T as Config>::Currency::deposit(
- &T::TreasuryAccountId::get(),
- T::CollectionCreationPrice::get(),
- Precision::Exact,
- )?);
- let credit =
- <T as Config>::Currency::settle(payer.as_sub(), imbalance, Preservation::Preserve)
- .map_err(|_| Error::<T>::NotSufficientFounds)?;
+ // Take a (non-refundable) deposit of collection creation
+ let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
+ imbalance.subsume(<T as Config>::Currency::deposit(
+ &T::TreasuryAccountId::get(),
+ T::CollectionCreationPrice::get(),
+ Precision::Exact,
+ )?);
+ let credit = <T as Config>::Currency::settle(
+ payer.as_sub(),
+ imbalance,
+ Preservation::Preserve,
+ )
+ .map_err(|_| Error::<T>::NotSufficientFounds)?;
- debug_assert!(credit.peek().is_zero())
+ debug_assert!(credit.peek().is_zero());
+ }
+ CollectionIssuer::Internals => {}
}
{
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth565657#[frame_support::pallet]57#[frame_support::pallet]58pub mod module {58pub mod module {59 use pallet_common::CollectionIssuer;59 use up_data_structs::{60 use up_data_structs::{60 CollectionDescription, Property, PropertyKeyPermission, PropertyPermission,61 CollectionDescription, Property, PropertyKeyPermission, PropertyPermission,61 };62 };169 .try_into()170 .try_into()170 .expect("description length < max description length; qed");171 .expect("description length < max description length; qed");171172172 let payer = None;173 let is_special_collection = true;174 let collection_id = T::CollectionDispatch::create_raw(173 let collection_id = T::CollectionDispatch::create(175 foreign_collection_owner,174 foreign_collection_owner,176 payer,175 CollectionIssuer::Internals,177 is_special_collection,178 CreateCollectionData {176 CreateCollectionData {179 name,177 name,180 token_prefix,178 token_prefix,pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -26,7 +26,7 @@
dispatch::CollectionDispatch,
erc::{static_property::key, CollectionHelpersEvents},
eth::{self, collection_id_to_address, map_eth_to_id},
- CollectionById, CollectionHandle, Pallet as PalletCommon,
+ CollectionById, CollectionHandle, CollectionIssuer, Pallet as PalletCommon,
};
use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
use pallet_evm_coder_substrate::{
@@ -110,9 +110,12 @@
let collection_helpers_address =
T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
- let collection_id =
- T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
- .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+ let collection_id = T::CollectionDispatch::create(
+ caller,
+ CollectionIssuer::User(collection_helpers_address),
+ data,
+ )
+ .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
let address = pallet_common::eth::collection_id_to_address(collection_id);
Ok(address)
}
@@ -241,9 +244,12 @@
let collection_helpers_address =
T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
- let collection_id =
- T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
- .map_err(dispatch_to_evm::<T>)?;
+ let collection_id = T::CollectionDispatch::create(
+ caller,
+ CollectionIssuer::User(collection_helpers_address),
+ data,
+ )
+ .map_err(dispatch_to_evm::<T>)?;
let address = pallet_common::eth::collection_id_to_address(collection_id);
Ok(address)
@@ -276,9 +282,12 @@
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, Some(collection_helpers_address), data)
- .map_err(dispatch_to_evm::<T>)?;
+ let collection_id = T::CollectionDispatch::create(
+ caller,
+ CollectionIssuer::User(collection_helpers_address),
+ data,
+ )
+ .map_err(dispatch_to_evm::<T>)?;
let address = pallet_common::eth::collection_id_to_address(collection_id);
Ok(address)
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -93,7 +93,8 @@
use frame_system::{ensure_root, ensure_signed};
use pallet_common::{
dispatch::{dispatch_tx, CollectionDispatch},
- CollectionHandle, CommonWeightInfo, Pallet as PalletCommon, RefungibleExtensionsWeightInfo,
+ CollectionHandle, CollectionIssuer, CommonWeightInfo, Pallet as PalletCommon,
+ RefungibleExtensionsWeightInfo,
};
use pallet_evm::account::CrossAccountId;
use pallet_structure::weights::WeightInfo as StructureWeightInfo;
@@ -401,7 +402,11 @@
// =========
let sender = T::CrossAccountId::from_sub(sender);
- let _id = T::CollectionDispatch::create(sender.clone(), Some(sender), data)?;
+ let _id = T::CollectionDispatch::create(
+ sender.clone(),
+ CollectionIssuer::User(sender),
+ data,
+ )?;
Ok(())
}
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -18,7 +18,7 @@
use pallet_balances_adapter::NativeFungibleHandle;
pub use pallet_common::dispatch::CollectionDispatch;
use pallet_common::{
- erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,
+ erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle, CollectionIssuer,
CommonCollectionOperations, Pallet as PalletCommon,
};
use pallet_evm::{PrecompileHandle, PrecompileResult};
@@ -66,10 +66,9 @@
}
}
- fn create_raw(
+ fn create(
sender: T::CrossAccountId,
- payer: Option<T::CrossAccountId>,
- is_special_collection: bool,
+ issuer: CollectionIssuer<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError> {
match data.mode {
@@ -87,7 +86,7 @@
_ => {}
};
- <PalletCommon<T>>::init_collection(sender, payer, is_special_collection, data)
+ <PalletCommon<T>>::init_collection(sender, issuer, data)
}
fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {