Skip to content

Commit 54f251e

Browse files
committed
refactor: reimplementing some methods directly in dash-chainstate to avoid extra heavy dependencies
Implemented: - ValueFromAmount (core_write.cpp) - GetPrettyExceptionStr (stacktrackes.cpp) Defined: - g_stats_client
1 parent b5adf8c commit 54f251e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/bitcoin-chainstate.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@
3030

3131
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
3232

33+
34+
//----------------
35+
// symbols g_stats_client, ValueFromAmount, GetPrettyExceptionStr are re-defined
36+
// here especially for dash-chainstate binary (kernel), because adding sources
37+
// containing them pulls too many extra dependencies recursively
38+
#include <stats/client.h>
39+
std::unique_ptr<StatsdClient> g_stats_client{std::make_unique<StatsdClient>()};
40+
41+
UniValue ValueFromAmount(const CAmount amount)
42+
{
43+
static_assert(COIN > 1);
44+
int64_t quotient = amount / COIN;
45+
int64_t remainder = amount % COIN;
46+
if (amount < 0) {
47+
quotient = -quotient;
48+
remainder = -remainder;
49+
}
50+
return UniValue(UniValue::VNUM,
51+
strprintf("%s%d.%08d", amount < 0 ? "-" : "", quotient, remainder));
52+
}
53+
std::string GetPrettyExceptionStr(const std::exception_ptr& e)
54+
{
55+
try {
56+
// rethrow and catch the exception as there is no other way to reliably cast to the real type (not possible with RTTI)
57+
std::rethrow_exception(e);
58+
} catch (const std::exception& e2) {
59+
return e2.what();
60+
} catch (...) {
61+
throw;
62+
}
63+
}
64+
//////////////////////
65+
3366
int main(int argc, char* argv[])
3467
{
3568
// SETUP: Argument parsing and handling

0 commit comments

Comments
 (0)