Merge #14196: [0.17][psbt] always drop the unnecessary utxo and convert non-witness utxo to witness when necessary

fcefc6851a Convert non-witness UTXOs to witness if witness sig created (Andrew Chow)
fcdea8ad2a Drop the unnecessary UTXO based on the UTXOs present, not on earlier wallet things (Andrew Chow)

Pull request description:

  When we sign an input in a psbt that has a non-witness utxo but a witness signature is produced, we will now replace the non-witness utxo with the corresponding witness utxo. Furthermore, we should make sure that the correct UTXO type is used based on what UTXOs are there, not based on earlier wallet behavior.

  Note that this is PR'd to the 0.17 branch because the code here no longer exists in master.

Tree-SHA512: 882e9e4e9b77d6ac1743c35c0d59023aad6f4f19193398f97f2c6b81f6627d74e5220b1d674a0edba1ff2fc2a7f61afbf838d3faf0a964fccd3dee97c631aa47
This commit is contained in:
MarcoFalke 2018-12-01 12:31:12 -05:00
commit 3362a95be3
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25

View file

@ -4534,8 +4534,15 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
complete &= SignPSBTInput(PublicOnlySigningProvider(pwallet), *psbtx.tx, input, sigdata, i, sighash_type);
}
if (it != pwallet->mapWallet.end()) {
// Drop the unnecessary UTXO if we added both from the wallet.
if (sigdata.witness) {
// Convert the non-witness utxo to witness
if (input.witness_utxo.IsNull() && input.non_witness_utxo) {
input.witness_utxo = input.non_witness_utxo->vout[txin.prevout.n];
}
}
// If both UTXO types are present, drop the unnecessary one.
if (input.non_witness_utxo && !input.witness_utxo.IsNull()) {
if (sigdata.witness) {
input.non_witness_utxo = nullptr;
} else {