Skip to content

Commit db225ce

Browse files
committed
wallet, refactor: Replace GetDisplayName() with LogName()
The GetDisplayName() method name was confusing because it suggested the return value could be used for display, while documentation and implementation indicated it only meant to be used for logging. Also the name didn't suggest that it was formatting the wallet names, which made it harder understand how messages were formatted in the places it was called. Fix these issues by splitting up the GetDisplayName() method and replacing it with LogName() / DisplayName() methods. This commit is a refactoring that does not change any behavior.
1 parent 0173788 commit db225ce

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
996996
WalletBatch batch(m_storage.GetDatabase());
997997
if (!batch.TxnBegin()) return false;
998998
bool res = TopUpWithDB(batch, size);
999-
if (!batch.TxnCommit()) throw std::runtime_error(strprintf("Error during descriptors keypool top up. Cannot commit changes for wallet %s", m_storage.GetDisplayName()));
999+
if (!batch.TxnCommit()) throw std::runtime_error(strprintf("Error during descriptors keypool top up. Cannot commit changes for wallet [%s]", m_storage.LogName()));
10001000
return res;
10011001
}
10021002

src/wallet/scriptpubkeyman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WalletStorage
4343
{
4444
public:
4545
virtual ~WalletStorage() = default;
46-
virtual std::string GetDisplayName() const = 0;
46+
virtual std::string LogName() const = 0;
4747
virtual WalletDatabase& GetDatabase() const = 0;
4848
virtual bool IsWalletFlagSet(uint64_t) const = 0;
4949
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
@@ -162,7 +162,7 @@ class ScriptPubKeyMan
162162
template <typename... Params>
163163
void WalletLogPrintf(util::ConstevalFormatString<sizeof...(Params)> wallet_fmt, const Params&... params) const
164164
{
165-
LogInfo("%s %s", m_storage.GetDisplayName(), tfm::format(wallet_fmt, params...));
165+
LogInfo("[%s] %s", m_storage.LogName(), tfm::format(wallet_fmt, params...));
166166
};
167167

168168
/** Keypool has new keys */

src/wallet/wallet.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,14 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
905905
/** Loads the flags into the wallet. (used by LoadWallet) */
906906
bool LoadWalletFlags(uint64_t flags);
907907

908-
/** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
909-
std::string GetDisplayName() const override
908+
/** Return wallet name for use in logs, will return "default wallet" if the wallet has no name. */
909+
std::string LogName() const override
910910
{
911-
std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
912-
return strprintf("[%s]", wallet_name);
911+
std::string name{GetName()};
912+
return name.empty() ? "default wallet" : name;
913913
};
914914

915-
/** Return wallet name for display, translating "default wallet" string if returned. */
915+
/** Return wallet name for display, like LogName() but translates "default wallet" string. */
916916
std::string DisplayName() const
917917
{
918918
std::string name{GetName()};
@@ -923,7 +923,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
923923
template <typename... Params>
924924
void WalletLogPrintf(util::ConstevalFormatString<sizeof...(Params)> wallet_fmt, const Params&... params) const
925925
{
926-
LogInfo("%s %s", GetDisplayName(), tfm::format(wallet_fmt, params...));
926+
LogInfo("[%s] %s", LogName(), tfm::format(wallet_fmt, params...));
927927
};
928928

929929
/** Upgrade the wallet */

0 commit comments

Comments
 (0)