From 22f76a04c01c0fe68ef8346bacae3c6d1e95ec90 Mon Sep 17 00:00:00 2001 From: gladcow Date: Wed, 6 Nov 2019 17:58:32 +0300 Subject: [PATCH] list_active_sons api call implementation --- .../wallet/include/graphene/wallet/wallet.hpp | 7 +++++ libraries/wallet/wallet.cpp | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 349ccea8..2b511ba7 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1363,6 +1363,13 @@ class wallet_api */ map list_sons(const string& lowerbound, uint32_t limit); + /** Lists active at the moment SONs. + * This returns a list of all account names that own active SON, and the associated SON id, + * sorted by name. + * @returns a list of active SONs mapping SON names to SON ids + */ + map list_active_sons(); + /** Creates a witness object owned by the given account. * * An account can have at most one witness object. diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 69f3cb7a..c427f373 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1932,6 +1932,32 @@ public: return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) } + map list_active_sons() + { try { + global_property_object gpo = get_global_properties(); + std::vector> son_objects = + _remote_db->get_sons(gpo.active_sons); + vector owners; + owners.resize(son_objects.size()); + std::transform(son_objects.begin(), son_objects.end(), owners.begin(), + [](const fc::optional& obj) { + if(!obj) + FC_THROW("Invalid active SONs list in global properties."); + return obj->son_account; + }); + vector> accs = _remote_db->get_accounts(owners); + map result; + std::transform(accs.begin(), accs.end(), gpo.active_sons.begin(), + std::inserter(result, result.end()), + [](fc::optional& acct, + son_id_type& sid) { + if(!acct) + FC_THROW("Invalid active SONs list in global properties."); + return std::make_pair(string(acct->name), std::move(sid)); + }); + return result; + } FC_CAPTURE_AND_RETHROW() } + signed_transaction create_witness(string owner_account, string url, bool broadcast /* = false */) @@ -4303,6 +4329,11 @@ map wallet_api::list_sons(const string& lowerbound, uint32_ return my->_remote_db->lookup_son_accounts(lowerbound, limit); } +map wallet_api::list_active_sons() +{ + return my->list_active_sons(); +} + signed_transaction wallet_api::create_witness(string owner_account, string url, bool broadcast /* = false */)