From f871c69191dfe1331861ebcdbadb6bd47e45c8b1 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Mon, 8 May 2023 14:49:37 +0200 Subject: kernel: Add warning method to notifications This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index. The DoWarning and AlertNotify functions are moved out of the validation.cpp file, which removes its dependency on interface_ui as well as util/system. --- src/node/kernel_notifications.cpp | 48 +++++++++++++++++++++++++++++++++++++++ src/node/kernel_notifications.h | 2 ++ 2 files changed, 50 insertions(+) (limited to 'src/node') diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index 9efbc6c4ca..2bc4544aee 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -4,8 +4,51 @@ #include +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include #include +#include +#include +#include #include +#include + +#include +#include +#include + +static void AlertNotify(const std::string& strMessage) +{ + uiInterface.NotifyAlertChanged(); +#if HAVE_SYSTEM + std::string strCmd = gArgs.GetArg("-alertnotify", ""); + if (strCmd.empty()) return; + + // Alert text should be plain ascii coming from a trusted source, but to + // be safe we first strip anything not in safeChars, then add single quotes around + // the whole string before passing it to the shell: + std::string singleQuote("'"); + std::string safeStatus = SanitizeString(strMessage); + safeStatus = singleQuote+safeStatus+singleQuote; + ReplaceAll(strCmd, "%s", safeStatus); + + std::thread t(runCommand, strCmd); + t.detach(); // thread runs free +#endif +} + +static void DoWarning(const bilingual_str& warning) +{ + static bool fWarned = false; + SetMiscWarning(warning); + if (!fWarned) { + AlertNotify(warning.original); + fWarned = true; + } +} namespace node { @@ -24,4 +67,9 @@ void KernelNotifications::progress(const bilingual_str& title, int progress_perc uiInterface.ShowProgress(title.translated, progress_percent, resume_possible); } +void KernelNotifications::warning(const bilingual_str& warning) +{ + DoWarning(warning); +} + } // namespace node diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h index ecd21c3a58..3e665bbf14 100644 --- a/src/node/kernel_notifications.h +++ b/src/node/kernel_notifications.h @@ -23,6 +23,8 @@ public: void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override; void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override; + + void warning(const bilingual_str& warning) override; }; } // namespace node -- cgit v1.2.3