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.rsdiffbeforeafterboth34 CollectionId,34 CollectionId,35};35};3637#[cfg(not(feature = "refungible"))]38use pallet_common::unsupported;363937pub enum CollectionDispatchT<T>40pub enum CollectionDispatchT<T>38where41where68 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,72 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,697370 #[cfg(not(feature = "refungible"))]74 #[cfg(not(feature = "refungible"))]71 CollectionMode::ReFungible => {75 CollectionMode::ReFungible => return unsupported!(T)72 return Err(DispatchError::Other("Refunginle pallet is not supported"))73 }74 };76 };75 Ok(id)77 Ok(id)76 }78 }runtime/common/mod.rsdiffbeforeafterboth--- 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<Runtime>;
+#[macro_export]
+macro_rules! unsupported {
+ () => {
+ pallet_common::unsupported!($crate::Runtime)
+ }
+}
/// The address format for describing accounts.
pub 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!();
}
}