diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index 820666caba..d1be0e8e29 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -19,6 +19,7 @@ use scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +// Substrate use sp_core::{ecdsa, H160, H256}; use sp_io::hashing::keccak_256; @@ -32,6 +33,17 @@ pub struct AccountId20(pub [u8; 20]); #[cfg(feature = "std")] impl_serde::impl_fixed_hash_serde!(AccountId20, 20); +#[cfg(feature = "std")] +impl std::str::FromStr for AccountId20 { + type Err = &'static str; + + fn from_str(s: &str) -> Result { + H160::from_str(s) + .map(Into::into) + .map_err(|_| "invalid hex address.") + } +} + #[cfg(feature = "std")] impl std::fmt::Display for AccountId20 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {