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

libbitcoin / libbitcoin-system / 19162822888

07 Nov 2025 08:37AM UTC coverage: 81.135% (+0.1%) from 80.989%
19162822888

push

github

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

Refactor stream/reader/chain object construction.

68 of 90 new or added lines in 17 files covered. (75.56%)

1 existing line in 1 file now uncovered.

10709 of 13199 relevant lines covered (81.13%)

3587823.84 hits per line

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

82.95
/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(const data_slice& data) NOEXCEPT
1✔
54
  : point(stream::in::fast(data))
1✔
55
{
56
}
1✔
57

58
// protected
59
point::point(stream::in::fast&& stream) NOEXCEPT
1✔
60
  : point(read::bytes::fast(stream))
1✔
61
{
62
}
1✔
63

NEW
64
point::point(stream::in::fast& stream) NOEXCEPT
×
NEW
65
  : point(read::bytes::fast(stream))
×
66
{
67
}
×
68
point::point(std::istream& stream) NOEXCEPT
2✔
69
  : point(read::bytes::istream(stream))
2✔
70
{
71
}
2✔
72

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

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

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

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

96
// Operators.
97
// ----------------------------------------------------------------------------
98

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

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

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

118
// Constant reference optimizers.
119

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

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

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

135

136
// Deserialization.
137
// ----------------------------------------------------------------------------
138

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

147
// Serialization.
148
// ----------------------------------------------------------------------------
149

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

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

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

171
// Properties.
172
// ----------------------------------------------------------------------------
173

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

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

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

189
// Validation.
190
// ----------------------------------------------------------------------------
191

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

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

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

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

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

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

228
} // namespace chain
229
} // namespace system
230
} // 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