Skip to content

Commit e92a764

Browse files
committed
refactor: add util::to_string(bool) for convenience
1 parent 08f04d5 commit e92a764

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

src/coinjoin/coinjoin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <chainlock/chainlock.h>
99
#include <instantsend/instantsend.h>
1010
#include <masternode/sync.h>
11+
#include <util/helpers.h>
1112

1213
#include <chain.h>
1314
#include <chainparams.h>
@@ -64,7 +65,7 @@ bool CCoinJoinQueue::IsTimeOutOfBounds(int64_t current_time) const
6465
[[nodiscard]] std::string CCoinJoinQueue::ToString() const
6566
{
6667
return strprintf("nDenom=%d, nTime=%lld, fReady=%s, fTried=%s, masternode=%s",
67-
nDenom, nTime, fReady ? "true" : "false", fTried ? "true" : "false", masternodeOutpoint.ToStringShort());
68+
nDenom, nTime, util::to_string(fReady), util::to_string(fTried), masternodeOutpoint.ToStringShort());
6869
}
6970

7071
uint256 CCoinJoinBroadcastTx::GetSignatureHash() const

src/llmq/quorumsman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp
285285
if (!quorum) {
286286
LogPrintf("%s: ERROR! Unexpected missing quorum with llmqType=%d, blockHash=%s, populate_cache=%s\n",
287287
__func__, std23::to_underlying(llmqType), pQuorumBaseBlockIndex->GetBlockHash().ToString(),
288-
populate_cache ? "true" : "false");
288+
util::to_string(populate_cache));
289289
return {};
290290
}
291291
vecResultQuorums.emplace_back(quorum);

src/qt/guiutil_font.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <qt/guiutil_font.h>
66

7+
#include <util/helpers.h>
8+
79
#include <tinyformat.h>
810
#include <util/system.h>
911

@@ -352,7 +354,7 @@ void setApplicationFont()
352354

353355
qDebug() << qstrprintf("%s: %s family: %s, style: %s match: %s", __func__, qApp->font().toString().toStdString(),
354356
qApp->font().family().toStdString(), qApp->font().styleName().toStdString(),
355-
qApp->font().exactMatch() ? "true" : "false");
357+
util::to_string(qApp->font().exactMatch()));
356358
}
357359

358360
void setFont(const std::vector<QWidget*>& vecWidgets, const FontAttrib& font_attrib)
@@ -518,7 +520,7 @@ QFont getFont(const FontAttrib& font_attrib)
518520
if (gArgs.GetBoolArg("-debug-ui", false)) {
519521
qDebug() << qstrprintf("%s: font size: %d, family: %s, style: %s, weight: %d match %s", __func__,
520522
font.pointSizeF(), font.family().toStdString(), font.styleName().toStdString(),
521-
font.weight(), font.exactMatch() ? "true" : "false");
523+
font.weight(), util::to_string(font.exactMatch()));
522524
}
523525

524526
return font;

src/rpc/mempool.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include <rpc/blockchain.h>
77

8+
#include <instantsend/instantsend.h>
9+
#include <llmq/context.h>
10+
#include <util/helpers.h>
11+
812
#include <core_io.h>
913
#include <fs.h>
1014
#include <policy/settings.h>
@@ -19,9 +23,6 @@
1923
#include <util/system.h>
2024
#include <util/time.h>
2125

22-
#include <instantsend/instantsend.h>
23-
#include <llmq/context.h>
24-
2526
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
2627
using node::NodeContext;
2728

@@ -325,7 +326,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
325326
}
326327

327328
info.pushKV("spentby", spent);
328-
info.pushKV("instantlock", isman ? (isman->IsLocked(tx.GetHash()) ? "true" : "false") : "unknown");
329+
info.pushKV("instantlock", isman ? util::to_string(isman->IsLocked(tx.GetHash())) : "unknown");
329330
info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetHash()));
330331
}
331332

src/util/helpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <optional>
1010
#include <ranges>
11+
#include <string_view>
1112

1213
namespace util {
1314
template <typename X, typename Z>
@@ -43,6 +44,11 @@ inline bool shared_ptr_not_equal(const std::shared_ptr<T>& lhs, const std::share
4344
if (!lhs || !rhs) return true; // Inequal initialization state
4445
return *lhs != *rhs; // Deep comparison
4546
}
47+
48+
inline constexpr std::string_view to_string(bool value)
49+
{
50+
return value ? "true" : "false";
51+
}
4652
} // namespace util
4753

4854
#endif // BITCOIN_UTIL_HELPERS_H

0 commit comments

Comments
 (0)