Skip to content

Commit d605fe9

Browse files
committed
Add is_block_segregated and is_tx_segregated, test.
1 parent 86ba41b commit d605fe9

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ inline bool CLASS::is_coinbase(const tx_link& link) const NOEXCEPT
5656
return store_.tx.get(link, tx) && tx.coinbase;
5757
}
5858

59+
TEMPLATE
60+
inline bool CLASS::is_tx_segregated(const tx_link& link) const NOEXCEPT
61+
{
62+
size_t light{}, heavy{};
63+
return get_tx_sizes(light, heavy, link) && heavy != light;
64+
}
65+
66+
TEMPLATE
67+
inline bool CLASS::is_block_segregated(const header_link& link) const NOEXCEPT
68+
{
69+
size_t light{}, heavy{};
70+
return get_block_sizes(light, heavy, link) && heavy != light;
71+
}
72+
5973
TEMPLATE
6074
inline bool CLASS::is_milestone(const header_link& link) const NOEXCEPT
6175
{

include/bitcoin/database/query.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ class query
326326
inline bool is_block(const hash_digest& key) const NOEXCEPT;
327327
inline bool is_tx(const hash_digest& key) const NOEXCEPT;
328328
inline bool is_coinbase(const tx_link& link) const NOEXCEPT;
329+
inline bool is_tx_segregated(const tx_link& link) const NOEXCEPT;
330+
inline bool is_block_segregated(const header_link& link) const NOEXCEPT;
329331
inline bool is_milestone(const header_link& link) const NOEXCEPT;
330332
inline bool is_associated(const header_link& link) const NOEXCEPT;
331333
inline bool is_confirmable(const header_link& link) const NOEXCEPT;

test/query/archive_read.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static_assert(is_same_type<database::context::flag_t::integer, decltype(system::
2828
// nop event handler.
2929
const auto events_handler = [](auto, auto) {};
3030

31+
// is_coinbase
32+
3133
BOOST_AUTO_TEST_CASE(query_archive_read__is_coinbase__coinbase__true)
3234
{
3335
settings settings{};
@@ -63,6 +65,40 @@ BOOST_AUTO_TEST_CASE(query_archive_read__is_coinbase__non_coinbase__false)
6365
BOOST_REQUIRE(!query.is_coinbase(42));
6466
}
6567

68+
// is_tx_segregated
69+
70+
BOOST_AUTO_TEST_CASE(query_archive_read__is_tx_segregated__always__expected)
71+
{
72+
settings settings{};
73+
settings.path = TEST_DIRECTORY;
74+
test::chunk_store store{ settings };
75+
test::query_accessor query{ store };
76+
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
77+
BOOST_REQUIRE(query.initialize(test::genesis));
78+
BOOST_REQUIRE(query.set(test::block1a, context{}, false, false));
79+
BOOST_REQUIRE(!query.is_tx_segregated(0));
80+
BOOST_REQUIRE( query.is_tx_segregated(1));
81+
BOOST_REQUIRE(!query.is_tx_segregated(2));
82+
}
83+
84+
// is_block_segregated
85+
86+
BOOST_AUTO_TEST_CASE(query_archive_read__is_block_segregated__always__expected)
87+
{
88+
settings settings{};
89+
settings.path = TEST_DIRECTORY;
90+
test::chunk_store store{ settings };
91+
test::query_accessor query{ store };
92+
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
93+
BOOST_REQUIRE(query.initialize(test::genesis));
94+
BOOST_REQUIRE(query.set(test::block1a, context{}, false, false));
95+
BOOST_REQUIRE(!query.is_block_segregated(0));
96+
BOOST_REQUIRE( query.is_block_segregated(1));
97+
BOOST_REQUIRE(!query.is_block_segregated(2));
98+
}
99+
100+
// is_milestone
101+
66102
BOOST_AUTO_TEST_CASE(query_archive_read__is_milestone__genesis__false)
67103
{
68104
settings settings{};

0 commit comments

Comments
 (0)