File tree Expand file tree Collapse file tree 14 files changed +50
-39
lines changed Expand file tree Collapse file tree 14 files changed +50
-39
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,7 @@ BITCOIN_CORE_H = \
239239 node/types.h \
240240 node/utxo_snapshot.h \
241241 node/validation_cache_args.h \
242+ node/warnings.h \
242243 noui.h \
243244 outputtype.h \
244245 policy/v3_policy.h \
@@ -367,7 +368,6 @@ BITCOIN_CORE_H = \
367368 wallet/wallettool.h \
368369 wallet/walletutil.h \
369370 walletinitinterface.h \
370- warnings.h \
371371 zmq/zmqabstractnotifier.h \
372372 zmq/zmqnotificationinterface.h \
373373 zmq/zmqpublishnotifier.h \
@@ -444,6 +444,7 @@ libbitcoin_node_a_SOURCES = \
444444 node/txreconciliation.cpp \
445445 node/utxo_snapshot.cpp \
446446 node/validation_cache_args.cpp \
447+ node/warnings.cpp \
447448 noui.cpp \
448449 policy/v3_policy.cpp \
449450 policy/fees.cpp \
@@ -721,7 +722,6 @@ libbitcoin_common_a_SOURCES = \
721722 script/sign.cpp \
722723 script/signingprovider.cpp \
723724 script/solver.cpp \
724- warnings.cpp \
725725 $(BITCOIN_CORE_H )
726726#
727727
Original file line number Diff line number Diff line change 1717#include < util/thread.h>
1818#include < util/translation.h>
1919#include < validation.h> // For g_chainman
20- #include < warnings.h>
2120
2221#include < string>
2322#include < utility>
Original file line number Diff line number Diff line change 66
77#include < logging.h>
88#include < node/interface_ui.h>
9+ #include < node/warnings.h>
910#include < util/signalinterrupt.h>
1011#include < util/translation.h>
11- #include < warnings.h>
1212
1313#include < atomic>
1414#include < cstdlib>
Original file line number Diff line number Diff line change 3232#include < node/mini_miner.h>
3333#include < node/transaction.h>
3434#include < node/types.h>
35+ #include < node/warnings.h>
3536#include < policy/feerate.h>
3637#include < policy/fees.h>
3738#include < policy/policy.h>
5354#include < util/translation.h>
5455#include < validation.h>
5556#include < validationinterface.h>
56- #include < warnings.h>
5757
5858#include < config/bitcoin-config.h> // IWYU pragma: keep
5959
Original file line number Diff line number Diff line change 1313#include < logging.h>
1414#include < node/abort.h>
1515#include < node/interface_ui.h>
16+ #include < node/warnings.h>
1617#include < util/check.h>
1718#include < util/signalinterrupt.h>
1819#include < util/strencodings.h>
1920#include < util/string.h>
2021#include < util/translation.h>
21- #include < warnings.h>
2222
2323#include < cstdint>
2424#include < string>
@@ -49,7 +49,7 @@ static void AlertNotify(const std::string& strMessage)
4949static void DoWarning (const bilingual_str& warning)
5050{
5151 static bool fWarned = false ;
52- SetMiscWarning (warning);
52+ node:: SetMiscWarning (warning);
5353 if (!fWarned ) {
5454 AlertNotify (warning.original );
5555 fWarned = true ;
Original file line number Diff line number Diff line change 55#include < logging.h>
66#include < node/interface_ui.h>
77#include < node/timeoffsets.h>
8+ #include < node/warnings.h>
89#include < sync.h>
910#include < tinyformat.h>
1011#include < util/time.h>
1112#include < util/translation.h>
12- #include < warnings.h>
1313
1414#include < algorithm>
1515#include < chrono>
@@ -49,7 +49,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
4949 // when median == std::numeric_limits<int64_t>::min(), calling std::chrono::abs is UB
5050 auto median{std::max (Median (), std::chrono::seconds (std::numeric_limits<int64_t >::min () + 1 ))};
5151 if (std::chrono::abs (median) <= WARN_THRESHOLD) {
52- SetMedianTimeOffsetWarning (std::nullopt );
52+ node:: SetMedianTimeOffsetWarning (std::nullopt );
5353 uiInterface.NotifyAlertChanged ();
5454 return false ;
5555 }
@@ -63,7 +63,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
6363 " RPC methods to get more info."
6464 ), Ticks<std::chrono::minutes>(WARN_THRESHOLD))};
6565 LogWarning (" %s\n " , msg.original );
66- SetMedianTimeOffsetWarning (msg);
66+ node:: SetMedianTimeOffsetWarning (msg);
6767 uiInterface.NotifyAlertChanged ();
6868 return true ;
6969}
Original file line number Diff line number Diff line change 55
66#include < config/bitcoin-config.h> // IWYU pragma: keep
77
8- #include < warnings.h>
8+ #include < node/ warnings.h>
99
1010#include < common/system.h>
1111#include < sync.h>
12+ #include < univalue.h>
1213#include < util/translation.h>
1314
1415#include < optional>
@@ -19,6 +20,7 @@ static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
1920static bool fLargeWorkInvalidChainFound GUARDED_BY (g_warnings_mutex) = false;
2021static std::optional<bilingual_str> g_timeoffset_warning GUARDED_BY (g_warnings_mutex){};
2122
23+ namespace node {
2224void SetMiscWarning (const bilingual_str& warning)
2325{
2426 LOCK (g_warnings_mutex);
@@ -63,3 +65,18 @@ std::vector<bilingual_str> GetWarnings()
6365
6466 return warnings;
6567}
68+
69+ UniValue GetWarningsForRpc (bool use_deprecated)
70+ {
71+ if (use_deprecated) {
72+ const auto all_warnings{GetWarnings ()};
73+ return all_warnings.empty () ? " " : all_warnings.back ().original ;
74+ }
75+
76+ UniValue warnings{UniValue::VARR};
77+ for (auto && warning : GetWarnings ()) {
78+ warnings.push_back (std::move (warning.original ));
79+ }
80+ return warnings;
81+ }
82+ } // namespace node
Original file line number Diff line number Diff line change 33// Distributed under the MIT software license, see the accompanying
44// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
6- #ifndef BITCOIN_WARNINGS_H
7- #define BITCOIN_WARNINGS_H
6+ #ifndef BITCOIN_NODE_WARNINGS_H
7+ #define BITCOIN_NODE_WARNINGS_H
88
99#include < optional>
1010#include < string>
1111#include < vector>
1212
13+ class UniValue ;
1314struct bilingual_str ;
1415
16+ namespace node {
1517void SetMiscWarning (const bilingual_str& warning);
1618void SetfLargeWorkInvalidChainFound (bool flag);
1719/* * Pass std::nullopt to disable the warning */
1820void SetMedianTimeOffsetWarning (std::optional<bilingual_str> warning);
1921/* * Return potential problems detected by the node. */
2022std::vector<bilingual_str> GetWarnings ();
23+ /* *
24+ * RPC helper function that wraps GetWarnings. Returns a UniValue::VSTR
25+ * with the latest warning if use_deprecated is set to true, or a
26+ * UniValue::VARR with all warnings otherwise.
27+ */
28+ UniValue GetWarningsForRpc (bool use_deprecated);
29+ } // namespace node
2130
22- #endif // BITCOIN_WARNINGS_H
31+ #endif // BITCOIN_NODE_WARNINGS_H
Original file line number Diff line number Diff line change 2929#include < node/context.h>
3030#include < node/transaction.h>
3131#include < node/utxo_snapshot.h>
32+ #include < node/warnings.h>
3233#include < primitives/transaction.h>
3334#include < rpc/server.h>
3435#include < rpc/server_util.h>
@@ -1308,7 +1309,7 @@ RPCHelpMan getblockchaininfo()
13081309 }
13091310 }
13101311
1311- obj.pushKV (" warnings" , GetNodeWarnings (IsDeprecatedRPCEnabled (" warnings" )));
1312+ obj.pushKV (" warnings" , node::GetWarningsForRpc (IsDeprecatedRPCEnabled (" warnings" )));
13121313 return obj;
13131314},
13141315 };
Original file line number Diff line number Diff line change 2020#include < net.h>
2121#include < node/context.h>
2222#include < node/miner.h>
23+ #include < node/warnings.h>
2324#include < pow.h>
2425#include < rpc/blockchain.h>
2526#include < rpc/mining.h>
@@ -454,7 +455,7 @@ static RPCHelpMan getmininginfo()
454455 obj.pushKV (" networkhashps" , getnetworkhashps ().HandleRequest (request));
455456 obj.pushKV (" pooledtx" , (uint64_t )mempool.size ());
456457 obj.pushKV (" chain" , chainman.GetParams ().GetChainTypeString ());
457- obj.pushKV (" warnings" , GetNodeWarnings (IsDeprecatedRPCEnabled (" warnings" )));
458+ obj.pushKV (" warnings" , node::GetWarningsForRpc (IsDeprecatedRPCEnabled (" warnings" )));
458459 return obj;
459460},
460461 };
You can’t perform that action at this time.
0 commit comments