• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-server / 42977519106

11 Nov 2026 07:10AM UTC coverage: 95.121% (+0.04%) from 95.086%
42977519106

push

github

web-flow
Merge pull request #1156 from evoskuil/master

Regenerate artifacts, brace macro invocations under conditionals.

2 of 2 new or added lines in 1 file covered. (100.0%)

21 existing lines in 4 files now uncovered.

12087 of 12707 relevant lines covered (95.12%)

252.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.16
/src/settings.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/server/settings.hpp>
20

21
#include <filesystem>
22
#include <bitcoin/server/define.hpp>
23

24
using namespace bc::system;
25
using namespace bc::network;
26

27
namespace libbitcoin {
28

29
// log
30
// ----------------------------------------------------------------------------
31

32
namespace log {
33

34
// Log states default to network compiled states or explicit false.
35
settings::settings() NOEXCEPT
1,579 ✔
36
  : application{ levels::application_defined },
1,579 ✔
37
    news{ levels::news_defined },
1,579 ✔
38
    session{ levels::session_defined },
1,579 ✔
39
    protocol{ false /*levels::protocol_defined*/ },
1,579 ✔
40
    proxy{ false /*levels::proxy_defined*/ },
1,579 ✔
41
    remote{ levels::remote_defined },
1,579 ✔
42
    fault{ levels::fault_defined },
1,579 ✔
43
    quitting{ false /*levels::quitting_defined*/ },
1,579 ✔
44
    objects{ false /*levels::objects_defined*/ },
1,579 ✔
45
    verbose{ false /*levels::verbose_defined*/ },
1,579 ✔
46
    console{ true },
1,579 ✔
47
    events{ true },
1,579 ✔
48
    limit{ 1'000'000_u32 }
1,579 ✔
49
{
50
}
1,579 ✔
51

52
settings::settings(chain::selection) NOEXCEPT
1,578 ✔
53
  : settings()
1,578 ✔
54
{
55
}
1,578 ✔
56

57
std::filesystem::path settings::log_file1() const NOEXCEPT
2 ✔
58
{
59
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
60
    return console_path / "console_new.log";
2 ✔
61
    BC_POP_WARNING()
62
}
63

64
std::filesystem::path settings::log_file2() const NOEXCEPT
1 ✔
65
{
66
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
67
    return console_path / "console_old.log";
1 ✔
68
    BC_POP_WARNING()
69
}
70

71
std::filesystem::path settings::events_file() const NOEXCEPT
1 ✔
72
{
73
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
74
    return events_path / "events.log";
1 ✔
75
    BC_POP_WARNING()
76
}
77

78
} // namespace log
79

80
// server
81
// ----------------------------------------------------------------------------
82

83
namespace server {
84

85
using namespace system::wallet;
86

87
// settings::settings
88
settings::settings(system::chain::selection context,
1,607 ✔
89
    const embedded_pages& native_pages,
90
    const embedded_pages& admin_pages) NOEXCEPT
1,607 ✔
91
  : network(context),
1,607 ✔
92
    wallet(context),
1,607 ✔
93
    admin("admin", admin_pages),
1,607 ✔
94
    native("native", native_pages)
3,214 ✔
95
{
96
    // Admin may accumulate a large amount of log backlog.
97
    admin.maximum_backlog = 10 * network::megabyte;
1,607 ✔
98

99
    // The largest btcd notification is a filtered block.
100
    btcd.maximum_backlog = 20 * network::megabyte;
1,607 ✔
101

102
    // btcd reports json-rpc errors in the response body only.
103
    btcd.error_status = false;
1,607 ✔
104

105
    // Raw block publications drop beyond the bound, eight blocks deep.
106
    zmq.maximum_backlog = 32 * network::megabyte;
1,607 ✔
107

108
    // Subscribers send nothing after subscribing, so publishers do not expire.
109
    zmq.inactivity_minutes = 0;
1,607 ✔
110
    zmq.expiration_minutes = 0;
1,607 ✔
111

112
    // A submitted block is base16 encoded within a json envelope.
113
    constexpr auto encoded = 2 * network::max_payload + 4 * network::kilobyte;
114
    bitcoind.maximum_request = encoded;
1,607 ✔
115
    btcd.maximum_request = encoded;
1,607 ✔
116

117
    // A broadcast transaction package is base16 encoded within a json envelope.
118
    electrum.maximum_request = encoded;
1,607 ✔
119
    sparrow.maximum_request = encoded;
1,607 ✔
120
    esplora.maximum_request = encoded;
1,607 ✔
121
}
1,607 ✔
122

123
// The service contexts are read from configured files, once, at startup.
124
code settings::initialize() NOEXCEPT
1,553 ✔
125
{
126
    // Service ports are offset by chain.
127
    const auto port = [this](uint16_t base) NOEXCEPT
29,507 ✔
128
    {
129
        switch (network)
29,507 ✔
130
        {
UNCOV
131
            case system::chain::selection::testnet3:
×
UNCOV
132
                return possible_narrow_cast<uint16_t>(base + 10000_u32);
×
133
            case system::chain::selection::regtest:
76 ✔
134
                return possible_narrow_cast<uint16_t>(base + 20000_u32);
76 ✔
UNCOV
135
            case system::chain::selection::signet:
×
UNCOV
136
                return possible_narrow_cast<uint16_t>(base + 30000_u32);
×
137
            case system::chain::selection::testnet4:
38 ✔
138
                return possible_narrow_cast<uint16_t>(base + 40000_u32);
38 ✔
139
            case system::chain::selection::testnet5:
19 ✔
140
                return possible_narrow_cast<uint16_t>(base + 50000_u32);
19 ✔
141
            default:
142
                return base;
143
        }
144
    };
1,553 ✔
145

146
    admin.bind_port = port(8080);
1,553 ✔
147
    admin.safe_port = port(8043);
1,553 ✔
148
    native.bind_port = port(8180);
1,553 ✔
149
    native.safe_port = port(8143);
1,553 ✔
150
    bitcoind.bind_port = port(8280);
1,553 ✔
151
    bitcoind.safe_port = port(8243);
1,553 ✔
152
    zmq.bind_port = port(8380);
1,553 ✔
153
    zmq.safe_port = port(8343);
1,553 ✔
154
    btcd.bind_port = port(8480);
1,553 ✔
155
    btcd.safe_port = port(8443);
1,553 ✔
156
    electrum.bind_port = port(8580);
1,553 ✔
157
    electrum.safe_port = port(8543);
1,553 ✔
158
    sparrow.bind_port = port(8680);
1,553 ✔
159
    sparrow.safe_port = port(8643);
1,553 ✔
160
    esplora.bind_port = port(8780);
1,553 ✔
161
    esplora.safe_port = port(8743);
1,553 ✔
162
    stratum_v1.bind_port = port(8880);
1,553 ✔
163
    stratum_v1.safe_port = port(8843);
1,553 ✔
164
    stratum_v2.bind_port = port(8980);
1,553 ✔
165

166
    // Service bindings without a port take the service's default port.
167
    admin.default_ports();
1,553 ✔
168
    native.default_ports();
1,553 ✔
169
    bitcoind.default_ports();
1,553 ✔
170
    zmq.default_ports();
1,553 ✔
171
    btcd.default_ports();
1,553 ✔
172
    electrum.default_ports();
1,553 ✔
173
    sparrow.default_ports();
1,553 ✔
174
    esplora.default_ports();
1,553 ✔
175
    stratum_v1.default_ports();
1,553 ✔
176
    stratum_v2.default_ports();
1,553 ✔
177

178
    const auto initialize = [this](auto& service) NOEXCEPT
15,522 ✔
179
    {
180
        const auto ec = service.initialize_context();
15,522 ✔
181
        if (ec)
15,522 ✔
182
            failure = service.name;
1 ✔
183

184
        return ec;
15,522 ✔
185
    };
1,553 ✔
186

187
    if (const auto ec = initialize(admin)) return ec;
1,553 ✔
188
    if (const auto ec = initialize(native)) return ec;
1,553 ✔
189
    if (const auto ec = initialize(bitcoind)) return ec;
1,552 ✔
190
    if (const auto ec = initialize(btcd)) return ec;
1,552 ✔
191
    if (const auto ec = initialize(electrum)) return ec;
1,552 ✔
192
    if (const auto ec = initialize(sparrow)) return ec;
1,552 ✔
193
    if (const auto ec = initialize(esplora)) return ec;
1,552 ✔
194
    if (const auto ec = initialize(stratum_v1)) return ec;
1,552 ✔
195
    if (const auto ec = initialize(stratum_v2)) return ec;
1,552 ✔
196
    return initialize(zmq);
1,552 ✔
197
}
198

199
// settings::wallet_settings
200
settings::wallet_settings::wallet_settings() NOEXCEPT
1 ✔
201
  : wallet_settings(system::chain::selection::mainnet)
1 ✔
202
{
203
}
1 ✔
204

205
static const context& to_wallet_context(
3,189 ✔
206
    system::chain::selection context) NOEXCEPT
207
{
208
    switch (context)
3,189 ✔
209
    {
210
        case system::chain::selection::testnet3:
211
        case system::chain::selection::testnet4:
212
        case system::chain::selection::testnet5:
213
        case system::chain::selection::signet:
214
            return ctx::btc::test;
215
        case system::chain::selection::regtest:
12 ✔
216
            return ctx::btc::regtest;
12 ✔
217
        case system::chain::selection::mainnet:
3,158 ✔
218
        case system::chain::selection::none:
219
        default:
220
            return ctx::btc::main;
3,158 ✔
221
    }
222
}
223

224
settings::wallet_settings::wallet_settings(
3,189 ✔
225
    system::chain::selection context) NOEXCEPT
3,189 ✔
226
{
227
    const auto& value = to_wallet_context(context);
3,189 ✔
228
    p2kh_prefix = value.p2kh;
3,189 ✔
229
    p2sh_prefix = value.p2sh;
3,189 ✔
230
    wif_prefix = value.wif;
3,189 ✔
231
    witness_prefix = value.p2w;
3,189 ✔
232
    silent_prefix = value.sp;
3,189 ✔
233
    hd_private_prefix = value.hd.prv;
3,189 ✔
234
    hd_public_prefix = value.hd.pub;
3,189 ✔
235
}
3,189 ✔
236

237
context settings::wallet_settings::to_context() const NOEXCEPT
8,978 ✔
238
{
239
    return
240
    {
241
        { hd_private_prefix, hd_public_prefix },
8,978 ✔
242
        witness_prefix,
8,978 ✔
243
        p2kh_prefix,
8,978 ✔
244
        p2sh_prefix,
8,978 ✔
245
        wif_prefix,
8,978 ✔
246
        silent_prefix
8,978 ✔
247
    };
8,978 ✔
248
}
17,956 ✔
249

250
// settings::embedded_pages
251
span_value settings::embedded_pages::css()  const NOEXCEPT { return {}; }
3 ✔
252
span_value settings::embedded_pages::html() const NOEXCEPT { return {}; }
6 ✔
253
span_value settings::embedded_pages::ecma() const NOEXCEPT { return {}; }
3 ✔
254
span_value settings::embedded_pages::font() const NOEXCEPT { return {}; }
3 ✔
255
span_value settings::embedded_pages::icon() const NOEXCEPT { return {}; }
3 ✔
256
bool settings::embedded_pages::enabled() const NOEXCEPT
9 ✔
257
{
258
    return !html().empty();
9 ✔
259
}
260

261
// settings::html_server
262
settings::html_server::html_server(const std::string_view& logging_name,
3,215 ✔
263
    const embedded_pages& embedded) NOEXCEPT
3,215 ✔
264
  : network::settings::websocket_server(logging_name),
265
    pages(embedded)
3,215 ✔
266
{
267
}
3,215 ✔
268

269
} // namespace server
270

271
// ----------------------------------------------------------------------------
272

273
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc