From 8ff2c94c52436d677a2be30d31b07fef31f9cb7f Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 16 Jul 2015 14:28:23 -0400 Subject: [PATCH] Update API to address #164 --- libraries/app/api.cpp | 27 ++++++++++++++-------- libraries/app/include/graphene/app/api.hpp | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index f192c765..864539c0 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -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 database_api::get_key_references( public_key_type key )const + vector> database_api::get_key_references( vector keys )const { - const auto& idx = _db.get_index_type(); - const auto& aidx = dynamic_cast&>(idx); - const auto& refs = aidx.get_secondary_index(); - auto itr = refs.account_to_key_memberships.find(key); - vector result; + vector< vector > 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(); + const auto& aidx = dynamic_cast&>(idx); + const auto& refs = aidx.get_secondary_index(); + auto itr = refs.account_to_key_memberships.find(key); + vector 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 */ diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 109de097..f820044b 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -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 get_account_references( account_id_type account_id )const; - vector get_key_references( public_key_type account_id )const; + vector> get_key_references( vector key )const; /** * @return all open margin positions for a given account id.