mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 15:11:02 +00:00
Make AuthorityId serialize/deserialize to/from ss58 (#1180)
* Make `AuthorityId` serialize/deserialize to/from `ss58` * Updates the wasm files
This commit is contained in:
@@ -24,6 +24,9 @@ use ring::{rand, signature};
|
||||
use {hash::H512, AuthorityId};
|
||||
use base58::{ToBase58, FromBase58};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{de, Serializer, Deserializer, Deserialize};
|
||||
|
||||
/// Alias to 512-bit hash when used in the context of a signature on the relay chain.
|
||||
pub type Signature = H512;
|
||||
|
||||
@@ -278,6 +281,25 @@ impl Verifiable for LocalizedSignature {
|
||||
}
|
||||
}
|
||||
|
||||
/// Deserialize from `ss58` into something that can be constructed from `[u8; 32]`.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn deserialize<'de, D, T: From<[u8; 32]>>(deserializer: D) -> Result<T, D::Error> where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let ss58 = String::deserialize(deserializer)?;
|
||||
Public::from_ss58check(&ss58)
|
||||
.map_err(|e| de::Error::custom(format!("{:?}", e)))
|
||||
.map(|v| v.0.into())
|
||||
}
|
||||
|
||||
/// Serializes something that implements `AsRef<[u8; 32]>` into `ss58`.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn serialize<S, T: AsRef<[u8; 32]>>(data: &T, serializer: S) -> Result<S::Ok, S::Error> where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&Public(*data.as_ref()).to_ss58check())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user