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..b61a090e50 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< vector< fc::variant > >(); + 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..d0145b5f53 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 ), @@ -73,15 +75,11 @@ struct rc_account_api_object { max_rc = get_maximum_rc( db.get_account( account ), rca ); - db.get_index< chain::comment_index, chain::by_permlink >(); // works - db.get_index< rc_outdel_drc_edge_index, by_edge >(); // does not work - db.get_index< rc_outdel_drc_edge_index >().indices().get< by_edge >(); // works - for( const account_name_type& pool : delegation_slots ) + for ( const account_name_type& pool : delegation_slots ) { pool_delegation del; - db.get< rc_outdel_drc_edge_object, by_edge >( boost::make_tuple( pool, account, VESTS_SYMBOL ) ); // does not work - auto indel_edge = db.find< rc_outdel_drc_edge_object, by_edge >( boost::make_tuple( pool, account, VESTS_SYMBOL ) ); // does not work + auto indel_edge = db.find< rc_outdel_drc_edge_object, by_edge >( boost::make_tuple( pool, account, VESTS_SYMBOL ) ); if( indel_edge != nullptr ) { del.rc_manabar = indel_edge->drc_manabar; diff --git a/libraries/wallet/include/steem/wallet/remote_node_api.hpp b/libraries/wallet/include/steem/wallet/remote_node_api.hpp index 9b0f347c67..87e3994b19 100644 --- a/libraries/wallet/include/steem/wallet/remote_node_api.hpp +++ b/libraries/wallet/include/steem/wallet/remote_node_api.hpp @@ -111,6 +111,12 @@ struct remote_node_api vector< database_api::api_proposal_vote_object > list_proposal_votes( fc::variant, uint32_t, database_api::sort_order_type, database_api::order_direction_type, database_api::proposal_status ); vector< asset_symbol_type > get_nai_pool(void); vector< database_api::api_smt_account_balance_object > get_smt_balances( vector< std::pair < string, string > > ); + vector< rc::rc_account_api_object > find_rc_accounts( vector< account_name_type >); + vector< rc::rc_account_api_object > list_rc_accounts( account_name_type, uint32_t, rc::sort_order_type ); + vector< rc::rc_delegation_pool_api_object > find_rc_delegation_pools( vector< account_name_type > ); + vector< rc::rc_delegation_pool_api_object > list_rc_delegation_pools( account_name_type, uint32_t, rc::sort_order_type ); + vector< rc::rc_indel_edge_api_object > find_rc_delegations( account_name_type ); + vector< rc::rc_indel_edge_api_object > list_rc_delegations( vector< account_name_type >, uint32_t, rc::sort_order_type ); }; } } @@ -206,4 +212,10 @@ FC_API( steem::wallet::remote_node_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) ) diff --git a/libraries/wallet/include/steem/wallet/wallet.hpp b/libraries/wallet/include/steem/wallet/wallet.hpp index c1f30839ba..278f6663c6 100644 --- a/libraries/wallet/include/steem/wallet/wallet.hpp +++ b/libraries/wallet/include/steem/wallet/wallet.hpp @@ -1311,6 +1311,112 @@ class wallet_api */ vector< asset_symbol_type > get_nai_pool(); + /** + * Delegate from a user to a pool. + * + * @param from_account The source account + * @param to_pool The destination pool + * @param amount The amount to delegate + * @param broadcast To broadcast this transaction or not + */ + condenser_api::legacy_signed_transaction delegate_to_pool( + account_name_type from_account, + account_name_type to_pool, + asset amount, + bool broadcast ); + + /** + * Delegate from a pool to a user. + * + * @param from_pool The source pool + * @param to_account The destination account + * @param to_slot The slot + * @param asset_symbol The symbol of the delegation + * @param drc_max_mana The maximum mana to delegate + * @param broadcast To broadcast this transaction or not + */ + condenser_api::legacy_signed_transaction delegate_drc_from_pool( + account_name_type from_pool, + account_name_type to_account, + uint8_t to_slot, + asset_symbol_type asset_symbol, + int64_t drc_max_mana, + bool broadcast ); + + /** + * Designate an account the privilege to delegate a slot. + * + * @param from_pool The source pool + * @param to_account The destination account + * @param to_slot The slot + * @param signer The appointed delegator + * @param broadcast To broadcast this transaction or not + */ + condenser_api::legacy_signed_transaction set_slot_delegator( + account_name_type from_pool, + account_name_type to_account, + uint8_t to_slot, + account_name_type signer, + bool broadcast ); + + /** + * Retrieve RC information for the given accounts. + * + * @param accounts The vector of accounts + */ + vector< rc::rc_account_api_object > find_rc_accounts( vector< account_name_type > accounts ); + + /** + * List RC accounts. + * + * @param account The starting account + * @param limit The limit of returned results + * @param order The sort order + */ + vector< rc::rc_account_api_object > list_rc_accounts( + account_name_type account, + uint32_t limit, + rc::sort_order_type order ); + + /** + * Retrieve RC delegation pools for the given accounts. + * + * @param accounts The vector of accounts + */ + vector< rc::rc_delegation_pool_api_object > find_rc_delegation_pools( vector< account_name_type > accounts ); + + /** + * List RC delegation pools. + * + * @param account The starting account + * @param limit The limit of returned results + * @param order The sort order + */ + vector< rc::rc_delegation_pool_api_object > list_rc_delegation_pools( + account_name_type account, + uint32_t limit, + rc::sort_order_type order ); + + /** + * Retrieve RC delegations information for the given account. + * + * @param account The account + */ + vector< rc::rc_indel_edge_api_object > find_rc_delegations( account_name_type account ); + + /** + * List RC delegations. + * + * @param account The starting account + * @param limit The limit of returned results + * @param order The sort order + */ + vector< rc::rc_indel_edge_api_object > list_rc_delegations( + vector< account_name_type > account, + uint32_t limit, + rc::sort_order_type order ); + + std::map> get_result_formatters() const; fc::signal lock_changed; @@ -1442,6 +1548,17 @@ FC_API( steem::wallet::wallet_api, (smt_setup) (smt_contribute) (get_nai_pool) + + /// delegation pool api + (delegate_to_pool) + (delegate_drc_from_pool) + (set_slot_delegator) + (find_rc_accounts) + (list_rc_accounts) + (find_rc_delegation_pools) + (list_rc_delegation_pools) + (find_rc_delegations) + (list_rc_delegations) ) FC_REFLECT( steem::wallet::memo_data, (from)(to)(nonce)(check)(encrypted) ) diff --git a/libraries/wallet/remote_node_api.cpp b/libraries/wallet/remote_node_api.cpp index 6593b73737..724fbab088 100644 --- a/libraries/wallet/remote_node_api.cpp +++ b/libraries/wallet/remote_node_api.cpp @@ -449,4 +449,35 @@ vector< asset_symbol_type > remote_node_api::get_nai_pool() FC_ASSERT( false ); } +vector< rc::rc_account_api_object > remote_node_api::find_rc_accounts( vector< account_name_type >) +{ + FC_ASSERT( false ); +} + +vector< rc::rc_account_api_object > remote_node_api::list_rc_accounts( account_name_type, uint32_t, rc::sort_order_type ) +{ + FC_ASSERT( false ); +} + +vector< rc::rc_delegation_pool_api_object > remote_node_api::find_rc_delegation_pools( vector< account_name_type > ) +{ + FC_ASSERT( false ); +} + +vector< rc::rc_delegation_pool_api_object > remote_node_api::list_rc_delegation_pools( account_name_type, uint32_t, rc::sort_order_type ) +{ + FC_ASSERT( false ); +} + +vector< rc::rc_indel_edge_api_object > remote_node_api::find_rc_delegations( account_name_type ) +{ + FC_ASSERT( false ); +} + +vector< rc::rc_indel_edge_api_object > remote_node_api::list_rc_delegations( vector< account_name_type >, uint32_t, rc::sort_order_type ) +{ + FC_ASSERT( false ); +} + + } } diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index a4d74c9c1a..04b416f5ec 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -12,6 +12,9 @@ #include #include +#include +#include +#include #include #include @@ -2789,4 +2792,132 @@ condenser_api::legacy_signed_transaction wallet_api::follow( string follower, st return my->_remote_api->get_nai_pool(); } + condenser_api::legacy_signed_transaction wallet_api::delegate_to_pool( + account_name_type from_account, + account_name_type to_pool, + asset amount, + bool broadcast ) + { + using namespace plugins::rc; + FC_ASSERT( !is_locked() ); + + delegate_to_pool_operation cop; + cop.from_account = from_account; + cop.to_pool = to_pool; + cop.amount = amount; + + custom_json_operation op; + op.json = fc::json::to_string( rc_plugin_operation( cop ) ); + op.id = STEEM_RC_PLUGIN_NAME; + + flat_set< account_name_type > required_auths; + cop.get_required_active_authorities( required_auths ); + op.required_auths = required_auths; + + signed_transaction trx; + trx.operations.push_back( op ); + trx.validate(); + return my->sign_transaction( trx, broadcast ); + } + + condenser_api::legacy_signed_transaction wallet_api::delegate_drc_from_pool( + account_name_type from_pool, + account_name_type to_account, + uint8_t to_slot, + asset_symbol_type asset_symbol, + int64_t drc_max_mana, + bool broadcast ) + { + using namespace plugins::rc; + FC_ASSERT( !is_locked() ); + + delegate_drc_from_pool_operation cop; + cop.from_pool = from_pool; + cop.to_account = to_account; + cop.to_slot = to_slot; + cop.drc_max_mana = drc_max_mana; + + custom_json_operation op; + op.json = fc::json::to_string( rc_plugin_operation( cop ) ); + op.id = STEEM_RC_PLUGIN_NAME; + + flat_set< account_name_type > required_auths; + cop.get_required_active_authorities( required_auths ); + op.required_auths = required_auths; + + signed_transaction trx; + trx.operations.push_back( op ); + trx.validate(); + return my->sign_transaction( trx, broadcast ); + } + + condenser_api::legacy_signed_transaction wallet_api::set_slot_delegator( + account_name_type from_pool, + account_name_type to_account, + uint8_t to_slot, + account_name_type signer, + bool broadcast ) + { + using namespace plugins::rc; + FC_ASSERT( !is_locked() ); + + set_slot_delegator_operation cop; + cop.from_pool = from_pool; + cop.to_account = to_account; + cop.to_slot = to_slot; + cop.signer = signer; + + custom_json_operation op; + op.json = fc::json::to_string( rc_plugin_operation( cop ) ); + op.id = STEEM_RC_PLUGIN_NAME; + + flat_set< account_name_type > required_auths; + cop.get_required_active_authorities( required_auths ); + op.required_auths = required_auths; + + signed_transaction trx; + trx.operations.push_back( op ); + trx.validate(); + return my->sign_transaction( trx, broadcast ); + } + + vector< rc::rc_account_api_object > wallet_api::find_rc_accounts( vector< account_name_type > accounts ) + { + return my->_remote_api->find_rc_accounts( accounts ); + } + + vector< rc::rc_account_api_object > wallet_api::list_rc_accounts( + account_name_type account, + uint32_t limit, + rc::sort_order_type order ) + { + return my->_remote_api->list_rc_accounts( account, limit, order ); + } + + vector< rc::rc_delegation_pool_api_object > wallet_api::find_rc_delegation_pools( vector< account_name_type > accounts ) + { + return my->_remote_api->find_rc_delegation_pools( accounts ); + } + + vector< rc::rc_delegation_pool_api_object > wallet_api::list_rc_delegation_pools( + account_name_type account, + uint32_t limit, + rc::sort_order_type order ) + { + return my->_remote_api->list_rc_delegation_pools( account, limit, order ); + } + + vector< rc::rc_indel_edge_api_object > wallet_api::find_rc_delegations( account_name_type account ) + { + return my->_remote_api->find_rc_delegations( account ); + } + + vector< rc::rc_indel_edge_api_object > wallet_api::list_rc_delegations( + vector< account_name_type > accounts, + uint32_t limit, + rc::sort_order_type order ) + { + return my->_remote_api->list_rc_delegations( accounts, limit, order ); + } + } } // steem::wallet