Rewrite json_handler::receivable in terms of receivable iterators

This commit is contained in:
Colin LeMahieu 2024-03-15 23:10:11 +00:00
commit 9d962e6e46
No known key found for this signature in database
GPG key ID: 43708520C8DFB938

View file

@ -3051,15 +3051,17 @@ void nano::json_handler::receivable ()
{ {
auto offset_counter = offset; auto offset_counter = offset;
boost::property_tree::ptree peers_l; boost::property_tree::ptree peers_l;
auto transaction (node.store.tx_begin_read ()); auto transaction = node.store.tx_begin_read ();
// The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used.
std::vector<std::pair<std::string, boost::property_tree::ptree>> hash_ptree_pairs; std::vector<std::pair<std::string, boost::property_tree::ptree>> hash_ptree_pairs;
std::vector<std::pair<std::string, nano::uint128_t>> hash_amount_pairs; std::vector<std::pair<std::string, nano::uint128_t>> hash_amount_pairs;
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) for (auto current = node.ledger.receivable_upper_bound (transaction, account, 0), end = node.ledger.receivable_end (); current != end && (should_sort || peers_l.size () < count); ++current)
{ {
nano::pending_key const & key (i->first); auto const & [key, info] = *current;
if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) if (include_only_confirmed && !node.ledger.block_confirmed (transaction, key.hash))
{ {
continue;
}
if (!should_sort && offset_counter > 0) if (!should_sort && offset_counter > 0)
{ {
--offset_counter; --offset_counter;
@ -3071,16 +3073,16 @@ void nano::json_handler::receivable ()
boost::property_tree::ptree entry; boost::property_tree::ptree entry;
entry.put ("", key.hash.to_string ()); entry.put ("", key.hash.to_string ());
peers_l.push_back (std::make_pair ("", entry)); peers_l.push_back (std::make_pair ("", entry));
continue;
} }
else if (info.amount.number () < threshold.number ())
{
nano::pending_info const & info (i->second);
if (info.amount.number () >= threshold.number ())
{ {
continue;
}
if (source || min_version) if (source || min_version)
{ {
boost::property_tree::ptree pending_tree; boost::property_tree::ptree pending_tree;
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ()); pending_tree.put ("amount", info.amount.number ().template convert_to<std::string> ());
if (source) if (source)
{ {
pending_tree.put ("source", info.source.to_account ()); pending_tree.put ("source", info.source.to_account ());
@ -3107,10 +3109,7 @@ void nano::json_handler::receivable ()
} }
else else
{ {
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ()); peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to<std::string> ());
}
}
}
} }
} }
} }