• 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.41
/src/protocols/native/protocol_native_input.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_inputs(const code& ec, interface::inputs,
355 ✔
32
    uint8_t, uint8_t media, const hash_cptr& hash, bool witness) NOEXCEPT
33
{
34
    if (stopped(ec))
355 ✔
35
        return;
355 ✔
36

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

45
    if (query.is_pruned(tx))
6 ✔
46
    {
47
        if (media != json)
2 ✔
48
        {
49
            send_not_found();
1 ✔
50
            return;
51
        }
52

53
        system::json::array out{};
1 ✔
54
        if (!to_pruned_inputs(out, tx))
1 ✔
55
        {
NEW
56
            send_internal_server_error(database::error::integrity);
×
NEW
57
            return;
×
58
        }
59

60
        send_json(std::move(out));
1 ✔
61
        return;
1 ✔
62
    }
1 ✔
63

64
    const auto inputs = query.get_inputs(tx, witness);
4 ✔
65
    if (!inputs || inputs->empty())
4 ✔
66
    {
67
        send_internal_server_error(database::error::integrity);
×
NEW
68
        return;
×
69
    }
70

71
    // Wire serialization of input does not include witness.
72
    const auto size = std::accumulate(inputs->begin(), inputs->end(), zero,
4 ✔
73
        [&](size_t total, const auto& input) NOEXCEPT
10 ✔
74
        { return total + input->serialized_size(false); });
10 ✔
75

76
    switch (media)
4 ✔
77
    {
78
        case data:
2 ✔
79
            send_chunk(to_bin_ptr_array(*inputs, size));
2 ✔
80
            return;
2 ✔
81
        case text:
1 ✔
82
            send_text(to_hex_ptr_array(*inputs, size));
1 ✔
83
            return;
1 ✔
84
        case json:
1 ✔
85
            // Json input serialization includes witness.
86
            send_json(value_from(*inputs));
1 ✔
87
            return;
1 ✔
88
    }
89

90
    send_not_found();
×
91
}
7 ✔
92

93
void protocol_native::handle_get_input(const code& ec, interface::input,
357 ✔
94
    uint8_t, uint8_t media, const hash_cptr& hash, uint32_t index,
95
    bool witness) NOEXCEPT
96
{
97
    if (stopped(ec))
357 ✔
98
        return;
356 ✔
99

100
    const auto& query = archive();
9 ✔
101
    const auto link = query.to_tx(*hash);
9 ✔
102
    if (query.is_pruned(link))
9 ✔
103
    {
104
        const auto point = query.to_point(link, index);
4 ✔
105
        system::json::value out{};
4 ✔
106
        if (media != json || point.is_terminal() ||
5 ✔
107
            !to_pruned_input(out, point))
1 ✔
108
        {
109
            send_not_found();
3 ✔
110
            return;
111
        }
112

113
        send_json(std::move(out));
1 ✔
114
        return;
115
    }
4 ✔
116

117
    if (const auto input = query.get_input(link, index, witness))
5 ✔
118
    {
119
        // Wire serialization of input does not include witness.
120
        const auto size = input->serialized_size(false);
4 ✔
121
        switch (media)
4 ✔
122
        {
123
            case data:
2 ✔
124
                send_chunk(to_bin(*input, size));
2 ✔
125
                return;
2 ✔
126
            case text:
1 ✔
127
                send_text(to_hex(*input, size));
1 ✔
128
                return;
1 ✔
129
            case json:
1 ✔
130
                // Json input serialization includes witness.
131
                send_json(value_from(input));
1 ✔
132
                return;
1 ✔
133
        }
134
    }
5 ✔
135

136
    send_not_found();
1 ✔
137
}
9 ✔
138

139
void protocol_native::handle_get_input_script(const code& ec,
353 ✔
140
    interface::input_script, uint8_t, uint8_t media, const hash_cptr& hash,
141
    uint32_t index) NOEXCEPT
142
{
143
    if (stopped(ec))
353 ✔
144
        return;
352 ✔
145

146
    const auto& query = archive();
5 ✔
147
    const auto link = query.to_tx(*hash);
5 ✔
148
    if (query.is_pruned(link))
5 ✔
149
    {
150
        send_not_found();
1 ✔
151
        return;
152
    }
153

154
    if (const auto script = query.get_input_script(query.to_point(link, index)))
4 ✔
155
    {
156
        const auto size = script->serialized_size(false);
3 ✔
157
        switch (media)
3 ✔
158
        {
159
            case data:
1 ✔
160
                send_chunk(to_bin(*script, size, false));
1 ✔
161
                return;
1 ✔
162
            case text:
1 ✔
163
                send_text(to_hex(*script, size, false));
1 ✔
164
                return;
1 ✔
165
            case json:
1 ✔
166
                send_json(value_from(script));
1 ✔
167
                return;
1 ✔
168
        }
169
    }
4 ✔
170

171
    send_not_found();
1 ✔
172
}
5 ✔
173

174
void protocol_native::handle_get_input_witness(const code& ec,
353 ✔
175
    interface::input_witness, uint8_t, uint8_t media, const hash_cptr& hash,
176
    uint32_t index) NOEXCEPT
177
{
178
    if (stopped(ec))
353 ✔
179
        return;
352 ✔
180

181
    const auto& query = archive();
5 ✔
182
    const auto link = query.to_tx(*hash);
5 ✔
183
    if (query.is_pruned(link))
5 ✔
184
    {
185
        send_not_found();
1 ✔
186
        return;
187
    }
188

189
    if (const auto witness = query.get_witness(query.to_point(link, index));
4 ✔
190
        !is_null(witness) && witness->is_valid())
4 ✔
191
    {
192
        const auto size = witness->serialized_size(false);
3 ✔
193
        switch (media)
3 ✔
194
        {
195
            case data:
1 ✔
196
                send_chunk(to_bin(*witness, size, false));
1 ✔
197
                return;
1 ✔
198
            case text:
1 ✔
199
                send_text(to_hex(*witness, size, false));
1 ✔
200
                return;
1 ✔
201
            case json:
1 ✔
202
                send_json(value_from(witness));
1 ✔
203
                return;
1 ✔
204
        }
205
    }
4 ✔
206

207
    send_not_found();
1 ✔
208
}
5 ✔
209

210
BC_POP_WARNING()
211
BC_POP_WARNING()
212

213
} // namespace server
214
} // 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