Skip to content

Commit

Permalink
Merge pull request #403 from evoskuil/master
Browse files Browse the repository at this point in the history
Add and test get_context_and_timestamp.
  • Loading branch information
evoskuil authored Feb 25, 2024
2 parents db6149c + ee6b657 commit 1924e40
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ bool CLASS::get_context(context& ctx,
return true;
}

TEMPLATE
bool CLASS::get_context_and_timestamp(context& ctx, uint32_t& timestamp,
const header_link& link) const NOEXCEPT
{
table::header::get_context_and_timestamp header{};
if (!store_.header.get(link, header))
return false;

ctx = std::move(header.ctx);
timestamp = header.timestamp;
return true;
}

TEMPLATE
code CLASS::get_block_state(const header_link& link) const NOEXCEPT
{
Expand Down
4 changes: 3 additions & 1 deletion include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ class query

bool get_timestamp(uint32_t& timestamp, const header_link& link) const NOEXCEPT;
bool get_version(uint32_t& version, const header_link& link) const NOEXCEPT;
bool get_context(context& ctx, const header_link& link) const NOEXCEPT;
bool get_bits(uint32_t& bits, const header_link& link) const NOEXCEPT;
bool get_context(context& ctx, const header_link& link) const NOEXCEPT;
bool get_context_and_timestamp(context& ctx, uint32_t& timestamp,
const header_link& link) const NOEXCEPT;

bool set_block_preconfirmable(const header_link& link) NOEXCEPT;
bool set_block_unconfirmable(const header_link& link) NOEXCEPT;
Expand Down
15 changes: 15 additions & 0 deletions include/bitcoin/database/tables/archives/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ struct header
uint32_t mtp{};
};

struct get_context_and_timestamp
: public schema::header
{
inline bool from_data(reader& source) NOEXCEPT
{
context::from_data(source, ctx);
source.skip_bytes(link::size + sizeof(uint32_t));
timestamp = source.read_little_endian<uint32_t>();
return source;
}

context ctx{};
uint32_t timestamp{};
};

struct record_context
: public schema::header
{
Expand Down
5 changes: 5 additions & 0 deletions test/tables/archives/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ BOOST_AUTO_TEST_CASE(header__put__get_context__expected)
table::header::record_context context{};
BOOST_REQUIRE(instance.get(1, context));
BOOST_REQUIRE(context.ctx == expected.ctx);

table::header::get_context_and_timestamp context_and_timestamp{};
BOOST_REQUIRE(instance.get(1, context_and_timestamp));
BOOST_REQUIRE(context_and_timestamp.ctx == expected.ctx);
BOOST_REQUIRE_EQUAL(context_and_timestamp.timestamp, expected.timestamp);
}

BOOST_AUTO_TEST_CASE(header__it__pk__expected)
Expand Down

0 comments on commit 1924e40

Please sign in to comment.