diff options
| author | Andrew Chow <[email protected]> | 2020-03-31 15:30:04 -0400 |
|---|---|---|
| committer | Andrew Chow <[email protected]> | 2020-04-23 13:59:48 -0400 |
| commit | 886e0d75f5fea2421190aa4812777d89f68962cc (patch) | |
| tree | ab86269efef2243335ea56e57257ae3c838ae48e /src | |
| parent | Return error when no ScriptPubKeyMan is available for specified type (diff) | |
| download | discoin-886e0d75f5fea2421190aa4812777d89f68962cc.tar.xz discoin-886e0d75f5fea2421190aa4812777d89f68962cc.zip | |
Implement CWallet::IsSpentKey for non-LegacySPKMans
Diffstat (limited to 'src')
| -rw-r--r-- | src/wallet/wallet.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 19ad61ac5..b6f25de64 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -754,22 +754,29 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const const CWalletTx* srctx = GetWalletTx(hash); 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)) { - WitnessV0KeyHash wpkh_dest(keyid); - if (GetDestData(wpkh_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; + 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)) { + WitnessV0KeyHash wpkh_dest(keyid); + if (GetDestData(wpkh_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; + } } } } |