@@ -443,14 +443,14 @@ void TaprootBuilder::Insert(TaprootBuilder::NodeInfo&& node, int depth)
443443 return branch.size () == 0 || (branch.size () == 1 && branch[0 ]);
444444}
445445
446- TaprootBuilder& TaprootBuilder::Add (int depth, const CScript& script, int leaf_version, bool track)
446+ TaprootBuilder& TaprootBuilder::Add (int depth, Span< const unsigned char > script, int leaf_version, bool track)
447447{
448448 assert ((leaf_version & ~TAPROOT_LEAF_MASK) == 0 );
449449 if (!IsValid ()) return *this ;
450450 /* Construct NodeInfo object with leaf hash and (if track is true) also leaf information. */
451451 NodeInfo node;
452- node.hash = (HashWriter{HASHER_TAPLEAF} << uint8_t ( leaf_version) << script). GetSHA256 ( );
453- if (track) node.leaves .emplace_back (LeafInfo{script, leaf_version, {}});
452+ node.hash = ComputeTapleafHash ( leaf_version, script);
453+ if (track) node.leaves .emplace_back (LeafInfo{std::vector< unsigned char >( script. begin (), script. end ()) , leaf_version, {}});
454454 /* Insert into the branch. */
455455 Insert (std::move (node), depth);
456456 return *this ;
@@ -506,13 +506,13 @@ TaprootSpendData TaprootBuilder::GetSpendData() const
506506 return spd;
507507}
508508
509- std::optional<std::vector<std::tuple<int , CScript , int >>> InferTaprootTree (const TaprootSpendData& spenddata, const XOnlyPubKey& output)
509+ std::optional<std::vector<std::tuple<int , std::vector< unsigned char > , int >>> InferTaprootTree (const TaprootSpendData& spenddata, const XOnlyPubKey& output)
510510{
511511 // Verify that the output matches the assumed Merkle root and internal key.
512512 auto tweak = spenddata.internal_key .CreateTapTweak (spenddata.merkle_root .IsNull () ? nullptr : &spenddata.merkle_root );
513513 if (!tweak || tweak->first != output) return std::nullopt ;
514514 // If the Merkle root is 0, the tree is empty, and we're done.
515- std::vector<std::tuple<int , CScript , int >> ret;
515+ std::vector<std::tuple<int , std::vector< unsigned char > , int >> ret;
516516 if (spenddata.merkle_root .IsNull ()) return ret;
517517
518518 /* * Data structure to represent the nodes of the tree we're going to build. */
@@ -523,7 +523,7 @@ std::optional<std::vector<std::tuple<int, CScript, int>>> InferTaprootTree(const
523523 std::unique_ptr<TreeNode> sub[2 ];
524524 /* * If this is known to be a leaf node, a pointer to the (script, leaf_ver) pair.
525525 * nullptr otherwise. */
526- const std::pair<CScript , int >* leaf = nullptr ;
526+ const std::pair<std::vector< unsigned char > , int >* leaf = nullptr ;
527527 /* * Whether or not this node has been explored (is known to be a leaf, or known to have children). */
528528 bool explored = false ;
529529 /* * Whether or not this node is an inner node (unknown until explored = true). */
@@ -641,10 +641,10 @@ std::optional<std::vector<std::tuple<int, CScript, int>>> InferTaprootTree(const
641641 return ret;
642642}
643643
644- std::vector<std::tuple<uint8_t , uint8_t , CScript >> TaprootBuilder::GetTreeTuples () const
644+ std::vector<std::tuple<uint8_t , uint8_t , std::vector< unsigned char > >> TaprootBuilder::GetTreeTuples () const
645645{
646646 assert (IsComplete ());
647- std::vector<std::tuple<uint8_t , uint8_t , CScript >> tuples;
647+ std::vector<std::tuple<uint8_t , uint8_t , std::vector< unsigned char > >> tuples;
648648 if (m_branch.size ()) {
649649 const auto & leaves = m_branch[0 ]->leaves ;
650650 for (const auto & leaf : leaves) {
0 commit comments