From 73ebd5a8cba497037e2cc9158283164fd9146868 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Tue, 18 Jul 2017 19:37:56 +0300 Subject: [PATCH] RPC wallet_work_get --- rai/node/rpc.cpp | 40 +++++++++++++++++++++++++++++++++++++++- rai/node/rpc.hpp | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp index db296f7c..df9f4d67 100755 --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -2564,6 +2564,40 @@ void rai::rpc_handler::wallet_representative_set () } } +void rai::rpc_handler::wallet_work_get () +{ + std::string wallet_text (request.get ("wallet")); + rai::uint256_union wallet; + auto error (wallet.decode_hex (wallet_text)); + if (!error) + { + auto existing (node.wallets.items.find (wallet)); + if (existing != node.wallets.items.end ()) + { + boost::property_tree::ptree response_l; + boost::property_tree::ptree works; + rai::transaction transaction (node.store.environment, nullptr, false); + for (auto i (existing->second->store.begin (transaction)), n (existing->second->store.end ()); i != n; ++i) + { + rai::account account(i->first); + uint64_t work (0); + auto error_work (existing->second->store.work_get (transaction, account, work)); + works.put (account.to_account (), rai::to_string_hex (work)); + } + response_l.add_child ("works", works); + response (response_l); + } + else + { + error_response (response, "Wallet not found"); + } + } + else + { + error_response (response, "Bad wallet number"); + } +} + void rai::rpc_handler::work_generate () { if (rpc.config.enable_control) @@ -2645,7 +2679,7 @@ void rai::rpc_handler::work_get () if (account_check != existing->second->store.end ()) { uint64_t work (0); - auto error (existing->second->store.work_get (transaction, account, work)); + auto error_work (existing->second->store.work_get (transaction, account, work)); boost::property_tree::ptree response_l; response_l.put ("work", rai::to_string_hex (work)); response (response_l); @@ -3151,6 +3185,10 @@ void rai::rpc_handler::process_request () { wallet_representative_set (); } + else if (action == "wallet_work_get") + { + wallet_work_get (); + } else if (action == "work_generate") { work_generate (); diff --git a/rai/node/rpc.hpp b/rai/node/rpc.hpp index cce2a1d8..ce62e3fb 100644 --- a/rai/node/rpc.hpp +++ b/rai/node/rpc.hpp @@ -164,6 +164,7 @@ public: void wallet_pending_threshold (); void wallet_representative (); void wallet_representative_set (); + void wallet_work_get (); void work_generate (); void work_cancel (); void work_get ();