From 65df816af6a070b0784a0594fe1291b0bff2d94d Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Tue, 8 Feb 2022 12:14:43 +0300 Subject: [PATCH] #270 add functions: get_witness_by_account_id(), get_committee_member_by_account_id(), get_workers_by_account_id() --- libraries/app/database_api.cpp | 47 +++++++++++++++---- .../app/include/graphene/app/database_api.hpp | 26 +++++++++- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 336cc8ebd..20f5fe2e3 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -170,12 +170,14 @@ class database_api_impl : public std::enable_shared_from_this // Witnesses vector> get_witnesses(const vector &witness_ids) const; + fc::optional get_witness_by_account_id(account_id_type account) const; fc::optional get_witness_by_account(const std::string account_id_or_name) const; map lookup_witness_accounts(const string &lower_bound_name, uint32_t limit) const; uint64_t get_witness_count() const; // Committee members vector> get_committee_members(const vector &committee_member_ids) const; + fc::optional get_committee_member_by_account_id(account_id_type account) const; fc::optional get_committee_member_by_account(const std::string account_id_or_name) const; map lookup_committee_member_accounts(const string &lower_bound_name, uint32_t limit) const; uint64_t get_committee_member_count() const; @@ -201,6 +203,7 @@ class database_api_impl : public std::enable_shared_from_this // Workers vector> get_workers(const vector &witness_ids) const; + vector get_workers_by_account_id(account_id_type account) const; vector get_workers_by_account(const std::string account_id_or_name) const; map lookup_worker_accounts(const string &lower_bound_name, uint32_t limit) const; uint64_t get_worker_count() const; @@ -1616,19 +1619,27 @@ vector> database_api_impl::get_witnesses(const vector database_api::get_witness_by_account(const std::string account_id_or_name) const { - return my->get_witness_by_account(account_id_or_name); +fc::optional database_api::get_witness_by_account_id(account_id_type account) const { + return my->get_witness_by_account_id(account); } -fc::optional database_api_impl::get_witness_by_account(const std::string account_id_or_name) const { +fc::optional database_api_impl::get_witness_by_account_id(account_id_type account) const { const auto &idx = _db.get_index_type().indices().get(); - const account_id_type account = get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); if (itr != idx.end()) return *itr; return {}; } +fc::optional database_api::get_witness_by_account(const std::string account_id_or_name) const { + return my->get_witness_by_account(account_id_or_name); +} + +fc::optional database_api_impl::get_witness_by_account(const std::string account_id_or_name) const { + const account_id_type account = get_account_from_string(account_id_or_name)->id; + return get_witness_by_account_id(account); +} + map database_api::lookup_witness_accounts(const string &lower_bound_name, uint32_t limit) const { return my->lookup_witness_accounts(lower_bound_name, limit); } @@ -1687,19 +1698,27 @@ vector> database_api_impl::get_committee_membe return result; } -fc::optional database_api::get_committee_member_by_account(const std::string account_id_or_name) const { - return my->get_committee_member_by_account(account_id_or_name); +fc::optional database_api::get_committee_member_by_account_id(account_id_type account) const { + return my->get_committee_member_by_account_id(account); } -fc::optional database_api_impl::get_committee_member_by_account(const std::string account_id_or_name) const { +fc::optional database_api_impl::get_committee_member_by_account_id(account_id_type account) const { const auto &idx = _db.get_index_type().indices().get(); - const account_id_type account = get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); if (itr != idx.end()) return *itr; return {}; } +fc::optional database_api::get_committee_member_by_account(const std::string account_id_or_name) const { + return my->get_committee_member_by_account(account_id_or_name); +} + +fc::optional database_api_impl::get_committee_member_by_account(const std::string account_id_or_name) const { + const account_id_type account = get_account_from_string(account_id_or_name)->id; + return get_committee_member_by_account_id(account); +} + map database_api::lookup_committee_member_accounts(const string &lower_bound_name, uint32_t limit) const { return my->lookup_committee_member_accounts(lower_bound_name, limit); } @@ -1943,6 +1962,10 @@ vector> database_api::get_workers(const vectorget_workers(worker_ids); } +vector database_api::get_workers_by_account_id(account_id_type account) const { + return my->get_workers_by_account_id(account); +} + vector database_api::get_workers_by_account(const std::string account_id_or_name) const { return my->get_workers_by_account(account_id_or_name); } @@ -1967,9 +1990,8 @@ vector> database_api_impl::get_workers(const vector database_api_impl::get_workers_by_account(const std::string account_id_or_name) const { +vector database_api_impl::get_workers_by_account_id(account_id_type account) const { const auto &idx = _db.get_index_type().indices().get(); - const account_id_type account = get_account_from_string(account_id_or_name)->id; auto itr = idx.find(account); vector result; @@ -1981,6 +2003,11 @@ vector database_api_impl::get_workers_by_account(const std::strin return result; } +vector database_api_impl::get_workers_by_account(const std::string account_id_or_name) const { + const account_id_type account = get_account_from_string(account_id_or_name)->id; + return get_workers_by_account_id(account); +} + map database_api_impl::lookup_worker_accounts(const string &lower_bound_name, uint32_t limit) const { FC_ASSERT(limit <= api_limit_lookup_worker_accounts, "Number of querying accounts can not be greater than ${configured_limit}", diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 7b7de4fa4..05f427079 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -560,6 +560,13 @@ class database_api { * @param account The ID of the account whose witness should be retrieved * @return The witness object, or null if the account does not have a witness */ + fc::optional get_witness_by_account_id(account_id_type account) const; + + /** + * @brief Get the witness owned by a given account + * @param account_id_or_name The ID or name of the account whose witness should be retrieved + * @return The witness object, or null if the account does not have a witness + */ fc::optional get_witness_by_account(const std::string account_name_or_id) const; /** @@ -588,6 +595,13 @@ class database_api { */ vector> get_committee_members(const vector &committee_member_ids) const; + /** + * @brief Get the committee_member owned by a given account + * @param account The ID of the account whose committee_member should be retrieved + * @return The committee_member object, or null if the account does not have a committee_member + */ + fc::optional get_committee_member_by_account_id(account_id_type account) const; + /** * @brief Get the committee_member owned by a given account * @param account_id_or_name The ID or name of the account whose committee_member should be retrieved @@ -727,7 +741,14 @@ class database_api { /** * @brief Return the worker objects associated with this account. - * @param account_id_or_name The ID or name of the account whose worker should be retrieved + * @param account The ID of the account whose workers should be retrieved + * @return The worker object or null if the account does not have a worker + */ + vector get_workers_by_account_id(account_id_type account) const; + + /** + * @brief Return the worker objects associated with this account. + * @param account_id_or_name The ID or name of the account whose workers should be retrieved * @return The worker object or null if the account does not have a worker */ vector get_workers_by_account(const std::string account_id_or_name) const; @@ -1104,12 +1125,14 @@ FC_API(graphene::app::database_api, // Witnesses (get_witnesses) + (get_witness_by_account_id) (get_witness_by_account) (lookup_witness_accounts) (get_witness_count) // Committee members (get_committee_members) + (get_committee_member_by_account_id) (get_committee_member_by_account) (lookup_committee_member_accounts) (get_committee_member_count) @@ -1135,6 +1158,7 @@ FC_API(graphene::app::database_api, // Workers (get_workers) + (get_workers_by_account_id) (get_workers_by_account) (lookup_worker_accounts) (get_worker_count)