diff options
author | Gregory Sanders <gsanders87@gmail.com> | 2019-11-27 10:56:04 -0500 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2020-01-14 10:35:34 +0000 |
commit | a5489c9892fc12cb70c6c7b017881a9218d0b041 (patch) | |
tree | 5b12ab6f3438443e7816c20b50bf12e65b7b3c44 /src/wallet/wallet.cpp | |
parent | 88729d804e39fbb42aa92c039afe3641edf9190c (diff) | |
download | bitcoin-a5489c9892fc12cb70c6c7b017881a9218d0b041.tar.xz |
IsUsedDestination should count any known single-key address
Github-Pull: #17621
Rebased-From: 09502452bbbe21bb974f1de8cf53196373921ab9
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 64c7623bff..2dfd60a913 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1073,17 +1073,31 @@ void CWallet::SetUsedDestinationState(const uint256& hash, unsigned int n, bool } } -bool CWallet::IsUsedDestination(const CTxDestination& dst) const -{ - LOCK(cs_wallet); - return ::IsMine(*this, dst) && GetDestData(dst, "used", nullptr); -} - bool CWallet::IsUsedDestination(const uint256& hash, unsigned int n) const { + AssertLockHeld(cs_wallet); CTxDestination dst; const CWalletTx* srctx = GetWalletTx(hash); - return srctx && ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst) && IsUsedDestination(dst); + if (srctx) { + assert(srctx->tx->vout.size() > n); + // When descriptor wallets arrive, these additional checks are + // likely superfluous and can be optimized out + for (const auto& keyid : GetAffectedKeys(srctx->tx->vout[n].scriptPubKey, *this)) { + WitnessV0KeyHash wpkh_dest(keyid); + if (GetDestData(wpkh_dest, "used", nullptr)) { + return true; + } + ScriptHash sh_wpkh_dest(wpkh_dest); + if (GetDestData(sh_wpkh_dest, "used", nullptr)) { + return true; + } + PKHash pkh_dest(keyid); + if (GetDestData(pkh_dest, "used", nullptr)) { + return true; + } + } + } + return false; } bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) |