Skip to content

Commit

Permalink
Implement CWallet::IsSpentKey for non-LegacySPKMans
Browse files Browse the repository at this point in the history
Summary: Backport of Core [[bitcoin/bitcoin#16528 | PR16528]] [40/43] : bitcoin/bitcoin@886e0d7

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D8466
  • Loading branch information
achow101 authored and deadalnix committed Nov 19, 2020
1 parent a33c930 commit 8b377d3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,22 @@ bool CWallet::IsUsedDestination(const TxId &txid, unsigned int n) const {
const CWalletTx *srctx = GetWalletTx(txid);
if (srctx) {
assert(srctx->tx->vout.size() > n);
LegacyScriptPubKeyMan *spk_man = GetLegacyScriptPubKeyMan();
// When descriptor wallets arrive, these additional checks are
// likely superfluous and can be optimized out
assert(spk_man != nullptr);
for (const auto &keyid :
GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
PKHash pkh_dest(keyid);
if (GetDestData(pkh_dest, "used", nullptr)) {
return true;
CTxDestination dest;
if (!ExtractDestination(srctx->tx->vout[n].scriptPubKey, dest)) {
return false;
}
if (GetDestData(dest, "used", nullptr)) {
return true;
}
if (IsLegacy()) {
LegacyScriptPubKeyMan *spk_man = GetLegacyScriptPubKeyMan();
assert(spk_man != nullptr);
for (const auto &keyid :
GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *spk_man)) {
PKHash pkh_dest(keyid);
if (GetDestData(pkh_dest, "used", nullptr)) {
return true;
}
}
}
}
Expand Down

0 comments on commit 8b377d3

Please sign in to comment.