Skip to content

Commit 4221eaf

Browse files
authored
Merge pull request #533 from evoskuil/master
Rename prevouts table to prevout, define schema and read/write.
2 parents 537f725 + 96cc113 commit 4221eaf

File tree

12 files changed

+128
-257
lines changed

12 files changed

+128
-257
lines changed

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test_libbitcoin_database_test_SOURCES = \
100100
test/tables/archives/spend.cpp \
101101
test/tables/archives/transaction.cpp \
102102
test/tables/archives/txs.cpp \
103-
test/tables/caches/prevouts.cpp \
103+
test/tables/caches/prevout.cpp \
104104
test/tables/caches/validated_bk.cpp \
105105
test/tables/caches/validated_tx.cpp \
106106
test/tables/indexes/height.cpp \
@@ -237,7 +237,7 @@ include_bitcoin_database_tables_archives_HEADERS = \
237237

238238
include_bitcoin_database_tables_cachesdir = ${includedir}/bitcoin/database/tables/caches
239239
include_bitcoin_database_tables_caches_HEADERS = \
240-
include/bitcoin/database/tables/caches/prevouts.hpp \
240+
include/bitcoin/database/tables/caches/prevout.hpp \
241241
include/bitcoin/database/tables/caches/validated_bk.hpp \
242242
include/bitcoin/database/tables/caches/validated_tx.hpp
243243

builds/cmake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ if (with-tests)
308308
"../../test/tables/archives/spend.cpp"
309309
"../../test/tables/archives/transaction.cpp"
310310
"../../test/tables/archives/txs.cpp"
311-
"../../test/tables/caches/prevouts.cpp"
311+
"../../test/tables/caches/prevout.cpp"
312312
"../../test/tables/caches/validated_bk.cpp"
313313
"../../test/tables/caches/validated_tx.cpp"
314314
"../../test/tables/indexes/height.cpp"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<ClCompile Include="..\..\..\..\test\tables\archives\spend.cpp" />
112112
<ClCompile Include="..\..\..\..\test\tables\archives\transaction.cpp" />
113113
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp" />
114-
<ClCompile Include="..\..\..\..\test\tables\caches\prevouts.cpp" />
114+
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp" />
115115
<ClCompile Include="..\..\..\..\test\tables\caches\validated_bk.cpp" />
116116
<ClCompile Include="..\..\..\..\test\tables\caches\validated_tx.cpp" />
117117
<ClCompile Include="..\..\..\..\test\tables\indexes\height.cpp" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp">
157157
<Filter>src\tables\archives</Filter>
158158
</ClCompile>
159-
<ClCompile Include="..\..\..\..\test\tables\caches\prevouts.cpp">
159+
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp">
160160
<Filter>src\tables\caches</Filter>
161161
</ClCompile>
162162
<ClCompile Include="..\..\..\..\test\tables\caches\validated_bk.cpp">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\spend.hpp" />
134134
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\transaction.hpp" />
135135
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp" />
136-
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevouts.hpp" />
136+
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp" />
137137
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_bk.hpp" />
138138
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_tx.hpp" />
139139
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\context.hpp" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp">
243243
<Filter>include\bitcoin\database\tables\archives</Filter>
244244
</ClInclude>
245-
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevouts.hpp">
245+
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp">
246246
<Filter>include\bitcoin\database\tables\caches</Filter>
247247
</ClInclude>
248248
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_bk.hpp">

include/bitcoin/database.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#include <bitcoin/database/tables/archives/spend.hpp>
6565
#include <bitcoin/database/tables/archives/transaction.hpp>
6666
#include <bitcoin/database/tables/archives/txs.hpp>
67-
#include <bitcoin/database/tables/caches/prevouts.hpp>
67+
#include <bitcoin/database/tables/caches/prevout.hpp>
6868
#include <bitcoin/database/tables/caches/validated_bk.hpp>
6969
#include <bitcoin/database/tables/caches/validated_tx.hpp>
7070
#include <bitcoin/database/tables/indexes/height.hpp>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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_TABLES_OPTIONALS_BUFFER_HPP
20+
#define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_BUFFER_HPP
21+
22+
#include <bitcoin/system.hpp>
23+
#include <bitcoin/database/define.hpp>
24+
#include <bitcoin/database/primitives/primitives.hpp>
25+
#include <bitcoin/database/tables/schema.hpp>
26+
27+
namespace libbitcoin {
28+
namespace database {
29+
namespace table {
30+
31+
/// prevout is an array map index of previous outputs by block.
32+
struct prevout
33+
: public array_map<schema::prevout>
34+
{
35+
using tx = linkage<schema::tx>;
36+
using spend = linkage<schema::spend_>;
37+
using array_map<schema::prevout>::arraymap;
38+
39+
struct record
40+
: public schema::prevout
41+
{
42+
inline bool from_data(reader& source) NOEXCEPT
43+
{
44+
coinbase = source.read_byte();
45+
spend_fk = source.read_little_endian<spend::integer, spend::size>();
46+
output_tx_fk = source.read_little_endian<tx::integer, tx::size>();
47+
BC_ASSERT(source.get_read_position() == count());
48+
return source;
49+
}
50+
51+
inline bool to_data(finalizer& sink) const NOEXCEPT
52+
{
53+
sink.write_byte(coinbase);
54+
sink.write_little_endian<spend::integer, spend::size>(spend_fk);
55+
sink.write_little_endian<tx::integer, tx::size>(output_tx_fk);
56+
BC_ASSERT(sink.get_write_position() == count());
57+
return sink;
58+
}
59+
60+
inline bool operator==(const record& other) const NOEXCEPT
61+
{
62+
return coinbase == other.coinbase
63+
&& spend_fk == other.spend_fk
64+
&& output_tx_fk == other.output_tx_fk;
65+
}
66+
67+
bool coinbase{};
68+
spend::integer spend_fk{};
69+
tx::integer output_tx_fk{};
70+
};
71+
};
72+
73+
} // namespace table
74+
} // namespace database
75+
} // namespace libbitcoin
76+
77+
#endif

include/bitcoin/database/tables/caches/prevouts.hpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

include/bitcoin/database/tables/schema.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace schema
6363

6464
namespace caches
6565
{
66+
constexpr auto prevout = "prevout";
6667
constexpr auto validated_bk = "validated_bk";
6768
constexpr auto validated_tx = "validated_tx";
6869
}
@@ -120,7 +121,6 @@ namespace schema
120121
constexpr size_t bk_slab = 3; // ->validated_bk record.
121122
constexpr size_t tx_slab = 5; // ->validated_tk record.
122123
constexpr size_t neutrino_ = 5; // ->neutrino record.
123-
////constexpr size_t buffer_ = 5; // ->buffer record (guestimate).
124124

125125
/// Search keys.
126126
constexpr size_t hash = system::hash_size;
@@ -355,6 +355,22 @@ namespace schema
355355
static_assert(minrow == 23u);
356356
};
357357

358+
// record arraymap
359+
struct prevout
360+
{
361+
static constexpr size_t pk = schema::spend_;
362+
static constexpr size_t sk = zero;
363+
static constexpr size_t minsize =
364+
schema::bit + // TODO: merge bit.
365+
schema::spend_ +
366+
schema::tx;
367+
static constexpr size_t minrow = minsize;
368+
static constexpr size_t size = minsize;
369+
static constexpr linkage<pk> count() NOEXCEPT { return 1; }
370+
static_assert(minsize == 9u);
371+
static_assert(minrow == 9u);
372+
};
373+
358374
// slab hashmap
359375
struct neutrino
360376
{

0 commit comments

Comments
 (0)