Skip to content

Commit

Permalink
Merge pull request #352 from oxarbitrage/database_api_changes
Browse files Browse the repository at this point in the history
database api changes in witnesses, committee members and workers calls.
  • Loading branch information
oxarbitrage authored Aug 20, 2017
2 parents fc8eb09 + 51fee3f commit 8b56fc5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 21 deletions.
91 changes: 73 additions & 18 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
* Copyright (c) 2017 Cryptonomex, Inc., and contributors.
*
* The MIT License
*
Expand Down Expand Up @@ -54,6 +54,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
database_api_impl( graphene::chain::database& db );
~database_api_impl();


// Objects
fc::variants get_objects(const vector<object_id_type>& ids)const;

Expand All @@ -78,7 +79,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

// Keys
vector<vector<account_id_type>> get_key_references( vector<public_key_type> key )const;
bool is_public_key_registered(string public_key) const;
bool is_public_key_registered(string public_key) const;

// Accounts
vector<optional<account_object>> get_accounts(const vector<account_id_type>& account_ids)const;
Expand Down Expand Up @@ -123,6 +124,12 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<optional<committee_member_object>> get_committee_members(const vector<committee_member_id_type>& committee_member_ids)const;
fc::optional<committee_member_object> get_committee_member_by_account(account_id_type account)const;
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_committee_count()const;

// Workers
vector<worker_object> get_all_workers()const;
vector<optional<worker_object>> get_workers_by_account(account_id_type account)const;
uint64_t get_worker_count()const;

// Votes
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
Expand All @@ -143,6 +150,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Blinded balances
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;


//private:
template<typename T>
void subscribe_to_item( const T& i )const
Expand Down Expand Up @@ -1337,22 +1345,6 @@ vector<optional<witness_object>> database_api::get_witnesses(const vector<witnes
return my->get_witnesses( witness_ids );
}

vector<worker_object> database_api::get_workers_by_account(account_id_type account)const
{
const auto& idx = my->_db.get_index_type<worker_index>().indices().get<by_account>();
auto itr = idx.find(account);
vector<worker_object> result;

if( itr != idx.end() && itr->worker_account == account )
{
result.emplace_back( *itr );
++itr;
}

return result;
}


vector<optional<witness_object>> database_api_impl::get_witnesses(const vector<witness_id_type>& witness_ids)const
{
vector<optional<witness_object>> result; result.reserve(witness_ids.size());
Expand Down Expand Up @@ -1482,6 +1474,69 @@ map<string, committee_member_id_type> database_api_impl::lookup_committee_member
return committee_members_by_account_name;
}

uint64_t database_api::get_committee_count()const
{
return my->get_committee_count();
}

uint64_t database_api_impl::get_committee_count()const
{
return _db.get_index_type<committee_member_index>().indices().size();
}


//////////////////////////////////////////////////////////////////////
// //
// Workers //
// //
//////////////////////////////////////////////////////////////////////

vector<worker_object> database_api::get_all_workers()const
{
return my->get_all_workers();
}

vector<worker_object> database_api_impl::get_all_workers()const
{
vector<worker_object> result;
const auto& workers_idx = _db.get_index_type<worker_index>().indices().get<by_id>();
for( const auto& w : workers_idx )
{
result.push_back( w );
}
return result;
}

vector<optional<worker_object>> database_api::get_workers_by_account(account_id_type account)const
{
return my->get_workers_by_account( account );
}

vector<optional<worker_object>> database_api_impl::get_workers_by_account(account_id_type account)const
{
vector<optional<worker_object>> result;
const auto& workers_idx = _db.get_index_type<worker_index>().indices().get<by_account>();

for( const auto& w : workers_idx )
{
if( w.worker_account == account )
result.push_back( w );
}
return result;
}

uint64_t database_api::get_worker_count()const
{
return my->get_worker_count();
}

uint64_t database_api_impl::get_worker_count()const
{
return _db.get_index_type<worker_index>().indices().size();
}



//////////////////////////////////////////////////////////////////////
// //
// Votes //
Expand Down
32 changes: 29 additions & 3 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,35 @@ class database_api
*/
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;

/**
* @brief Get the total number of committee registered with the blockchain
*/
uint64_t get_committee_count()const;

/// WORKERS

///////////////////////
// Worker proposals //
///////////////////////

/**
* @brief Get all workers
* @return All the workers
*
*/
vector<worker_object> get_all_workers()const;

/**
* Return the worker objects associated with this account.
* @brief Get the workers owned by a given account
* @param account The ID of the account whose worker should be retrieved
* @return The worker object, or null if the account does not have a worker
*/
vector<worker_object> get_workers_by_account(account_id_type account)const;
vector<optional<worker_object>> get_workers_by_account(account_id_type account)const;

/**
* @brief Get the total number of workers registered with the blockchain
*/
uint64_t get_worker_count()const;



///////////
Expand Down Expand Up @@ -657,9 +679,13 @@ FC_API(graphene::app::database_api,
(get_committee_members)
(get_committee_member_by_account)
(lookup_committee_member_accounts)
(get_committee_count)

// workers
(get_all_workers)
(get_workers_by_account)
(get_worker_count)

// Votes
(lookup_vote_ids)

Expand Down

0 comments on commit 8b56fc5

Please sign in to comment.