Skip to content

Commit 47eaf66

Browse files
committed
refactor: add util::to_string(bool) for convenience
1 parent 1025198 commit 47eaf66

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
@@ -7,6 +7,7 @@
77
#include <bls/bls.h>
88
#include <chainlock/chainlock.h>
99
#include <instantsend/instantsend.h>
10+
#include <util/helpers.h>
1011

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

6970
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/std23.h>
911
#include <util/system.h>
@@ -186,7 +188,7 @@ QFont getFont(const GUIUtil::FontAttrib& font_attrib)
186188
if (gArgs.GetBoolArg("-debug-ui", false)) {
187189
qDebug() << qstrprintf("%s: font size: %d, family: %s, style: %s, weight: %d match %s", __func__,
188190
font.pointSizeF(), font.family().toStdString(), font.styleName().toStdString(),
189-
font.weight(), font.exactMatch() ? "true" : "false");
191+
font.weight(), util::to_string(font.exactMatch()));
190192
}
191193

192194
return font;
@@ -533,7 +535,7 @@ void setApplicationFont()
533535

534536
qDebug() << qstrprintf("%s: %s family: %s, style: %s match: %s", __func__, qApp->font().toString().toStdString(),
535537
qApp->font().family().toStdString(), qApp->font().styleName().toStdString(),
536-
qApp->font().exactMatch() ? "true" : "false");
538+
util::to_string(qApp->font().exactMatch()));
537539
}
538540

539541
void setFont(const std::vector<QWidget*>& vecWidgets, const FontAttrib& font_attrib)

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 <chainparams.h>
913
#include <core_io.h>
1014
#include <fs.h>
@@ -20,9 +24,6 @@
2024
#include <util/system.h>
2125
#include <util/time.h>
2226

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

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

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

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)