diff --git a/descriptors/src/descriptor.rs b/descriptors/src/descriptor.rs index 60e3b92..8ce8f18 100644 --- a/descriptors/src/descriptor.rs +++ b/descriptors/src/descriptor.rs @@ -21,7 +21,8 @@ // limitations under the License. use std::collections::{BTreeSet, HashMap}; -use std::iter; +use std::fmt::{Display, Formatter}; +use std::{fmt, iter}; use derive::{ Bip340Sig, Derive, DeriveCompr, DeriveScripts, DeriveSet, DeriveXOnly, DerivedScript, @@ -282,3 +283,17 @@ where Self: Derive } } } + +impl Display for StdDescr +where + S::Legacy: Display, + S::Compr: Display, + S::XOnly: Display, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + StdDescr::Wpkh(d) => Display::fmt(d, f), + StdDescr::TrKey(d) => Display::fmt(d, f), + } + } +} diff --git a/descriptors/src/segwit.rs b/descriptors/src/segwit.rs index 10254f4..456ebc3 100644 --- a/descriptors/src/segwit.rs +++ b/descriptors/src/segwit.rs @@ -21,6 +21,7 @@ // limitations under the License. use std::collections::{BTreeSet, HashMap}; +use std::fmt::{self, Display, Formatter}; use std::iter; use derive::{ @@ -96,3 +97,7 @@ impl Descriptor for Wpkh { None } } + +impl Display for Wpkh { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "wpkh({})", self.0) } +} diff --git a/descriptors/src/taproot.rs b/descriptors/src/taproot.rs index 78311cf..c3262db 100644 --- a/descriptors/src/taproot.rs +++ b/descriptors/src/taproot.rs @@ -21,6 +21,7 @@ // limitations under the License. use std::collections::{BTreeSet, HashMap}; +use std::fmt::{self, Display, Formatter}; use std::iter; use derive::{ @@ -99,6 +100,10 @@ impl Descriptor for TrKey { } } +impl Display for TrKey { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "tr({})", self.0) } +} + /* pub struct TrScript { internal_key: K,