#270 get_worker_count(), lookup_worker_accounts() and list_workers() functions
This commit is contained in:
parent
1eafca86a4
commit
d74b9eeebf
4 changed files with 76 additions and 0 deletions
|
|
@ -202,6 +202,8 @@ public:
|
|||
// Workers
|
||||
vector<optional<worker_object>> get_workers(const vector<worker_id_type> &witness_ids) const;
|
||||
fc::optional<worker_object> get_worker_by_account(const std::string account_id_or_name) const;
|
||||
map<string, worker_id_type> lookup_worker_accounts(const string &lower_bound_name, uint32_t limit) const;
|
||||
uint64_t get_worker_count() const;
|
||||
|
||||
// Votes
|
||||
vector<variant> lookup_vote_ids(const vector<vote_id_type> &votes) const;
|
||||
|
|
@ -294,6 +296,7 @@ public:
|
|||
uint32_t api_limit_lookup_witness_accounts = 1000;
|
||||
uint32_t api_limit_lookup_committee_member_accounts = 1000;
|
||||
uint32_t api_limit_lookup_son_accounts = 1000;
|
||||
uint32_t api_limit_lookup_worker_accounts = 1000;
|
||||
uint32_t api_limit_get_trade_history = 100;
|
||||
uint32_t api_limit_get_trade_history_by_sequence = 100;
|
||||
|
||||
|
|
@ -1944,6 +1947,14 @@ fc::optional<worker_object> database_api::get_worker_by_account(const std::strin
|
|||
return my->get_worker_by_account(account_id_or_name);
|
||||
}
|
||||
|
||||
map<string, worker_id_type> database_api::lookup_worker_accounts(const string &lower_bound_name, uint32_t limit) const {
|
||||
return my->lookup_worker_accounts(lower_bound_name, limit);
|
||||
}
|
||||
|
||||
uint64_t database_api::get_worker_count() const {
|
||||
return my->get_worker_count();
|
||||
}
|
||||
|
||||
vector<optional<worker_object>> database_api_impl::get_workers(const vector<worker_id_type> &worker_ids) const {
|
||||
vector<optional<worker_object>> result;
|
||||
result.reserve(worker_ids.size());
|
||||
|
|
@ -1965,6 +1976,35 @@ fc::optional<worker_object> database_api_impl::get_worker_by_account(const std::
|
|||
return {};
|
||||
}
|
||||
|
||||
map<string, worker_id_type> 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}",
|
||||
("configured_limit", api_limit_lookup_worker_accounts));
|
||||
|
||||
const auto &workers_by_id = _db.get_index_type<worker_index>().indices().get<by_id>();
|
||||
|
||||
// we want to order workers by account name, but that name is in the account object
|
||||
// so the worker_index doesn't have a quick way to access it.
|
||||
// get all the names and look them all up, sort them, then figure out what
|
||||
// records to return. This could be optimized, but we expect the
|
||||
// number of witnesses to be few and the frequency of calls to be rare
|
||||
std::map<std::string, worker_id_type> workers_by_account_name;
|
||||
for (const worker_object &worker : workers_by_id)
|
||||
if (auto account_iter = _db.find(worker.worker_account))
|
||||
if (account_iter->name >= lower_bound_name) // we can ignore anything below lower_bound_name
|
||||
workers_by_account_name.insert(std::make_pair(account_iter->name, worker.id));
|
||||
|
||||
auto end_iter = workers_by_account_name.begin();
|
||||
while (end_iter != workers_by_account_name.end() && limit--)
|
||||
++end_iter;
|
||||
workers_by_account_name.erase(end_iter, workers_by_account_name.end());
|
||||
return workers_by_account_name;
|
||||
}
|
||||
|
||||
uint64_t database_api_impl::get_worker_count() const {
|
||||
return _db.get_index_type<worker_index>().indices().size();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Votes //
|
||||
|
|
|
|||
|
|
@ -732,6 +732,19 @@ public:
|
|||
*/
|
||||
fc::optional<worker_object> get_worker_by_account(const std::string account_id_or_name) const;
|
||||
|
||||
/**
|
||||
* @brief Get names and IDs for registered workers
|
||||
* @param lower_bound_name Lower bound of the first name to return
|
||||
* @param limit Maximum number of results to return -- must not exceed 1000
|
||||
* @return Map of worker names to corresponding IDs
|
||||
*/
|
||||
map<string, worker_id_type> lookup_worker_accounts(const string &lower_bound_name, uint32_t limit) const;
|
||||
|
||||
/**
|
||||
* @brief Get the total number of workers registered with the blockchain
|
||||
*/
|
||||
uint64_t get_worker_count() const;
|
||||
|
||||
///////////
|
||||
// Votes //
|
||||
///////////
|
||||
|
|
@ -1123,6 +1136,8 @@ FC_API(graphene::app::database_api,
|
|||
// Workers
|
||||
(get_workers)
|
||||
(get_worker_by_account)
|
||||
(lookup_worker_accounts)
|
||||
(get_worker_count)
|
||||
|
||||
// Votes
|
||||
(lookup_vote_ids)
|
||||
|
|
|
|||
|
|
@ -1346,6 +1346,21 @@ class wallet_api
|
|||
*/
|
||||
map<string, committee_member_id_type> list_committee_members(const string& lowerbound, uint32_t limit);
|
||||
|
||||
/** Lists all workers in the blockchain.
|
||||
* This returns a list of all account names that own worker, and the associated worker id,
|
||||
* sorted by name. This lists workers whether they are currently voted in or not.
|
||||
*
|
||||
* Use the \c lowerbound and limit parameters to page through the list. To retrieve all workers,
|
||||
* start by setting \c lowerbound to the empty string \c "", and then each iteration, pass
|
||||
* the last worker name returned as the \c lowerbound for the next \c list_workers() call.
|
||||
*
|
||||
* @param lowerbound the name of the first worker to return. If the named worker does not exist,
|
||||
* the list will start at the worker that comes after \c lowerbound
|
||||
* @param limit the maximum number of worker to return (max: 1000)
|
||||
* @returns a list of worker mapping worker names to worker ids
|
||||
*/
|
||||
map<string, worker_id_type> list_workers(const string& lowerbound, uint32_t limit);
|
||||
|
||||
/** Returns information about the given SON.
|
||||
* @param owner_account the name or id of the SON account owner, or the id of the SON
|
||||
* @returns the information about the SON stored in the block chain
|
||||
|
|
@ -2660,6 +2675,7 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(get_committee_member)
|
||||
(list_witnesses)
|
||||
(list_committee_members)
|
||||
(list_workers)
|
||||
(create_son)
|
||||
(try_create_son)
|
||||
(update_son)
|
||||
|
|
|
|||
|
|
@ -5027,6 +5027,11 @@ map<string,committee_member_id_type> wallet_api::list_committee_members(const st
|
|||
return my->_remote_db->lookup_committee_member_accounts(lowerbound, limit);
|
||||
}
|
||||
|
||||
map<string, worker_id_type> wallet_api::list_workers(const string& lowerbound, uint32_t limit)
|
||||
{
|
||||
return my->_remote_db->lookup_worker_accounts(lowerbound, limit);
|
||||
}
|
||||
|
||||
son_object wallet_api::get_son(string owner_account)
|
||||
{
|
||||
return my->get_son(owner_account);
|
||||
|
|
|
|||
Loading…
Reference in a new issue