Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination

This commit does not change behavior.
This commit is contained in:
Andrew Chow 2019-10-07 14:11:34 -04:00
parent acedc5b823
commit 769acef857
3 changed files with 9 additions and 6 deletions

View file

@ -11,9 +11,8 @@
#include <wallet/scriptpubkeyman.h>
#include <wallet/wallet.h>
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error)
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
{
LOCK(cs_wallet);
error.clear();
TopUpKeyPool();
@ -25,8 +24,6 @@ bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, const std::
}
LearnRelatedScripts(new_key, type);
dest = GetDestinationForKey(new_key, type);
m_wallet.SetAddressBook(dest, label, "receive");
return true;
}

View file

@ -146,6 +146,7 @@ protected:
public:
ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
virtual ~ScriptPubKeyMan() {};
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
virtual bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return false; }
@ -245,7 +246,7 @@ private:
void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
public:
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error);
bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) override;
isminetype IsMine(const CScript& script) const override;
//! will encrypt previously unencrypted keys

View file

@ -3034,12 +3034,17 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
bool CWallet::GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error)
{
LOCK(cs_wallet);
error.clear();
bool result = false;
auto spk_man = m_spk_man.get();
if (spk_man) {
result = spk_man->GetNewDestination(type, label, dest, error);
result = spk_man->GetNewDestination(type, dest, error);
}
if (result) {
SetAddressBook(dest, label, "receive");
}
return result;
}