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

libbitcoin / libbitcoin-server / 45308589906

24 Nov 2026 01:55AM UTC coverage: 93.872% (+2.7%) from 91.147%
45308589906

push

github

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

Stratum_v1, native block viewer, pruning fixes to native embed.

1246 of 1333 new or added lines in 43 files covered. (93.47%)

1 existing line in 1 file now uncovered.

14216 of 15144 relevant lines covered (93.87%)

454.75 hits per line

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

89.29
/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
void protocol_native::handle_get_address(const code& ec, interface::address,
355 ✔
37
    uint8_t, uint8_t media, const hash_cptr& hash, bool turbo) NOEXCEPT
38
{
39
    BC_ASSERT(stranded());
355 ✔
40

41
    if (stopped(ec))
355 ✔
42
        return;
43

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

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

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

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

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

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

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

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

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

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

107
    send_not_found();
×
108
}
109

110
// handle_get_address_confirmed
111
// ----------------------------------------------------------------------------
112

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

119
    if (stopped(ec))
351 ✔
120
        return;
121

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

128
    PARALLEL(do_get_address_confirmed, media, turbo && turbo_, hash, gate());
4 ✔
129
}
130

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

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

144
// handle_get_address_unconfirmed
145
// ----------------------------------------------------------------------------
146

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

153
    if (stopped(ec))
350 ✔
154
        return;
155

156
    if (!archive().address_enabled())
2 ✔
157
    {
158
        send_not_implemented();
×
NEW
159
        return;
×
160
    }
161

162
    PARALLEL(do_get_address_unconfirmed, media, turbo && turbo_, hash, gate());
4 ✔
163
}
164

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

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

178
// handle_get_address_balance
179
// ----------------------------------------------------------------------------
180

181
void protocol_native::handle_get_address_balance(const code& ec,
355 ✔
182
    interface::address_balance, uint8_t, uint8_t media,
183
    const hash_cptr& hash, bool turbo) NOEXCEPT
184
{
185
    BC_ASSERT(stranded());
355 ✔
186

187
    if (stopped(ec))
355 ✔
188
        return;
189

190
    const auto& query = archive();
7 ✔
191
    if (!query.address_enabled())
7 ✔
192
    {
193
        send_not_implemented();
1 ✔
194
        return;
1 ✔
195
    }
196

197
    PARALLEL(do_get_address_balance, media, turbo && turbo_, hash, gate());
12 ✔
198
}
199

200
void protocol_native::do_get_address_balance(uint8_t media, bool turbo,
6 ✔
201
    const hash_cptr& hash, const gate_t::ptr& gate) NOEXCEPT
202
{
203
    BC_ASSERT(!stranded());
6 ✔
204

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

212
void protocol_native::complete_get_address_balance(const code& ec,
6 ✔
213
    uint8_t media, uint64_t balance, const gate_t::ptr&) NOEXCEPT
214
{
215
    BC_ASSERT(stranded());
6 ✔
216

217
    // Suppresses cancelation error response.
218
    if (stopped())
6 ✔
219
        return;
220

221
    if (ec == database::error::depth_limited)
6 ✔
222
    {
223
        send_bad_request();
×
224
        return;
×
225
    }
226

227
    if (ec)
6 ✔
228
    {
229
        send_internal_server_error(ec);
×
230
        return;
×
231
    }
232

233
    switch (media)
6 ✔
234
    {
235
        case data:
2 ✔
236
            send_chunk(to_bin(balance));
2 ✔
237
            return;
2 ✔
238
        case text:
2 ✔
239
            send_text(encode_base16(to_bin(balance)));
2 ✔
240
            return;
2 ✔
241
        case json:
2 ✔
242
            send_json(balance);
2 ✔
243
            return;
2 ✔
244
    }
245

246
    send_not_found();
×
247
}
248

249
void protocol_native::handle_get_address_subscribe(const code& ec,
350 ✔
250
    interface::address_subscribe, uint8_t version, uint8_t media,
251
    const system::hash_cptr& hash, bool turbo, bool stop) NOEXCEPT
252
{
253
    if (stopped(ec))
350 ✔
254
        return;
255

256
    // TODO: map.
257
    address_subscribe_.store(!stop, std::memory_order_relaxed);
2 ✔
258
    if (stop)
2 ✔
259
    {
260
        send_empty();
1 ✔
261
        return;
1 ✔
262
    }
263

264
    return handle_get_address(ec, {}, version, media, hash, turbo);
1 ✔
265
}
266

267
BC_POP_WARNING()
268

269
} // namespace server
270
} // 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