mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
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.
This commit is contained in:
parent
4452707ede
commit
f871c69191
5 changed files with 56 additions and 33 deletions
|
@ -99,6 +99,10 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
std::cout << "Progress: " << title.original << ", " << progress_percent << ", " << resume_possible << std::endl;
|
||||
}
|
||||
void warning(const bilingual_str& warning) override
|
||||
{
|
||||
std::cout << "Warning: " << warning.original << std::endl;
|
||||
}
|
||||
};
|
||||
auto notifications = std::make_unique<KernelNotifications>();
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
virtual void blockTip(SynchronizationState state, CBlockIndex& index) {}
|
||||
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
|
||||
virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {}
|
||||
virtual void warning(const bilingual_str& warning) {}
|
||||
};
|
||||
} // namespace kernel
|
||||
|
||||
|
|
|
@ -4,8 +4,51 @@
|
|||
|
||||
#include <node/kernel_notifications.h>
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <common/args.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <warnings.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <logging.h>
|
||||
#include <logging/timer.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/rbf.h>
|
||||
|
@ -53,7 +52,6 @@
|
|||
#include <util/moneystr.h>
|
||||
#include <util/rbf.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
#include <util/time.h>
|
||||
#include <util/trace.h>
|
||||
#include <util/translation.h>
|
||||
|
@ -1641,26 +1639,6 @@ bool Chainstate::IsInitialBlockDownload() const
|
|||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void Chainstate::CheckForkWarningConditions()
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
@ -2601,16 +2579,6 @@ void Chainstate::PruneAndFlush()
|
|||
}
|
||||
}
|
||||
|
||||
static void DoWarning(const bilingual_str& warning)
|
||||
{
|
||||
static bool fWarned = false;
|
||||
SetMiscWarning(warning);
|
||||
if (!fWarned) {
|
||||
AlertNotify(warning.original);
|
||||
fWarned = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Private helper function that concatenates warning messages. */
|
||||
static void AppendWarning(bilingual_str& res, const bilingual_str& warn)
|
||||
{
|
||||
|
@ -2677,7 +2645,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
|
|||
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
|
||||
const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
|
||||
if (state == ThresholdState::ACTIVE) {
|
||||
DoWarning(warning);
|
||||
m_chainman.GetNotifications().warning(warning);
|
||||
} else {
|
||||
AppendWarning(warning_messages, warning);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue