Implement CWallet::IsSpentKey for non-LegacySPKMans

This commit is contained in:
Andrew Chow 2020-03-31 15:30:04 -04:00
parent 3c19fdd2a2
commit 886e0d75f5

View File

@ -754,22 +754,29 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
const CWalletTx* srctx = GetWalletTx(hash); const CWalletTx* srctx = GetWalletTx(hash);
if (srctx) { if (srctx) {
assert(srctx->tx->vout.size() > n); assert(srctx->tx->vout.size() > n);
LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan(); CTxDestination dest;
// When descriptor wallets arrive, these additional checks are if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) {
// likely superfluous and can be optimized out return false;
assert(spk_man != nullptr); }
for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) { if (GetDestData(dest, "used", nullptr)) {
WitnessV0KeyHash wpkh_dest(keyid); return true;
if (GetDestData(wpkh_dest, "used", nullptr)) { }
return true; if (IsLegacy()) {
} LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan();
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); assert(spk_man != nullptr);
if (GetDestData(sh_wpkh_dest, "used", nullptr)) { for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
return true; WitnessV0KeyHash wpkh_dest(keyid);
} if (GetDestData(wpkh_dest, "used", nullptr)) {
PKHash pkh_dest(keyid); return true;
if (GetDestData(pkh_dest, "used", nullptr)) { }
return true; ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
if (GetDestData(sh_wpkh_dest, "used", nullptr)) {
return true;
}
PKHash pkh_dest(keyid);
if (GetDestData(pkh_dest, "used", nullptr)) {
return true;
}
} }
} }
} }