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.rsdiffbeforeafterboth111 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());111 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());112112113 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)113 let collection_id =114 T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)114 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;115 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;115 let address = pallet_common::eth::collection_id_to_address(collection_id);116 let address = pallet_common::eth::collection_id_to_address(collection_id);116 Ok(address)117 Ok(address)241 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());242 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());242243243 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)244 let collection_id =245 T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)244 .map_err(dispatch_to_evm::<T>)?;246 .map_err(dispatch_to_evm::<T>)?;245247246 let address = pallet_common::eth::collection_id_to_address(collection_id);248 let address = pallet_common::eth::collection_id_to_address(collection_id);275 let collection_helpers_address =277 let collection_helpers_address =276 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());278 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());277 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)279 let collection_id =280 T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)278 .map_err(dispatch_to_evm::<T>)?;281 .map_err(dispatch_to_evm::<T>)?;279282280 let address = pallet_common::eth::collection_id_to_address(collection_id);283 let address = pallet_common::eth::collection_id_to_address(collection_id);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.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, unsupported, CollectionById, CollectionHandle,
+ erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,
CommonCollectionOperations, Pallet as PalletCommon,
};
use pallet_evm::{PrecompileHandle, PrecompileResult};
@@ -68,7 +68,7 @@
fn create(
sender: T::CrossAccountId,
- payer: T::CrossAccountId,
+ payer: Option<T::CrossAccountId>,
data: CreateCollectionData<T::CrossAccountId>,
) -> Result<CollectionId, DispatchError> {
match data.mode {
@@ -85,28 +85,7 @@
_ => {}
};
-
- <PalletCommon<T>>::init_collection(sender, Some(payer), data)
- }
- fn create_foreign(
- sender: <T>::CrossAccountId,
- data: CreateCollectionData<<T>::CrossAccountId>,
- ) -> Result<CollectionId, DispatchError> {
- match data.mode {
- CollectionMode::Fungible(decimal_points) => {
- // check params
- ensure!(
- decimal_points <= MAX_DECIMAL_POINTS,
- pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded
- );
- }
-
- CollectionMode::ReFungible => return unsupported!(T),
- _ => {}
- };
-
- let payer = None;
<PalletCommon<T>>::init_collection(sender, payer, data)
}