From aabe3472e35375b915473f2f017c22075d88578e Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Thu, 15 Feb 2018 09:28:35 -0800 Subject: [PATCH] Fix condenser_api.get_witnesses_by_vote #2126 --- .../apis/condenser_api/condenser_api.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libraries/plugins/apis/condenser_api/condenser_api.cpp b/libraries/plugins/apis/condenser_api/condenser_api.cpp index e40ccc8c07..e16d2ed316 100644 --- a/libraries/plugins/apis/condenser_api/condenser_api.cpp +++ b/libraries/plugins/apis/condenser_api/condenser_api.cpp @@ -1136,16 +1136,26 @@ namespace detail DEFINE_API_IMPL( condenser_api_impl, get_witnesses_by_vote ) { CHECK_ARG_SIZE( 2 ) - auto start = _database_api->list_witnesses( { args[0], 1, database_api::by_name } ); + account_name_type start_name = args[0].as< account_name_type >(); + vector< fc::variant > start_key; + + if( start_name == account_name_type() ) + { + start_key.push_back( fc::variant( std::numeric_limits< int64_t >::max() ) ); + start_key.push_back( fc::variant( account_name_type() ) ); + } + else + { + auto start = _database_api->list_witnesses( { args[0], 1, database_api::by_name } ); - if( start.witnesses.size() == 0 ) - return get_witnesses_by_vote_return(); + if( start.witnesses.size() == 0 ) + return get_witnesses_by_vote_return(); - auto limit = args[1].as< uint32_t >(); - vector< fc::variant > start_key; - start_key.push_back( fc::variant( start.witnesses[0].votes ) ); - start_key.push_back( fc::variant( start.witnesses[0].owner ) ); + start_key.push_back( fc::variant( start.witnesses[0].votes ) ); + start_key.push_back( fc::variant( start.witnesses[0].owner ) ); + } + auto limit = args[1].as< uint32_t >(); auto witnesses = _database_api->list_witnesses( { fc::variant( start_key ), limit, database_api::by_vote_name } ).witnesses; get_witnesses_by_vote_return result;