Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_NODE_WARNINGS_H7#define BITCOIN_NODE_WARNINGS_H9#include <sync.h>10#include <util/translation.h>12#include <map>13#include <variant>14#include <vector>16class UniValue;18namespace kernel {19enum class Warning;20} // namespace kernel22namespace node {23enum class Warning {24CLOCK_OUT_OF_SYNC,25PRE_RELEASE_TEST_BUILD,26FATAL_INTERNAL_ERROR,27};29/**30* @class Warnings31* @brief Manages warning messages within a node.32*33* The Warnings class provides mechanisms to set, unset, and retrieve34* warning messages. It updates the GUI when warnings are changed.35*36* This class is designed to be non-copyable to ensure warnings37* are managed centrally.38*/39class Warnings40{41typedef std::variant<kernel::Warning, node::Warning> warning_type;43mutable Mutex m_mutex;44std::map<warning_type, bilingual_str> m_warnings GUARDED_BY(m_mutex);46public:47Warnings();48//! A warnings instance should always be passed by reference, never copied.49Warnings(const Warnings&) = delete;50Warnings& operator=(const Warnings&) = delete;51/**52* @brief Set a warning message. If a warning with the specified53* `id` is already active, false is returned and the new54* warning is ignored. If `id` does not yet exist, the55* warning is set, the UI is updated, and true is returned.56*57* @param[in] id Unique identifier of the warning.58* @param[in] message Warning message to be shown.59*60* @returns true if the warning was indeed set (i.e. there is no61* active warning with this `id`), otherwise false.62*/63bool Set(warning_type id, bilingual_str message) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);64/**65* @brief Unset a warning message. If a warning with the specified66* `id` is active, it is unset, the UI is updated, and true67* is returned. Otherwise, no warning is unset and false is68* returned.69*70* @param[in] id Unique identifier of the warning.71*72* @returns true if the warning was indeed unset (i.e. there is an73* active warning with this `id`), otherwise false.74*/75bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);76/** Return potential problems detected by the node, sorted by the77* warning_type id */78std::vector<bilingual_str> GetMessages() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);79};81/**82* RPC helper function that wraps warnings.GetMessages().83*84* Returns a UniValue::VSTR with the latest warning if use_deprecated is85* set to true, or a UniValue::VARR with all warnings otherwise.86*/87UniValue GetWarningsForRpc(const Warnings& warnings, bool use_deprecated);88} // namespace node90#endif // BITCOIN_NODE_WARNINGS_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.