-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database api changes in witnesses, committee members and workers calls. #352
Merged
oxarbitrage
merged 3 commits into
bitshares:develop
from
oxarbitrage:database_api_changes
Aug 20, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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()); | ||
|
@@ -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 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid iterating through the whole index. Use |
||
{ | ||
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 // | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a bug here,
if
should bewhile
. Fixed in this PR.