Abstract tap branch hash computing into a dedicated method

This commit is contained in:
Dr Maxim Orlovsky 2022-03-31 15:16:39 +02:00
parent 58a958e3f7
commit 1b28375658
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
1 changed files with 15 additions and 0 deletions

View File

@ -131,6 +131,21 @@ impl TapLeafHash {
}
}
impl TapBranchHash {
/// Computes branch hash given two hashes of the nodes underneath it.
pub fn from_node_hashes(a: sha256::Hash, b: sha256::Hash) -> TapBranchHash {
let mut eng = TapBranchHash::engine();
if a < b {
eng.input(&a);
eng.input(&b);
} else {
eng.input(&b);
eng.input(&a);
};
TapBranchHash::from_engine(eng)
}
}
/// Maximum depth of a taproot tree script spend path.
// https://github.com/bitcoin/bitcoin/blob/e826b22da252e0599c61d21c98ff89f366b3120f/src/script/interpreter.h#L229
pub const TAPROOT_CONTROL_MAX_NODE_COUNT: usize = 128;