Skip to content

Commit 917353c

Browse files
committed
Make SignPSBTInput operate on a private SignatureData object
1 parent cad5dd2 commit 917353c

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,7 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
16411641
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
16421642
PSBTInput& input = psbtx.inputs.at(i);
16431643

1644-
SignatureData sigdata;
1645-
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, sigdata, i, 1);
1644+
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, 1);
16461645
}
16471646

16481647
UniValue result(UniValue::VOBJ);

src/script/sign.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,15 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
237237
return sigdata.complete;
238238
}
239239

240-
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash)
240+
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
241241
{
242242
// if this input has a final scriptsig or scriptwitness, don't do anything with it
243243
if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) {
244244
return true;
245245
}
246246

247247
// Fill SignatureData with input info
248+
SignatureData sigdata;
248249
input.FillSignatureData(sigdata);
249250

250251
// Get UTXO
@@ -276,6 +277,16 @@ bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& t
276277
// Verify that a witness signature was produced in case one was required.
277278
if (require_witness_sig && !sigdata.witness) return false;
278279
input.FromSignatureData(sigdata);
280+
281+
// If both UTXO types are present, drop the unnecessary one.
282+
if (input.non_witness_utxo && !input.witness_utxo.IsNull()) {
283+
if (sigdata.witness) {
284+
input.non_witness_utxo = nullptr;
285+
} else {
286+
input.witness_utxo.SetNull();
287+
}
288+
}
289+
279290
return sig_complete;
280291
}
281292

src/script/sign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, C
696696
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
697697

698698
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
699-
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, SignatureData& sigdata, int index, int sighash = 1);
699+
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash = SIGHASH_ALL);
700700

701701
/** Extract signature data from a transaction input, and insert it. */
702702
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4461,17 +4461,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, const C
44614461
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Specified Sighash and sighash in PSBT do not match.");
44624462
}
44634463

4464-
SignatureData sigdata;
4465-
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, sigdata, i, sighash_type);
4466-
4467-
if (it != pwallet->mapWallet.end()) {
4468-
// Drop the unnecessary UTXO if we added both from the wallet.
4469-
if (sigdata.witness) {
4470-
input.non_witness_utxo = nullptr;
4471-
} else {
4472-
input.witness_utxo.SetNull();
4473-
}
4474-
}
4464+
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, i, sighash_type);
44754465
}
44764466

44774467
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change

0 commit comments

Comments
 (0)