From 67a1a4181e35f68ebc897154574f3b7bab0e10bb Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 17:43:32 +0100 Subject: [PATCH] Revert "Rewrite json_handler::receivable in terms of receivable iterators" This reverts commit 9d962e6e462c3ec1a2d26b9720b9f06d718d39a4. # Conflicts: # nano/node/json_handler.cpp --- nano/node/json_handler.cpp | 93 +++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index e5f87a7c4..83f4323bd 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3110,61 +3110,62 @@ void nano::json_handler::receivable () // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. std::vector> hash_ptree_pairs; std::vector> hash_amount_pairs; - for (auto current = node.ledger.any.receivable_upper_bound (transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && (should_sort || peers_l.size () < count); ++current) + for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end ()); i != n && nano::pending_key (i->first).account == account && (should_sort || peers_l.size () < count); ++i) { - auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash)) + nano::pending_key const & key (i->first); + if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) { - continue; - } - if (!should_sort && offset_counter > 0) - { - --offset_counter; - continue; - } - - if (simple) - { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - continue; - } - if (info.amount.number () < threshold.number ()) - { - continue; - } - if (source || min_version) - { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().template convert_to ()); - if (source) + if (!should_sort && offset_counter > 0) { - pending_tree.put ("source", info.source.to_account ()); - } - if (min_version) - { - pending_tree.put ("min_version", epoch_as_string (info.epoch)); + --offset_counter; + continue; } - if (should_sort) + if (simple) { - hash_ptree_pairs.emplace_back (key.hash.to_string (), pending_tree); + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); } else { - peers_l.add_child (key.hash.to_string (), pending_tree); - } - } - else - { - if (should_sort) - { - hash_amount_pairs.emplace_back (key.hash.to_string (), info.amount.number ()); - } - else - { - peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to ()); + nano::pending_info const & info (i->second); + if (info.amount.number () >= threshold.number ()) + { + if (source || min_version) + { + boost::property_tree::ptree pending_tree; + pending_tree.put ("amount", info.amount.number ().convert_to ()); + if (source) + { + pending_tree.put ("source", info.source.to_account ()); + } + if (min_version) + { + pending_tree.put ("min_version", epoch_as_string (info.epoch)); + } + + if (should_sort) + { + hash_ptree_pairs.emplace_back (key.hash.to_string (), pending_tree); + } + else + { + peers_l.add_child (key.hash.to_string (), pending_tree); + } + } + else + { + if (should_sort) + { + hash_amount_pairs.emplace_back (key.hash.to_string (), info.amount.number ()); + } + else + { + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + } + } + } } } }