From ee6b657c65ae4ae0bd64d3a972204a02aee527b1 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 24 Feb 2024 21:41:23 -0500 Subject: [PATCH] Add and test get_context_and_timestamp. --- include/bitcoin/database/impl/query/validate.ipp | 13 +++++++++++++ include/bitcoin/database/query.hpp | 4 +++- .../bitcoin/database/tables/archives/header.hpp | 15 +++++++++++++++ test/tables/archives/header.cpp | 5 +++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index 9b458171..28b20aa6 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -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 { diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index bdaaaf0e..33b61945 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -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; diff --git a/include/bitcoin/database/tables/archives/header.hpp b/include/bitcoin/database/tables/archives/header.hpp index 5cfdf1f6..225091c6 100644 --- a/include/bitcoin/database/tables/archives/header.hpp +++ b/include/bitcoin/database/tables/archives/header.hpp @@ -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(); + return source; + } + + context ctx{}; + uint32_t timestamp{}; + }; + struct record_context : public schema::header { diff --git a/test/tables/archives/header.cpp b/test/tables/archives/header.cpp index 2dbfd8e6..1e263a88 100644 --- a/test/tables/archives/header.cpp +++ b/test/tables/archives/header.cpp @@ -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)