diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index 7d2927c2..12f0a6cb 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -678,14 +678,6 @@ typename CLASS::inputs_ptr CLASS::get_spenders(const tx_link& link, // ---------------------------------------------------------------------------- // The only multitable write query (except initialize/genesis). -// deprecated -TEMPLATE -tx_link CLASS::set_link(const transaction& tx) NOEXCEPT -{ - tx_link tx_fk{}; - return set_code(tx_fk, tx) ? tx_link{} : tx_fk; -} - TEMPLATE code CLASS::set_code(const transaction& tx) NOEXCEPT { @@ -876,16 +868,6 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT // set header // ---------------------------------------------------------------------------- -// deprecated -TEMPLATE -header_link CLASS::set_link(const header& header, const auto& ctx, - bool milestone) NOEXCEPT -{ - header_link header_fk{}; - return set_code(header_fk, header, ctx, milestone) ? header_link{} : - header_fk; -} - TEMPLATE code CLASS::set_code(const header& header, const context& ctx, bool milestone) NOEXCEPT @@ -954,16 +936,6 @@ code CLASS::set_code(header_link& out_fk, const header& header, // set block // ---------------------------------------------------------------------------- -// deprecated -TEMPLATE -header_link CLASS::set_link(const block& block, const auto& ctx, - bool milestone, bool strong) NOEXCEPT -{ - header_link header_fk{}; - return set_code(header_fk, block, ctx, milestone, strong) ? header_link{} : - header_fk; -} - TEMPLATE code CLASS::set_code(const block& block, const context& ctx, bool milestone, bool strong) NOEXCEPT @@ -998,26 +970,15 @@ code CLASS::set_code(header_link& out_fk, const block& block, const context& ctx, bool milestone, bool strong) NOEXCEPT { const auto ec = set_code(out_fk, block.header(), ctx, milestone); - if (ec) - return ec; - - const auto size = block.serialized_size(true); - return set_code(*block.transactions_ptr(), out_fk, size, strong); + return ec ? ec : set_code(block, out_fk, strong); } // set txs from block // ---------------------------------------------------------------------------- - -// deprecated // This sets only the txs of a block with header/context already archived. -TEMPLATE -header_link CLASS::set_link(const block& block, bool strong) NOEXCEPT -{ - header_link header_fk{}; - return set_code(header_fk, block, strong) ? header_link{} : header_fk; -} +// Block MUST be kept in scope until all transactions are written. ~block() +// releases all memory for parts of itself, due to the custom allocator. -// This sets only the txs of a block with header/context already archived. TEMPLATE code CLASS::set_code(const block& block, bool strong) NOEXCEPT { @@ -1025,7 +986,6 @@ code CLASS::set_code(const block& block, bool strong) NOEXCEPT return set_code(unused, block, strong); } -// This sets only the txs of a block with header/context already archived. TEMPLATE code CLASS::set_code(header_link& out_fk, const block& block, bool strong) NOEXCEPT @@ -1034,40 +994,34 @@ code CLASS::set_code(header_link& out_fk, const block& block, if (out_fk.is_terminal()) return error::txs_header; - txs_link unused{}; - const auto size = block.serialized_size(true); - return set_code(unused, *block.transactions_ptr(), out_fk, size, strong); + return set_code(block, out_fk, strong); } - -// set txs -// ---------------------------------------------------------------------------- - -// deprecated TEMPLATE -txs_link CLASS::set_link(const transactions& txs, const header_link& key, - size_t size, bool strong) NOEXCEPT +code CLASS::set_code(const block& block, const header_link& key, + bool strong) NOEXCEPT { - txs_link txs_fk{}; - return set_code(txs_fk, txs, key, size, strong) ? txs_link{} : txs_fk; + txs_link unused{}; + return set_code(unused, block, key, strong, block.serialized_size(true)); } TEMPLATE -code CLASS::set_code(const transactions& txs, const header_link& key, - size_t block_size, bool strong) NOEXCEPT +code CLASS::set_code(const block& block, const header_link& key, + bool strong, size_t block_size) NOEXCEPT { txs_link unused{}; - return set_code(unused, txs, key, block_size, strong); + return set_code(unused, block, key, strong, block_size); } TEMPLATE -code CLASS::set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t block_size, bool strong) NOEXCEPT +code CLASS::set_code(txs_link& out_fk, const block& block, + const header_link& key, bool strong, size_t block_size) NOEXCEPT { if (key.is_terminal()) return error::txs_header; - if (txs.empty()) + const auto count = block.transactions(); + if (is_zero(count)) return error::txs_empty; ////// GUARD (block (txs) redundancy) @@ -1079,8 +1033,8 @@ code CLASS::set_code(txs_link& out_fk, const transactions& txs, code ec{}; tx_link tx_fk{}; tx_links links{}; - links.reserve(txs.size()); - for (const auto& tx: txs) + links.reserve(count); + for (const auto& tx: *block.transactions_ptr()) { // Each tx is set under a distinct transactor. if ((ec = set_code(tx_fk, *tx))) diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index dcbf195d..f7ef0914 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -402,7 +402,6 @@ class query /// Set transaction. code set_code(const transaction& tx) NOEXCEPT; code set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT; - tx_link set_link(const transaction& tx) NOEXCEPT; /// Set header (headers-first). code set_code(const header& header, const context& ctx, @@ -413,8 +412,6 @@ class query const context& ctx, bool milestone, bool=false) NOEXCEPT; code set_code(header_link& out_fk, const header& header, const chain_context& ctx, bool milestone, bool=false) NOEXCEPT; - header_link set_link(const header& header, const auto& ctx, - bool milestone) NOEXCEPT; /// Set full block (blocks-first). code set_code(const block& block, const context& ctx, bool milestone, @@ -425,22 +422,15 @@ class query bool milestone, bool strong) NOEXCEPT; code set_code(header_link& out_fk, const block& block, const chain_context& ctx, bool milestone, bool strong) NOEXCEPT; - header_link set_link(const block& block, const auto& ctx, bool milestone, - bool strong) NOEXCEPT; - - /// Set txs (headers-first). - code set_code(const transactions& txs, const header_link& key, - size_t block_size, bool strong) NOEXCEPT; - code set_code(txs_link& out_fk, const transactions& txs, - const header_link& key, size_t block_size, bool strong) NOEXCEPT; - txs_link set_link(const transactions& txs, const header_link& key, - size_t block_size, bool strong) NOEXCEPT; /// Set block.txs (headers-first). code set_code(const block& block, bool strong) NOEXCEPT; - code set_code(header_link& out_fk, const block& block, - bool strong) NOEXCEPT; - header_link set_link(const block& block, bool strong) NOEXCEPT; + code set_code(header_link& out_fk, const block& block, bool strong) NOEXCEPT; + code set_code(const block& block, const header_link& key, bool strong) NOEXCEPT; + code set_code(const block& block, const header_link& key, bool strong, + size_t block_size) NOEXCEPT; + code set_code(txs_link& out_fk, const block& block, const header_link& key, + bool strong, size_t block_size) NOEXCEPT; /// Chain state. /// ----------------------------------------------------------------------- diff --git a/test/query/archive.cpp b/test/query/archive.cpp index 0a8ae498..bd2f7da3 100644 --- a/test/query/archive.cpp +++ b/test/query/archive.cpp @@ -137,6 +137,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) "64636261" // nonce "119192939495969798999a9b9c9d9e9f229192939495969798999a9b9c9d9e9f"); //merkle_root + header_link link{}; settings settings{}; settings.header_buckets = 10; settings.path = TEST_DIRECTORY; @@ -147,7 +148,8 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_header__is_header__expected) // store open/close flushes record count to head. BOOST_REQUIRE(!query.is_header(header.hash())); BOOST_REQUIRE(!query.is_associated(0)); - BOOST_REQUIRE(!query.set_link(header, test::context, milestone).is_terminal()); + BOOST_REQUIRE(!query.set_code(link, header, test::context, milestone)); + BOOST_REQUIRE(!link.is_terminal()); BOOST_REQUIRE(query.is_header(header.hash())); BOOST_REQUIRE(!query.is_associated(0)); table::header::record element1{}; @@ -284,6 +286,7 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_tx__null_input__expected) BOOST_REQUIRE_EQUAL(tx_hash, tx.hash(false)); // data_chunk store. + tx_link link{}; settings settings{}; settings.tx_buckets = 5; settings.point_buckets = 5; @@ -292,9 +295,8 @@ BOOST_AUTO_TEST_CASE(query_archive__set_link_tx__null_input__expected) test::chunk_store store{ settings }; test::query_accessor query{ store }; BOOST_REQUIRE(!store.create(events_handler)); - const auto link = query.set_link(tx); + BOOST_REQUIRE(!query.set_code(link, tx)); BOOST_REQUIRE(!link.is_terminal()); - ////BOOST_REQUIRE_EQUAL(query.set_link(tx), link); BOOST_REQUIRE(!store.close(events_handler)); BOOST_REQUIRE_EQUAL(store.tx_head(), expected_tx_head); diff --git a/test/query/translate.cpp b/test/query/translate.cpp index 711c8b97..d65ca150 100644 --- a/test/query/translate.cpp +++ b/test/query/translate.cpp @@ -131,12 +131,15 @@ BOOST_AUTO_TEST_CASE(query_translate__to_header__always__expected) settings.path = TEST_DIRECTORY; test::chunk_store store{ settings }; test::query_accessor query{ store }; + header_link link{}; + BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success); BOOST_REQUIRE_EQUAL(query.to_header(test::genesis.hash()), header_link::terminal); BOOST_REQUIRE(query.initialize(test::genesis)); BOOST_REQUIRE_EQUAL(query.to_header(test::genesis.hash()), 0u); BOOST_REQUIRE_EQUAL(query.to_header(test::block1.hash()), header_link::terminal); - BOOST_REQUIRE_EQUAL(query.set_link(test::block1.header(), test::context, false), 1u); + BOOST_REQUIRE_EQUAL(query.set_code(link, test::block1.header(), test::context, false), error::success); + BOOST_REQUIRE_EQUAL(link, 1u); BOOST_REQUIRE_EQUAL(query.to_header(test::block1.hash()), 1u); }