Reimplement json_handler::accounts_receivable in terms of receivable iterators.
This commit is contained in:
parent
a5e1500680
commit
b08d6ff522
1 changed files with 27 additions and 28 deletions
|
|
@ -1041,42 +1041,41 @@ void nano::json_handler::accounts_receivable ()
|
||||||
bool const sorting = request.get<bool> ("sorting", false);
|
bool const sorting = request.get<bool> ("sorting", false);
|
||||||
auto simple (threshold.is_zero () && !source && !sorting); // if simple, response is a list of hashes for each account
|
auto simple (threshold.is_zero () && !source && !sorting); // if simple, response is a list of hashes for each account
|
||||||
boost::property_tree::ptree pending;
|
boost::property_tree::ptree pending;
|
||||||
auto transaction (node.store.tx_begin_read ());
|
auto transaction = node.store.tx_begin_read ();
|
||||||
for (auto & accounts : request.get_child ("accounts"))
|
for (auto & accounts : request.get_child ("accounts"))
|
||||||
{
|
{
|
||||||
auto account (account_impl (accounts.second.data ()));
|
auto account (account_impl (accounts.second.data ()));
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree peers_l;
|
boost::property_tree::ptree peers_l;
|
||||||
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 && peers_l.size () < count; ++i)
|
for (auto current = node.ledger.receivable_upper_bound (transaction, account, 0), end = node.ledger.receivable_end (); current != end; ++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))
|
||||||
{
|
{
|
||||||
if (simple)
|
continue;
|
||||||
{
|
}
|
||||||
boost::property_tree::ptree entry;
|
if (simple)
|
||||||
entry.put ("", key.hash.to_string ());
|
{
|
||||||
peers_l.push_back (std::make_pair ("", entry));
|
boost::property_tree::ptree entry;
|
||||||
}
|
entry.put ("", key.hash.to_string ());
|
||||||
else
|
peers_l.push_back (std::make_pair ("", entry));
|
||||||
{
|
continue;
|
||||||
nano::pending_info const & info (i->second);
|
}
|
||||||
if (info.amount.number () >= threshold.number ())
|
if (info.amount.number () < threshold.number ())
|
||||||
{
|
{
|
||||||
if (source)
|
continue;
|
||||||
{
|
}
|
||||||
boost::property_tree::ptree pending_tree;
|
if (source)
|
||||||
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
|
{
|
||||||
pending_tree.put ("source", info.source.to_account ());
|
boost::property_tree::ptree pending_tree;
|
||||||
peers_l.add_child (key.hash.to_string (), pending_tree);
|
pending_tree.put ("amount", info.amount.number ().template convert_to<std::string> ());
|
||||||
}
|
pending_tree.put ("source", info.source.to_account ());
|
||||||
else
|
peers_l.add_child (key.hash.to_string (), pending_tree);
|
||||||
{
|
}
|
||||||
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
|
else
|
||||||
}
|
{
|
||||||
}
|
peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to<std::string> ());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sorting && !simple)
|
if (sorting && !simple)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue