mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Merge 5bf65ec66e into merged_master (Bitcoin PR bitcoin/bitcoin#22558)
This commit is contained in:
commit
2d07ef8fc1
17 changed files with 710 additions and 31 deletions
71
src/psbt.cpp
71
src/psbt.cpp
|
|
@ -386,6 +386,24 @@ void PSBTInput::FillSignatureData(SignatureData& sigdata) const
|
|||
for (const auto& key_pair : hd_keypaths) {
|
||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
|
||||
}
|
||||
if (!m_tap_key_sig.empty()) {
|
||||
sigdata.taproot_key_path_sig = m_tap_key_sig;
|
||||
}
|
||||
for (const auto& [pubkey_leaf, sig] : m_tap_script_sigs) {
|
||||
sigdata.taproot_script_sigs.emplace(pubkey_leaf, sig);
|
||||
}
|
||||
if (!m_tap_internal_key.IsNull()) {
|
||||
sigdata.tr_spenddata.internal_key = m_tap_internal_key;
|
||||
}
|
||||
if (!m_tap_merkle_root.IsNull()) {
|
||||
sigdata.tr_spenddata.merkle_root = m_tap_merkle_root;
|
||||
}
|
||||
for (const auto& [leaf_script, control_block] : m_tap_scripts) {
|
||||
sigdata.tr_spenddata.scripts.emplace(leaf_script, control_block);
|
||||
}
|
||||
for (const auto& [pubkey, leaf_origin] : m_tap_bip32_paths) {
|
||||
sigdata.taproot_misc_pubkeys.emplace(pubkey, leaf_origin);
|
||||
}
|
||||
}
|
||||
|
||||
void PSBTInput::FromSignatureData(const SignatureData& sigdata)
|
||||
|
|
@ -415,6 +433,24 @@ void PSBTInput::FromSignatureData(const SignatureData& sigdata)
|
|||
for (const auto& entry : sigdata.misc_pubkeys) {
|
||||
hd_keypaths.emplace(entry.second);
|
||||
}
|
||||
if (!sigdata.taproot_key_path_sig.empty()) {
|
||||
m_tap_key_sig = sigdata.taproot_key_path_sig;
|
||||
}
|
||||
for (const auto& [pubkey_leaf, sig] : sigdata.taproot_script_sigs) {
|
||||
m_tap_script_sigs.emplace(pubkey_leaf, sig);
|
||||
}
|
||||
if (!sigdata.tr_spenddata.internal_key.IsNull()) {
|
||||
m_tap_internal_key = sigdata.tr_spenddata.internal_key;
|
||||
}
|
||||
if (!sigdata.tr_spenddata.merkle_root.IsNull()) {
|
||||
m_tap_merkle_root = sigdata.tr_spenddata.merkle_root;
|
||||
}
|
||||
for (const auto& [leaf_script, control_block] : sigdata.tr_spenddata.scripts) {
|
||||
m_tap_scripts.emplace(leaf_script, control_block);
|
||||
}
|
||||
for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
|
||||
m_tap_bip32_paths.emplace(pubkey, leaf_origin);
|
||||
}
|
||||
}
|
||||
|
||||
bool PSBTInput::Merge(const PSBTInput& input)
|
||||
|
|
@ -424,7 +460,6 @@ bool PSBTInput::Merge(const PSBTInput& input)
|
|||
|
||||
if (!non_witness_utxo && input.non_witness_utxo) non_witness_utxo = input.non_witness_utxo;
|
||||
if (witness_utxo.IsNull() && !input.witness_utxo.IsNull()) {
|
||||
// TODO: For segwit v1, we will want to clear out the non-witness utxo when setting a witness one. For v0 and non-segwit, this is not safe
|
||||
witness_utxo = input.witness_utxo;
|
||||
}
|
||||
|
||||
|
|
@ -435,6 +470,9 @@ bool PSBTInput::Merge(const PSBTInput& input)
|
|||
hash256_preimages.insert(input.hash256_preimages.begin(), input.hash256_preimages.end());
|
||||
hd_keypaths.insert(input.hd_keypaths.begin(), input.hd_keypaths.end());
|
||||
unknown.insert(input.unknown.begin(), input.unknown.end());
|
||||
m_tap_script_sigs.insert(input.m_tap_script_sigs.begin(), input.m_tap_script_sigs.end());
|
||||
m_tap_scripts.insert(input.m_tap_scripts.begin(), input.m_tap_scripts.end());
|
||||
m_tap_bip32_paths.insert(input.m_tap_bip32_paths.begin(), input.m_tap_bip32_paths.end());
|
||||
|
||||
if (redeem_script.empty() && !input.redeem_script.empty()) redeem_script = input.redeem_script;
|
||||
if (witness_script.empty() && !input.witness_script.empty()) witness_script = input.witness_script;
|
||||
|
|
@ -470,6 +508,10 @@ bool PSBTInput::Merge(const PSBTInput& input)
|
|||
|
||||
if (m_utxo_rangeproof.empty() && !input.m_utxo_rangeproof.empty()) m_utxo_rangeproof = input.m_utxo_rangeproof;
|
||||
|
||||
if (m_tap_key_sig.empty() && !input.m_tap_key_sig.empty()) m_tap_key_sig = input.m_tap_key_sig;
|
||||
if (m_tap_internal_key.IsNull() && !input.m_tap_internal_key.IsNull()) m_tap_internal_key = input.m_tap_internal_key;
|
||||
if (m_tap_merkle_root.IsNull() && !input.m_tap_merkle_root.IsNull()) m_tap_merkle_root = input.m_tap_merkle_root;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -484,6 +526,15 @@ 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();
|
||||
|
||||
sigdata.tr_spenddata.internal_key = m_tap_internal_key;
|
||||
sigdata.tr_spenddata.Merge(spenddata);
|
||||
}
|
||||
for (const auto& [pubkey, leaf_origin] : m_tap_bip32_paths) {
|
||||
sigdata.taproot_misc_pubkeys.emplace(pubkey, leaf_origin);
|
||||
}
|
||||
}
|
||||
|
||||
void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
|
||||
|
|
@ -497,6 +548,15 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
|
|||
for (const auto& entry : sigdata.misc_pubkeys) {
|
||||
hd_keypaths.emplace(entry.second);
|
||||
}
|
||||
if (!sigdata.tr_spenddata.internal_key.IsNull()) {
|
||||
m_tap_internal_key = sigdata.tr_spenddata.internal_key;
|
||||
}
|
||||
if (sigdata.tr_builder.has_value()) {
|
||||
m_tap_tree = sigdata.tr_builder;
|
||||
}
|
||||
for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
|
||||
m_tap_bip32_paths.emplace(pubkey, leaf_origin);
|
||||
}
|
||||
}
|
||||
|
||||
bool PSBTOutput::IsNull() const
|
||||
|
|
@ -512,6 +572,7 @@ bool PSBTOutput::Merge(const PSBTOutput& output)
|
|||
|
||||
hd_keypaths.insert(output.hd_keypaths.begin(), output.hd_keypaths.end());
|
||||
unknown.insert(output.unknown.begin(), output.unknown.end());
|
||||
m_tap_bip32_paths.insert(output.m_tap_bip32_paths.begin(), output.m_tap_bip32_paths.end());
|
||||
|
||||
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;
|
||||
|
|
@ -542,6 +603,9 @@ bool PSBTOutput::Merge(const PSBTOutput& output)
|
|||
m_blind_asset_proof = output.m_blind_asset_proof;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -702,10 +766,11 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
|
|||
input.FromSignatureData(sigdata);
|
||||
|
||||
// If we have a witness signature, put a witness UTXO.
|
||||
// TODO: For segwit v1, we should remove the non_witness_utxo
|
||||
if (sigdata.witness) {
|
||||
input.witness_utxo = utxo;
|
||||
// input.non_witness_utxo = nullptr;
|
||||
// We can remove the non_witness_utxo if and only if there are no non-segwit or segwit v0
|
||||
// inputs in this transaction. Since this requires inspecting the entire transaction, this
|
||||
// is something for the caller to deal with (i.e. FillPSBT).
|
||||
}
|
||||
|
||||
// Fill in the missing info
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue