MCPcopy Create free account
hub / github.com/ElementsProject/elements / Insert

Method Insert

src/script/standard.cpp:413–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411}
412
413void TaprootBuilder::Insert(TaprootBuilder::NodeInfo&& node, int depth)
414{
415 assert(depth >= 0 && (size_t)depth <= TAPROOT_CONTROL_MAX_NODE_COUNT);
416 /* We cannot insert a leaf at a lower depth while a deeper branch is unfinished. Doing
417 * so would mean the Add() invocations do not correspond to a DFS traversal of a
418 * binary tree. */
419 if ((size_t)depth + 1 < m_branch.size()) {
420 m_valid = false;
421 return;
422 }
423 /* As long as an entry in the branch exists at the specified depth, combine it and propagate up.
424 * The 'node' variable is overwritten here with the newly combined node. */
425 while (m_valid && m_branch.size() > (size_t)depth && m_branch[depth].has_value()) {
426 node = Combine(std::move(node), std::move(*m_branch[depth]));
427 m_branch.pop_back();
428 if (depth == 0) m_valid = false; /* Can't propagate further up than the root */
429 --depth;
430 }
431 if (m_valid) {
432 /* Make sure the branch is big enough to place the new node. */
433 if (m_branch.size() <= (size_t)depth) m_branch.resize((size_t)depth + 1);
434 assert(!m_branch[depth].has_value());
435 m_branch[depth] = std::move(node);
436 }
437}
438
439/*static*/ bool TaprootBuilder::ValidDepths(const std::vector<int>& depths)
440{

Callers 6

BOOST_AUTO_TEST_CASEFunction · 0.45
FUZZ_TARGETFunction · 0.45
WriteBlockMethod · 0.45
ReverseBlockMethod · 0.45
add_coinFunction · 0.45
ApplyHashFunction · 0.45

Calls 3

sizeMethod · 0.45
pop_backMethod · 0.45
resizeMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.36
FUZZ_TARGETFunction · 0.36