Skip to content

Commit 0f5bda2

Browse files
committed
Simplify arguments to SignPSBTInput
Remove redundant arguments to SignPSBTInput -- since it needs several bits of the PartiallySignedTransaction, pass in a reference instead of doing it piecemeal. This saves us having to pass in both a PSBTInput and its index, as well as having to pass in the CTransaction. Also avoid redundantly passing the sighash_type, which is contained in the PSBTInput already.
1 parent 53e6fff commit 0f5bda2

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,9 +1542,7 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
15421542
// script.
15431543
bool complete = true;
15441544
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
1545-
PSBTInput& input = psbtx.inputs.at(i);
1546-
1547-
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, SIGHASH_ALL);
1545+
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, SIGHASH_ALL);
15481546
}
15491547

15501548
UniValue result(UniValue::VOBJ);

src/script/sign.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,11 @@ bool PSBTInputSigned(PSBTInput& input)
244244
return !input.final_script_sig.empty() || !input.final_script_witness.IsNull();
245245
}
246246

247-
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash)
247+
bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash)
248248
{
249+
PSBTInput& input = psbt.inputs.at(index);
250+
const CMutableTransaction& tx = *psbt.tx;
251+
249252
if (PSBTInputSigned(input)) {
250253
return true;
251254
}

src/script/sign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom,
734734
bool PSBTInputSigned(PSBTInput& input);
735735

736736
/** Signs a PSBTInput, verifying that all provided data matches what is being signed. */
737-
bool SignPSBTInput(const SigningProvider& provider, const CMutableTransaction& tx, PSBTInput& input, int index, int sighash = SIGHASH_ALL);
737+
bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash = SIGHASH_ALL);
738738

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

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, int sig
37603760
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Specified Sighash and sighash in PSBT do not match.");
37613761
}
37623762

3763-
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), *psbtx.tx, input, i, sighash_type);
3763+
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), psbtx, i, sighash_type);
37643764
}
37653765

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

src/wallet/rpcwallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ bool EnsureWalletIsAvailable(CWallet *, bool avoidException);
3030

3131
UniValue getaddressinfo(const JSONRPCRequest& request);
3232
UniValue signrawtransactionwithwallet(const JSONRPCRequest& request);
33-
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, int sighash_type = 1, bool sign = true, bool bip32derivs = false);
33+
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false);
3434
#endif //BITCOIN_WALLET_RPCWALLET_H

src/wallet/test/psbt_wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
6060
ssData >> psbtx;
6161

6262
// Fill transaction with our data
63-
FillPSBT(&m_wallet, psbtx, 1, false, true);
63+
FillPSBT(&m_wallet, psbtx, SIGHASH_ALL, false, true);
6464

6565
// Get the final tx
6666
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);

0 commit comments

Comments
 (0)