From c9f414f4ed7e9f6891eded667a6181dd5345590c Mon Sep 17 00:00:00 2001 From: Fredrik Simonsson Date: Tue, 17 Jan 2023 18:42:44 +0900 Subject: [PATCH] Implement deserialize (#773) --- subxt/src/utils/account_id.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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())