aboutsummaryrefslogtreecommitdiff
path: root/src/psbt.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-08-16 21:17:43 -0400
committerfanquake <fanquake@gmail.com>2022-10-13 23:45:06 +0800
commitd810fde8ea64b71567f8b50895ac76bcb7afbfbc (patch)
tree9ed4968272667dd76aac7cfee97ab9b11d81d13b /src/psbt.cpp
parenta9419eff0cc21d21755165e66cc0e496aab65650 (diff)
downloadbitcoin-d810fde8ea64b71567f8b50895ac76bcb7afbfbc.tar.xz
psbt: Change m_tap_tree to store just the tuples
Instead of having an entire TaprootBuilder which may or may not be complete, and could potentially have future changes that interact oddly with taproot tree tuples, have m_tap_tree be just the tuples. When needed in other a TaprootBuilder for actual use, the tuples will be added to a a TaprootBuilder that, in the future, can take in whatever other data is needed as well. Github-Pull: #25858 Rebased-From: 0577d423adda8e719d7611d03355680c8fbacab8
Diffstat (limited to 'src/psbt.cpp')
-rw-r--r--src/psbt.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 6b75de91f8..6c6ea6a555 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -218,8 +218,14 @@ void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
for (const auto& key_pair : hd_keypaths) {
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
}
- if (m_tap_tree.has_value() && m_tap_internal_key.IsFullyValid()) {
- TaprootSpendData spenddata = m_tap_tree->GetSpendData();
+ if (!m_tap_tree.empty() && m_tap_internal_key.IsFullyValid()) {
+ TaprootBuilder builder;
+ for (const auto& [depth, leaf_ver, script] : m_tap_tree) {
+ builder.Add((int)depth, script, (int)leaf_ver, /*track=*/true);
+ }
+ assert(builder.IsComplete());
+ builder.Finalize(m_tap_internal_key);
+ TaprootSpendData spenddata = builder.GetSpendData();
sigdata.tr_spenddata.internal_key = m_tap_internal_key;
sigdata.tr_spenddata.Merge(spenddata);
@@ -244,7 +250,7 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
m_tap_internal_key = sigdata.tr_spenddata.internal_key;
}
if (sigdata.tr_builder.has_value()) {
- m_tap_tree = sigdata.tr_builder;
+ m_tap_tree = sigdata.tr_builder->GetTreeTuples();
}
for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
m_tap_bip32_paths.emplace(pubkey, leaf_origin);
@@ -265,7 +271,7 @@ void PSBTOutput::Merge(const PSBTOutput& output)
if (redeem_script.empty() && !output.redeem_script.empty()) redeem_script = output.redeem_script;
if (witness_script.empty() && !output.witness_script.empty()) witness_script = output.witness_script;
if (m_tap_internal_key.IsNull() && !output.m_tap_internal_key.IsNull()) m_tap_internal_key = output.m_tap_internal_key;
- if (!m_tap_tree.has_value() && output.m_tap_tree.has_value()) m_tap_tree = output.m_tap_tree;
+ if (m_tap_tree.empty() && !output.m_tap_tree.empty()) m_tap_tree = output.m_tap_tree;
}
bool PSBTInputSigned(const PSBTInput& input)
{