adding API call to return all accounts that reference a particular key id or account

This commit is contained in:
Daniel Larimer 2015-06-24 15:38:28 -04:00
parent 045cfbd914
commit ffd797c048
2 changed files with 24 additions and 0 deletions

View file

@ -478,6 +478,25 @@ namespace graphene { namespace app {
return result; return result;
} FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) } } FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) }
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> database_api::get_account_references( object_id_type key_or_account_id )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_memberships.find(key_or_account_id);
vector<account_id_type> result;
if( itr != refs.account_to_memberships.end() )
{
result.reserve( itr->second.size() );
for( auto item : itr->second ) result.push_back(item);
}
return result;
}
/** TODO: add secondary index that will accelerate this process */ /** TODO: add secondary index that will accelerate this process */
vector<proposal_object> database_api::get_proposed_transactions( account_id_type id )const vector<proposal_object> database_api::get_proposed_transactions( account_id_type id )const
{ {

View file

@ -237,6 +237,10 @@ namespace graphene { namespace app {
*/ */
vector<proposal_object> get_proposed_transactions( account_id_type id )const; vector<proposal_object> get_proposed_transactions( account_id_type id )const;
/**
* @return all accounts that referr to the key or account id in their owner or active authorities.
*/
vector<account_id_type> get_account_references( object_id_type key_or_account_id )const;
private: private:
/** called every time a block is applied to report the objects that were changed */ /** called every time a block is applied to report the objects that were changed */
@ -378,6 +382,7 @@ FC_API(graphene::app::database_api,
(cancel_all_subscriptions) (cancel_all_subscriptions)
(get_transaction_hex) (get_transaction_hex)
(get_proposed_transactions) (get_proposed_transactions)
(get_account_references)
) )
FC_API(graphene::app::history_api, (get_account_history)(get_market_history)(get_market_history_buckets)) FC_API(graphene::app::history_api, (get_account_history)(get_market_history)(get_market_history_buckets))
FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers)) FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers))