diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-04-27 11:01:35 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-06-08 11:22:39 -0300 |
commit | 3d8a2822570e3cf4d1bc4f9d59b5dcb0145920ad (patch) | |
tree | 112ad0963a371d4b45cd058ebdfd9b3132b21470 /src | |
parent | a06fa94ff81e2bccef0316ea5ec4eca0f4de5071 (diff) |
wallet: decouple IsSpentKey(scriptPubKey) from IsSpentKey(hash, n)
This will be used in a follow-up commit to prevent extra 'GetWalletTx' lookups if the function caller already have the wtx and can just provide the scriptPubKey directly.
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet.cpp | 55 | ||||
-rw-r--r-- | src/wallet/wallet.h | 1 |
2 files changed, 31 insertions, 25 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index de5f191520..57abc6fb19 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -910,31 +910,36 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const { AssertLockHeld(cs_wallet); const CWalletTx* srctx = GetWalletTx(hash); - if (srctx) { - assert(srctx->tx->vout.size() > n); - CTxDestination dest; - if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) { - return false; - } - if (IsAddressUsed(dest)) { - return true; - } - if (IsLegacy()) { - LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan(); - assert(spk_man != nullptr); - for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) { - WitnessV0KeyHash wpkh_dest(keyid); - if (IsAddressUsed(wpkh_dest)) { - return true; - } - ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); - if (IsAddressUsed(sh_wpkh_dest)) { - return true; - } - PKHash pkh_dest(keyid); - if (IsAddressUsed(pkh_dest)) { - return true; - } + if (!srctx) return false; + assert(srctx->tx->vout.size() > n); + return IsSpentKey(srctx->tx->vout[n].scriptPubKey); +} + +bool CWallet::IsSpentKey(const CScript& scriptPubKey) const +{ + AssertLockHeld(cs_wallet); + CTxDestination dest; + if (!ExtractDestination(scriptPubKey, dest)) { + return false; + } + if (IsAddressUsed(dest)) { + return true; + } + if (IsLegacy()) { + LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan(); + assert(spk_man != nullptr); + for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) { + WitnessV0KeyHash wpkh_dest(keyid); + if (IsAddressUsed(wpkh_dest)) { + return true; + } + ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); + if (IsAddressUsed(sh_wpkh_dest)) { + return true; + } + PKHash pkh_dest(keyid); + if (IsAddressUsed(pkh_dest)) { + return true; } } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7969b59f4a..61b59e7895 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -445,6 +445,7 @@ public: // Whether this or any known UTXO with the same single key has been spent. bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); /** Display address on an external signer. Returns false if external signer support is not compiled */ |