Skip to content

Commit

Permalink
#3593: Implement condenser wrapper APIs for RC APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Feb 24, 2020
1 parent bd0c574 commit e51fbaa
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions libraries/plugins/apis/condenser_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target_link_libraries( condenser_api_plugin
market_history_api_plugin
network_broadcast_api_plugin
tags_api_plugin
rc_api_plugin
steem_utilities )
target_include_directories( condenser_api_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
86 changes: 86 additions & 0 deletions libraries/plugins/apis/condenser_api/condenser_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <steem/plugins/follow_api/follow_api_plugin.hpp>
#include <steem/plugins/reputation_api/reputation_api_plugin.hpp>
#include <steem/plugins/market_history_api/market_history_api_plugin.hpp>
#include <steem/plugins/rc_api/rc_api_plugin.hpp>


#include <steem/utilities/git_revision.hpp>
Expand Down Expand Up @@ -137,6 +138,12 @@ namespace detail
(list_proposal_votes)
(get_nai_pool)
(get_smt_balances)
(find_rc_accounts)
(list_rc_accounts)
(find_rc_delegation_pools)
(list_rc_delegation_pools)
(find_rc_delegations)
(list_rc_delegations)
)
void recursively_fetch_content( state& _state, tags::discussion& root, set<string>& referenced_accounts );
Expand All @@ -159,6 +166,7 @@ namespace detail
std::shared_ptr< follow::follow_api > _follow_api;
std::shared_ptr< reputation::reputation_api > _reputation_api;
std::shared_ptr< market_history::market_history_api > _market_history_api;
std::shared_ptr< rc::rc_api > _rc_api;
map< transaction_id_type, confirmation_callback > _callbacks;
map< time_point_sec, vector< transaction_id_type > > _callback_expirations;
boost::signals2::connection _on_post_apply_block_conn;
Expand Down Expand Up @@ -2144,6 +2152,72 @@ namespace detail
return _database_api->find_smt_token_balances( dbapi_args ).balances;
}
DEFINE_API_IMPL( condenser_api_impl, find_rc_accounts )
{
CHECK_ARG_SIZE( 1 )
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
return _rc_api->find_rc_accounts( { args[0].as< vector< account_name_type > >() } ).rc_accounts;
}
DEFINE_API_IMPL( condenser_api_impl, list_rc_accounts )
{
FC_ASSERT( args.size() == 3, "Expected 3 arguments, was ${n}", ("n", args.size()) );
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
rc::list_rc_accounts_args a;
a.start = args[0].as< account_name_type >();
a.limit = args[1].as< uint32_t >();
a.order = args[2].as< rc::sort_order_type >();
return _rc_api->list_rc_accounts( a ).rc_accounts;
}
DEFINE_API_IMPL( condenser_api_impl, find_rc_delegation_pools )
{
CHECK_ARG_SIZE( 1 )
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
return _rc_api->find_rc_delegation_pools( { args[0].as< vector< account_name_type > >() } ).rc_delegation_pools;
}
DEFINE_API_IMPL( condenser_api_impl, list_rc_delegation_pools )
{
FC_ASSERT( args.size() == 3, "Expected 3 arguments, was ${n}", ("n", args.size()) );
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
rc::list_rc_delegation_pools_args a;
a.start = args[0].as< account_name_type >();
a.limit = args[1].as< uint32_t >();
a.order = args[2].as< rc::sort_order_type >();
return _rc_api->list_rc_delegation_pools( a ).rc_delegation_pools;
}
DEFINE_API_IMPL( condenser_api_impl, find_rc_delegations )
{
CHECK_ARG_SIZE( 1 )
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
rc::find_rc_delegations_args a;
a.account = args[0].as< account_name_type >();
return _rc_api->find_rc_delegations( a ).rc_delegations;
}
DEFINE_API_IMPL( condenser_api_impl, list_rc_delegations )
{
FC_ASSERT( args.size() == 3, "Expected 3 arguments, was ${n}", ("n", args.size()) );
FC_ASSERT( _rc_api, "rc_api_plugin not enabled." );
rc::list_rc_delegations_args a;
a.start = args[0].as< account_name_type >();
a.limit = args[1].as< uint32_t >();
a.order = args[2].as< rc::sort_order_type >();
return _rc_api->list_rc_delegations( a ).rc_delegations;
}
} // detail
uint16_t api_account_object::_compute_voting_power( const database_api::api_account_object& a )
Expand Down Expand Up @@ -2250,6 +2324,12 @@ void condenser_api::api_startup()
{
my->_market_history_api = market_history->api;
}
auto rc = appbase::app().find_plugin< rc::rc_api_plugin >();
if( rc != nullptr )
{
my->_rc_api = rc->api;
}
}
DEFINE_LOCKLESS_APIS( condenser_api,
Expand Down Expand Up @@ -2345,6 +2425,12 @@ DEFINE_READ_APIS( condenser_api,
(find_proposals)
(get_nai_pool)
(get_smt_balances)
(find_rc_accounts)
(list_rc_accounts)
(find_rc_delegation_pools)
(list_rc_delegation_pools)
(find_rc_delegations)
(list_rc_delegations)
)
} } } // steem::plugins::condenser_api
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <steem/plugins/reputation_api/reputation_api.hpp>
#include <steem/plugins/market_history_api/market_history_api.hpp>
#include <steem/plugins/condenser_api/condenser_api_legacy_objects.hpp>
#include <steem/plugins/rc_api/rc_api.hpp>

#include <fc/optional.hpp>
#include <fc/variant.hpp>
Expand Down Expand Up @@ -1077,6 +1078,12 @@ DEFINE_API_ARGS( find_proposals, vector< variant >, ve
DEFINE_API_ARGS( list_proposal_votes, vector< variant >, vector< database_api::api_proposal_vote_object > )
DEFINE_API_ARGS( get_nai_pool, vector< variant >, vector< asset_symbol_type > )
DEFINE_API_ARGS( get_smt_balances, vector< variant >, vector< database_api::api_smt_account_balance_object > )
DEFINE_API_ARGS( find_rc_accounts, vector< variant >, vector< rc::rc_account_api_object > )
DEFINE_API_ARGS( list_rc_accounts, vector< variant >, vector< rc::rc_account_api_object > )
DEFINE_API_ARGS( find_rc_delegation_pools, vector< variant >, vector< rc::rc_delegation_pool_api_object > )
DEFINE_API_ARGS( list_rc_delegation_pools, vector< variant >, vector< rc::rc_delegation_pool_api_object > )
DEFINE_API_ARGS( find_rc_delegations, vector< variant >, vector< rc::rc_indel_edge_api_object > )
DEFINE_API_ARGS( list_rc_delegations, vector< variant >, vector< rc::rc_indel_edge_api_object > )

#undef DEFINE_API_ARGS

Expand Down Expand Up @@ -1176,6 +1183,12 @@ class condenser_api
(list_proposal_votes)
(get_nai_pool)
(get_smt_balances)
(find_rc_accounts)
(list_rc_accounts)
(find_rc_delegation_pools)
(list_rc_delegation_pools)
(find_rc_delegations)
(list_rc_delegations)
)

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct pool_delegation

struct rc_account_api_object
{
rc_account_api_object(){}

rc_account_api_object( const rc_account_object& rca, const database& db ) :
account( rca.account ),
creator( rca.creator ),
Expand Down

0 comments on commit e51fbaa

Please sign in to comment.