fix: CheckWalletOwnsScript/CheckWalletOwnsKey to use wallet instead of SPK

This commit is contained in:
Konstantin Akimov 2024-04-30 01:01:19 +07:00
parent b2ede8bfee
commit a33dcb3283
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524

View File

@ -1264,33 +1264,15 @@ static void protx_list_help(const JSONRPCRequest& request)
} }
#ifdef ENABLE_WALLET #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) { static bool CheckWalletOwnsScript(const CWallet* const pwallet, const CScript& script) {
if (!pwallet) { if (!pwallet) {
return false; return false;
} }
const LegacyScriptPubKeyMan* const spk_man = pwallet->GetLegacyScriptPubKeyMan(); return WITH_LOCK(pwallet->cs_wallet, return pwallet->IsMine(script)) == isminetype::ISMINE_SPENDABLE;
if (!spk_man) { }
return false;
}
CTxDestination dest; static bool CheckWalletOwnsKey(const CWallet* const pwallet, const CKeyID& keyID) {
if (ExtractDestination(script, dest)) { return CheckWalletOwnsScript(pwallet, GetScriptForDestination(PKHash(keyID)));
if ((std::get_if<PKHash>(&dest) && spk_man->HaveKey(ToKeyID(*std::get_if<PKHash>(&dest)))) || (std::get_if<ScriptHash>(&dest) && spk_man->HaveCScript(CScriptID{ScriptHash(*std::get_if<ScriptHash>(&dest))}))) {
return true;
}
}
return false;
} }
#endif #endif