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

libbitcoin / libbitcoin-system / 23122982107

16 Mar 2026 12:30AM UTC coverage: 81.516% (+0.2%) from 81.295%
23122982107

push

github

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

Implement basic bitcoind serialization annotations/tests.

139 of 153 new or added lines in 10 files covered. (90.85%)

11149 of 13677 relevant lines covered (81.52%)

3465166.92 hits per line

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

80.0
/src/chain/json/input.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS)
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/system/chain/json/json.hpp>
20

21
#include <ranges>
22
#include <bitcoin/system/chain/input.hpp>
23
#include <bitcoin/system/chain/point.hpp>
24
#include <bitcoin/system/chain/script.hpp>
25
#include <bitcoin/system/chain/witness.hpp>
26
#include <bitcoin/system/define.hpp>
27

28
namespace libbitcoin {
29
namespace system {
30
namespace chain {
31

32
DEFINE_JSON_TO_TAG(input)
5✔
33
{
34
    return
5✔
35
    {
36
        value_to<point>(value.at("point")),
5✔
37
        value_to<script>(value.at("script")),
10✔
38
        value_to<witness>(value.at("witness")),
10✔
39
        value.at("sequence").to_number<uint32_t>()
10✔
40
    };
10✔
41
}
42

43
DEFINE_JSON_FROM_TAG(input)
10✔
44
{
45
    if (instance.witness().is_valid())
10✔
46
    {
47
        value =
40✔
48
        {
49
            { "point", value_from(instance.point()) },
20✔
50
            { "script", value_from(instance.script()) },
20✔
51
            { "witness", value_from(instance.witness()) },
20✔
52
            { "sequence", instance.sequence() }
53
        };
10✔
54
    }
55
    else
56
    {
57
        value =
×
58
        {
59
            { "point", value_from(instance.point()) },
×
60
            { "script", value_from(instance.script()) },
×
61
            { "sequence", instance.sequence() }
62
        };
×
63
    }
64
}
10✔
65

66
DEFINE_JSON_TO_TAG(input::cptr)
×
67
{
68
    return to_shared(tag_invoke(to_tag<input>{}, value));
×
69
}
70

71
DEFINE_JSON_FROM_TAG(input::cptr)
8✔
72
{
73
    tag_invoke(from_tag{}, value, *instance);
8✔
74
}
8✔
75

76
// bitcoind
77
// ----------------------------------------------------------------------------
78

79
DEFINE_JSON_FROM_TAGGED(bitcoind_tag, input)
2✔
80
{
81
    const auto& in = instance.value;
2✔
82
    if (in.is_coinbase())
2✔
83
    {
NEW
84
        value =
×
85
        {
NEW
86
            { "coinbase", encode_base16(in.script().to_data(false)) },
×
87
            { "sequence", in.sequence() }
NEW
88
        };
×
89
    }
90
    else
91
    {
92
        value =
8✔
93
        {
94
            { "txid", encode_hash(in.point().hash()) },
2✔
95
            { "vout", in.point().index() },
2✔
96
            { "scriptSig", value_from(bitcoind(in.script())) },
4✔
97
            { "sequence", in.sequence() }
98
        };
2✔
99

100
        if (!in.witness().stack().empty())
2✔
101
            value.as_object()["txinwitness"] = value_from(bitcoind(in.witness()));
4✔
102
    }
103
}
2✔
104

105
DEFINE_JSON_FROM_TAGGED(bitcoind_tag, input_cptrs)
1✔
106
{
107
    const auto& ins = instance.value;
1✔
108
    value = boost::json::array(ins.size());
1✔
109
    std::ranges::transform(ins, value.as_array().begin(),
2✔
110
        [](const chain::input::cptr& in) NOEXCEPT
2✔
111
        {
112
            return value_from(bitcoind(*in));
2✔
113
        });
114
}
1✔
115

116
} // namespace chain
117
} // namespace system
118
} // 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