Update API to address #164

This commit is contained in:
Daniel Larimer 2015-07-16 14:28:23 -04:00
parent 46f35d0f89
commit 8ff2c94c52
2 changed files with 18 additions and 11 deletions

View file

@ -650,20 +650,27 @@ namespace graphene { namespace app {
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> database_api::get_key_references( public_key_type key )const
vector<vector<account_id_type>> database_api::get_key_references( vector<public_key_type> keys )const
{
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_key_memberships.find(key);
vector<account_id_type> result;
vector< vector<account_id_type> > final_result;
final_result.reserve(keys.size());
if( itr != refs.account_to_key_memberships.end() )
for( auto& key : keys )
{
result.reserve( itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const primary_index<account_index>&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
auto itr = refs.account_to_key_memberships.find(key);
vector<account_id_type> result;
if( itr != refs.account_to_key_memberships.end() )
{
result.reserve( itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
}
final_result.emplace_back( std::move(result) );
}
return result;
return final_result;
}
/** TODO: add secondary index that will accelerate this process */

View file

@ -276,7 +276,7 @@ namespace graphene { namespace app {
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> get_account_references( account_id_type account_id )const;
vector<account_id_type> get_key_references( public_key_type account_id )const;
vector<vector<account_id_type>> get_key_references( vector<public_key_type> key )const;
/**
* @return all open margin positions for a given account id.