MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Insert

Method Insert

src/script/signingprovider.cpp:389–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387}
388
389void TaprootBuilder::Insert(TaprootBuilder::NodeInfo&& node, int depth)
390{
391 assert(depth >= 0 && (size_t)depth <= TAPROOT_CONTROL_MAX_NODE_COUNT);
392 /* We cannot insert a leaf at a lower depth while a deeper branch is unfinished. Doing
393 * so would mean the Add() invocations do not correspond to a DFS traversal of a
394 * binary tree. */
395 if ((size_t)depth + 1 < m_branch.size()) {
396 m_valid = false;
397 return;
398 }
399 /* As long as an entry in the branch exists at the specified depth, combine it and propagate up.
400 * The 'node' variable is overwritten here with the newly combined node. */
401 while (m_valid && m_branch.size() > (size_t)depth && m_branch[depth].has_value()) {
402 node = Combine(std::move(node), std::move(*m_branch[depth]));
403 m_branch.pop_back();
404 if (depth == 0) m_valid = false; /* Can't propagate further up than the root */
405 --depth;
406 }
407 if (m_valid) {
408 /* Make sure the branch is big enough to place the new node. */
409 if (m_branch.size() <= (size_t)depth) m_branch.resize((size_t)depth + 1);
410 assert(!m_branch[depth].has_value());
411 m_branch[depth] = std::move(node);
412 }
413}
414
415/*static*/ bool TaprootBuilder::ValidDepths(const std::vector<int>& depths)
416{

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.45
has_valueMethod · 0.45
pop_backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected