#260 get_son_by_account and get_son_by_account_id functions

This commit is contained in:
Vlad Dobromyslov 2022-02-04 14:25:13 +03:00
parent 2d237469a0
commit 0f3ea3d637
2 changed files with 23 additions and 5 deletions

View file

@ -157,7 +157,8 @@ public:
// SON members // SON members
vector<optional<son_object>> get_sons(const vector<son_id_type> &son_ids) const; vector<optional<son_object>> get_sons(const vector<son_id_type> &son_ids) const;
fc::optional<son_object> get_son_by_account(account_id_type account) const; fc::optional<son_object> get_son_by_account_id(account_id_type account) const;
fc::optional<son_object> get_son_by_account(const std::string account_id_or_name) const;
map<string, son_id_type> lookup_son_accounts(const string &lower_bound_name, uint32_t limit) const; map<string, son_id_type> lookup_son_accounts(const string &lower_bound_name, uint32_t limit) const;
uint64_t get_son_count() const; uint64_t get_son_count() const;
@ -1719,11 +1720,11 @@ vector<optional<son_object>> database_api_impl::get_sons(const vector<son_id_typ
return result; return result;
} }
fc::optional<son_object> database_api::get_son_by_account(account_id_type account) const { fc::optional<son_object> database_api::get_son_by_account_id(account_id_type account) const {
return my->get_son_by_account(account); return my->get_son_by_account_id(account);
} }
fc::optional<son_object> database_api_impl::get_son_by_account(account_id_type account) const { fc::optional<son_object> database_api_impl::get_son_by_account_id(account_id_type account) const {
const auto &idx = _db.get_index_type<son_index>().indices().get<by_account>(); const auto &idx = _db.get_index_type<son_index>().indices().get<by_account>();
auto itr = idx.find(account); auto itr = idx.find(account);
if (itr != idx.end()) if (itr != idx.end())
@ -1731,6 +1732,15 @@ fc::optional<son_object> database_api_impl::get_son_by_account(account_id_type a
return {}; return {};
} }
fc::optional<son_object> database_api::get_son_by_account(const std::string account_id_or_name) const {
return my->get_son_by_account(account_id_or_name);
}
fc::optional<son_object> database_api_impl::get_son_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_son_by_account_id(account);
}
map<string, son_id_type> database_api::lookup_son_accounts(const string &lower_bound_name, uint32_t limit) const { map<string, son_id_type> database_api::lookup_son_accounts(const string &lower_bound_name, uint32_t limit) const {
return my->lookup_son_accounts(lower_bound_name, limit); return my->lookup_son_accounts(lower_bound_name, limit);
} }

View file

@ -620,7 +620,14 @@ public:
* @param account The ID of the account whose SON should be retrieved * @param account The ID of the account whose SON should be retrieved
* @return The SON object, or null if the account does not have a SON * @return The SON object, or null if the account does not have a SON
*/ */
fc::optional<son_object> get_son_by_account(account_id_type account) const; fc::optional<son_object> get_son_by_account_id(account_id_type account) const;
/**
* @brief Get the SON owned by a given account
* @param account The ID of the account whose SON should be retrieved
* @return The SON object, or null if the account does not have a SON
*/
fc::optional<son_object> get_son_by_account(const std::string account_id_or_name) const;
/** /**
* @brief Get names and IDs for registered SONs * @brief Get names and IDs for registered SONs
@ -1086,6 +1093,7 @@ FC_API(graphene::app::database_api,
// SON members // SON members
(get_sons) (get_sons)
(get_son_by_account_id)
(get_son_by_account) (get_son_by_account)
(lookup_son_accounts) (lookup_son_accounts)
(get_son_count) (get_son_count)