difftreelog
refactor create collection with optional payer
in: master
5 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -72,20 +72,11 @@
/// 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` - The user who pays the collection creation fee.
+ /// * `payer` - If set, the user who pays the collection creation deposit.
/// * `data` - Description of the created collection.
fn create(
sender: T::CrossAccountId,
- payer: T::CrossAccountId,
- data: CreateCollectionData<T::CrossAccountId>,
- ) -> Result<CollectionId, DispatchError>;
-
- /// Create a foreign 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.
- /// * `data` - Description of the created collection.
- fn create_foreign(
- sender: T::CrossAccountId,
+ payer: Option<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError>;
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -152,8 +152,10 @@
.try_into()
.expect("description length < max description length; qed");
- let collection_id = T::CollectionDispatch::create_foreign(
+ let payer = None;
+ let collection_id = T::CollectionDispatch::create(
foreign_collection_owner,
+ payer,
CreateCollectionData {
name,
description,
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -110,8 +110,9 @@
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, Some(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)
}
@@ -240,8 +241,9 @@
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, Some(collection_helpers_address), data)
+ .map_err(dispatch_to_evm::<T>)?;
let address = pallet_common::eth::collection_id_to_address(collection_id);
Ok(address)
@@ -274,8 +276,9 @@
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, Some(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
@@ -401,7 +401,7 @@
// =========
let sender = T::CrossAccountId::from_sub(sender);
- let _id = T::CollectionDispatch::create(sender.clone(), sender, data)?;
+ let _id = T::CollectionDispatch::create(sender.clone(), Some(sender), data)?;
Ok(())
}
runtime/common/dispatch.rsdiffbeforeafterboth18use pallet_balances_adapter::NativeFungibleHandle;18use pallet_balances_adapter::NativeFungibleHandle;19pub use pallet_common::dispatch::CollectionDispatch;19pub use pallet_common::dispatch::CollectionDispatch;20use pallet_common::{20use pallet_common::{21 erc::CommonEvmHandler, eth::map_eth_to_id, unsupported, CollectionById, CollectionHandle,21 erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,22 CommonCollectionOperations, Pallet as PalletCommon,22 CommonCollectionOperations, Pallet as PalletCommon,23};23};24use pallet_evm::{PrecompileHandle, PrecompileResult};24use pallet_evm::{PrecompileHandle, PrecompileResult};686869 fn create(69 fn create(70 sender: T::CrossAccountId,70 sender: T::CrossAccountId,71 payer: T::CrossAccountId,71 payer: Option<T::CrossAccountId>,72 data: CreateCollectionData<T::CrossAccountId>,72 data: CreateCollectionData<T::CrossAccountId>,73 ) -> Result<CollectionId, DispatchError> {73 ) -> Result<CollectionId, DispatchError> {74 match data.mode {74 match data.mode {86 _ => {}86 _ => {}87 };87 };888889 <PalletCommon<T>>::init_collection(sender, Some(payer), data)89 <PalletCommon<T>>::init_collection(sender, payer, data)90 }90 }9192 fn create_foreign(93 sender: <T>::CrossAccountId,94 data: CreateCollectionData<<T>::CrossAccountId>,95 ) -> Result<CollectionId, DispatchError> {96 match data.mode {97 CollectionMode::Fungible(decimal_points) => {98 // check params99 ensure!(100 decimal_points <= MAX_DECIMAL_POINTS,101 pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded102 );103 }104105 CollectionMode::ReFungible => return unsupported!(T),106 _ => {}107 };108109 let payer = None;110 <PalletCommon<T>>::init_collection(sender, payer, data)111 }11291113 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {92 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {114 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {93 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {