Skip to content

Commit

Permalink
descriptor: implement Display
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 15, 2024
1 parent 1fb4971 commit 6f405ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 16 additions & 1 deletion descriptors/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -282,3 +283,17 @@ where Self: Derive<DerivedScript>
}
}
}

impl<S: DeriveSet> Display for StdDescr<S>
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),
}
}
}
5 changes: 5 additions & 0 deletions descriptors/src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// limitations under the License.

use std::collections::{BTreeSet, HashMap};
use std::fmt::{self, Display, Formatter};
use std::iter;

use derive::{
Expand Down Expand Up @@ -96,3 +97,7 @@ impl<K: DeriveCompr> Descriptor<K> for Wpkh<K> {
None
}
}

impl<K: DeriveCompr + Display> Display for Wpkh<K> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "wpkh({})", self.0) }
}
5 changes: 5 additions & 0 deletions descriptors/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// limitations under the License.

use std::collections::{BTreeSet, HashMap};
use std::fmt::{self, Display, Formatter};
use std::iter;

use derive::{
Expand Down Expand Up @@ -99,6 +100,10 @@ impl<K: DeriveXOnly> Descriptor<K> for TrKey<K> {
}
}

impl<K: DeriveXOnly + Display> Display for TrKey<K> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "tr({})", self.0) }
}

/*
pub struct TrScript<K: DeriveXOnly> {
internal_key: K,
Expand Down

0 comments on commit 6f405ab

Please sign in to comment.