Bitcoin ABC 0.32.12
P2P Digital Currency
kernel_notifications.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#if defined(HAVE_CONFIG_H)
8#include <config/bitcoin-config.h>
9#endif
10
11#include <common/args.h>
12#include <common/system.h>
13#include <kernel/context.h>
14#include <logging.h>
15#include <node/abort.h>
16#include <node/ui_interface.h>
17#include <shutdown.h>
18#include <util/check.h>
19#include <util/strencodings.h>
20#include <util/string.h>
21#include <util/translation.h>
22
23#include <cstdint>
24#include <string>
25#include <thread>
26
28
29static void AlertNotify(const std::string &strMessage) {
30 uiInterface.NotifyAlertChanged();
31#if defined(HAVE_SYSTEM)
32 std::string strCmd = gArgs.GetArg("-alertnotify", "");
33 if (strCmd.empty()) {
34 return;
35 }
36
37 // Alert text should be plain ascii coming from a trusted source, but to be
38 // safe we first strip anything not in safeChars, then add single quotes
39 // around the whole string before passing it to the shell:
40 std::string singleQuote("'");
41 std::string safeStatus = SanitizeString(strMessage);
42 safeStatus = singleQuote + safeStatus + singleQuote;
43 ReplaceAll(strCmd, "%s", safeStatus);
44
45 std::thread t(runCommand, strCmd);
46 // thread runs free
47 t.detach();
48#endif
49}
50
51namespace node {
52
54 CBlockIndex &index) {
55 uiInterface.NotifyBlockTip(state, &index);
56}
57
59 int64_t timestamp, bool presync) {
60 uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
61}
62
64 int progress_percent, bool resume_possible) {
65 uiInterface.ShowProgress(title.translated, progress_percent,
66 resume_possible);
67}
68
69void KernelNotifications::warning(const std::string &warning) {
71}
72
73void KernelNotifications::flushError(const std::string &debug_message) {
74 AbortNode(m_exit_status, debug_message);
75}
76
77void KernelNotifications::fatalError(const std::string &debug_message,
78 const bilingual_str &user_message) {
79 node::AbortNode(m_exit_status, debug_message, user_message,
81}
82
83} // namespace node
ArgsManager gArgs
Definition: args.cpp:39
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:462
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
std::atomic< int > & m_exit_status
void progress(const bilingual_str &title, int progress_percent, bool resume_possible) override
void flushError(const std::string &debug_message) override
The flush error notification is sent to notify the user that an error occurred while flushing block d...
void warning(const std::string &warning) override
void fatalError(const std::string &debug_message, const bilingual_str &user_message={}) override
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
void blockTip(SynchronizationState state, CBlockIndex &index) override
bool m_shutdown_on_fatal_error
Useful for tests, can be set to false to avoid shutdown on fatal error.
static void AlertNotify(const std::string &strMessage)
Definition: messages.h:12
void AbortNode(std::atomic< int > &exit_status, const std::string &debug_message, const bilingual_str &user_message, bool shutdown)
Definition: abort.cpp:19
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
Definition: string.cpp:11
Bilingual messages:
Definition: translation.h:17
std::string translated
Definition: translation.h:19
CClientUIInterface uiInterface
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:118