22
22
23
23
pub use sp_core:: crypto:: { key_types, CryptoTypeId , KeyTypeId } ;
24
24
#[ doc( hidden) ]
25
+ #[ cfg( any( feature = "full_crypto" , feature = "serde" ) ) ]
26
+ pub use sp_core:: crypto:: { DeriveJunction , Ss58Codec } ;
25
27
#[ cfg( feature = "full_crypto" ) ]
26
- pub use sp_core:: crypto:: { DeriveError , DeriveJunction , Pair , SecretStringError , Ss58Codec } ;
28
+ pub use sp_core:: crypto:: { DeriveError , Pair , SecretStringError } ;
27
29
#[ doc( hidden) ]
28
30
pub use sp_core:: {
29
31
self ,
@@ -36,7 +38,7 @@ pub use codec;
36
38
#[ doc( hidden) ]
37
39
pub use scale_info;
38
40
#[ doc( hidden) ]
39
- #[ cfg( feature = "std " ) ]
41
+ #[ cfg( feature = "serde " ) ]
40
42
pub use serde;
41
43
#[ doc( hidden) ]
42
44
pub use sp_std:: { ops:: Deref , vec:: Vec } ;
@@ -278,7 +280,7 @@ macro_rules! app_crypto_public_not_full_crypto {
278
280
#[ macro_export]
279
281
macro_rules! app_crypto_public_common {
280
282
( $public: ty, $sig: ty, $key_type: expr, $crypto_type: expr) => {
281
- $crate:: app_crypto_public_common_if_std !( ) ;
283
+ $crate:: app_crypto_public_common_if_serde !( ) ;
282
284
283
285
impl AsRef <[ u8 ] > for Public {
284
286
fn as_ref( & self ) -> & [ u8 ] {
@@ -312,11 +314,11 @@ macro_rules! app_crypto_public_common {
312
314
} ;
313
315
}
314
316
315
- /// Implements traits for the public key type if `feature = "std "` is enabled.
316
- #[ cfg( feature = "std " ) ]
317
+ /// Implements traits for the public key type if `feature = "serde "` is enabled.
318
+ #[ cfg( feature = "serde " ) ]
317
319
#[ doc( hidden) ]
318
320
#[ macro_export]
319
- macro_rules! app_crypto_public_common_if_std {
321
+ macro_rules! app_crypto_public_common_if_serde {
320
322
( ) => {
321
323
impl $crate:: Derive for Public {
322
324
fn derive<Iter : Iterator <Item = $crate:: DeriveJunction >>(
@@ -327,15 +329,15 @@ macro_rules! app_crypto_public_common_if_std {
327
329
}
328
330
}
329
331
330
- impl std :: fmt:: Display for Public {
331
- fn fmt( & self , f: & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
332
+ impl core :: fmt:: Display for Public {
333
+ fn fmt( & self , f: & mut core :: fmt:: Formatter ) -> core :: fmt:: Result {
332
334
use $crate:: Ss58Codec ;
333
335
write!( f, "{}" , self . 0 . to_ss58check( ) )
334
336
}
335
337
}
336
338
337
339
impl $crate:: serde:: Serialize for Public {
338
- fn serialize<S >( & self , serializer: S ) -> std :: result:: Result <S :: Ok , S :: Error >
340
+ fn serialize<S >( & self , serializer: S ) -> core :: result:: Result <S :: Ok , S :: Error >
339
341
where
340
342
S : $crate:: serde:: Serializer ,
341
343
{
@@ -345,22 +347,27 @@ macro_rules! app_crypto_public_common_if_std {
345
347
}
346
348
347
349
impl <' de> $crate:: serde:: Deserialize <' de> for Public {
348
- fn deserialize<D >( deserializer: D ) -> std :: result:: Result <Self , D :: Error >
350
+ fn deserialize<D >( deserializer: D ) -> core :: result:: Result <Self , D :: Error >
349
351
where
350
352
D : $crate:: serde:: Deserializer <' de>,
351
353
{
354
+ #[ cfg( not( feature = "std" ) ) ]
355
+ extern crate alloc;
356
+ #[ cfg( not( feature = "std" ) ) ]
357
+ use alloc:: { format, string:: String } ;
352
358
use $crate:: Ss58Codec ;
359
+
353
360
Public :: from_ss58check( & String :: deserialize( deserializer) ?)
354
361
. map_err( |e| $crate:: serde:: de:: Error :: custom( format!( "{:?}" , e) ) )
355
362
}
356
363
}
357
364
} ;
358
365
}
359
366
360
- #[ cfg( not( feature = "std " ) ) ]
367
+ #[ cfg( not( feature = "serde " ) ) ]
361
368
#[ doc( hidden) ]
362
369
#[ macro_export]
363
- macro_rules! app_crypto_public_common_if_std {
370
+ macro_rules! app_crypto_public_common_if_serde {
364
371
( ) => {
365
372
impl $crate:: Derive for Public { }
366
373
} ;
0 commit comments