From 8607a66d74e7b3682226d741f575fe76ceedbaad Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Sep 2023 02:41:13 +0100 Subject: [PATCH] Moving representative_visitor in to ledger file where it is used --- nano/secure/ledger.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ nano/secure/store.cpp | 43 ---------------------------- nano/secure/store.hpp | 23 --------------- 3 files changed, 63 insertions(+), 66 deletions(-) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 4bf4c793..38e464e0 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -678,6 +678,69 @@ ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::write_transac transaction (transaction_a) { } + +/** + * Determine the representative for this block + */ +class representative_visitor final : public nano::block_visitor +{ +public: + representative_visitor (nano::transaction const & transaction_a, nano::store & store_a); + ~representative_visitor () = default; + void compute (nano::block_hash const & hash_a); + void send_block (nano::send_block const & block_a) override; + void receive_block (nano::receive_block const & block_a) override; + void open_block (nano::open_block const & block_a) override; + void change_block (nano::change_block const & block_a) override; + void state_block (nano::state_block const & block_a) override; + nano::transaction const & transaction; + nano::store & store; + nano::block_hash current; + nano::block_hash result; +}; + +representative_visitor::representative_visitor (nano::transaction const & transaction_a, nano::store & store_a) : + transaction (transaction_a), + store (store_a), + result (0) +{ +} + +void representative_visitor::compute (nano::block_hash const & hash_a) +{ + current = hash_a; + while (result.is_zero ()) + { + auto block (store.block.get (transaction, current)); + debug_assert (block != nullptr); + block->visit (*this); + } +} + +void representative_visitor::send_block (nano::send_block const & block_a) +{ + current = block_a.previous (); +} + +void representative_visitor::receive_block (nano::receive_block const & block_a) +{ + current = block_a.previous (); +} + +void representative_visitor::open_block (nano::open_block const & block_a) +{ + result = block_a.hash (); +} + +void representative_visitor::change_block (nano::change_block const & block_a) +{ + result = block_a.hash (); +} + +void representative_visitor::state_block (nano::state_block const & block_a) +{ + result = block_a.hash (); +} } // namespace nano::ledger::ledger (nano::store & store_a, nano::stats & stat_a, nano::ledger_constants & constants, nano::generate_cache const & generate_cache_a) : diff --git a/nano/secure/store.cpp b/nano/secure/store.cpp index 28d4a4dc..1aa93ad0 100644 --- a/nano/secure/store.cpp +++ b/nano/secure/store.cpp @@ -2,49 +2,6 @@ #include #include -nano::representative_visitor::representative_visitor (nano::transaction const & transaction_a, nano::store & store_a) : - transaction (transaction_a), - store (store_a), - result (0) -{ -} - -void nano::representative_visitor::compute (nano::block_hash const & hash_a) -{ - current = hash_a; - while (result.is_zero ()) - { - auto block (store.block.get (transaction, current)); - debug_assert (block != nullptr); - block->visit (*this); - } -} - -void nano::representative_visitor::send_block (nano::send_block const & block_a) -{ - current = block_a.previous (); -} - -void nano::representative_visitor::receive_block (nano::receive_block const & block_a) -{ - current = block_a.previous (); -} - -void nano::representative_visitor::open_block (nano::open_block const & block_a) -{ - result = block_a.hash (); -} - -void nano::representative_visitor::change_block (nano::change_block const & block_a) -{ - result = block_a.hash (); -} - -void nano::representative_visitor::state_block (nano::state_block const & block_a) -{ - result = block_a.hash (); -} - nano::read_transaction::read_transaction (std::unique_ptr read_transaction_impl) : impl (std::move (read_transaction_impl)) { diff --git a/nano/secure/store.hpp b/nano/secure/store.hpp index 6798a695..f701a42d 100644 --- a/nano/secure/store.hpp +++ b/nano/secure/store.hpp @@ -401,29 +401,6 @@ private: return result; } }; - -class transaction; -class store; - -/** - * Determine the representative for this block - */ -class representative_visitor final : public nano::block_visitor -{ -public: - representative_visitor (nano::transaction const & transaction_a, nano::store & store_a); - ~representative_visitor () = default; - void compute (nano::block_hash const & hash_a); - void send_block (nano::send_block const & block_a) override; - void receive_block (nano::receive_block const & block_a) override; - void open_block (nano::open_block const & block_a) override; - void change_block (nano::change_block const & block_a) override; - void state_block (nano::state_block const & block_a) override; - nano::transaction const & transaction; - nano::store & store; - nano::block_hash current; - nano::block_hash result; -}; template class store_iterator_impl {