| 496 | WitnessV1Taproot TaprootBuilder::GetOutput() { return WitnessV1Taproot{m_output_key}; } |
| 497 | |
| 498 | TaprootSpendData TaprootBuilder::GetSpendData() const |
| 499 | { |
| 500 | assert(IsComplete()); |
| 501 | TaprootSpendData spd; |
| 502 | spd.merkle_root = m_branch.size() == 0 ? uint256() : m_branch[0]->hash; |
| 503 | spd.internal_key = m_internal_key; |
| 504 | if (m_branch.size()) { |
| 505 | // If any script paths exist, they have been combined into the root m_branch[0] |
| 506 | // by now. Compute the control block for each of its tracked leaves, and put them in |
| 507 | // spd.scripts. |
| 508 | for (const auto& leaf : m_branch[0]->leaves) { |
| 509 | std::vector<unsigned char> control_block; |
| 510 | control_block.resize(TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * leaf.merkle_branch.size()); |
| 511 | control_block[0] = leaf.leaf_version | (m_parity ? 1 : 0); |
| 512 | std::copy(m_internal_key.begin(), m_internal_key.end(), control_block.begin() + 1); |
| 513 | if (leaf.merkle_branch.size()) { |
| 514 | std::copy(leaf.merkle_branch[0].begin(), |
| 515 | leaf.merkle_branch[0].begin() + TAPROOT_CONTROL_NODE_SIZE * leaf.merkle_branch.size(), |
| 516 | control_block.begin() + TAPROOT_CONTROL_BASE_SIZE); |
| 517 | } |
| 518 | spd.scripts[{leaf.script, leaf.leaf_version}].insert(std::move(control_block)); |
| 519 | } |
| 520 | } |
| 521 | return spd; |
| 522 | } |
| 523 | |
| 524 | std::optional<std::vector<std::tuple<int, CScript, int>>> InferTaprootTree(const TaprootSpendData& spenddata, const XOnlyPubKey& output) |
| 525 | { |