From e51fbaafd76aebd7549b56bd5c3bb2e2031e2a17 Mon Sep 17 00:00:00 2001 From: Steve Gerbino Date: Mon, 24 Feb 2020 17:59:08 -0500 Subject: [PATCH] #3593: Implement condenser wrapper APIs for RC APIs --- .../plugins/apis/condenser_api/CMakeLists.txt | 1 + .../apis/condenser_api/condenser_api.cpp | 86 +++++++++++++++++++ .../plugins/condenser_api/condenser_api.hpp | 13 +++ .../include/steem/plugins/rc_api/rc_api.hpp | 2 + 4 files changed, 102 insertions(+) diff --git a/libraries/plugins/apis/condenser_api/CMakeLists.txt b/libraries/plugins/apis/condenser_api/CMakeLists.txt index 50fd9e767f..769ae38d82 100644 --- a/libraries/plugins/apis/condenser_api/CMakeLists.txt +++ b/libraries/plugins/apis/condenser_api/CMakeLists.txt @@ -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" ) diff --git a/libraries/plugins/apis/condenser_api/condenser_api.cpp b/libraries/plugins/apis/condenser_api/condenser_api.cpp index 3c472a28f4..191beede2e 100644 --- a/libraries/plugins/apis/condenser_api/condenser_api.cpp +++ b/libraries/plugins/apis/condenser_api/condenser_api.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -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& referenced_accounts ); @@ -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; @@ -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 ) @@ -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, @@ -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 diff --git a/libraries/plugins/apis/condenser_api/include/steem/plugins/condenser_api/condenser_api.hpp b/libraries/plugins/apis/condenser_api/include/steem/plugins/condenser_api/condenser_api.hpp index f3a05c6479..aa595fe242 100644 --- a/libraries/plugins/apis/condenser_api/include/steem/plugins/condenser_api/condenser_api.hpp +++ b/libraries/plugins/apis/condenser_api/include/steem/plugins/condenser_api/condenser_api.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -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 @@ -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: diff --git a/libraries/plugins/apis/rc_api/include/steem/plugins/rc_api/rc_api.hpp b/libraries/plugins/apis/rc_api/include/steem/plugins/rc_api/rc_api.hpp index b348fcee3a..67bb11ff27 100644 --- a/libraries/plugins/apis/rc_api/include/steem/plugins/rc_api/rc_api.hpp +++ b/libraries/plugins/apis/rc_api/include/steem/plugins/rc_api/rc_api.hpp @@ -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 ),