Skip to content

Commit 53e6fff

Browse files
committed
Add bool PSBTInputSigned
Refactor out a "PSBTInputSigned" function to check if a PSBT is signed, for use in subsequent commits. Also improve a related comment.
1 parent 65166d4 commit 53e6fff

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,12 +1536,15 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
15361536
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
15371537
}
15381538

1539-
// Get all of the previous transactions
1539+
// Finalize input signatures -- in case we have partial signatures that add up to a complete
1540+
// signature, but have not combined them yet (e.g. because the combiner that created this
1541+
// PartiallySignedTransaction did not understand them), this will combine them into a final
1542+
// script.
15401543
bool complete = true;
15411544
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
15421545
PSBTInput& input = psbtx.inputs.at(i);
15431546

1544-
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, 1);
1547+
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, SIGHASH_ALL);
15451548
}
15461549

15471550
UniValue result(UniValue::VOBJ);

src/script/sign.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
239239
return sigdata.complete;
240240
}
241241

242+
bool PSBTInputSigned(PSBTInput& input)
243+
{
244+
return !input.final_script_sig.empty() || !input.final_script_witness.IsNull();
245+
}
246+
242247
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
243248
{
244-
// if this input has a final scriptsig or scriptwitness, don't do anything with it
245-
if (!input.final_script_sig.empty() || !input.final_script_witness.IsNull()) {
249+
if (PSBTInputSigned(input)) {
246250
return true;
247251
}
248252

src/script/sign.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
730730
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType);
731731
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
732732

733+
/** Checks whether a PSBTInput is already signed. */
734+
bool PSBTInputSigned(PSBTInput& input);
735+
733736
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
734737
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash = SIGHASH_ALL);
735738

0 commit comments

Comments
 (0)