diff --git a/subxt/src/utils/account_id.rs b/subxt/src/utils/account_id.rs index 34e56cd87e..2c8ae354c1 100644 --- a/subxt/src/utils/account_id.rs +++ b/subxt/src/utils/account_id.rs @@ -10,7 +10,10 @@ use codec::{ Decode, Encode, }; -use serde::Serialize; +use serde::{ + Deserialize, + Serialize, +}; /// A 32-byte cryptographic identifier. This is a simplified version of Substrate's /// `sp_core::crypto::AccountId32`. To obtain more functionality, convert this into @@ -127,6 +130,16 @@ impl Serialize for AccountId32 { } } +impl<'de> Deserialize<'de> for AccountId32 { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + AccountId32::from_ss58check(&String::deserialize(deserializer)?) + .map_err(|e| serde::de::Error::custom(format!("{:?}", e))) + } +} + impl std::fmt::Display for AccountId32 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.to_ss58check())