static*/
| 413 | } |
| 414 | |
| 415 | /*static*/ bool TaprootBuilder::ValidDepths(const std::vector<int>& depths) |
| 416 | { |
| 417 | std::vector<bool> branch; |
| 418 | for (int depth : depths) { |
| 419 | // This inner loop corresponds to effectively the same logic on branch |
| 420 | // as what Insert() performs on the m_branch variable. Instead of |
| 421 | // storing a NodeInfo object, just remember whether or not there is one |
| 422 | // at that depth. |
| 423 | if (depth < 0 || (size_t)depth > TAPROOT_CONTROL_MAX_NODE_COUNT) return false; |
| 424 | if ((size_t)depth + 1 < branch.size()) return false; |
| 425 | while (branch.size() > (size_t)depth && branch[depth]) { |
| 426 | branch.pop_back(); |
| 427 | if (depth == 0) return false; |
| 428 | --depth; |
| 429 | } |
| 430 | if (branch.size() <= (size_t)depth) branch.resize((size_t)depth + 1); |
| 431 | assert(!branch[depth]); |
| 432 | branch[depth] = true; |
| 433 | } |
| 434 | // And this check corresponds to the IsComplete() check on m_branch. |
| 435 | return branch.size() == 0 || (branch.size() == 1 && branch[0]); |
| 436 | } |
| 437 | |
| 438 | TaprootBuilder& TaprootBuilder::Add(int depth, std::span<const unsigned char> script, int leaf_version, bool track) |
| 439 | { |