diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index 17c706e2..b8da31e1 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -154,8 +154,8 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT BC_ASSERT(!tx.is_coinbase()); auto result = true; - const auto& ins = *tx.inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx.inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate(*in); }); @@ -166,16 +166,16 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT TEMPLATE bool CLASS::populate(const block& block) const NOEXCEPT { - const auto& txs = *block.transactions_ptr(); - if (txs.empty()) + const auto& txs = block.transactions_ptr(); + if (txs->empty()) return false; auto result = true; - std::for_each(std::next(txs.begin()), txs.end(), + std::for_each(std::next(txs->begin()), txs->end(), [&](const auto& tx) NOEXCEPT { - const auto& ins = *tx->inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx->inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate(*in); }); @@ -225,8 +225,8 @@ bool CLASS::populate_with_metadata(const transaction& tx, const tx_link& link) const NOEXCEPT { auto result = true; - const auto& ins = *tx.inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx.inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate_with_metadata(*in, link); }); @@ -240,7 +240,7 @@ bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT BC_ASSERT(is_coinbase(tx)); // A coinbase tx is allowed only one input. - const auto& input = *tx.inputs_ptr()->front(); + const auto& input = tx.inputs_ptr()->front(); // Find any confirmed unspent duplicates of tx (unspent_coinbase_collision). const auto ec = unspent_duplicates(tx); @@ -248,29 +248,29 @@ bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT return false; // The prevout of a coinbase is null (not an output of a coinbase tx). - input.metadata.coinbase = false; - input.metadata.spent = (ec != error::unspent_coinbase_collision); - input.metadata.median_time_past = max_uint32; - input.metadata.height = zero; + input->metadata.coinbase = false; + input->metadata.spent = (ec != error::unspent_coinbase_collision); + input->metadata.median_time_past = max_uint32; + input->metadata.height = zero; return true; } TEMPLATE bool CLASS::populate_with_metadata(const block& block) const NOEXCEPT { - const auto& txs = *block.transactions_ptr(); - if (txs.empty()) + const auto& txs = block.transactions_ptr(); + if (txs->empty()) return false; auto result = true; - const auto coinbase = populate_with_metadata(txs.front()); - std::for_each(std::next(txs.begin()), txs.end(), + const auto coinbase = populate_with_metadata(txs->front()); + std::for_each(std::next(txs->begin()), txs->end(), [&](const auto& tx) NOEXCEPT { const auto link = to_tx(tx.get_hash()); result &= !link.is_terminal(); - const auto& ins = *tx->inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx->inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate_with_metadata(*in, link); }); @@ -743,15 +743,15 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT const auto& key = tx.get_hash(false); // Declare puts record. - const auto& ins = *tx.inputs_ptr(); - const auto& outs = *tx.outputs_ptr(); + const auto& ins = tx.inputs_ptr(); + const auto& outs = tx.outputs_ptr(); table::puts::slab puts{}; - puts.spend_fks.reserve(ins.size()); - puts.out_fks.reserve(outs.size()); + puts.spend_fks.reserve(ins->size()); + puts.out_fks.reserve(outs->size()); // Declare spends buffer. std_vector spends{}; - spends.reserve(ins.size()); + spends.reserve(ins->size()); // TODO: eliminate shared memory pointer reallocations. // ======================================================================== @@ -765,13 +765,13 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT // Allocate spend records. // Clean single allocation failure (e.g. disk full). - const auto count = possible_narrow_cast(ins.size()); + const auto count = possible_narrow_cast(ins->size()); auto spend_fk = store_.spend.allocate(count); if (spend_fk.is_terminal()) return error::tx_spend_allocate; // Commit input records (spend records not indexed). - for (const auto& in: ins) + for (const auto& in: *ins) { // Commit input record. // Safe allocation failure, blob linked by unindexed spend. @@ -833,7 +833,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT } // Commit output records. - for (const auto& out: outs) + for (const auto& out: *outs) { // Safe allocation failure, blob unlinked. output_link output_fk{}; @@ -864,8 +864,8 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT { {}, tx, - system::possible_narrow_cast(ins.size()), - system::possible_narrow_cast(outs.size()), + system::possible_narrow_cast(ins->size()), + system::possible_narrow_cast(outs->size()), puts_fk })) { @@ -888,7 +888,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT if (address_enabled()) { auto output_fk = puts.out_fks.begin(); - for (const auto& out: outs) + for (const auto& out: *outs) { // Safe allocation failure, unindexed tx outputs linked by address, // others unlinked. A replay of committed addresses without indexed diff --git a/test/query/archive.cpp b/test/query/archive.cpp index 64b54a80..911a3b3f 100644 --- a/test/query/archive.cpp +++ b/test/query/archive.cpp @@ -1273,9 +1273,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_input__genesis__expected) BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); - const auto& input = *tx->inputs_ptr()->front(); - BOOST_REQUIRE(input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); - BOOST_REQUIRE(input == *query.get_input(0)); + const auto input = tx->inputs_ptr()->front(); + BOOST_REQUIRE(*input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); + BOOST_REQUIRE(*input == *query.get_input(0)); } BOOST_AUTO_TEST_CASE(query_archive__get_inputs__tx_not_found__nullptr) @@ -1328,10 +1328,10 @@ BOOST_AUTO_TEST_CASE(query_archive__get_output__genesis__expected) BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); - const auto& output1 = *tx->outputs_ptr()->front(); - BOOST_REQUIRE(output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); - BOOST_REQUIRE(output1 == *query.get_output({ tx->hash(false), 0u })); - BOOST_REQUIRE(output1 == *query.get_output(0)); + const auto output1 = tx->outputs_ptr()->front(); + BOOST_REQUIRE(*output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); + BOOST_REQUIRE(*output1 == *query.get_output({ tx->hash(false), 0u })); + BOOST_REQUIRE(*output1 == *query.get_output(0)); } BOOST_AUTO_TEST_CASE(query_archive__get_outputs__tx_not_found__nullptr) @@ -1473,11 +1473,11 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected //// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u); //// //// // Match the two spenders. -//// const auto& block_inputs = *test::block2a.transactions_ptr()->front()->inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *block_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *block_inputs.back()); +//// const auto block_inputs = test::block2a.transactions_ptr()->front()->inputs_ptr(); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*block_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*block_inputs).back()); //// //// // Each of the two outputs of block1a spent twice (two unconfirmed double spends). //// BOOST_REQUIRE(query.set(test::tx4)); @@ -1489,15 +1489,15 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected //// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u); //// //// // Match the four spenders. -//// const auto& tx_inputs = *test::tx4.inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *tx_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *tx_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *block_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *tx_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *tx_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *block_inputs.back()); +//// const auto tx_inputs = test::tx4.inputs_ptr(); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*tx_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*tx_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *(*block_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*tx_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*tx_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *(*block_inputs).back()); ////} BOOST_AUTO_TEST_CASE(query_archive__get_value__genesis__expected) diff --git a/test/tables/caches/buffer.cpp b/test/tables/caches/buffer.cpp index 04094491..a67a5d1e 100644 --- a/test/tables/caches/buffer.cpp +++ b/test/tables/caches/buffer.cpp @@ -24,11 +24,11 @@ ////using namespace system; ////const chain::transaction empty{}; ////const auto genesis = system::settings{ system::chain::selection::mainnet }.genesis_block; -////const auto& genesis_tx = *genesis.transactions_ptr()->front(); +////const auto genesis_tx = genesis.transactions_ptr()->front(); ////const table::buffer::key key1{ 0x01, 0x02, 0x03, 0x04 }; ////const table::buffer::key key2{ 0xa1, 0xa2, 0xa3, 0xa4 }; ////const table::buffer::slab slab1{ {}, empty }; -////const table::buffer::slab slab2{ {}, genesis_tx }; +////const table::buffer::slab slab2{ {}, *genesis_tx }; ////const data_chunk expected_head = base16_chunk ////( //// "0000000000"