diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index baabd4d5b5..597b1a1544 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -62,6 +62,11 @@ bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) if (ret) info = std::move(out.second); return ret; } +bool FlatSigningProvider::HaveKey(const CKeyID &keyid) const +{ + CKey key; + return LookupHelper(keys, keyid, key); +} bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); } bool FlatSigningProvider::GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const { diff --git a/src/script/signingprovider.h b/src/script/signingprovider.h index efdfd9ee56..f0fb21c8b1 100644 --- a/src/script/signingprovider.h +++ b/src/script/signingprovider.h @@ -215,6 +215,7 @@ struct FlatSigningProvider final : public SigningProvider bool GetCScript(const CScriptID& scriptid, CScript& script) const override; bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override; bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override; + bool HaveKey(const CKeyID &keyid) const override; bool GetKey(const CKeyID& keyid, CKey& key) const override; bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const override; bool GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const override; diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index cc11500844..b620c6beb0 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -2468,7 +2468,11 @@ std::unique_ptr DescriptorScriptPubKeyMan::GetSigningProvid int32_t index = it->second; // Always try to get the signing provider with private keys. This function should only be called during signing anyways - return GetSigningProvider(index, true); + std::unique_ptr out = GetSigningProvider(index, true); + if (!out->HaveKey(pubkey.GetID())) { + return nullptr; + } + return out; } std::unique_ptr DescriptorScriptPubKeyMan::GetSigningProvider(int32_t index, bool include_private) const diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 9b62a35bed..0d19eb9222 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -613,8 +613,6 @@ private: mutable std::map m_map_signing_providers; // Fetch the SigningProvider for the given script and optionally include private keys std::unique_ptr GetSigningProvider(const CScript& script, bool include_private = false) const; - // Fetch the SigningProvider for the given pubkey and always include private keys. This should only be called by signing code. - std::unique_ptr GetSigningProvider(const CPubKey& pubkey) const; // Fetch the SigningProvider for a given index and optionally include private keys. Called by the above functions. std::unique_ptr GetSigningProvider(int32_t index, bool include_private = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man); @@ -678,6 +676,9 @@ public: bool CanProvide(const CScript& script, SignatureData& sigdata) override; + // Fetch the SigningProvider for the given pubkey and always include private keys. This should only be called by signing code. + std::unique_ptr GetSigningProvider(const CPubKey& pubkey) const; + 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; std::optional 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; diff --git a/src/wallet/test/ismine_tests.cpp b/src/wallet/test/ismine_tests.cpp index f6688ed30a..3b27c7db9a 100644 --- a/src/wallet/test/ismine_tests.cpp +++ b/src/wallet/test/ismine_tests.cpp @@ -20,26 +20,6 @@ using namespace util::hex_literals; namespace wallet { BOOST_FIXTURE_TEST_SUITE(ismine_tests, BasicTestingSetup) -wallet::ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success) -{ - keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); - - FlatSigningProvider keys; - std::string error; - auto parsed_descs = Parse(desc_str, keys, error, false); - BOOST_CHECK(success == (!parsed_descs.empty())); - if (!success) return nullptr; - auto& desc = parsed_descs.at(0); - - const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1; - - WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index); - - LOCK(keystore.cs_wallet); - - return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false)); -}; - BOOST_AUTO_TEST_CASE(ismine_standard) { CKey keys[2]; diff --git a/src/wallet/test/scriptpubkeyman_tests.cpp b/src/wallet/test/scriptpubkeyman_tests.cpp index 15bff04221..f27865865d 100644 --- a/src/wallet/test/scriptpubkeyman_tests.cpp +++ b/src/wallet/test/scriptpubkeyman_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include