@@ -727,6 +727,12 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
727727 return success;
728728}
729729
730+ static bool IsUsedDest (const std::map<CTxDestination, CAddressBookData>& address_book, const CTxDestination& dest)
731+ {
732+ auto it = address_book.find (dest);
733+ return it != address_book.end () && it->second .IsUsed ();
734+ }
735+
730736void CWallet::SetSpentKeyState (WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations)
731737{
732738 AssertLockHeld (cs_wallet);
@@ -736,12 +742,12 @@ void CWallet::SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned
736742 CTxDestination dst;
737743 if (ExtractDestination (srctx->tx ->vout [n].scriptPubKey , dst)) {
738744 if (IsMine (dst)) {
739- if (used && ! GetDestData (dst, " used " , nullptr )) {
740- if (AddDestData (batch, dst, " used" , " p " )) { // p for "present", opposite of absent (null)
745+ if (used != IsUsedDest (m_address_book, dst )) {
746+ if (used) {
741747 tx_destinations.insert (dst);
742748 }
743- } else if (!used && GetDestData ( dst, " used" , nullptr )) {
744- EraseDestData ( batch, dst, " used" );
749+ m_address_book[ dst]. SetUsed ( used);
750+ batch. WriteUsed ( dst, used);
745751 }
746752 }
747753 }
@@ -758,23 +764,23 @@ bool CWallet::IsSpentKey(const uint256& hash, unsigned int n) const
758764 if (!ExtractDestination (srctx->tx ->vout [n].scriptPubKey , dest)) {
759765 return false ;
760766 }
761- if (GetDestData (dest, " used " , nullptr )) {
767+ if (IsUsedDest (m_address_book, dest )) {
762768 return true ;
763769 }
764770 if (IsLegacy ()) {
765771 LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan ();
766772 assert (spk_man != nullptr );
767773 for (const auto & keyid : GetAffectedKeys (srctx->tx ->vout [n].scriptPubKey , *spk_man)) {
768774 WitnessV0KeyHash wpkh_dest (keyid);
769- if (GetDestData (wpkh_dest, " used " , nullptr )) {
775+ if (IsUsedDest (m_address_book, wpkh_dest )) {
770776 return true ;
771777 }
772778 ScriptHash sh_wpkh_dest (GetScriptForDestination (wpkh_dest));
773- if (GetDestData (sh_wpkh_dest, " used " , nullptr )) {
779+ if (IsUsedDest (m_address_book, sh_wpkh_dest )) {
774780 return true ;
775781 }
776782 PKHash pkh_dest (keyid);
777- if (GetDestData (pkh_dest, " used " , nullptr )) {
783+ if (IsUsedDest (m_address_book, pkh_dest )) {
778784 return true ;
779785 }
780786 }
@@ -3178,12 +3184,7 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
31783184 LOCK (cs_wallet);
31793185
31803186 // Delete destdata tuples associated with address
3181- std::string strAddress = EncodeDestination (address);
3182- for (const std::pair<const std::string, std::string> &item : m_address_book[address].destdata )
3183- {
3184- WalletBatch (*database).EraseDestData (strAddress, item.first );
3185- }
3186- m_address_book.erase (address);
3187+ WalletBatch (*database).EraseDestData (address);
31873188 }
31883189
31893190 NotifyAddressBookChanged (this , address, " " , IsMine (address) != ISMINE_NO, " " , CT_DELETED);
@@ -3626,56 +3627,6 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
36263627 return nTimeSmart;
36273628}
36283629
3629- bool CWallet::AddDestData (WalletBatch& batch, const CTxDestination &dest, const std::string &key, const std::string &value)
3630- {
3631- if (boost::get<CNoDestination>(&dest))
3632- return false ;
3633-
3634- m_address_book[dest].destdata .insert (std::make_pair (key, value));
3635- return batch.WriteDestData (EncodeDestination (dest), key, value);
3636- }
3637-
3638- bool CWallet::EraseDestData (WalletBatch& batch, const CTxDestination &dest, const std::string &key)
3639- {
3640- if (!m_address_book[dest].destdata .erase (key))
3641- return false ;
3642- return batch.EraseDestData (EncodeDestination (dest), key);
3643- }
3644-
3645- void CWallet::LoadDestData (const CTxDestination &dest, const std::string &key, const std::string &value)
3646- {
3647- m_address_book[dest].destdata .insert (std::make_pair (key, value));
3648- }
3649-
3650- bool CWallet::GetDestData (const CTxDestination &dest, const std::string &key, std::string *value) const
3651- {
3652- std::map<CTxDestination, CAddressBookData>::const_iterator i = m_address_book.find (dest);
3653- if (i != m_address_book.end ())
3654- {
3655- CAddressBookData::StringMap::const_iterator j = i->second .destdata .find (key);
3656- if (j != i->second .destdata .end ())
3657- {
3658- if (value)
3659- *value = j->second ;
3660- return true ;
3661- }
3662- }
3663- return false ;
3664- }
3665-
3666- std::vector<std::string> CWallet::GetDestValues (const std::string& prefix) const
3667- {
3668- std::vector<std::string> values;
3669- for (const auto & address : m_address_book) {
3670- for (const auto & data : address.second .destdata ) {
3671- if (!data.first .compare (0 , prefix.size (), prefix)) {
3672- values.emplace_back (data.second );
3673- }
3674- }
3675- }
3676- return values;
3677- }
3678-
36793630bool CWallet::Verify (interfaces::Chain& chain, const WalletLocation& location, bool salvage_wallet, std::string& error_string, std::vector<std::string>& warnings)
36803631{
36813632 // Do some checking on wallet path. It should be either a:
0 commit comments