Skip to content

Commit

Permalink
#3610: Distinguish sort types and struct tags with enum class, cleanu…
Browse files Browse the repository at this point in the history
…p compilation errors
  • Loading branch information
sgerbino committed Feb 14, 2020
1 parent a065e3a commit 6f67d42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detail
class rc_api_impl;
}

enum sort_order_type
enum class sort_order_type
{
by_name,
by_edge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace steem { namespace plugins { namespace rc {

using namespace appbase;

class rc_api_plugin : public appbase::plugin< rc_api_plugin >
{
public:
Expand Down
38 changes: 22 additions & 16 deletions libraries/plugins/apis/rc_api/rc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,22 @@ DEFINE_API_IMPL( rc_api_impl, list_rc_accounts )

switch( args.order )
{
case( by_name ):
case( sort_order_type::by_name ):
{
iterate_results(
_db.get_index< rc_account_index, by_name >(),
args.start.as< account_name_type >,
args.start.as< account_name_type >(),
result.rc_accounts,
args.limit,
[&]( const rc_account_object& rca ){ return rc_account_api_object( rca, _db ); }
[&]( const rc_account_object& rca ){ return rc_account_api_object( rca, _db ); },
&filter_default< rc_account_object > );
break;
}
default:
FC_ASSERT( false, "Unknown or unsupported sort order" );
}

return result;
}

DEFINE_API_IMPL( rc_api_impl, find_rc_delegation_pools )
Expand Down Expand Up @@ -161,20 +163,22 @@ DEFINE_API_IMPL( rc_api_impl, list_rc_delegation_pools )

switch( args.order )
{
case( by_name ):
case( sort_order_type::by_name ):
{
iterate_results(
_db.get_index< rc_delegation_pool_index, by_account_symbol >(),
boost::make_tuple( args.start.as< account_name_type >(), VESTS_SYMBOL ),
result.rc_delegation_pools,
args.limit,
&on_push_default< rc_delegation_pool_object >
&on_push_default< rc_delegation_pool_object >,
&filter_default< rc_delegation_pool_object > );
break;
}
default:
FC_ASSERT( false, "Unknown or unsupported sort order" );
}

return result;
}

DEFINE_API_IMPL( rc_api_impl, find_rc_delegations )
Expand All @@ -184,7 +188,7 @@ DEFINE_API_IMPL( rc_api_impl, find_rc_delegations )
find_rc_delegations_return result;
result.rc_delegations.reserve( STEEM_RC_MAX_INDEL );

const auto& del_idx = _db.get_index< rc_outdel_drc_edge_index, by_edge >();
const auto& del_idx = _db.get_index< rc_indel_edge_index, by_edge >();

for( auto itr = del_idx.lower_bound( args.account ); itr != del_idx.end() && itr->from_account == args.account; ++itr )
{
Expand All @@ -203,37 +207,39 @@ DEFINE_API_IMPL( rc_api_impl, list_rc_delegations )

switch( args.order )
{
case( by_edge ):
case( sort_order_type::by_edge ):
{
auto key = args.start.as< vector< fc::variant > >();
FC_ASSERT( key.size() == 2, "by_edge start requires 2 values. (from_account, pool_name)" );

iterate_results(
_db.get_index< rc_outdel_drc_edge_index, by_edge >(),
boost::make_tuple( key[0].as< account_name_type >(), key[1].as< account_name_type >() ),
_db.get_index< rc_indel_edge_index, by_edge >(),
boost::make_tuple( key[0].as< account_name_type >(), asset_symbol_type(), key[1].as< account_name_type >() ),
result.rc_delegations,
args.limit,
&on_push_default< rc_outdel_drc_edge_object >
&filter_default< rc_outdel_drc_edge_object > );
&on_push_default< rc_indel_edge_object >,
&filter_default< rc_indel_edge_object > );
break;
}
case( by_pool ):
case( sort_order_type::by_pool ):
{
auto key = args.start.as< vector< fc::variant > >();
FC_ASSERT( key.size() == 2, "by_edge start requires 2 values. (from_account, pool_name)" );

iterate_results(
_db.get_index< rc_outdel_drc_edge_index, by_pool >(),
boost::make_tuple( key[0].as< account_name_type >(), key[1].as< account_name_type >() ),
_db.get_index< rc_indel_edge_index, by_pool >(),
boost::make_tuple( key[0].as< account_name_type >(), asset_symbol_type(), key[1].as< account_name_type >() ),
result.rc_delegations,
args.limit,
&on_push_default< rc_outdel_drc_edge_object >
&filter_default< rc_outdel_drc_edge_object > );
&on_push_default< rc_indel_edge_object >,
&filter_default< rc_indel_edge_object > );
break;
}
default:
FC_ASSERT( false, "Unknown or unsupported sort order" );
}

return result;
}

} // detail
Expand Down

0 comments on commit 6f67d42

Please sign in to comment.