git.delta.rocks / unique-network / refs/commits / 5eadf5f526c3

difftreelog

refactor unsupported! macro

Daniel Shiposha2022-08-09parent: #24b248d.patch.diff
in: master

4 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
535535
536 /// Can't transfer tokens to ethereum zero address536 /// Can't transfer tokens to ethereum zero address
537 AddressIsZero,537 AddressIsZero,
538 /// Target collection doesn't support this operation538
539 /// The oprtation is not supported
539 UnsupportedOperation,540 UnsupportedOperation,
540541
541 /// Insufficient funds to perform an action542 /// Insufficient funds to perform an action
570 /// Tried to access an internal collection with an external API571 /// Tried to access an internal collection with an external API
571 CollectionIsInternal,572 CollectionIsInternal,
572
573 /// A method of an unsupported API was called
574 UnsupportedRuntimeApi,
575 }573 }
576574
577 /// Storage of the count of created collections. Essentially contains the last collection ID.575 /// Storage of the count of created collections. Essentially contains the last collection ID.
1356/// Indicates unsupported methods by returning [Error::UnsupportedOperation].1354/// Indicates unsupported methods by returning [Error::UnsupportedOperation].
1357#[macro_export]1355#[macro_export]
1358macro_rules! unsupported {1356macro_rules! unsupported {
1359 () => {1357 ($runtime:path) => {
1360 Err(<Error<T>>::UnsupportedOperation.into())1358 Err($crate::Error::<$runtime>::UnsupportedOperation.into())
1361 };1359 };
1362}1360}
13631361
modifiedruntime/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)
 	}
modifiedruntime/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, ()>;
modifiedruntime/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!();
                 }
             }