Skip to content

Commit 86bee15

Browse files
committed
tr: move Liftable impl for TapTree
Moving this separately from the rest of the TapTree stuff because I changed the Policy import to Semantic and the Error import to just crate::Error (since this is the only place that type is used in the taptree module, and I don't really like this type). So this is a move-only diff but it might not look like it, so I figured I should at least make the diff small.
1 parent b463007 commit 86bee15

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/descriptor/tr/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,6 @@ impl<Pk: MiniscriptKey> fmt::Display for Tr<Pk> {
480480
}
481481
}
482482

483-
impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
484-
fn lift(&self) -> Result<Policy<Pk>, Error> {
485-
fn lift_helper<Pk: MiniscriptKey>(s: &TapTree<Pk>) -> Result<Policy<Pk>, Error> {
486-
match *s {
487-
TapTree::Tree { ref left, ref right, height: _ } => Ok(Policy::Thresh(
488-
Threshold::or(Arc::new(lift_helper(left)?), Arc::new(lift_helper(right)?)),
489-
)),
490-
TapTree::Leaf(ref leaf) => leaf.lift(),
491-
}
492-
}
493-
494-
let pol = lift_helper(self)?;
495-
Ok(pol.normalized())
496-
}
497-
}
498-
499483
impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
500484
fn lift(&self) -> Result<Policy<Pk>, Error> {
501485
match &self.tree {

src/descriptor/tr/taptree.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use core::{cmp, fmt};
55
use bitcoin::taproot::{LeafVersion, TapLeafHash};
66

77
use crate::miniscript::context::Tap;
8+
use crate::policy::{Liftable, Semantic};
89
use crate::prelude::Vec;
910
use crate::sync::Arc;
10-
use crate::{Miniscript, MiniscriptKey, ToPublicKey, TranslateErr, Translator};
11+
use crate::{Miniscript, MiniscriptKey, Threshold, ToPublicKey, TranslateErr, Translator};
1112

1213
/// A Taproot Tree representation.
1314
// Hidden leaves are not yet supported in descriptor spec. Conceptually, it should
@@ -69,6 +70,22 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
6970
}
7071
}
7172

73+
impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
74+
fn lift(&self) -> Result<Semantic<Pk>, crate::Error> {
75+
fn lift_helper<Pk: MiniscriptKey>(s: &TapTree<Pk>) -> Result<Semantic<Pk>, crate::Error> {
76+
match *s {
77+
TapTree::Tree { ref left, ref right, height: _ } => Ok(Semantic::Thresh(
78+
Threshold::or(Arc::new(lift_helper(left)?), Arc::new(lift_helper(right)?)),
79+
)),
80+
TapTree::Leaf(ref leaf) => leaf.lift(),
81+
}
82+
}
83+
84+
let pol = lift_helper(self)?;
85+
Ok(pol.normalized())
86+
}
87+
}
88+
7289
impl<Pk: MiniscriptKey> fmt::Display for TapTree<Pk> {
7390
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7491
match self {

0 commit comments

Comments
 (0)