Skip to content

Commit 886e0d7

Browse files
committed
Implement CWallet::IsSpentKey for non-LegacySPKMans
1 parent 3c19fdd commit 886e0d7

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/wallet/wallet.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -754,22 +754,29 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
754754
const CWalletTx* srctx = GetWalletTx(hash);
755755
if (srctx) {
756756
assert(srctx->tx->vout.size() > n);
757-
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
758-
// When descriptor wallets arrive, these additional checks are
759-
// likely superfluous and can be optimized out
760-
assert(spk_man != nullptr);
761-
for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
762-
WitnessV0KeyHash wpkh_dest(keyid);
763-
if (GetDestData(wpkh_dest, "used", nullptr)) {
764-
return true;
765-
}
766-
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
767-
if (GetDestData(sh_wpkh_dest, "used", nullptr)) {
768-
return true;
769-
}
770-
PKHash pkh_dest(keyid);
771-
if (GetDestData(pkh_dest, "used", nullptr)) {
772-
return true;
757+
CTxDestination dest;
758+
if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) {
759+
return false;
760+
}
761+
if (GetDestData(dest, "used", nullptr)) {
762+
return true;
763+
}
764+
if (IsLegacy()) {
765+
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
766+
assert(spk_man != nullptr);
767+
for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
768+
WitnessV0KeyHash wpkh_dest(keyid);
769+
if (GetDestData(wpkh_dest, "used", nullptr)) {
770+
return true;
771+
}
772+
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
773+
if (GetDestData(sh_wpkh_dest, "used", nullptr)) {
774+
return true;
775+
}
776+
PKHash pkh_dest(keyid);
777+
if (GetDestData(pkh_dest, "used", nullptr)) {
778+
return true;
779+
}
773780
}
774781
}
775782
}

0 commit comments

Comments
 (0)