diff --git a/rai/core_test/rpc.cpp b/rai/core_test/rpc.cpp index 78529494e3..8e286179b5 100644 --- a/rai/core_test/rpc.cpp +++ b/rai/core_test/rpc.cpp @@ -2335,6 +2335,13 @@ TEST (rpc, accounts_pending) rai::keypair key1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); + auto iterations (0); + while (system.nodes[0]->active.active (*block1)) + { + system.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; @@ -2541,6 +2548,13 @@ TEST (rpc, wallet_pending) system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system0.wallet (0)->insert_adhoc (key1.prv); auto block1 (system0.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); + auto iterations (0); + while (system0.nodes[0]->active.active (*block1)) + { + system0.poll (); + ++iterations; + ASSERT_LT (iterations, 200); + } rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; @@ -2553,6 +2567,7 @@ TEST (rpc, wallet_pending) system0.poll (); } ASSERT_EQ (200, response.status); + ASSERT_EQ (1, response.json.get_child ("blocks").size ()); for (auto & pending : response.json.get_child ("blocks")) { std::string account_text (pending.first); @@ -2568,6 +2583,7 @@ TEST (rpc, wallet_pending) } ASSERT_EQ (200, response0.status); std::unordered_map blocks; + ASSERT_EQ (1, response0.json.get_child ("blocks").size ()); for (auto & pending : response0.json.get_child ("blocks")) { std::string account_text (pending.first); @@ -2606,6 +2622,7 @@ TEST (rpc, wallet_pending) ASSERT_EQ (200, response2.status); std::unordered_map amounts; std::unordered_map sources; + ASSERT_EQ (1, response0.json.get_child ("blocks").size ()); for (auto & pending : response2.json.get_child ("blocks")) { std::string account_text (pending.first); diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index 9143947dd3..d5d958d5b2 100644 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -757,6 +757,7 @@ void rai::rpc_handler::accounts_pending () auto count (count_optional_impl ()); auto threshold (threshold_optional_impl ()); const bool source = request.get ("source", false); + const bool include_active = request.get ("include_active", false); boost::property_tree::ptree pending; rai::transaction transaction (node.store.environment, nullptr, false); for (auto & accounts : request.get_child ("accounts")) @@ -769,27 +770,32 @@ void rai::rpc_handler::accounts_pending () for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (node.store.pending_begin (transaction, rai::pending_key (end, 0))); i != n && peers_l.size () < count; ++i) { rai::pending_key key (i->first); - if (threshold.is_zero () && !source) + std::shared_ptr block (node.store.block_get (transaction, key.hash)); + assert (block); + if (include_active || (block && !node.active.active (*block))) { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - } - else - { - rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0); - if (info.amount.number () >= threshold.number ()) + if (threshold.is_zero () && !source) { - if (source) - { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().convert_to ()); - pending_tree.put ("source", info.source.to_account ()); - peers_l.add_child (key.hash.to_string (), pending_tree); - } - else + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); + } + else + { + rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0); + if (info.amount.number () >= threshold.number ()) { - peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + if (source) + { + boost::property_tree::ptree pending_tree; + pending_tree.put ("amount", info.amount.number ().convert_to ()); + pending_tree.put ("source", info.source.to_account ()); + peers_l.add_child (key.hash.to_string (), pending_tree); + } + else + { + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + } } } } @@ -3111,6 +3117,7 @@ void rai::rpc_handler::wallet_pending () auto threshold (threshold_optional_impl ()); const bool source = request.get ("source", false); const bool min_version = request.get ("min_version", false); + const bool include_active = request.get ("include_active", false); if (!ec) { boost::property_tree::ptree pending; @@ -3123,34 +3130,39 @@ void rai::rpc_handler::wallet_pending () for (auto ii (node.store.pending_begin (transaction, rai::pending_key (account, 0))), nn (node.store.pending_begin (transaction, rai::pending_key (end, 0))); ii != nn && peers_l.size () < count; ++ii) { rai::pending_key key (ii->first); - if (threshold.is_zero () && !source) - { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - } - else + std::shared_ptr block (node.store.block_get (transaction, key.hash)); + assert (block); + if (include_active || (block && !node.active.active (*block))) { - rai::pending_info info (ii->second, ii->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0); - if (info.amount.number () >= threshold.number ()) + if (threshold.is_zero () && !source) { - if (source || min_version) + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); + } + else + { + rai::pending_info info (ii->second, ii->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0); + if (info.amount.number () >= threshold.number ()) { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().convert_to ()); - if (source) + if (source || min_version) { - pending_tree.put ("source", info.source.to_account ()); + 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", info.epoch == rai::epoch::epoch_1 ? "1" : "0"); + } + peers_l.add_child (key.hash.to_string (), pending_tree); } - if (min_version) + else { - pending_tree.put ("min_version", info.epoch == rai::epoch::epoch_1 ? "1" : "0"); + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); } - peers_l.add_child (key.hash.to_string (), pending_tree); - } - else - { - peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); } } }