Bitcoin ABC 0.33.10
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 <chain.h>
12#include <common/args.h>
13#include <common/system.h>
14#include <kernel/context.h>
15#include <logging.h>
16#include <node/abort.h>
17#include <node/ui_interface.h>
18#include <shutdown.h>
19#include <util/check.h>
20#include <util/strencodings.h>
21#include <util/string.h>
22#include <util/translation.h>
23
24#include <cstdint>
25#include <string>
26#include <thread>
27
29
30static void AlertNotify(const std::string &strMessage) {
31 uiInterface.NotifyAlertChanged();
32#if defined(HAVE_SYSTEM)
33 std::string strCmd = gArgs.GetArg("-alertnotify", "");
34 if (strCmd.empty()) {
35 return;
36 }
37
38 // Alert text should be plain ascii coming from a trusted source, but to be
39 // safe we first strip anything not in safeChars, then add single quotes
40 // around the whole string before passing it to the shell:
41 std::string singleQuote("'");
42 std::string safeStatus = SanitizeString(strMessage);
43 safeStatus = singleQuote + safeStatus + singleQuote;
44 ReplaceAll(strCmd, "%s", safeStatus);
45
46 std::thread t(runCommand, strCmd);
47 // thread runs free
48 t.detach();
49#endif
50}
51
52namespace node {
53
56 uiInterface.NotifyBlockTip(state, &index);
59 return kernel::Interrupted{};
60 }
61 return {};
62}
63
65 int64_t timestamp, bool presync) {
66 uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
67}
68
70 int progress_percent, bool resume_possible) {
71 uiInterface.ShowProgress(title.translated, progress_percent,
72 resume_possible);
73}
74
75void KernelNotifications::warning(const std::string &warning) {
77}
78
79void KernelNotifications::flushError(const std::string &debug_message) {
80 AbortNode(m_exit_status, debug_message);
81}
82
83void KernelNotifications::fatalError(const std::string &debug_message,
84 const bilingual_str &user_message) {
85 node::AbortNode(m_exit_status, debug_message, user_message,
87}
88
90 KernelNotifications &notifications) {
91 if (auto value{args.GetIntArg("-stopatheight")}) {
92 notifications.m_stop_at_height = *value;
93 }
94}
95
96} // namespace node
ArgsManager gArgs
Definition: args.cpp:39
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:494
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
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:38
int m_stop_at_height
Block height after which blockTip notification will return Interrupted{}, if >0.
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'...
kernel::InterruptResult 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)
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
Definition: messages.h:12
void ReadNotificationArgs(const ArgsManager &args, KernelNotifications &notifications)
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
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:16
Bilingual messages:
Definition: translation.h:17
std::string translated
Definition: translation.h:19
Result type for use with std::variant to indicate that an operation should be interrupted.
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:110