From a33dcb328375edb3c13c04ba9360d1e9a88d84d7 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 30 Apr 2024 01:01:19 +0700 Subject: [PATCH] fix: CheckWalletOwnsScript/CheckWalletOwnsKey to use wallet instead of SPK --- src/rpc/evo.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 8283d62099..ce8b4e844e 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -1264,33 +1264,15 @@ static void protx_list_help(const JSONRPCRequest& request) } #ifdef ENABLE_WALLET -static bool CheckWalletOwnsKey(const CWallet* const pwallet, const CKeyID& keyID) { - if (!pwallet) { - return false; - } - const LegacyScriptPubKeyMan* const spk_man = pwallet->GetLegacyScriptPubKeyMan(); - if (!spk_man) { - return false; - } - return spk_man->HaveKey(keyID); -} - static bool CheckWalletOwnsScript(const CWallet* const pwallet, const CScript& script) { if (!pwallet) { return false; } - const LegacyScriptPubKeyMan* const spk_man = pwallet->GetLegacyScriptPubKeyMan(); - if (!spk_man) { - return false; - } + return WITH_LOCK(pwallet->cs_wallet, return pwallet->IsMine(script)) == isminetype::ISMINE_SPENDABLE; +} - CTxDestination dest; - if (ExtractDestination(script, dest)) { - if ((std::get_if(&dest) && spk_man->HaveKey(ToKeyID(*std::get_if(&dest)))) || (std::get_if(&dest) && spk_man->HaveCScript(CScriptID{ScriptHash(*std::get_if(&dest))}))) { - return true; - } - } - return false; +static bool CheckWalletOwnsKey(const CWallet* const pwallet, const CKeyID& keyID) { + return CheckWalletOwnsScript(pwallet, GetScriptForDestination(PKHash(keyID))); } #endif