From d3992669df826899a3de78a77a366dab46028026 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 20 Jul 2021 22:05:28 -0400 Subject: [PATCH] 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. --- src/core_read.cpp | 2 +- src/wallet/scriptpubkeyman.h | 6 +++--- src/wallet/wallet.h | 2 +- test/functional/rpc_psbt.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core_read.cpp b/src/core_read.cpp index 2149b428d265e..484f41f262c44 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -248,7 +248,7 @@ std::vector ParseHexUV(const UniValue& v, const std::string& strN int ParseSighashString(const UniValue& sighash) { - int hash_type = SIGHASH_ALL; + int hash_type = SIGHASH_DEFAULT; if (!sighash.isNull()) { static std::map map_sighash_values = { {std::string("DEFAULT"), int(SIGHASH_DEFAULT)}, diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index ebe064fa0a092..dda31d2c0b124 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -236,7 +236,7 @@ class ScriptPubKeyMan /** Sign a message with the given script */ virtual SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const { return SigningResult::SIGNING_FAILED; }; /** Adds script and derivation path information to a PSBT, and optionally signs it. */ - virtual TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const { return TransactionError::INVALID_PSBT; } + virtual TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = SIGHASH_DEFAULT, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const { return TransactionError::INVALID_PSBT; } virtual uint256 GetID() const { return uint256(); } @@ -400,7 +400,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv bool SignTransaction(CMutableTransaction& tx, const std::map& coins, int sighash, std::map& input_errors) const override; SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override; - TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override; + TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = SIGHASH_DEFAULT, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override; uint256 GetID() const override; @@ -609,7 +609,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan bool SignTransaction(CMutableTransaction& tx, const std::map& coins, int sighash, std::map& input_errors) const override; SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const override; - TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = 1 /* SIGHASH_ALL */, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override; + TransactionError FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, int sighash_type = SIGHASH_DEFAULT, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override; uint256 GetID() const override; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index dbf0f6375d04e..93150cc583860 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -561,7 +561,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati */ TransactionError FillPSBT(PartiallySignedTransaction& psbtx, bool& complete, - int sighash_type = 1 /* SIGHASH_ALL */, + int sighash_type = SIGHASH_DEFAULT, bool sign = true, bool bip32derivs = true, size_t* n_signed = nullptr, diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index a8034849cc14a..153a201e95f27 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -457,7 +457,7 @@ def run_test(self): wrpc = self.nodes[2].get_wallet_rpc("wallet{}".format(i)) for key in signer['privkeys']: wrpc.importprivkey(key) - signed_tx = wrpc.walletprocesspsbt(signer['psbt'])['psbt'] + signed_tx = wrpc.walletprocesspsbt(signer['psbt'], True, "ALL")['psbt'] assert_equal(signed_tx, signer['result']) # Combiner test