Skip to content

Commit

Permalink
RemoteWallet: Improve DerivationPathComponent FromStr readability
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nelson authored and mergify[bot] committed Jul 21, 2020
1 parent 73f3d04 commit b0d1c70
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions remote-wallet/src/remote_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,13 @@ impl FromStr for DerivationPathComponent {
type Err = RemoteWalletError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Replace str::splitn() with str::strip_suffix() once stabilized
let parts: Vec<_> = s.splitn(2, '\'').collect();
if parts.len() == 2 {
let index_str = if let Some(stripped) = s.strip_suffix('\'') {
eprintln!("all path components are promoted to hardened representation");
}
parts[0].parse::<u32>().map(|ki| ki.into()).map_err(|_| {
stripped
} else {
s
};
index_str.parse::<u32>().map(|ki| ki.into()).map_err(|_| {
RemoteWalletError::InvalidDerivationPath(format!(
"failed to parse path component: {:?}",
s
Expand Down

0 comments on commit b0d1c70

Please sign in to comment.