@@ -754,22 +754,29 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
754
754
const CWalletTx* srctx = GetWalletTx (hash);
755
755
if (srctx) {
756
756
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
+ }
773
780
}
774
781
}
775
782
}
0 commit comments