@@ -713,7 +713,7 @@ struct PSBTOutput
713
713
CScript witness_script;
714
714
std::map<CPubKey, KeyOriginInfo> hd_keypaths;
715
715
XOnlyPubKey m_tap_internal_key;
716
- std::optional<TaprootBuilder > m_tap_tree;
716
+ std::vector<std::tuple< uint8_t , uint8_t , CScript> > m_tap_tree;
717
717
std::map<XOnlyPubKey, std::pair<std::set<uint256>, KeyOriginInfo>> m_tap_bip32_paths;
718
718
std::map<std::vector<unsigned char >, std::vector<unsigned char >> unknown;
719
719
std::set<PSBTProprietary> m_proprietary;
@@ -754,15 +754,11 @@ struct PSBTOutput
754
754
}
755
755
756
756
// Write taproot tree
757
- if (m_tap_tree.has_value ()) {
757
+ if (! m_tap_tree.empty ()) {
758
758
SerializeToVector (s, PSBT_OUT_TAP_TREE);
759
759
std::vector<unsigned char > value;
760
760
CVectorWriter s_value (s.GetType (), s.GetVersion (), value, 0 );
761
- const auto & tuples = m_tap_tree->GetTreeTuples ();
762
- for (const auto & tuple : tuples) {
763
- uint8_t depth = std::get<0 >(tuple);
764
- uint8_t leaf_ver = std::get<1 >(tuple);
765
- CScript script = std::get<2 >(tuple);
761
+ for (const auto & [depth, leaf_ver, script] : m_tap_tree) {
766
762
s_value << depth;
767
763
s_value << leaf_ver;
768
764
s_value << script;
@@ -858,13 +854,13 @@ struct PSBTOutput
858
854
} else if (key.size () != 1 ) {
859
855
throw std::ios_base::failure (" Output Taproot tree key is more than one byte type" );
860
856
}
861
- m_tap_tree.emplace ();
862
857
std::vector<unsigned char > tree_v;
863
858
s >> tree_v;
864
859
SpanReader s_tree (s.GetType (), s.GetVersion (), tree_v);
865
860
if (s_tree.empty ()) {
866
861
throw std::ios_base::failure (" Output Taproot tree must not be empty" );
867
862
}
863
+ TaprootBuilder builder;
868
864
while (!s_tree.empty ()) {
869
865
uint8_t depth;
870
866
uint8_t leaf_ver;
@@ -878,9 +874,10 @@ struct PSBTOutput
878
874
if ((leaf_ver & ~TAPROOT_LEAF_MASK) != 0 ) {
879
875
throw std::ios_base::failure (" Output Taproot tree has a leaf with an invalid leaf version" );
880
876
}
881
- m_tap_tree->Add ((int )depth, script, (int )leaf_ver, true /* track */ );
877
+ m_tap_tree.push_back (std::make_tuple (depth, leaf_ver, script));
878
+ builder.Add ((int )depth, script, (int )leaf_ver, true /* track */ );
882
879
}
883
- if (!m_tap_tree-> IsComplete ()) {
880
+ if (!builder. IsComplete ()) {
884
881
throw std::ios_base::failure (" Output Taproot tree is malformed" );
885
882
}
886
883
break ;
@@ -934,11 +931,6 @@ struct PSBTOutput
934
931
}
935
932
}
936
933
937
- // Finalize m_tap_tree so that all of the computed things are computed
938
- if (m_tap_tree.has_value () && m_tap_tree->IsComplete () && m_tap_internal_key.IsFullyValid ()) {
939
- m_tap_tree->Finalize (m_tap_internal_key);
940
- }
941
-
942
934
if (!found_sep) {
943
935
throw std::ios_base::failure (" Separator is missing at the end of an output map" );
944
936
}
0 commit comments