Skip to content

Commit

Permalink
#270 get_workers() function in wallet_api
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Dobromyslov committed Feb 8, 2022
1 parent 65df816 commit b24a6ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,12 @@ class wallet_api
*/
committee_member_object get_committee_member(string owner_account);

/** Returns information about the given worker.
* @param owner_account the name or id of the worker account owner, or the id of the worker
* @returns the information about the workers stored in the block chain
*/
vector<worker_object> get_workers(string owner_account);


/** Creates a SON object owned by the given account.
*
Expand Down Expand Up @@ -2673,6 +2679,7 @@ FC_API( graphene::wallet::wallet_api,
(get_witness)
(is_witness)
(get_committee_member)
(get_workers)
(list_witnesses)
(list_committee_members)
(list_workers)
Expand Down
48 changes: 48 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,49 @@ class wallet_api_impl
FC_CAPTURE_AND_RETHROW( (owner_account) )
}

vector<worker_object> get_workers(string owner_account)
{
try
{
fc::optional<worker_id_type> worker_id = maybe_id<worker_id_type>(owner_account);
if (worker_id)
{
std::vector<worker_id_type> ids_to_get;
ids_to_get.push_back(*worker_id);
std::vector<fc::optional<worker_object>> worker_objects = _remote_db->get_workers(ids_to_get);

if(!worker_objects.empty()) {
std::vector<worker_object> result;
for (const auto &worker_object : worker_objects) {
if (worker_object)
result.emplace_back(*worker_object);
}
return result;
}
else
FC_THROW("No workers is registered for id ${id}", ("id", owner_account));
}
else
{
// then maybe it's the owner account
try
{
std::string owner_account_id = account_id_to_string(get_account_id(owner_account));
auto workers = _remote_db->get_workers_by_account(owner_account_id);
if (!workers.empty())
return workers;
else
FC_THROW("No workers is registered for account ${account}", ("account", owner_account));
}
catch (const fc::exception&)
{
FC_THROW("No account or worker named ${account}", ("account", owner_account));
}
}
}
FC_CAPTURE_AND_RETHROW( (owner_account) )
}

bool is_witness(string owner_account)
{
try
Expand Down Expand Up @@ -5052,6 +5095,11 @@ committee_member_object wallet_api::get_committee_member(string owner_account)
return my->get_committee_member(owner_account);
}

vector<worker_object> wallet_api::get_workers(string owner_account)
{
return my->get_workers(owner_account);
}

signed_transaction wallet_api::create_vesting_balance(string owner_account,
string amount,
string asset_symbol,
Expand Down

0 comments on commit b24a6ac

Please sign in to comment.