RemoteWallet: Improve DerivationPathComponent FromStr readability
This commit is contained in:
committed by
mergify[bot]
parent
73f3d04798
commit
b0d1c70718
@ -345,12 +345,13 @@ impl FromStr for DerivationPathComponent {
|
|||||||
type Err = RemoteWalletError;
|
type Err = RemoteWalletError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
// Replace str::splitn() with str::strip_suffix() once stabilized
|
let index_str = if let Some(stripped) = s.strip_suffix('\'') {
|
||||||
let parts: Vec<_> = s.splitn(2, '\'').collect();
|
|
||||||
if parts.len() == 2 {
|
|
||||||
eprintln!("all path components are promoted to hardened representation");
|
eprintln!("all path components are promoted to hardened representation");
|
||||||
}
|
stripped
|
||||||
parts[0].parse::<u32>().map(|ki| ki.into()).map_err(|_| {
|
} else {
|
||||||
|
s
|
||||||
|
};
|
||||||
|
index_str.parse::<u32>().map(|ki| ki.into()).map_err(|_| {
|
||||||
RemoteWalletError::InvalidDerivationPath(format!(
|
RemoteWalletError::InvalidDerivationPath(format!(
|
||||||
"failed to parse path component: {:?}",
|
"failed to parse path component: {:?}",
|
||||||
s
|
s
|
||||||
|
Reference in New Issue
Block a user