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
34 CollectionId,34 CollectionId,
35};35};
36
37#[cfg(not(feature = "refungible"))]
38use pallet_common::unsupported;
3639
37pub enum CollectionDispatchT<T>40pub enum CollectionDispatchT<T>
38where41where
68 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,72 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,
6973
70 #[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 }
modifiedruntime/common/mod.rsdiffbeforeafterboth
43};43};
44use common_types::{AccountId, BlockNumber};44use common_types::{AccountId, BlockNumber};
4545
46#[macro_export]
47macro_rules! unsupported {
48 () => {
46pub type CommonError = pallet_common::Error<Runtime>;49 pallet_common::unsupported!($crate::Runtime)
50 }
51}
4752
48/// 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, ()>;
modifiedruntime/common/runtime_apis.rsdiffbeforeafterboth
205 return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();205 return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();
206206
207 #[cfg(not(feature = "rmrk"))]207 #[cfg(not(feature = "rmrk"))]
208 return Err(CommonError::UnsupportedRuntimeApi.into());208 return unsupported!();
209 }209 }
210210
211 #[allow(unused_variables)]211 #[allow(unused_variables)]
214 return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);214 return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);
215215
216 #[cfg(not(feature = "rmrk"))]216 #[cfg(not(feature = "rmrk"))]
217 return Err(CommonError::UnsupportedRuntimeApi.into());217 return unsupported!();
218 }218 }
219219
220 #[allow(unused_variables)]220 #[allow(unused_variables)]
223 return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);223 return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);
224224
225 #[cfg(not(feature = "rmrk"))]225 #[cfg(not(feature = "rmrk"))]
226 return Err(CommonError::UnsupportedRuntimeApi.into());226 return unsupported!();
227 }227 }
228228
229 #[allow(unused_variables)]229 #[allow(unused_variables)]
232 return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);232 return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);
233233
234 #[cfg(not(feature = "rmrk"))]234 #[cfg(not(feature = "rmrk"))]
235 return Err(CommonError::UnsupportedRuntimeApi.into());235 return unsupported!();
236 }236 }
237237
238 #[allow(unused_variables)]238 #[allow(unused_variables)]
241 return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);241 return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);
242242
243 #[cfg(not(feature = "rmrk"))]243 #[cfg(not(feature = "rmrk"))]
244 return Err(CommonError::UnsupportedRuntimeApi.into());244 return unsupported!();
245 }245 }
246246
247 #[allow(unused_variables)]247 #[allow(unused_variables)]
253 return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);253 return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);
254254
255 #[cfg(not(feature = "rmrk"))]255 #[cfg(not(feature = "rmrk"))]
256 return Err(CommonError::UnsupportedRuntimeApi.into());256 return unsupported!();
257 }257 }
258258
259 #[allow(unused_variables)]259 #[allow(unused_variables)]
266 return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);266 return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);
267267
268 #[cfg(not(feature = "rmrk"))]268 #[cfg(not(feature = "rmrk"))]
269 return Err(CommonError::UnsupportedRuntimeApi.into());269 return unsupported!();
270 }270 }
271271
272 #[allow(unused_variables)]272 #[allow(unused_variables)]
275 return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);275 return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);
276276
277 #[cfg(not(feature = "rmrk"))]277 #[cfg(not(feature = "rmrk"))]
278 return Err(CommonError::UnsupportedRuntimeApi.into());278 return unsupported!();
279 }279 }
280280
281 #[allow(unused_variables)]281 #[allow(unused_variables)]
288 return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);288 return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);
289289
290 #[cfg(not(feature = "rmrk"))]290 #[cfg(not(feature = "rmrk"))]
291 return Err(CommonError::UnsupportedRuntimeApi.into());291 return unsupported!();
292 }292 }
293293
294 #[allow(unused_variables)]294 #[allow(unused_variables)]
297 return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);297 return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);
298298
299 #[cfg(not(feature = "rmrk"))]299 #[cfg(not(feature = "rmrk"))]
300 return Err(CommonError::UnsupportedRuntimeApi.into());300 return unsupported!();
301 }301 }
302302
303 #[allow(unused_variables)]303 #[allow(unused_variables)]
306 return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);306 return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);
307307
308 #[cfg(not(feature = "rmrk"))]308 #[cfg(not(feature = "rmrk"))]
309 return Err(CommonError::UnsupportedRuntimeApi.into());309 return unsupported!();
310 }310 }
311311
312 #[allow(unused_variables)]312 #[allow(unused_variables)]
315 return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);315 return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);
316316
317 #[cfg(not(feature = "rmrk"))]317 #[cfg(not(feature = "rmrk"))]
318 return Err(CommonError::UnsupportedRuntimeApi.into());318 return unsupported!();
319 }319 }
320320
321 #[allow(unused_variables)]321 #[allow(unused_variables)]
328 return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);328 return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);
329329
330 #[cfg(not(feature = "rmrk"))]330 #[cfg(not(feature = "rmrk"))]
331 return Err(CommonError::UnsupportedRuntimeApi.into());331 return unsupported!();
332 }332 }
333 }333 }
334334