git.delta.rocks / unique-network / refs/commits / a07e65584822

difftreelog

refactor create collection with optional payer

Daniel Shiposha2023-10-18parent: #383b7ef.patch.diff
in: master

5 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
72 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).72 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
73 ///73 ///
74 /// * `sender` - The user who will become the owner of the collection.74 /// * `sender` - The user who will become the owner of the collection.
75 /// * `payer` - The user who pays the collection creation fee.75 /// * `payer` - If set, the user who pays the collection creation deposit.
76 /// * `data` - Description of the created collection.76 /// * `data` - Description of the created collection.
77 fn create(77 fn create(
78 sender: T::CrossAccountId,78 sender: T::CrossAccountId,
79 payer: T::CrossAccountId,79 payer: Option<T::CrossAccountId>,
80 data: CreateCollectionData<T::CrossAccountId>,80 data: CreateCollectionData<T::CrossAccountId>,
81 ) -> Result<CollectionId, DispatchError>;81 ) -> Result<CollectionId, DispatchError>;
82
83 /// Create a foreign collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
84 ///
85 /// * `sender` - The user who will become the owner of the collection.
86 /// * `data` - Description of the created collection.
87 fn create_foreign(
88 sender: T::CrossAccountId,
89 data: CreateCollectionData<T::CrossAccountId>,
90 ) -> Result<CollectionId, DispatchError>;
9182
92 /// Delete the collection.83 /// Delete the collection.
93 ///84 ///
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
152 .try_into()152 .try_into()
153 .expect("description length < max description length; qed");153 .expect("description length < max description length; qed");
154154
155 let payer = None;
155 let collection_id = T::CollectionDispatch::create_foreign(156 let collection_id = T::CollectionDispatch::create(
156 foreign_collection_owner,157 foreign_collection_owner,
158 payer,
157 CreateCollectionData {159 CreateCollectionData {
158 name,160 name,
159 description,161 description,
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
111 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());111 T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
112112
113 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());
242243
243 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>)?;
245247
246 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>)?;
279282
280 let address = pallet_common::eth::collection_id_to_address(collection_id);283 let address = pallet_common::eth::collection_id_to_address(collection_id);
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
401401
402 // =========402 // =========
403 let sender = T::CrossAccountId::from_sub(sender);403 let sender = T::CrossAccountId::from_sub(sender);
404 let _id = T::CollectionDispatch::create(sender.clone(), sender, data)?;404 let _id = T::CollectionDispatch::create(sender.clone(), Some(sender), data)?;
405405
406 Ok(())406 Ok(())
407 }407 }
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
18use 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};
6868
69 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 };
8888
89 <PalletCommon<T>>::init_collection(sender, Some(payer), data)89 <PalletCommon<T>>::init_collection(sender, payer, data)
90 }90 }
91
92 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 params
99 ensure!(
100 decimal_points <= MAX_DECIMAL_POINTS,
101 pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded
102 );
103 }
104
105 CollectionMode::ReFungible => return unsupported!(T),
106 _ => {}
107 };
108
109 let payer = None;
110 <PalletCommon<T>>::init_collection(sender, payer, data)
111 }
11291
113 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 {