difftreelog
refactor unsupported! macro
in: master
4 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -535,7 +535,8 @@
/// Can't transfer tokens to ethereum zero address
AddressIsZero,
- /// Target collection doesn't support this operation
+
+ /// The oprtation is not supported
UnsupportedOperation,
/// Insufficient funds to perform an action
@@ -569,9 +570,6 @@
/// Tried to access an internal collection with an external API
CollectionIsInternal,
-
- /// A method of an unsupported API was called
- UnsupportedRuntimeApi,
}
/// Storage of the count of created collections. Essentially contains the last collection ID.
@@ -1356,8 +1354,8 @@
/// Indicates unsupported methods by returning [Error::UnsupportedOperation].
#[macro_export]
macro_rules! unsupported {
- () => {
- Err(<Error<T>>::UnsupportedOperation.into())
+ ($runtime:path) => {
+ Err($crate::Error::<$runtime>::UnsupportedOperation.into())
};
}
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -34,6 +34,9 @@
CollectionId,
};
+#[cfg(not(feature = "refungible"))]
+use pallet_common::unsupported;
+
pub enum CollectionDispatchT<T>
where
T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,
@@ -64,13 +67,12 @@
);
<PalletFungible<T>>::init_collection(sender, data)?
}
+
#[cfg(feature = "refungible")]
CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,
#[cfg(not(feature = "refungible"))]
- CollectionMode::ReFungible => {
- return Err(DispatchError::Other("Refunginle pallet is not supported"))
- }
+ CollectionMode::ReFungible => return unsupported!(T)
};
Ok(id)
}
runtime/common/mod.rsdiffbeforeafterboth43};43};44use common_types::{AccountId, BlockNumber};44use common_types::{AccountId, BlockNumber};454546#[macro_export]47macro_rules! unsupported {48 () => {46pub type CommonError = pallet_common::Error<Runtime>;49 pallet_common::unsupported!($crate::Runtime)50 }51}475248/// The address format for describing accounts.53/// The address format for describing accounts.49pub type Address = sp_runtime::MultiAddress<AccountId, ()>;54pub type Address = sp_runtime::MultiAddress<AccountId, ()>;runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -205,7 +205,7 @@
return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -214,7 +214,7 @@
return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -223,7 +223,7 @@
return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -232,7 +232,7 @@
return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -241,7 +241,7 @@
return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -253,7 +253,7 @@
return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -266,7 +266,7 @@
return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -275,7 +275,7 @@
return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -288,7 +288,7 @@
return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -297,7 +297,7 @@
return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -306,7 +306,7 @@
return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -315,7 +315,7 @@
return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
#[allow(unused_variables)]
@@ -328,7 +328,7 @@
return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);
#[cfg(not(feature = "rmrk"))]
- return Err(CommonError::UnsupportedRuntimeApi.into());
+ return unsupported!();
}
}