--- 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(>::UnsupportedOperation.into()) + ($runtime:path) => { + Err($crate::Error::<$runtime>::UnsupportedOperation.into()) }; } --- 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 where T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config, @@ -64,13 +67,12 @@ ); >::init_collection(sender, data)? } + #[cfg(feature = "refungible")] CollectionMode::ReFungible => >::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) } --- a/runtime/common/mod.rs +++ b/runtime/common/mod.rs @@ -43,7 +43,12 @@ }; use common_types::{AccountId, BlockNumber}; -pub type CommonError = pallet_common::Error; +#[macro_export] +macro_rules! unsupported { + () => { + pallet_common::unsupported!($crate::Runtime) + } +} /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; --- 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::(); #[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::(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::(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::(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::(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::(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::(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::(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::(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::(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::(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::(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::(base_id, theme_name, filter_keys); #[cfg(not(feature = "rmrk"))] - return Err(CommonError::UnsupportedRuntimeApi.into()); + return unsupported!(); } }