Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delegation pool support to the cli wallet #3609

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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< 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 )
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 All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions libraries/wallet/include/steem/wallet/remote_node_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};

} }
Expand Down Expand Up @@ -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)
)
117 changes: 117 additions & 0 deletions libraries/wallet/include/steem/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,std::function<string(fc::variant,const fc::variants&)>> get_result_formatters() const;
fc::signal<void(bool)> lock_changed;

Expand Down Expand Up @@ -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) )
31 changes: 31 additions & 0 deletions libraries/wallet/remote_node_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


} }
Loading