diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2020-12-01 18:54:35 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2020-12-01 18:54:35 +0100 |
| commit | e00c34041a67b3e59de4aaf0c8efe24823a1e5f3 (patch) | |
| tree | 3a25a1cd301d2076e99c12e2c04a354c24c1404b /src/hdk/path.rs | |
| parent | a699b6b4fe6f0e2567f7298fd8174e779f1bd43d (diff) | |
added ability to sign
Diffstat (limited to 'src/hdk/path.rs')
| -rw-r--r-- | src/hdk/path.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/hdk/path.rs b/src/hdk/path.rs index f67446a..3d7c0a3 100644 --- a/src/hdk/path.rs +++ b/src/hdk/path.rs @@ -1,7 +1,10 @@ //! Module implementing parsing for BIP-0032 HD paths used for key derivation. use anyhow::{anyhow, Context as _, Result}; -use std::str::FromStr; +use std::{ + fmt::{self, Display, Formatter}, + str::FromStr, +}; /// A parsed hierarchical derivation path. #[derive(Debug)] @@ -16,6 +19,17 @@ impl Path { } } +impl Display for Path { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str("m")?; + for component in self.components() { + write!(f, "/{}", component)?; + } + + Ok(()) + } +} + impl FromStr for Path { type Err = anyhow::Error; @@ -40,6 +54,15 @@ pub enum Component { Normal(u32), } +impl Display for Component { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Hardened(value) => write!(f, "{}'", value), + Self::Normal(value) => write!(f, "{}", value), + } + } +} + impl FromStr for Component { type Err = anyhow::Error; |
