Skip to content

Commit 3432575

Browse files
authored
Merge pull request #694 from evoskuil/master
Create separate header for namespace level typedefs.
2 parents f708fca + 509b66b commit 3432575

File tree

8 files changed

+116
-58
lines changed

8 files changed

+116
-58
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ include_bitcoin_database_HEADERS = \
144144
include/bitcoin/database/query.hpp \
145145
include/bitcoin/database/settings.hpp \
146146
include/bitcoin/database/store.hpp \
147+
include/bitcoin/database/types.hpp \
147148
include/bitcoin/database/version.hpp
148149

149150
include_bitcoin_database_filedir = ${includedir}/bitcoin/database/file

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\states.hpp" />
198198
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\table.hpp" />
199199
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\tables.hpp" />
200+
<ClInclude Include="..\..\..\..\include\bitcoin\database\types.hpp" />
200201
<ClInclude Include="..\..\..\..\include\bitcoin\database\version.hpp" />
201202
<ClInclude Include="..\..\..\..\src\memory\mman-win32\mman.hpp" />
202203
</ItemGroup>

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@
290290
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\tables.hpp">
291291
<Filter>include\bitcoin\database\tables</Filter>
292292
</ClInclude>
293+
<ClInclude Include="..\..\..\..\include\bitcoin\database\types.hpp">
294+
<Filter>include\bitcoin\database</Filter>
295+
</ClInclude>
293296
<ClInclude Include="..\..\..\..\include\bitcoin\database\version.hpp">
294297
<Filter>include\bitcoin\database</Filter>
295298
</ClInclude>

include/bitcoin/database.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <bitcoin/database/query.hpp>
2222
#include <bitcoin/database/settings.hpp>
2323
#include <bitcoin/database/store.hpp>
24+
#include <bitcoin/database/types.hpp>
2425
#include <bitcoin/database/version.hpp>
2526
#include <bitcoin/database/file/file.hpp>
2627
#include <bitcoin/database/file/rotator.hpp>

include/bitcoin/database/impl/query/consensus.ipp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ bool CLASS::is_strong(const tx_link& tx) const NOEXCEPT
185185

186186
// protected
187187
TEMPLATE
188-
error::error_t CLASS::unspendable(uint32_t sequence, bool coinbase,
188+
code CLASS::unspendable(uint32_t sequence, bool coinbase,
189189
const tx_link& tx, uint32_t version, const context& ctx) const NOEXCEPT
190190
{
191191
// Ensure prevout tx is in a strong block, first try self link.
@@ -317,27 +317,27 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
317317

318318
// Get points for each tx, and sum the total number.
319319
std::transform(parallel, txs.begin(), txs.end(), sets.begin(), to_set);
320-
if (failure)
321-
return { failure.load() };
320+
if (failure != error::success)
321+
return failure.load();
322322

323323
// Check double spends strength, populates prevout parent tx/cb/sq links.
324324
if ((ec = populate_prevouts(sets, points, link)))
325325
return ec;
326326

327-
const auto is_unspendable = [this, &ctx, &failure](const auto& set) NOEXCEPT
327+
const auto is_spendable = [this, &ctx, &failure](const auto& set) NOEXCEPT
328328
{
329-
error::error_t ec{};
329+
code ec{};
330330
for (const auto& point: set.points)
331331
if (!point.tx.is_terminal() && ((ec = unspendable(point.sequence,
332332
point.coinbase, point.tx, set.version, ctx))))
333-
failure.store(ec);
333+
failure.store(static_cast<error::error_t>(ec.value()));
334334

335-
return failure != error::success;
335+
return failure == error::success;
336336
};
337337

338338
// Check all spends for spendability (strong, unlocked and mature).
339-
if (std::any_of(parallel, sets.begin(), sets.end(), is_unspendable))
340-
return { failure.load() };
339+
if (!std::all_of(parallel, sets.begin(), sets.end(), is_spendable))
340+
return failure.load();
341341

342342
return error::success;
343343
}

include/bitcoin/database/impl/query/objects.ipp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,27 @@ typename CLASS::output::cptr CLASS::get_output(
305305
}
306306

307307
TEMPLATE
308-
typename CLASS::outpoint CLASS::get_spent(
309-
const output_link& link) const NOEXCEPT
308+
typename CLASS::inputs_ptr CLASS::get_spenders(
309+
const output_link& link, bool witness) const NOEXCEPT
310+
{
311+
using namespace system;
312+
const auto point_fks = to_spenders(link);
313+
const auto inputs = to_shared<chain::input_cptrs>();
314+
inputs->reserve(point_fks.size());
315+
316+
// TODO: eliminate shared memory pointer reallocation.
317+
for (const auto& point_fk: point_fks)
318+
if (!push_bool(*inputs, get_input(point_fk, witness)))
319+
return {};
320+
321+
return inputs;
322+
}
323+
324+
// Inpoint and outpoint result sets.
325+
// ----------------------------------------------------------------------------
326+
327+
TEMPLATE
328+
outpoint CLASS::get_spent(const output_link& link) const NOEXCEPT
310329
{
311330
table::output::get_parent_value out{};
312331
if (!store_.output.get(link, out))
@@ -320,34 +339,28 @@ typename CLASS::outpoint CLASS::get_spent(
320339
}
321340

322341
TEMPLATE
323-
typename CLASS::point CLASS::get_spender(const point_link& link) const NOEXCEPT
342+
inpoint CLASS::get_spender(const point_link& link) const NOEXCEPT
324343
{
325-
const auto tx = to_spending_tx(link);
326-
if (tx.is_terminal())
344+
const auto tx_fk = to_spending_tx(link);
345+
if (tx_fk.is_terminal())
327346
return {};
328347

329-
const auto index = to_input_index(tx, link);
348+
const auto index = to_input_index(tx_fk, link);
330349
if (index == point::null_index)
331350
return {};
332351

333-
return { get_tx_key(tx), index };
352+
return { get_tx_key(tx_fk), index };
334353
}
335354

336355
TEMPLATE
337-
typename CLASS::inputs_ptr CLASS::get_spenders(
338-
const output_link& link, bool witness) const NOEXCEPT
356+
inpoints CLASS::get_spenders(const point& point) const NOEXCEPT
339357
{
340-
using namespace system;
341-
const auto point_fks = to_spenders(link);
342-
const auto inputs = to_shared<chain::input_cptrs>();
343-
inputs->reserve(point_fks.size());
344-
345-
// TODO: eliminate shared memory pointer reallocation.
346-
for (const auto& point_fk: point_fks)
347-
if (!push_bool(*inputs, get_input(point_fk, witness)))
348-
return {};
358+
inpoints ins{};
359+
for (const auto& point_fk: to_spenders(point))
360+
ins.insert(get_spender(point_fk));
349361

350-
return inputs;
362+
// std::set (lexically sorted/deduped).
363+
return ins;
351364
}
352365

353366
// Populate prevout objects.

include/bitcoin/database/query.hpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,11 @@
2424
#include <utility>
2525
#include <bitcoin/system.hpp>
2626
#include <bitcoin/database/define.hpp>
27-
#include <bitcoin/database/error.hpp>
28-
#include <bitcoin/database/primitives/primitives.hpp>
29-
#include <bitcoin/database/tables/tables.hpp>
27+
#include <bitcoin/database/types.hpp>
3028

3129
namespace libbitcoin {
3230
namespace database {
3331

34-
/// Database type aliases.
35-
using height_link = table::height::link;
36-
using header_link = table::header::link;
37-
using output_link = table::output::link;
38-
using input_link = table::input::link;
39-
using outs_link = table::outs::link;
40-
using ins_link = table::ins::link;
41-
using point_link = table::point::link;
42-
using tx_link = table::transaction::link;
43-
using filter_link = table::filter_tx::link;
44-
using strong_link = table::strong_tx::link;
45-
46-
using header_links = std::vector<header_link::integer>;
47-
using tx_links = std::vector<tx_link::integer>;
48-
using input_links = std::vector<input_link::integer>;
49-
using output_links = std::vector<output_link::integer>;
50-
using point_links = std::vector<point_link::integer>;
51-
using two_counts = std::pair<size_t, size_t>;
52-
using point_key = table::point::key;
53-
54-
struct header_state{ header_link link; code ec; };
55-
using header_states = std::vector<header_state>;
56-
5732
// Writers (non-const) are only: push_, pop_, set_ and initialize.
5833
template <typename Store>
5934
class query
@@ -66,7 +41,6 @@ class query
6641
using point = system::chain::point;
6742
using input = system::chain::input;
6843
using output = system::chain::output;
69-
using outpoint = system::chain::outpoint;
7044
using header = system::chain::header;
7145
using script = system::chain::script;
7246
using witness = system::chain::witness;
@@ -396,14 +370,17 @@ class query
396370
input::cptr get_input(const tx_link& link, uint32_t index,
397371
bool witness) const NOEXCEPT;
398372

399-
point get_spender(const point_link& link) const NOEXCEPT;
400-
outpoint get_spent(const output_link& link) const NOEXCEPT;
401373
script::cptr get_output_script(const output_link& link) const NOEXCEPT;
402374
output::cptr get_output(const output_link& link) const NOEXCEPT;
403375
output::cptr get_output(const tx_link& link, uint32_t index) const NOEXCEPT;
404376
inputs_ptr get_spenders(const output_link& link,
405377
bool witness) const NOEXCEPT;
406378

379+
/// Inpoint and outpoint result sets.
380+
outpoint get_spent(const output_link& link) const NOEXCEPT;
381+
inpoint get_spender(const point_link& link) const NOEXCEPT;
382+
inpoints get_spenders(const point& point) const NOEXCEPT;
383+
407384
/// False implies missing prevouts, node input.metadata is populated.
408385
bool populate_with_metadata(const input& input) const NOEXCEPT;
409386
bool populate_with_metadata(const block& block) const NOEXCEPT;
@@ -652,7 +629,7 @@ class query
652629
const context& ctx) const NOEXCEPT;
653630

654631
/// Called by block_confirmable (populate and check double spends).
655-
error::error_t unspendable(uint32_t sequence, bool coinbase,
632+
code unspendable(uint32_t sequence, bool coinbase,
656633
const tx_link& prevout_tx, uint32_t version,
657634
const context& ctx) const NOEXCEPT;
658635

include/bitcoin/database/types.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
#ifndef LIBBITCOIN_DATABASE_TYPES_HPP
20+
#define LIBBITCOIN_DATABASE_TYPES_HPP
21+
22+
#include <set>
23+
#include <utility>
24+
#include <bitcoin/database/define.hpp>
25+
#include <bitcoin/database/tables/tables.hpp>
26+
27+
namespace libbitcoin {
28+
namespace database {
29+
30+
/// Database type aliases.
31+
using height_link = table::height::link;
32+
using header_link = table::header::link;
33+
using output_link = table::output::link;
34+
using input_link = table::input::link;
35+
using outs_link = table::outs::link;
36+
using ins_link = table::ins::link;
37+
using point_link = table::point::link;
38+
using tx_link = table::transaction::link;
39+
using filter_link = table::filter_tx::link;
40+
using strong_link = table::strong_tx::link;
41+
42+
using header_links = std::vector<header_link::integer>;
43+
using tx_links = std::vector<tx_link::integer>;
44+
using input_links = std::vector<input_link::integer>;
45+
using output_links = std::vector<output_link::integer>;
46+
using point_links = std::vector<point_link::integer>;
47+
using two_counts = std::pair<size_t, size_t>;
48+
using point_key = table::point::key;
49+
50+
struct header_state{ header_link link; code ec; };
51+
using header_states = std::vector<header_state>;
52+
53+
// TODO: define a system::chain::inpoint with added state.
54+
using inpoint = system::chain::point;
55+
using inpoints = std::set<inpoint>;
56+
using outpoint = system::chain::outpoint;
57+
using outpoints = std::set<outpoint>;
58+
59+
} // namespace database
60+
} // namespace libbitcoin
61+
62+
#endif

0 commit comments

Comments
 (0)