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

libbitcoin / libbitcoin-system / 18823651969

26 Oct 2025 09:01PM UTC coverage: 80.946% (+0.04%) from 80.903%
18823651969

push

github

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

Simplify and optimize JSON annotation defines.

104 of 136 new or added lines in 16 files covered. (76.47%)

1 existing line in 1 file now uncovered.

10591 of 13084 relevant lines covered (80.95%)

3619070.67 hits per line

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

79.55
/src/chain/point.cpp
1
/**
2
 * Copyright (c) 2011-2025 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/point.hpp>
20

21
#include <utility>
22
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
23
#include <bitcoin/system/define.hpp>
24
#include <bitcoin/system/math/math.hpp>
25
#include <bitcoin/system/stream/stream.hpp>
26

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

31
// This sentinel is serialized and defined by consensus, not implementation.
32
const uint32_t point::null_index = no_previous_output;
33

34
// Constructors.
35
// ----------------------------------------------------------------------------
36

37
// Invalid default used in signature hashing.
38
point::point() NOEXCEPT
887✔
39
  : point(null_hash, point::null_index, false)
40
{
41
}
887✔
42

43
point::point(hash_digest&& hash, uint32_t index) NOEXCEPT
34✔
44
  : point(std::move(hash), index, true)
45
{
46
}
28✔
47

48
point::point(const hash_digest& hash, uint32_t index) NOEXCEPT
59✔
49
  : point(hash, index, true)
50
{
51
}
59✔
52

53
point::point(stream::in::fast&& stream) NOEXCEPT
1✔
54
  : point(read::bytes::fast(stream))
1✔
55
{
56
}
1✔
57

58
point::point(stream::in::fast& stream) NOEXCEPT
×
59
  : point(read::bytes::fast(stream))
×
60
{
61
}
×
62

63
point::point(std::istream&& stream) NOEXCEPT
×
64
  : point(read::bytes::istream(stream))
×
65
{
66
}
×
67

68
point::point(std::istream& stream) NOEXCEPT
2✔
69
  : point(read::bytes::istream(stream))
2✔
70
{
71
}
2✔
72

73
point::point(reader&& source) NOEXCEPT
3✔
74
  : point(source)
3✔
75
{
76
}
×
77

78
point::point(reader& source) NOEXCEPT
283✔
79
{
80
    assign_data(source);
283✔
81
}
283✔
82

83
// protected
84
point::point(hash_digest&& hash, uint32_t index, bool valid) NOEXCEPT
34✔
85
  : hash_(std::move(hash)), index_(index), valid_(valid)
34✔
86
{
87
}
×
88

89
// protected
90
point::point(const hash_digest& hash, uint32_t index, bool valid) NOEXCEPT
946✔
91
  : hash_(hash), index_(index), valid_(valid)
946✔
92
{
93
}
×
94

95
// Operators.
96
// ----------------------------------------------------------------------------
97

98
bool point::operator==(const point& other) const NOEXCEPT
74✔
99
{
100
    return (hash_ == other.hash_)
74✔
101
        && (index_ == other.index_);
74✔
102
}
103

104
bool point::operator!=(const point& other) const NOEXCEPT
2✔
105
{
106
    return !(*this == other);
2✔
107
}
108

109
bool operator<(const point& left, const point& right) NOEXCEPT
8✔
110
{
111
    // Arbitrary compare, for uniqueness sorting.
112
    return left.index() == right.index() ?
5✔
113
        left.hash() < right.hash() :
3✔
114
        left.index() < right.index();
8✔
115
}
116

117
// Constant reference optimizers.
118

119
bool operator<(const point_cref& left, const point_cref& right) NOEXCEPT
×
120
{
121
    return left.get() < right.get();
×
122
}
123

124
bool operator==(const point_cref& left, const point_cref& right) NOEXCEPT
5✔
125
{
126
    return left.get() == right.get();
5✔
127
}
128

129
bool operator!=(const point_cref& left, const point_cref& right) NOEXCEPT
×
130
{
131
    return !(left == right);
×
132
}
133

134

135
// Deserialization.
136
// ----------------------------------------------------------------------------
137

138
// private
139
void point::assign_data(reader& source) NOEXCEPT
283✔
140
{
141
    source.read_bytes(hash_.data(), hash_size);
283✔
142
    index_ = source.read_4_bytes_little_endian();
283✔
143
    valid_ = source;
283✔
144
}
283✔
145

146
// Serialization.
147
// ----------------------------------------------------------------------------
148

149
data_chunk point::to_data() const NOEXCEPT
1✔
150
{
151
    data_chunk data(serialized_size());
1✔
152
    stream::out::fast ostream(data);
1✔
153
    write::bytes::fast out(ostream);
1✔
154
    to_data(out);
1✔
155
    return data;
2✔
156
}
1✔
157

158
void point::to_data(std::ostream& stream) const NOEXCEPT
1✔
159
{
160
    write::bytes::ostream out(stream);
1✔
161
    to_data(out);
1✔
162
}
1✔
163

164
void point::to_data(writer& sink) const NOEXCEPT
1,445✔
165
{
166
    sink.write_bytes(hash_);
1,445✔
167
    sink.write_4_bytes_little_endian(index_);
1,445✔
168
}
1,445✔
169

170
// Properties.
171
// ----------------------------------------------------------------------------
172

173
bool point::is_valid() const NOEXCEPT
7✔
174
{
175
    return valid_;
7✔
176
}
177

178
const hash_digest& point::hash() const NOEXCEPT
40✔
179
{
180
    return hash_;
3✔
181
}
182

183
uint32_t point::index() const NOEXCEPT
41✔
184
{
185
    return index_;
20✔
186
}
187

188
// Validation.
189
// ----------------------------------------------------------------------------
190

191
bool point::is_null() const NOEXCEPT
70✔
192
{
193
    return (index_ == null_index) && (hash_ == null_hash);
70✔
194
}
195

196
// JSON value convertors.
197
// ----------------------------------------------------------------------------
198

199
DEFINE_JSON_TO_TAG(point)
6✔
200
{
201
    return
6✔
202
    {
203
        decode_hash<hash_size>(value.at("hash").as_string()),
6✔
204
        value.at("index").to_number<uint32_t>()
6✔
205
    };
6✔
206
}
207

208
DEFINE_JSON_FROM_TAG(point)
12✔
209
{
210
    value =
36✔
211
    {
212
        { "hash", encode_hash(instance.hash()) },
12✔
213
        { "index", instance.index() }
214
    };
12✔
215
}
12✔
216

NEW
217
DEFINE_JSON_TO_TAG(point::cptr)
×
218
{
NEW
219
    return to_shared(tag_invoke(to_tag<point>{}, value));
×
220
}
221

NEW
222
DEFINE_JSON_FROM_TAG(point::cptr)
×
223
{
NEW
224
    tag_invoke(from_tag{}, value, *instance);
×
225
}
×
226

227
} // namespace chain
228
} // namespace system
229
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc