From 7d74ffdbf786713a6213640d26f240dcfece28e3 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 1 Dec 2025 16:33:18 -0500 Subject: [PATCH] Add to_transaction(header_link, position). --- .../bitcoin/database/impl/query/translate.ipp | 27 ++++++++++++------ include/bitcoin/database/query.hpp | 4 ++- .../bitcoin/database/tables/archives/txs.hpp | 28 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/bitcoin/database/impl/query/translate.ipp b/include/bitcoin/database/impl/query/translate.ipp index 05d3cbd62..516fb22f9 100644 --- a/include/bitcoin/database/impl/query/translate.ipp +++ b/include/bitcoin/database/impl/query/translate.ipp @@ -411,19 +411,19 @@ output_links CLASS::to_block_prevouts(const header_link& link) const NOEXCEPT // ---------------------------------------------------------------------------- TEMPLATE -tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT +tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT { - table::txs::get_coinbase txs{}; + table::txs::get_txs txs{}; if (!store_.txs.at(to_txs(link), txs)) return {}; - return txs.coinbase_fk; + return std::move(txs.tx_fks); } TEMPLATE -tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT +tx_links CLASS::to_spending_txs(const header_link& link) const NOEXCEPT { - table::txs::get_txs txs{}; + table::txs::get_spending_txs txs{}; if (!store_.txs.at(to_txs(link), txs)) return {}; @@ -431,13 +431,24 @@ tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT } TEMPLATE -tx_links CLASS::to_spending_txs(const header_link& link) const NOEXCEPT +tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT { - table::txs::get_spending_txs txs{}; + table::txs::get_coinbase txs{}; if (!store_.txs.at(to_txs(link), txs)) return {}; - return std::move(txs.tx_fks); + return txs.coinbase_fk; +} + +TEMPLATE +tx_link CLASS::to_transaction(const header_link& link, + size_t position) const NOEXCEPT +{ + table::txs::get_tx txs{ {}, position }; + if (!store_.txs.at(to_txs(link), txs)) + return {}; + + return txs.tx_fk; } // header to arraymap tables (guard domain transitions) diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index f1cfe2d90..fab2f245d 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -314,9 +314,11 @@ class query output_links to_block_prevouts(const header_link& link) const NOEXCEPT; /// block to txs (forward navigation) - tx_link to_coinbase(const header_link& link) const NOEXCEPT; tx_links to_transactions(const header_link& link) const NOEXCEPT; tx_links to_spending_txs(const header_link& link) const NOEXCEPT; + tx_link to_coinbase(const header_link& link) const NOEXCEPT; + tx_link to_transaction(const header_link& link, + size_t position) const NOEXCEPT; /// header to arraymap tables (guard domain transitions) constexpr size_t to_validated_bk(const header_link& link) const NOEXCEPT; diff --git a/include/bitcoin/database/tables/archives/txs.hpp b/include/bitcoin/database/tables/archives/txs.hpp index 4fa536bbb..ad61f7b5d 100644 --- a/include/bitcoin/database/tables/archives/txs.hpp +++ b/include/bitcoin/database/tables/archives/txs.hpp @@ -171,6 +171,34 @@ struct txs tx::integer coinbase_fk{}; }; + struct get_tx + : public schema::txs + { + link count() const NOEXCEPT + { + BC_ASSERT(false); + return {}; + } + + inline bool from_data(reader& source) NOEXCEPT + { + const auto number = source.read_little_endian(); + source.skip_bytes(bytes::size); + if (number > position) + { + source.skip_bytes(position * tx::size); + tx_fk = source.read_little_endian(); + return source; + } + + source.invalidate(); + return source; + } + + const size_t position{}; + tx::integer tx_fk{}; + }; + struct get_block_size : public schema::txs {