• 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

95.33
/src/protocols/native/protocol_native_output.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 <bitcoin/server/define.hpp>
22

23
namespace libbitcoin {
24
namespace server {
25

26
using namespace system;
27

28
BC_PUSH_WARNING(NO_INCOMPLETE_SWITCH)
29
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
30

31
void protocol_native::handle_get_outputs(const code& ec, interface::outputs,
352 ✔
32
    uint8_t, uint8_t media, const hash_cptr& hash) NOEXCEPT
33
{
34
    if (stopped(ec))
352 ✔
35
        return;
352 ✔
36

37
    const auto& query = archive();
4 ✔
38
    const auto tx = query.to_tx(*hash);
4 ✔
39
    if (tx.is_terminal())
4 ✔
40
    {
41
        send_not_found();
1 ✔
42
        return;
43
    }
44

45
    const auto outputs = query.get_outputs(tx);
3 ✔
46
    if (!outputs || outputs->empty())
3 ✔
47
    {
48
        send_internal_server_error(database::error::integrity);
×
NEW
49
        return;
×
50
    }
51

52
    // Wire serialization size of outputs set.
53
    const auto size = std::accumulate(outputs->begin(), outputs->end(), zero,
3 ✔
54
        [](size_t total, const auto& output) NOEXCEPT
6 ✔
55
        { return total + output->serialized_size(); });
6 ✔
56

57
    switch (media)
3 ✔
58
    {
59
        case data:
1 ✔
60
            send_chunk(to_bin_ptr_array(*outputs, size));
1 ✔
61
            return;
1 ✔
62
        case text:
1 ✔
63
            send_text(to_hex_ptr_array(*outputs, size));
1 ✔
64
            return;
1 ✔
65
        case json:
1 ✔
66
            send_json(value_from(*outputs));
1 ✔
67
            return;
1 ✔
68
    }
69

70
    send_not_found();
×
71
}
4 ✔
72

73
void protocol_native::handle_get_output(const code& ec, interface::output,
353 ✔
74
    uint8_t, uint8_t media, const hash_cptr& hash,
75
    uint32_t index) NOEXCEPT
76
{
77
    if (stopped(ec))
353 ✔
78
        return;
79

80
    const auto& query = archive();
5 ✔
81
    if (const auto output = query.get_output(query.to_tx(*hash), index))
5 ✔
82
    {
83
        const auto size = output->serialized_size();
4 ✔
84
        switch (media)
4 ✔
85
        {
86
            case data:
2 ✔
87
                send_chunk(to_bin(*output, size));
2 ✔
88
                return;
2 ✔
89
            case text:
1 ✔
90
                send_text(to_hex(*output, size));
1 ✔
91
                return;
1 ✔
92
            case json:
1 ✔
93
                send_json(value_from(output));
1 ✔
94
                return;
1 ✔
95
        }
96
    }
5 ✔
97

98
    send_not_found();
1 ✔
99
}
100

101
void protocol_native::handle_get_output_script(const code& ec,
352 ✔
102
    interface::output_script, uint8_t, uint8_t media, const hash_cptr& hash,
103
    uint32_t index) NOEXCEPT
104
{
105
    if (stopped(ec))
352 ✔
106
        return;
107

108
    const auto& query = archive();
4 ✔
109
    if (const auto script = query.get_output_script(query.to_output(
8 ✔
110
        query.to_tx(*hash), index)))
12 ✔
111
    {
112
        const auto size = script->serialized_size(false);
3 ✔
113
        switch (media)
3 ✔
114
        {
115
            case data:
1 ✔
116
                send_chunk(to_bin(*script, size, false));
1 ✔
117
                return;
1 ✔
118
            case text:
1 ✔
119
                send_text(to_hex(*script, size, false));
1 ✔
120
                return;
1 ✔
121
            case json:
1 ✔
122
                send_json(value_from(script));
1 ✔
123
                return;
1 ✔
124
        }
125
    }
4 ✔
126

127
    send_not_found();
1 ✔
128
}
129

130
void protocol_native::handle_get_output_spender(const code& ec,
352 ✔
131
    interface::output_spender, uint8_t, uint8_t media, const hash_cptr& hash,
132
    uint32_t index) NOEXCEPT
133
{
134
    if (stopped(ec))
352 ✔
135
        return;
352 ✔
136

137
    const auto& query = archive();
4 ✔
138
    const chain::point spent{ *hash, index };
4 ✔
139
    const auto spender = query.get_spender(query.find_confirmed_spender(spent));
4 ✔
140
    if (spender.is_null())
4 ✔
141
    {
142
        send_not_found();
1 ✔
143
        return;
144
    }
145

146
    constexpr auto size = chain::point::serialized_size();
147
    switch (media)
3 ✔
148
    {
149
        case data:
1 ✔
150
            send_chunk(to_bin(spender, size));
1 ✔
151
            return;
1 ✔
152
        case text:
1 ✔
153
            send_text(to_hex(spender, size));
1 ✔
154
            return;
1 ✔
155
        case json:
1 ✔
156
            send_json(value_from(spender));
1 ✔
157
            return;
1 ✔
158
    }
159

160
    send_not_found();
×
161
}
4 ✔
162

163
void protocol_native::handle_get_output_spenders(const code& ec,
352 ✔
164
    interface::output_spenders, uint8_t, uint8_t media, const hash_cptr& hash,
165
    uint32_t index) NOEXCEPT
166
{
167
    if (stopped(ec))
352 ✔
168
        return;
352 ✔
169

170
    const auto ins = archive().get_spenders({ *hash, index });
4 ✔
171
    if (ins.empty())
4 ✔
172
    {
173
        send_not_found();
1 ✔
174
        return;
175
    }
176

177
    const auto size = ins.size() * database::inpoint::serialized_size();
3 ✔
178
    switch (media)
3 ✔
179
    {
180
        case data:
1 ✔
181
            send_chunk(to_bin_array(ins, size));
1 ✔
182
            return;
1 ✔
183
        case text:
1 ✔
184
            send_text(to_hex_array(ins, size));
1 ✔
185
            return;
1 ✔
186
        case json:
1 ✔
187
            send_json(value_from(ins));
1 ✔
188
            return;
1 ✔
189
    }
190

191
    send_not_found();
×
192
}
4 ✔
193

194
void protocol_native::handle_get_output_subscribe(const code& ec,
350 ✔
195
    interface::output_subscribe, uint8_t version, uint8_t media,
196
    const system::hash_cptr& hash, uint32_t index, bool stop) NOEXCEPT
197
{
198
    if (stopped(ec))
350 ✔
199
        return;
200

201
    // TODO: map.
202
    output_subscribe_.store(stop, std::memory_order_relaxed);
2 ✔
203
    if (stop)
2 ✔
204
    {
205
        send_empty();
1 ✔
206
        return;
1 ✔
207
    }
208

209
    return handle_get_output(ec, {}, version, media, hash, index);
1 ✔
210
}
211

212
BC_POP_WARNING()
213
BC_POP_WARNING()
214

215
} // namespace server
216
} // 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