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:
2 files changed
+10
-4
No files matched your search
@@ -910,10 +910,16 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
|
|||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
const CWalletTx* srctx = GetWalletTx(hash);
|
const CWalletTx* srctx = GetWalletTx(hash);
|
||||||
if (srctx) {
|
if (!srctx) return false;
|
||||||
assert(srctx->tx->vout.size() > n);
|
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;
|
CTxDestination dest;
|
||||||
if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) {
|
if (!ExtractDestination(scriptPubKey, dest)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (IsAddressUsed(dest)) {
|
if (IsAddressUsed(dest)) {
|
||||||
@@ -922,7 +928,7 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
|
|||||||
if (IsLegacy()) {
|
if (IsLegacy()) {
|
||||||
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
|
||||||
assert(spk_man != nullptr);
|
assert(spk_man != nullptr);
|
||||||
for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
|
for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) {
|
||||||
WitnessV0KeyHash wpkh_dest(keyid);
|
WitnessV0KeyHash wpkh_dest(keyid);
|
||||||
if (IsAddressUsed(wpkh_dest)) {
|
if (IsAddressUsed(wpkh_dest)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -937,7 +943,6 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -445,6 +445,7 @@ public:
|
|||||||
|
|
||||||
// Whether this or any known UTXO with the same single key has been spent.
|
// 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 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);
|
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 */
|
/** Display address on an external signer. Returns false if external signer support is not compiled */
|
||||||
|
|||||||
Reference in new issue
Block a user