mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 11:57:56 +00:00
support custom ss58addressformat in from_ss58check_with_version (#5526)
* support custom ss58addressformat in from_ss58check_with_version * fix str parse 1. if can parse with u8, use u8 into. 2. if u8 can't parse, convert to str then parse * add a test * typo * add error description in test * fix the `TryFrom<u8>` for `Ss58AddressFormat` change check logic in TryFrom<u8> to replace modified code in `from_ss58check_with_version` * use Ss58AddressFormat::default() replace DEFAULT_VERSION * Apply suggestions from code review * Update primitives/core/src/crypto.rs * Update primitives/core/src/crypto.rs * Update primitives/core/src/crypto.rs * Update primitives/core/src/crypto.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -366,7 +366,16 @@ macro_rules! ss58_address_format {
|
||||
fn try_from(x: u8) -> Result<Ss58AddressFormat, ()> {
|
||||
match x {
|
||||
$($number => Ok(Ss58AddressFormat::$identifier)),*,
|
||||
_ => Err(()),
|
||||
_ => {
|
||||
#[cfg(feature = "std")]
|
||||
match Ss58AddressFormat::default() {
|
||||
Ss58AddressFormat::Custom(n) if n == x => Ok(Ss58AddressFormat::Custom(x)),
|
||||
_ => Err(()),
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -377,7 +386,7 @@ macro_rules! ss58_address_format {
|
||||
fn try_from(x: &'a str) -> Result<Ss58AddressFormat, ()> {
|
||||
match x {
|
||||
$($name => Ok(Ss58AddressFormat::$identifier)),*,
|
||||
a => a.parse::<u8>().map(Ss58AddressFormat::Custom).map_err(|_| ()),
|
||||
a => a.parse::<u8>().map_err(|_| ()).and_then(TryFrom::try_from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user