difftreelog
chore cargo fmt
in: master
4 files changed
pallets/foreign-assets/src/lib.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -310,11 +310,8 @@
..Default::default()
};
let owner = T::CrossAccountId::from_sub(owner);
- let bounded_collection_id = <PalletFungible<T>>::init_foreign_collection(
- owner.clone(),
- owner,
- data,
- )?;
+ let bounded_collection_id =
+ <PalletFungible<T>>::init_foreign_collection(owner.clone(), owner, data)?;
let foreign_asset_id =
Self::do_register_foreign_asset(&location, &metadata, bounded_collection_id)?;
pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -250,8 +250,12 @@
..Default::default()
};
- let collection_id_res =
- <PalletNft<T>>::init_collection(cross_sender.clone(), cross_sender.clone(), data, true);
+ let collection_id_res = <PalletNft<T>>::init_collection(
+ cross_sender.clone(),
+ cross_sender.clone(),
+ data,
+ true,
+ );
if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
return Err(<Error<T>>::NoAvailableBaseId.into());
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -174,10 +174,12 @@
add_properties,
)?;
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_helpers_address =
+ T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
- let collection_id = T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)
- .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+ let collection_id =
+ T::CollectionDispatch::create(caller.clone(), 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)
}
@@ -189,7 +191,11 @@
.map_err(|_| ()) // workaround for `expect` requiring `Debug` trait
.expect("Collection creation price should be convertible to u128");
if value != creation_price {
- return Err(format!("Sent amount not equals to collection creation price ({0})", creation_price).into());
+ return Err(format!(
+ "Sent amount not equals to collection creation price ({0})",
+ creation_price
+ )
+ .into());
}
Ok(())
}
@@ -225,9 +231,10 @@
false,
)?;
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_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 address = pallet_common::eth::collection_id_to_address(collection_id);
Ok(address)
@@ -255,7 +262,8 @@
true,
)?;
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_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>)?;
@@ -317,6 +325,14 @@
Ok(false)
}
+
+ fn collection_creation_fee(&self) -> Result<value> {
+ let price: u128 = T::CollectionCreationPrice::get()
+ .try_into()
+ .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait
+ .expect("Collection creation price should be convertible to u128");
+ Ok(price.into())
+ }
}
/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]
runtime/common/dispatch.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{dispatch::DispatchResult, ensure};18use pallet_evm::{PrecompileHandle, PrecompileResult};19use sp_core::H160;20use sp_runtime::DispatchError;21use sp_std::{borrow::ToOwned, vec::Vec};22use pallet_common::{23 CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,24 eth::map_eth_to_id,25};26pub use pallet_common::dispatch::CollectionDispatch;27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};28use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};29use pallet_refungible::{30 Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,31};32use up_data_structs::{33 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,34 CollectionId,35};3637#[cfg(not(feature = "refungible"))]38use pallet_common::unsupported;3940pub enum CollectionDispatchT<T>41where42 T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,43{44 Fungible(FungibleHandle<T>),45 Nonfungible(NonfungibleHandle<T>),46 Refungible(RefungibleHandle<T>),47}48impl<T> CollectionDispatch<T> for CollectionDispatchT<T>49where50 T: pallet_common::Config51 + pallet_unique::Config52 + pallet_fungible::Config53 + pallet_nonfungible::Config54 + pallet_refungible::Config,55{56 fn create(57 sender: T::CrossAccountId,58 payer: T::CrossAccountId,59 data: CreateCollectionData<T::AccountId>,60 ) -> Result<CollectionId, DispatchError> {61 let id = match data.mode {62 CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, payer, data, false)?,63 CollectionMode::Fungible(decimal_points) => {64 // check params65 ensure!(66 decimal_points <= MAX_DECIMAL_POINTS,67 pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded68 );69 <PalletFungible<T>>::init_collection(sender, payer, data)?70 }7172 #[cfg(feature = "refungible")]73 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, payer, data)?,7475 #[cfg(not(feature = "refungible"))]76 CollectionMode::ReFungible => return unsupported!(T),77 };78 Ok(id)79 }8081 fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {82 match collection.mode {83 CollectionMode::ReFungible => {84 PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?85 }86 CollectionMode::Fungible(_) => {87 PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?88 }89 CollectionMode::NFT => {90 PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?91 }92 }93 Ok(())94 }9596 fn dispatch(handle: CollectionHandle<T>) -> Self {97 match handle.mode {98 CollectionMode::Fungible(_) => Self::Fungible(FungibleHandle::cast(handle)),99 CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),100 CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),101 }102 }103104 fn into_inner(self) -> CollectionHandle<T> {105 match self {106 Self::Fungible(f) => f.into_inner(),107 Self::Nonfungible(f) => f.into_inner(),108 Self::Refungible(f) => f.into_inner(),109 }110 }111112 fn as_dyn(&self) -> &dyn CommonCollectionOperations<T> {113 match self {114 Self::Fungible(h) => h,115 Self::Nonfungible(h) => h,116 Self::Refungible(h) => h,117 }118 }119}120121impl<T> pallet_evm::OnMethodCall<T> for CollectionDispatchT<T>122where123 T: pallet_common::Config124 + pallet_unique::Config125 + pallet_fungible::Config126 + pallet_nonfungible::Config127 + pallet_refungible::Config,128 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,129{130 fn is_reserved(target: &H160) -> bool {131 map_eth_to_id(target).is_some()132 }133 fn is_used(target: &H160) -> bool {134 map_eth_to_id(target)135 .map(<CollectionById<T>>::contains_key)136 .unwrap_or(false)137 }138 fn get_code(target: &H160) -> Option<Vec<u8>> {139 if let Some(collection_id) = map_eth_to_id(target) {140 let collection = <CollectionById<T>>::get(collection_id)?;141 Some(142 match collection.mode {143 CollectionMode::NFT => <NonfungibleHandle<T>>::CODE,144 CollectionMode::Fungible(_) => <FungibleHandle<T>>::CODE,145 CollectionMode::ReFungible => <RefungibleHandle<T>>::CODE,146 }147 .to_owned(),148 )149 } else if let Some((collection_id, _token_id)) =150 <T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(target)151 {152 let collection = <CollectionById<T>>::get(collection_id)?;153 if collection.mode != CollectionMode::ReFungible {154 return None;155 }156 // TODO: check token existence157 Some(<RefungibleTokenHandle<T>>::CODE.to_owned())158 } else {159 None160 }161 }162 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {163 if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {164 let collection =165 <CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;166 let dispatched = Self::dispatch(collection);167168 match dispatched {169 Self::Fungible(h) => h.call(handle),170 Self::Nonfungible(h) => h.call(handle),171 Self::Refungible(h) => h.call(handle),172 }173 } else if let Some((collection_id, token_id)) =174 <T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(175 &handle.code_address(),176 ) {177 let collection =178 <CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;179 if collection.mode != CollectionMode::ReFungible {180 return None;181 }182183 let h = RefungibleHandle::cast(collection);184 // TODO: check token existence185 RefungibleTokenHandle(h, token_id).call(handle)186 } else {187 None188 }189 }190}