Skip to content

Commit

Permalink
Merge pull request steemit#3614 from steemit/3610-rc-api-delegation-p…
Browse files Browse the repository at this point in the history
…ools

rc_api delegation pools
  • Loading branch information
sgerbino authored Feb 18, 2020
2 parents 2c80a6e + e4e50bb commit 581b1f2
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 218 deletions.
8 changes: 5 additions & 3 deletions libraries/plugins/apis/database_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB HEADERS "include/steem/plugins/database_api/*.hpp")
file(GLOB HEADERS "include/steem/plugins/database_api/*.hpp" "include/steem/plugins/database_api/util/*.hpp")

add_library( database_api_plugin
database_api.cpp
Expand All @@ -8,7 +8,8 @@ add_library( database_api_plugin

target_link_libraries( database_api_plugin chain_plugin json_rpc_plugin )
target_include_directories( database_api_plugin
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}"
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

if( CLANG_TIDY_EXE )
set_target_properties(
Expand All @@ -17,10 +18,11 @@ if( CLANG_TIDY_EXE )
)
endif( CLANG_TIDY_EXE )

install( TARGETS
INSTALL( TARGETS
database_api_plugin

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
INSTALL( FILES ${HEADERS} DESTINATION "include/steem/plugins/database_api" )
361 changes: 185 additions & 176 deletions libraries/plugins/apis/database_api/database_api.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

namespace steem { namespace plugins { namespace database_api { namespace util {

template< typename ResultType >
static ResultType on_push_default( const ResultType& r ) { return r; }

template< typename ValueType >
static bool filter_default( const ValueType& r ) { return true; }

template<typename IndexType, typename StartType, typename ResultType, typename OnPushType, typename FilterType>
void iterate_results(
const IndexType& idx,
StartType start,
std::vector<ResultType>& result,
uint32_t limit,
OnPushType&& on_push,
FilterType&& filter,
bool ascending = true )
{
if( ascending )
{
auto itr = idx.lower_bound( start );
auto end = idx.end();

while( result.size() < limit && itr != end )
{
if( filter( *itr ) )
result.push_back( on_push( *itr ) );

++itr;
}
}
else
{
auto itr = boost::make_reverse_iterator( idx.lower_bound( start ) );
auto end = idx.rend();

while( result.size() < limit && itr != end )
{
if( filter( *itr ) )
result.push_back( on_push( *itr ) );

++itr;
}
}
}

} } } } // steem::plugins::database_api::util
2 changes: 1 addition & 1 deletion libraries/plugins/apis/rc_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_library( rc_api_plugin
${HEADERS}
)

target_link_libraries( rc_api_plugin rc_plugin json_rpc_plugin )
target_link_libraries( rc_api_plugin rc_plugin database_api_plugin json_rpc_plugin )
target_include_directories( rc_api_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

if( CLANG_TIDY_EXE )
Expand Down
159 changes: 142 additions & 17 deletions libraries/plugins/apis/rc_api/include/steem/plugins/rc_api/rc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <steem/plugins/json_rpc/utility.hpp>
#include <steem/plugins/rc/rc_objects.hpp>

#include <steem/protocol/types.hpp>
#include <steem/chain/comment_object.hpp>

#include <fc/optional.hpp>
#include <fc/variant.hpp>
Expand All @@ -17,6 +17,20 @@ namespace detail
class rc_api_impl;
}

enum class sort_order_type
{
by_name,
by_edge,
by_pool
};

struct list_object_args_type
{
fc::variant start;
uint32_t limit;
sort_order_type order;
};

using plugins::json_rpc::void_type;

typedef void_type get_resource_params_args;
Expand All @@ -40,12 +54,57 @@ struct get_resource_pool_return
variant_object resource_pool;
};

struct pool_delegation
{
steem::chain::util::manabar rc_manabar;
int64_t max_mana = 0;
};

struct rc_account_api_object
{
account_name_type account;
rc_account_api_object( const rc_account_object& rca, const database& db ) :
account( rca.account ),
creator( rca.creator ),
rc_manabar( rca.rc_manabar ),
max_rc_creation_adjustment( rca.max_rc_creation_adjustment ),
vests_delegated_to_pools( rca.vests_delegated_to_pools ),
delegation_slots( rca.indel_slots ),
out_delegation_total( rca.out_delegations )
{
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 )
{
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
if( indel_edge != nullptr )
{
del.rc_manabar = indel_edge->drc_manabar;
del.max_mana = indel_edge->drc_max_mana;
}

incoming_delegations[ pool ] = del;
}
}

account_name_type account;
account_name_type creator;
steem::chain::util::manabar rc_manabar;
asset max_rc_creation_adjustment = asset( 0, VESTS_SYMBOL );
int64_t max_rc = 0;
asset max_rc_creation_adjustment = asset( 0, VESTS_SYMBOL );
int64_t max_rc = 0;
asset vests_delegated_to_pools = asset( 0 , VESTS_SYMBOL );
fc::array< account_name_type, STEEM_RC_MAX_SLOTS >
delegation_slots;

flat_map< account_name_type, pool_delegation >
incoming_delegations;

uint32_t out_delegation_total = 0;

//
// This is used for bug-catching, to match that the vesting shares in a
Expand All @@ -61,14 +120,50 @@ struct rc_account_api_object

struct find_rc_accounts_args
{
std::vector< account_name_type > accounts;
std::vector< account_name_type > accounts;
};

struct find_rc_accounts_return
{
std::vector< rc_account_api_object > rc_accounts;
std::vector< rc_account_api_object > rc_accounts;
};

typedef list_object_args_type list_rc_accounts_args;

typedef find_rc_accounts_return list_rc_accounts_return;

typedef rc_delegation_pool_object rc_delegation_pool_api_object;

struct find_rc_delegation_pools_args
{
std::vector< account_name_type > accounts;
};

struct find_rc_delegation_pools_return
{
std::vector< rc_delegation_pool_api_object > rc_delegation_pools;
};

typedef list_object_args_type list_rc_delegation_pools_args;

typedef find_rc_delegation_pools_return list_rc_delegation_pools_return;

typedef rc_indel_edge_object rc_indel_edge_api_object;

struct find_rc_delegations_args
{
account_name_type account;
};

struct find_rc_delegations_return
{
std::vector< rc_indel_edge_api_object > rc_delegations;
};

typedef list_object_args_type list_rc_delegations_args;

typedef find_rc_delegations_return list_rc_delegations_return;

class rc_api
{
public:
Expand All @@ -79,6 +174,11 @@ class rc_api
(get_resource_params)
(get_resource_pool)
(find_rc_accounts)
(list_rc_accounts)
(find_rc_delegation_pools)
(list_rc_delegation_pools)
(find_rc_delegations)
(list_rc_delegations)
)

private:
Expand All @@ -87,31 +187,56 @@ class rc_api

} } } // steem::plugins::rc

FC_REFLECT_ENUM( steem::plugins::rc::sort_order_type,
(by_name)
(by_edge)
(by_pool) )

FC_REFLECT( steem::plugins::rc::list_object_args_type,
(start)
(limit)
(order) )

FC_REFLECT( steem::plugins::rc::get_resource_params_return,
(resource_names)
(resource_params)
(size_info)
)
(size_info) )

FC_REFLECT( steem::plugins::rc::resource_pool_api_object,
(pool)
)
(pool) )

FC_REFLECT( steem::plugins::rc::get_resource_pool_return,
(resource_pool)
)
(resource_pool) )

FC_REFLECT( steem::plugins::rc::pool_delegation,
(rc_manabar)
(max_mana) )

FC_REFLECT( steem::plugins::rc::rc_account_api_object,
(account)
(creator)
(rc_manabar)
(max_rc_creation_adjustment)
(max_rc)
)
(vests_delegated_to_pools)
(delegation_slots)
(incoming_delegations)
(out_delegation_total) )

FC_REFLECT( steem::plugins::rc::find_rc_accounts_args,
(accounts)
)
(accounts) )

FC_REFLECT( steem::plugins::rc::find_rc_accounts_return,
(rc_accounts)
)
(rc_accounts) )

FC_REFLECT( steem::plugins::rc::find_rc_delegation_pools_args,
(accounts) )

FC_REFLECT( steem::plugins::rc::find_rc_delegation_pools_return,
(rc_delegation_pools) )

FC_REFLECT( steem::plugins::rc::find_rc_delegations_args,
(account) )

FC_REFLECT( steem::plugins::rc::find_rc_delegations_return,
(rc_delegations) )
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
Loading

0 comments on commit 581b1f2

Please sign in to comment.