mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
Add TaprootBuilder::GetTreeTuples
GetTreeTuples returns the leaves in DFS order as tuples of depth, leaf version, and script. This is a representation of the tree that can be serialized.
This commit is contained in:
@@ -642,3 +642,19 @@ std::optional<std::vector<std::tuple<int, CScript, int>>> InferTaprootTree(const
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::tuple<uint8_t, uint8_t, CScript>> TaprootBuilder::GetTreeTuples() const
|
||||
{
|
||||
assert(IsComplete());
|
||||
std::vector<std::tuple<uint8_t, uint8_t, CScript>> tuples;
|
||||
if (m_branch.size()) {
|
||||
const auto& leaves = m_branch[0]->leaves;
|
||||
for (const auto& leaf : leaves) {
|
||||
assert(leaf.merkle_branch.size() <= TAPROOT_CONTROL_MAX_NODE_COUNT);
|
||||
uint8_t depth = (uint8_t)leaf.merkle_branch.size();
|
||||
uint8_t leaf_ver = (uint8_t)leaf.leaf_version;
|
||||
tuples.push_back(std::make_tuple(depth, leaf_ver, leaf.script));
|
||||
}
|
||||
}
|
||||
return tuples;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user