Skip to content

Commit

Permalink
Apply the batch treatment to CWallet::SetAddressBook via ImportScript…
Browse files Browse the repository at this point in the history
…PubKeys
  • Loading branch information
Empact committed Apr 4, 2019
1 parent c5d9eec commit b363aa7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/wallet/wallet.cpp
Expand Up @@ -1693,7 +1693,10 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
CTxDestination dest;
ExtractDestination(script, dest);
if (!internal && IsValidDestination(dest)) {
SetAddressBook(dest, label, "receive");
SetAddressBookWithDB(*batch, dest, label, "receive");
if (++cnt % 1000 == 0) {
batch.reset(new WalletBatch(*database));
}
}
}
return true;
Expand Down Expand Up @@ -3349,8 +3352,7 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
return DBErrors::LOAD_OK;
}


bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& strPurpose)
bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose)
{
bool fUpdated = false;
{
Expand All @@ -3363,9 +3365,15 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
}
NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address) != ISMINE_NO,
strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) );
if (!strPurpose.empty() && !WalletBatch(*database).WritePurpose(EncodeDestination(address), strPurpose))
if (!strPurpose.empty() && !batch.WritePurpose(EncodeDestination(address), strPurpose))
return false;
return WalletBatch(*database).WriteName(EncodeDestination(address), strName);
return batch.WriteName(EncodeDestination(address), strName);
}

bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& strPurpose)
{
WalletBatch batch(*database);
return SetAddressBookWithDB(batch, address, strName, strPurpose);
}

bool CWallet::DelAddressBook(const CTxDestination& address)
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallet.h
Expand Up @@ -733,6 +733,8 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific

void AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch);

bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose);

/** Interface for accessing chain state. */
interfaces::Chain& m_chain;

Expand Down

0 comments on commit b363aa7

Please sign in to comment.