diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 128632dcb..a2a780521 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -906,6 +906,26 @@ void nano::json_handler::accounts_balances () response_errors (); } +void nano::json_handler::accounts_representatives () +{ + boost::property_tree::ptree representatives; + for (auto & accounts : request.get_child ("accounts")) + { + auto account (account_impl (accounts.second.data ())); + auto transaction (node.store.tx_begin_read ()); + auto info (account_info_impl (transaction, account)); + + if (!ec) + { + boost::property_tree::ptree entry; + entry.put ("", info.representative.to_account ()); + representatives.push_back (std::make_pair (accounts.second.data (), entry)); + } + } + response_l.add_child ("representatives", representatives); + response_errors (); +} + void nano::json_handler::accounts_create () { node.workers.push_task (create_worker_task ([] (std::shared_ptr const & rpc_l) { @@ -5167,6 +5187,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map () no_arg_funcs.emplace ("account_representative_set", &nano::json_handler::account_representative_set); no_arg_funcs.emplace ("account_weight", &nano::json_handler::account_weight); no_arg_funcs.emplace ("accounts_balances", &nano::json_handler::accounts_balances); + no_arg_funcs.emplace ("accounts_representatives", &nano::json_handler::accounts_representatives); no_arg_funcs.emplace ("accounts_create", &nano::json_handler::accounts_create); no_arg_funcs.emplace ("accounts_frontiers", &nano::json_handler::accounts_frontiers); no_arg_funcs.emplace ("accounts_pending", &nano::json_handler::accounts_pending); diff --git a/nano/node/json_handler.hpp b/nano/node/json_handler.hpp index eb743d4b5..c204a65ee 100644 --- a/nano/node/json_handler.hpp +++ b/nano/node/json_handler.hpp @@ -40,6 +40,7 @@ public: void account_representative_set (); void account_weight (); void accounts_balances (); + void accounts_representatives (); void accounts_create (); void accounts_frontiers (); void accounts_pending (); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 3b02a74e7..7624f3daa 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2973,6 +2973,23 @@ TEST (rpc, accounts_balances) } } +TEST (rpc, accounts_representatives) +{ + nano::system system; + auto node = add_ipc_enabled_node (system); + auto [rpc, rpc_ctx] = add_rpc (system, node); + boost::property_tree::ptree request; + request.put ("action", "accounts_representatives"); + boost::property_tree::ptree entry; + boost::property_tree::ptree accounts; + entry.put ("", nano::dev::genesis_key.pub.to_account ()); + accounts.push_back (std::make_pair ("", entry)); + request.add_child ("accounts", accounts); + auto response (wait_response (system, rpc, request)); + auto response_representative (response.get_child("representatives").get(nano::dev::genesis->account ().to_account ())); + ASSERT_EQ (response_representative, nano::dev::genesis->account ().to_account ()); +} + TEST (rpc, accounts_frontiers) { nano::system system;