Don't discard partial sigs when loading PSBT files #5671
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently when loading PSBT files, the Coldcard plugin's multisig support (added in #5440 by @peter-conalgo) causes any partial signatures to be discarded. This happens because the plugin sets the Transaction input field 'x_pubkeys' to the the same value as 'pubkeys', which is in turn parsed from the multisig script. The full xpubs are not contained in the script however, so this value is incorrect. This causes the following behaviour:
When loading the transaction dialog, Electrum compares the provided xpubs with the expected xpubs calculated from the MultisigWallet (see wallet.py line 2121). Where these differ, any signatures provided with that input are discarded. This can be tested using any PSBT that is partially signed - once this file is loaded through Tools -> Load Transaction -> From PSBT File the transaction dialog Status field will show 'Unsigned' and the partial signature is lost.
This PR resolves this issue by setting the xpubs correctly. They are retrieved from the PSBT by parsing the values retrieved from the PSBT_GLOBAL_XPUB field, and adding the relevant address indexes as parsed from the PSBT_IN_BIP32_DERIVATION field since Electrum expects them to be appended.
The result is that partial signatures from PSBT files are preserved, and the transaction dialog reflects the correct status - 'Partially Signed (m/n)'.