Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
app_crypto: macro improvements (#14263)
Browse files Browse the repository at this point in the history
* app_crypto: macro improvements

During `app_crypto`  macro expansion the `cfg` feature gate was injected
  into the macro client crate. This resulted in compilation error if
`serde` or `std` was not defined in client crate. This PR fixes this
problem.

For reference, the error was:

```
  error: cannot find macro `format` in this scope
    --> /home/miszka/parity/10-genesis-config/substrate-2/primitives/consensus/aura/src/lib.rs:32:3
     |
  32 |         app_crypto!(sr25519, AURA);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
...

  error[E0433]: failed to resolve: use of undeclared type `String`
    -->
/home/miszka/parity/10-genesis-config/substrate-2/primitives/consensus/aura/src/lib.rs:32:3
     |
  32 |         app_crypto!(sr25519, AURA);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `String`
```

* app_crypto: cleanup
  • Loading branch information
michalkucharczyk authored May 30, 2023
1 parent 06d8934 commit 252156d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions primitives/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub use sp_core::{
crypto::{ByteArray, CryptoType, Derive, IsWrappedBy, Public, UncheckedFrom, Wraps},
RuntimeDebug,
};
#[doc(hidden)]
#[cfg(all(not(feature = "std"), feature = "serde"))]
pub use sp_std::alloc::{format, string::String};

#[doc(hidden)]
pub use codec;
Expand Down Expand Up @@ -328,6 +325,14 @@ macro_rules! app_crypto_public_common {
};
}

#[doc(hidden)]
pub mod module_format_string_prelude {
#[cfg(all(not(feature = "std"), feature = "serde"))]
pub use sp_std::alloc::{format, string::String};
#[cfg(feature = "std")]
pub use std::{format, string::String};
}

/// Implements traits for the public key type if `feature = "serde"` is enabled.
#[cfg(feature = "serde")]
#[doc(hidden)]
Expand Down Expand Up @@ -365,9 +370,7 @@ macro_rules! app_crypto_public_common_if_serde {
where
D: $crate::serde::Deserializer<'de>,
{
use $crate::Ss58Codec;
#[cfg(all(not(feature = "std"), feature = "serde"))]
use $crate::{format, String};
use $crate::{module_format_string_prelude::*, Ss58Codec};

Public::from_ss58check(&String::deserialize(deserializer)?)
.map_err(|e| $crate::serde::de::Error::custom(format!("{:?}", e)))
Expand Down

0 comments on commit 252156d

Please sign in to comment.