@@ -125,36 +125,49 @@ impl PartialEq for TapTree {
125
125
126
126
impl Eq for TapTree { }
127
127
128
+ impl From < TapTree > for TaprootBuilder {
129
+ #[ inline]
130
+ fn from ( tree : TapTree ) -> Self {
131
+ tree. into_builder ( )
132
+ }
133
+ }
134
+
128
135
impl TapTree {
129
136
/// Gets the inner node info as the builder is finalized.
130
- fn node_info ( & self ) -> & NodeInfo {
137
+ pub fn node_info ( & self ) -> & NodeInfo {
131
138
// The builder algorithm invariant guarantees that is_complete builder
132
139
// have only 1 element in branch and that is not None.
133
140
// We make sure that we only allow is_complete builders via the from_inner
134
141
// constructor
135
142
self . 0 . branch ( ) [ 0 ] . as_ref ( ) . expect ( "from_inner only parses is_complete builders" )
136
143
}
137
144
138
- /// Converts a [`TaprootBuilder `] into a tree if it is complete binary tree.
145
+ /// Constructs [`TapTree `] from a [`TaprootBuilder`] if it is complete binary tree.
139
146
///
140
147
/// # Returns
141
- /// A [`TapTree`] iff the `inner` builder is complete, otherwise return [`IncompleteTapTree`]
142
- /// error with the content of incomplete builder `inner ` instance.
143
- pub fn from_inner ( inner : TaprootBuilder ) -> Result < Self , IncompleteTapTree > {
144
- if !inner . is_finalized ( ) {
145
- Err ( IncompleteTapTree :: NotFinalized ( inner ) )
146
- } else if inner . has_hidden_nodes ( ) {
147
- Err ( IncompleteTapTree :: HiddenParts ( inner ) )
148
+ /// A [`TapTree`] iff the `builder` is complete, otherwise return [`IncompleteTapTree`]
149
+ /// error with the content of incomplete `builder ` instance.
150
+ pub fn from_builder ( builder : TaprootBuilder ) -> Result < Self , IncompleteTapTree > {
151
+ if !builder . is_finalized ( ) {
152
+ Err ( IncompleteTapTree :: NotFinalized ( builder ) )
153
+ } else if builder . has_hidden_nodes ( ) {
154
+ Err ( IncompleteTapTree :: HiddenParts ( builder ) )
148
155
} else {
149
- Ok ( TapTree ( inner ) )
156
+ Ok ( TapTree ( builder ) )
150
157
}
151
158
}
152
159
153
160
/// Converts self into builder [`TaprootBuilder`]. The builder is guaranteed to be finalized.
154
- pub fn into_inner ( self ) -> TaprootBuilder {
161
+ pub fn into_builder ( self ) -> TaprootBuilder {
155
162
self . 0
156
163
}
157
164
165
+ /// Constructs [`TaprootBuilder`] by internally cloning the `self`. The builder is guaranteed
166
+ /// to be finalized.
167
+ pub fn to_builder ( & self ) -> TaprootBuilder {
168
+ self . 0 . clone ( )
169
+ }
170
+
158
171
/// Returns [`TapTreeIter`] iterator for a taproot script tree, operating in DFS order over
159
172
/// tree [`ScriptLeaf`]s.
160
173
pub fn script_leaves ( & self ) -> TapTreeIter {
0 commit comments