Skip to content

Commit 96f78ed

Browse files
committed
psbt: Actually use SIGHASH_DEFAULT
Make the behavior align with the help text by actually using SIGHASH_DEFAULT as the default sighash for signing PSBTs.
1 parent bb09ec6 commit 96f78ed

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/core_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strN
257257

258258
int ParseSighashString(const UniValue& sighash)
259259
{
260-
int hash_type = SIGHASH_ALL;
260+
int hash_type = SIGHASH_DEFAULT;
261261
if (!sighash.isNull()) {
262262
static std::map<std::string, int> map_sighash_values = {
263263
{std::string("DEFAULT"), int(SIGHASH_DEFAULT)},

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ TransactionError LegacyScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psb
624624
}
625625

626626
// Get the Sighash type
627-
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
627+
if (sign && input.sighash_type > 0 && sighash_type > 0 && input.sighash_type != sighash_type) {
628628
return TransactionError::SIGHASH_MISMATCH;
629629
}
630630

@@ -2092,7 +2092,7 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
20922092
}
20932093

20942094
// Get the Sighash type
2095-
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
2095+
if (sign && input.sighash_type > 0 && sighash_type > 0 && input.sighash_type != sighash_type) {
20962096
return TransactionError::SIGHASH_MISMATCH;
20972097
}
20982098

src/wallet/scriptpubkeyman.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class ScriptPubKeyMan
234234
/** Sign a message with the given script */
235235
virtual SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const { return SigningResult::SIGNING_FAILED; };
236236
/** Adds script and derivation path information to a PSBT, and optionally signs it. */
237-
virtual TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const { return TransactionError::INVALID_PSBT; }
237+
virtual TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 0 /* SIGHASH_DEFAULT */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const { return TransactionError::INVALID_PSBT; }
238238

239239
virtual uint256 GetID() const { return uint256(); }
240240

@@ -398,7 +398,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
398398

399399
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const override;
400400
SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override;
401-
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
401+
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 0 /* SIGHASH_DEFAULT */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
402402

403403
uint256 GetID() const override;
404404

@@ -603,7 +603,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
603603

604604
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const override;
605605
SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override;
606-
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
606+
TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 0 /* SIGHASH_DEFAULT */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr) const override;
607607

608608
uint256 GetID() const override;
609609

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
581581
*/
582582
TransactionError FillPSBT(PartiallySignedTransaction& psbtx,
583583
bool& complete,
584-
int sighash_type = 1 /* SIGHASH_ALL */,
584+
int sighash_type = 0 /* SIGHASH_DEFAULT */,
585585
bool sign = true,
586586
bool bip32derivs = true,
587587
size_t* n_signed = nullptr) const;

0 commit comments

Comments
 (0)