File tree Expand file tree Collapse file tree
include/bitcoin/system/chain Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class BC_API block
4343 typedef std::shared_ptr<const block> cptr;
4444
4545 static bool is_malleable64 (const transaction_cptrs& txs) NOEXCEPT;
46+ static hashes merkle_branch (size_t position, hashes&& leaves) NOEXCEPT;
4647 static uint64_t subsidy (size_t height, uint64_t subsidy_interval,
4748 uint64_t initial_block_subsidy_satoshi, bool bip42) NOEXCEPT;
4849
Original file line number Diff line number Diff line change @@ -444,24 +444,29 @@ bool block::is_invalid_merkle_root() const NOEXCEPT
444444 return generate_merkle_root (false ) != header_->merkle_root ();
445445}
446446
447- hashes block::merkle_branch (size_t position, bool witness) const NOEXCEPT
447+ // static
448+ hashes block::merkle_branch (size_t position, hashes&& leaves) NOEXCEPT
448449{
449- auto level = transaction_hashes (witness);
450- if (position >= level.size ())
450+ if (position >= leaves.size ())
451451 return {};
452452
453453 hashes branch{};
454- branch.reserve (ceilinged_log2 (level .size ()));
455- for (auto at = position; level .size () > one; at = to_half (at))
454+ branch.reserve (ceilinged_log2 (leaves .size ()));
455+ for (auto at = position; leaves .size () > one; at = to_half (at))
456456 {
457- if (is_odd (level .size ())) level .push_back (level .back ());
458- branch.push_back (level .at (is_even (at) ? add1 (at) : sub1 (at)));
459- sha256::merkle_hash (level );
457+ if (is_odd (leaves .size ())) leaves .push_back (leaves .back ());
458+ branch.push_back (leaves .at (is_even (at) ? add1 (at) : sub1 (at)));
459+ sha256::merkle_hash (leaves );
460460 }
461461
462462 return branch;
463463}
464464
465+ hashes block::merkle_branch (size_t position, bool witness) const NOEXCEPT
466+ {
467+ return merkle_branch (position, transaction_hashes (witness));
468+ }
469+
465470// Accept (contextual).
466471// ----------------------------------------------------------------------------
467472
You can’t perform that action at this time.
0 commit comments