From 585ad26e024299be04759ba35ef55edde2ec8177 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 17 Dec 2025 21:46:52 -0500 Subject: [PATCH] Add is_validateable(). --- include/bitcoin/database/impl/query/validate.ipp | 13 +++++++++++++ include/bitcoin/database/query.hpp | 1 + 2 files changed, 14 insertions(+) diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index 86ec1f26..4b14445d 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -29,6 +29,19 @@ namespace database { // States. // ---------------------------------------------------------------------------- +TEMPLATE +bool CLASS::is_validateable(size_t height) const NOEXCEPT +{ + const auto ec = get_block_state(to_candidate(height)); + + // First block state should be unvalidated, valid, or confirmable. + return + (ec == database::error::unvalidated) || + (ec == database::error::block_valid) || + (ec == database::error::unknown_state) || + (ec == database::error::block_confirmable); +} + // protected TEMPLATE inline code CLASS::to_block_code( diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 8ee9b3a5..4f796904 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -457,6 +457,7 @@ class query /// ----------------------------------------------------------------------- /// States. + bool is_validateable(size_t height) const NOEXCEPT; uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT; uint64_t get_block_fees(const header_link& link) const NOEXCEPT; code get_block_state(const header_link& link) const NOEXCEPT;