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

libbitcoin / libbitcoin-system / 14434326165

13 Apr 2025 11:21PM UTC coverage: 82.798% (-0.1%) from 82.939%
14434326165

push

github

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

Move golomb_coding from /crypto to new /filter folder.

62 of 64 new or added lines in 13 files covered. (96.88%)

32 existing lines in 9 files now uncovered.

10190 of 12307 relevant lines covered (82.8%)

3818174.07 hits per line

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

78.89
/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
28✔
44
  : point(std::move(hash), index, true)
45
{
46
}
28✔
47

48
point::point(const hash_digest& hash, uint32_t index) NOEXCEPT
65✔
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

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

UNCOV
63
point::point(std::istream&& stream) NOEXCEPT
×
UNCOV
64
  : point(read::bytes::istream(stream))
×
65
{
UNCOV
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
28✔
85
  : hash_(std::move(hash)), index_(index), valid_(valid)
28✔
86
{
87
}
×
88

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

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

98
bool point::operator==(const point& other) const NOEXCEPT
70✔
99
{
100
    return (hash_ == other.hash_)
70✔
101
        && (index_ == other.index_);
70✔
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
1✔
125
{
126
    return left.get() == right.get();
1✔
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;
1✔
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,454✔
165
{
166
    sink.write_bytes(hash_);
1,454✔
167
    sink.write_4_bytes_little_endian(index_);
1,454✔
168
}
1,454✔
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
37✔
179
{
180
    return hash_;
3✔
181
}
182

183
uint32_t point::index() const NOEXCEPT
38✔
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
namespace json = boost::json;
200

201
// boost/json will soon have NOEXCEPT: github.com/boostorg/json/pull/636
202
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
203

204
point tag_invoke(json::value_to_tag<point>, const json::value& value) NOEXCEPT
6✔
205
{
206
    hash_digest hash;
6✔
207
    if (!decode_hash(hash, value.at("hash").get_string().c_str()))
6✔
208
        return {};
×
209

210
    return
6✔
211
    {
212
        hash,
213
        value.at("index").to_number<uint32_t>()
12✔
214
    };
6✔
215
}
216

217
void tag_invoke(json::value_from_tag, json::value& value,
12✔
218
    const point& point) NOEXCEPT
219
{
220
    value =
36✔
221
    {
222
        { "hash", encode_hash(point.hash()) },
12✔
223
        { "index", point.index() }
224
    };
12✔
225
}
12✔
226

227
BC_POP_WARNING()
228

229
point::cptr tag_invoke(json::value_to_tag<point::cptr>,
×
230
    const json::value& value) NOEXCEPT
231
{
232
    return to_shared(tag_invoke(json::value_to_tag<point>{}, value));
×
233
}
234

235
// Shared pointer overload is required for navigation.
236
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
237
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
238

239
void tag_invoke(json::value_from_tag tag, json::value& value,
×
240
    const point::cptr& output) NOEXCEPT
241
{
242
    tag_invoke(tag, value, *output);
×
243
}
×
244

245
BC_POP_WARNING()
246
BC_POP_WARNING()
247

248
} // namespace chain
249
} // namespace system
250
} // 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