SDK: More conversion for `DerivationPath`
This commit is contained in:
parent
9b7120bf73
commit
722de942ca
|
@ -1,7 +1,7 @@
|
||||||
use {
|
use {
|
||||||
core::{iter::IntoIterator, slice::Iter},
|
core::{iter::IntoIterator, slice::Iter},
|
||||||
derivation_path::{ChildIndex, DerivationPath as DerivationPathInner},
|
derivation_path::{ChildIndex, DerivationPath as DerivationPathInner},
|
||||||
std::{fmt, str::FromStr},
|
std::{convert::{Infallible, TryFrom}, fmt, str::FromStr},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,13 +9,21 @@ const ACCOUNT_INDEX: usize = 2;
|
||||||
const CHANGE_INDEX: usize = 3;
|
const CHANGE_INDEX: usize = 3;
|
||||||
|
|
||||||
/// Derivation path error.
|
/// Derivation path error.
|
||||||
#[derive(Error, Debug, Clone)]
|
#[derive(Error, Debug, Clone, PartialEq)]
|
||||||
pub enum DerivationPathError {
|
pub enum DerivationPathError {
|
||||||
#[error("invalid derivation path: {0}")]
|
#[error("invalid derivation path: {0}")]
|
||||||
InvalidDerivationPath(String),
|
InvalidDerivationPath(String),
|
||||||
|
#[error("infallible")]
|
||||||
|
Infallible,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
impl From<Infallible> for DerivationPathError {
|
||||||
|
fn from(_: Infallible) -> Self {
|
||||||
|
Self::Infallible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct DerivationPath(DerivationPathInner);
|
pub struct DerivationPath(DerivationPathInner);
|
||||||
|
|
||||||
impl Default for DerivationPath {
|
impl Default for DerivationPath {
|
||||||
|
@ -24,6 +32,13 @@ impl Default for DerivationPath {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for DerivationPath {
|
||||||
|
type Error = DerivationPathError;
|
||||||
|
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||||
|
Self::from_key_str(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl DerivationPath {
|
impl DerivationPath {
|
||||||
fn new<P: Into<Box<[ChildIndex]>>>(path: P) -> Self {
|
fn new<P: Into<Box<[ChildIndex]>>>(path: P) -> Self {
|
||||||
Self(DerivationPathInner::new(path))
|
Self(DerivationPathInner::new(path))
|
||||||
|
|
Loading…
Reference in New Issue