Skip to content

Commit c596cdb

Browse files
committed
Abstract tap branch hash computing into a dedicated method
1 parent 2f7fc0e commit c596cdb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/util/taproot.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ impl TapLeafHash {
131131
}
132132
}
133133

134+
impl TapBranchHash {
135+
/// Computes branch hash given two hashes of the nodes underneath it.
136+
pub fn from_node_hashes(a: sha256::Hash, b: sha256::Hash) -> TapBranchHash {
137+
let mut eng = TapBranchHash::engine();
138+
if a < b {
139+
eng.input(&a);
140+
eng.input(&b);
141+
} else {
142+
eng.input(&b);
143+
eng.input(&a);
144+
};
145+
TapBranchHash::from_engine(eng)
146+
}
147+
}
148+
134149
/// Maximum depth of a taproot tree script spend path.
135150
// https://github.com/bitcoin/bitcoin/blob/e826b22da252e0599c61d21c98ff89f366b3120f/src/script/interpreter.h#L229
136151
pub const TAPROOT_CONTROL_MAX_NODE_COUNT: usize = 128;

0 commit comments

Comments
 (0)