mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
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.
This commit is contained in:
parent
a06fa94ff8
commit
3d8a282257
2 changed files with 31 additions and 25 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue