Coverage Report

Created: 2026-07-14 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/noui.cpp
Line
Count
Source
1
// Copyright (c) 2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#include <noui.h>
7
8
#include <node/interface_ui.h>
9
#include <util/btcsignals.h>
10
#include <util/log.h>
11
#include <util/translation.h>
12
13
#include <string>
14
15
/** Store connections so we can disconnect them when suppressing output */
16
btcsignals::connection noui_ThreadSafeMessageBoxConn;
17
btcsignals::connection noui_ThreadSafeQuestionConn;
18
btcsignals::connection noui_InitMessageConn;
19
20
void noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style)
21
54
{
22
54
    bool fSecure = style & CClientUIInterface::SECURE;
23
54
    style &= ~CClientUIInterface::SECURE;
24
25
54
    std::string strCaption;
26
54
    switch (style) {
27
54
    case CClientUIInterface::MSG_ERROR:
  Branch (27:5): [True: 54, False: 0]
28
54
        strCaption = "Error: ";
29
54
        if (!fSecure) LogError("%s\n", message.original);
  Branch (29:13): [True: 54, False: 0]
30
54
        break;
31
0
    case CClientUIInterface::MSG_WARNING:
  Branch (31:5): [True: 0, False: 54]
32
0
        strCaption = "Warning: ";
33
0
        if (!fSecure) LogWarning("%s\n", message.original);
  Branch (33:13): [True: 0, False: 0]
34
0
        break;
35
0
    case CClientUIInterface::MSG_INFORMATION:
  Branch (35:5): [True: 0, False: 54]
36
0
        strCaption = "Information: ";
37
0
        if (!fSecure) LogInfo("%s\n", message.original);
  Branch (37:13): [True: 0, False: 0]
38
0
        break;
39
0
    default:
  Branch (39:5): [True: 0, False: 54]
40
0
        if (!fSecure) LogInfo("%s%s\n", strCaption, message.original);
  Branch (40:13): [True: 0, False: 0]
41
54
    }
42
43
54
    tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
44
54
}
45
46
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
47
0
{
48
0
    noui_ThreadSafeMessageBox(Untranslated(message), style);
49
0
    return false; // Answer the question with false in the noui context
50
0
}
51
52
void noui_InitMessage(const std::string& message)
53
135
{
54
135
    LogInfo("init message: %s", message);
55
135
}
56
57
void noui_connect()
58
27
{
59
27
    noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox);
60
27
    noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion);
61
27
    noui_InitMessageConn = uiInterface.InitMessage.connect(noui_InitMessage);
62
27
}
63
64
void noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, unsigned int style)
65
0
{
66
0
    LogInfo("%s", message.original);
67
0
}
68
69
bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
70
0
{
71
0
    LogInfo("%s", message);
72
0
    return false;
73
0
}
74
75
void noui_InitMessageRedirect(const std::string& message)
76
0
{
77
0
    LogInfo("init message: %s", message);
78
0
}
79
80
void noui_test_redirect()
81
0
{
82
0
    noui_ThreadSafeMessageBoxConn.disconnect();
83
0
    noui_ThreadSafeQuestionConn.disconnect();
84
0
    noui_InitMessageConn.disconnect();
85
0
    noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBoxRedirect);
86
0
    noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestionRedirect);
87
0
    noui_InitMessageConn = uiInterface.InitMessage.connect(noui_InitMessageRedirect);
88
0
}
89
90
void noui_reconnect()
91
0
{
92
0
    noui_ThreadSafeMessageBoxConn.disconnect();
93
0
    noui_ThreadSafeQuestionConn.disconnect();
94
0
    noui_InitMessageConn.disconnect();
95
0
    noui_connect();
96
0
}