mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-14 15:25:51 +02:00
psbt: avoid duplicate global xpub keys when merging
The global xpubs are stored in a map of key origin to set of xpubs, while the serialization writes one record per xpub, keyed by the xpub. Merging two PSBTs origin-by-origin can store the same xpub under two origins, which serializes as a PSBT with duplicate keys that the deserializer (and BIP 174) reject. Notably, combinepsbt returned a PSBT that no RPC could parse again when the combined PSBTs provide different key origins for the same xpub. Deduplicate by xpub when merging, keeping the origin that is already present, and share the logic between combinepsbt and joinpsbts.
This commit is contained in:
@@ -1918,13 +1918,7 @@ static RPCMethod joinpsbts()
|
||||
for (const PSBTOutput& output : psbt.outputs) {
|
||||
merged_psbt.AddOutput(output);
|
||||
}
|
||||
for (auto& xpub_pair : psbt.m_xpubs) {
|
||||
if (!merged_psbt.m_xpubs.contains(xpub_pair.first)) {
|
||||
merged_psbt.m_xpubs[xpub_pair.first] = xpub_pair.second;
|
||||
} else {
|
||||
merged_psbt.m_xpubs[xpub_pair.first].insert(xpub_pair.second.begin(), xpub_pair.second.end());
|
||||
}
|
||||
}
|
||||
merged_psbt.MergeGlobalXPubs(psbt);
|
||||
merged_psbt.unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user