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

libbitcoin / libbitcoin-server / 44995759449

22 Nov 2026 06:53AM UTC coverage: 94.385% (-0.2%) from 94.577%
44995759449

push

github

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

Interface and embedded site updates.

196 of 222 new or added lines in 20 files covered. (88.29%)

179 existing lines in 6 files now uncovered.

13111 of 13891 relevant lines covered (94.38%)

453.76 hits per line

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

89.66
/src/protocols/native/protocol_native_address.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/protocols/protocol_native.hpp>
20

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

24
namespace libbitcoin {
25
namespace server {
26

27
#define CLASS protocol_native
28

29
using namespace system;
30

31
BC_PUSH_WARNING(NO_INCOMPLETE_SWITCH)
32

33
// handle_get_address
34
// ----------------------------------------------------------------------------
35

36
bool protocol_native::handle_get_address(const code& ec, interface::address,
320 ✔
37
    uint8_t, uint8_t media, const hash_cptr& hash, bool turbo) NOEXCEPT
38
{
39
    BC_ASSERT(stranded());
320 ✔
40

41
    if (stopped(ec))
320 ✔
42
        return false;
43

44
    if (!archive().address_enabled())
7 ✔
45
    {
46
        send_not_implemented();
1 ✔
47
        return true;
1 ✔
48
    }
49

50
    PARALLEL(do_get_address, media, turbo && turbo_, hash, gate());
12 ✔
51
    return true;
6 ✔
52
}
53

54
// private
55
void protocol_native::do_get_address(uint8_t media, bool turbo,
6 ✔
56
    const hash_cptr& hash, const gate_t::ptr& gate) NOEXCEPT
57
{
58
    BC_ASSERT(!stranded());
6 ✔
59

60
    database::outpoints set{};
6 ✔
61
    const auto& query = archive();
6 ✔
62
    const auto ec = query.get_address_outpoints(stopping_, set, *hash,
6 ✔
63
        options().maximum_history, turbo);
6 ✔
64
    POST(complete_get_address, ec, media, std::move(set), gate);
6 ✔
65
}
6 ✔
66

67
// This is shared by the three get_address... methods.
68
void protocol_native::complete_get_address(const code& ec, uint8_t media,
10 ✔
69
    const database::outpoints& set, const gate_t::ptr&) NOEXCEPT
70
{
71
    BC_ASSERT(stranded());
10 ✔
72

73
    if (stopped())
10 ✔
74
        return;
75

76
    if (ec == database::error::depth_limited)
10 ✔
77
    {
78
        send_bad_request();
×
79
        return;
×
80
    }
81

82
    if (ec)
10 ✔
83
    {
UNCOV
84
        send_internal_server_error(ec);
×
UNCOV
85
        return;
×
86
    }
87

88
    if (set.empty())
10 ✔
89
    {
90
        send_not_found();
3 ✔
91
        return;
3 ✔
92
    }
93

94
    const auto size = set.size() * chain::outpoint::serialized_size();
7 ✔
95
    switch (media)
7 ✔
96
    {
97
        case data:
4 ✔
98
            send_chunk(to_bin_array(set, size));
4 ✔
99
            return;
4 ✔
100
        case text:
1 ✔
101
            send_text(to_hex_array(set, size));
1 ✔
102
            return;
1 ✔
103
        case json:
2 ✔
104
            send_json(value_from(set));
2 ✔
105
            return;
2 ✔
106
    }
107

UNCOV
108
    send_not_found();
×
109
}
110

111
// handle_get_address_confirmed
112
// ----------------------------------------------------------------------------
113

114
bool protocol_native::handle_get_address_confirmed(const code& ec,
316 ✔
115
    interface::address_confirmed, uint8_t, uint8_t media,
116
    const hash_cptr& hash, bool turbo) NOEXCEPT
117
{
118
    BC_ASSERT(stranded());
316 ✔
119

120
    if (stopped(ec))
316 ✔
121
        return false;
122

123
    if (!archive().address_enabled())
3 ✔
124
    {
125
        send_not_implemented();
1 ✔
126
        return true;
1 ✔
127
    }
128

129
    PARALLEL(do_get_address_confirmed, media, turbo && turbo_, hash, gate());
4 ✔
130
    return true;
2 ✔
131
}
132

133
// private
134
void protocol_native::do_get_address_confirmed(uint8_t media, bool turbo,
2 ✔
135
    const hash_cptr& hash, const gate_t::ptr& gate) NOEXCEPT
136
{
137
    BC_ASSERT(!stranded());
2 ✔
138

139
    database::outpoints set{};
2 ✔
140
    const auto& query = archive();
2 ✔
141
    auto ec = query.get_confirmed_unspent_outpoints(stopping_, set, *hash,
2 ✔
142
        options().maximum_history, turbo);
2 ✔
143
    POST(complete_get_address, ec, media, std::move(set), gate);
2 ✔
144
}
2 ✔
145

146
// handle_get_address_unconfirmed
147
// ----------------------------------------------------------------------------
148

149
bool protocol_native::handle_get_address_unconfirmed(const code& ec,
315 ✔
150
    interface::address_unconfirmed, uint8_t, uint8_t media,
151
    const hash_cptr& hash, bool turbo) NOEXCEPT
152
{
153
    BC_ASSERT(stranded());
315 ✔
154

155
    if (stopped(ec))
315 ✔
156
        return false;
157

158
    if (!archive().address_enabled())
2 ✔
159
    {
UNCOV
160
        send_not_implemented();
×
UNCOV
161
        return true;
×
162
    }
163

164
    PARALLEL(do_get_address_unconfirmed, media, turbo && turbo_, hash, gate());
4 ✔
165
    return true;
2 ✔
166
}
167

168
// private
169
void protocol_native::do_get_address_unconfirmed(uint8_t media, bool turbo,
2 ✔
170
    const hash_cptr& hash, const gate_t::ptr& gate) NOEXCEPT
171
{
172
    BC_ASSERT(!stranded());
2 ✔
173

174
    database::outpoints set{};
2 ✔
175
    const auto& query = archive();
2 ✔
176
    auto ec = query.get_unconfirmed_unspent_outpoints(stopping_, set, *hash,
2 ✔
177
        options().maximum_history, turbo);
2 ✔
178
    POST(complete_get_address, ec, media, std::move(set), gate);
2 ✔
179
}
2 ✔
180

181
// handle_get_address_balance
182
// ----------------------------------------------------------------------------
183

184
bool protocol_native::handle_get_address_balance(const code& ec,
320 ✔
185
    interface::address_balance, uint8_t, uint8_t media,
186
    const hash_cptr& hash, bool turbo) NOEXCEPT
187
{
188
    BC_ASSERT(stranded());
320 ✔
189

190
    if (stopped(ec))
320 ✔
191
        return false;
192

193
    const auto& query = archive();
7 ✔
194
    if (!query.address_enabled())
7 ✔
195
    {
196
        send_not_implemented();
1 ✔
197
        return true;
1 ✔
198
    }
199

200
    PARALLEL(do_get_address_balance, media, turbo && turbo_, hash, gate());
12 ✔
201
    return true;
6 ✔
202
}
203

204
void protocol_native::do_get_address_balance(uint8_t media, bool turbo,
6 ✔
205
    const hash_cptr& hash, const gate_t::ptr& gate) NOEXCEPT
206
{
207
    BC_ASSERT(!stranded());
6 ✔
208

209
    uint64_t balance{};
6 ✔
210
    const auto& query = archive();
6 ✔
211
    auto ec = query.get_confirmed_balance(stopping_, balance, *hash,
6 ✔
212
        options().maximum_history, turbo);
6 ✔
213
    POST(complete_get_address_balance, ec, media, balance, gate);
6 ✔
214
}
6 ✔
215

216
void protocol_native::complete_get_address_balance(const code& ec,
6 ✔
217
    uint8_t media, uint64_t balance, const gate_t::ptr&) NOEXCEPT
218
{
219
    BC_ASSERT(stranded());
6 ✔
220

221
    // Suppresses cancelation error response.
222
    if (stopped())
6 ✔
223
        return;
224

225
    if (ec == database::error::depth_limited)
6 ✔
226
    {
UNCOV
227
        send_bad_request();
×
UNCOV
228
        return;
×
229
    }
230

231
    if (ec)
6 ✔
232
    {
UNCOV
233
        send_internal_server_error(ec);
×
UNCOV
234
        return;
×
235
    }
236

237
    switch (media)
6 ✔
238
    {
239
        case data:
2 ✔
240
            send_chunk(to_bin(balance));
2 ✔
241
            return;
2 ✔
242
        case text:
2 ✔
243
            send_text(encode_base16(to_bin(balance)));
2 ✔
244
            return;
2 ✔
245
        case json:
2 ✔
246
            send_json(balance);
2 ✔
247
            return;
2 ✔
248
    }
249

UNCOV
250
    send_not_found();
×
251
}
252

253
bool protocol_native::handle_get_address_subscribe(const code& ec,
315 ✔
254
    interface::address_subscribe, uint8_t version, uint8_t media,
255
    const system::hash_cptr& hash, bool turbo, bool stop) NOEXCEPT
256
{
257
    if (stopped(ec))
315 ✔
258
        return false;
259

260
    // TODO: map.
261
    address_subscribe_.store(!stop, std::memory_order_relaxed);
2 ✔
262
    if (stop)
2 ✔
263
    {
264
        send_empty();
1 ✔
265
        return true;
1 ✔
266
    }
267

268
    return handle_get_address(ec, {}, version, media, hash, turbo);
1 ✔
269
}
270

271
BC_POP_WARNING()
272

273
} // namespace server
274
} // 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