Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7185 from EOSIO/add-get-account-ram-corrections
Browse files Browse the repository at this point in the history
add get_account_ram_corrections to producer API
  • Loading branch information
arhag committed Apr 23, 2019
2 parents 3443d37 + 19ea05c commit 3ed95b4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/producer_api_plugin/producer_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void producer_api_plugin::plugin_startup() {
CALL(producer, producer, get_supported_protocol_features,
INVOKE_R_R(producer, get_supported_protocol_features,
producer_plugin::get_supported_protocol_features_params), 201),
CALL(producer, producer, get_account_ram_corrections,
INVOKE_R_R(producer, get_account_ram_corrections, producer_plugin::get_account_ram_corrections_params), 201),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ class producer_plugin : public appbase::plugin<producer_plugin> {
bool exclude_unactivatable = false;
};

struct get_account_ram_corrections_params {
optional<account_name> lower_bound;
optional<account_name> upper_bound;
uint32_t limit = 10;
bool reverse = false;
};

struct get_account_ram_corrections_result {
std::vector<fc::variant> rows;
optional<account_name> more;
};

template<typename T>
using next_function = std::function<void(const fc::static_variant<fc::exception_ptr, T>&)>;

Expand Down Expand Up @@ -100,6 +112,8 @@ class producer_plugin : public appbase::plugin<producer_plugin> {

fc::variants get_supported_protocol_features( const get_supported_protocol_features_params& params ) const;

get_account_ram_corrections_result get_account_ram_corrections( const get_account_ram_corrections_params& params ) const;

signal<void(const chain::producer_confirmation&)> confirmed_block;
private:
std::shared_ptr<class producer_plugin_impl> my;
Expand All @@ -114,3 +128,5 @@ FC_REFLECT(eosio::producer_plugin::integrity_hash_information, (head_block_id)(i
FC_REFLECT(eosio::producer_plugin::snapshot_information, (head_block_id)(snapshot_name))
FC_REFLECT(eosio::producer_plugin::scheduled_protocol_feature_activations, (protocol_features_to_activate))
FC_REFLECT(eosio::producer_plugin::get_supported_protocol_features_params, (exclude_disabled)(exclude_unactivatable))
FC_REFLECT(eosio::producer_plugin::get_account_ram_corrections_params, (lower_bound)(upper_bound)(limit)(reverse))
FC_REFLECT(eosio::producer_plugin::get_account_ram_corrections_result, (rows)(more))
44 changes: 44 additions & 0 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,50 @@ fc::variants producer_plugin::get_supported_protocol_features( const get_support
return results;
}

producer_plugin::get_account_ram_corrections_result
producer_plugin::get_account_ram_corrections( const get_account_ram_corrections_params& params ) const {
get_account_ram_corrections_result result;
const auto& db = my->chain_plug->chain().db();

const auto& idx = db.get_index<chain::account_ram_correction_index, chain::by_name>();
account_name lower_bound_value = std::numeric_limits<uint64_t>::lowest();
account_name upper_bound_value = std::numeric_limits<uint64_t>::max();

if( params.lower_bound ) {
lower_bound_value = *params.lower_bound;
}

if( params.upper_bound ) {
upper_bound_value = *params.upper_bound;
}

if( upper_bound_value < lower_bound_value )
return result;

auto walk_range = [&]( auto itr, auto end_itr ) {
for( unsigned int count = 0;
count < params.limit && itr != end_itr;
++itr )
{
result.rows.push_back( fc::variant( *itr ) );
++count;
}
if( itr != end_itr ) {
result.more = itr->name;
}
};

auto lower = idx.lower_bound( lower_bound_value );
auto upper = idx.upper_bound( upper_bound_value );
if( params.reverse ) {
walk_range( boost::make_reverse_iterator(upper), boost::make_reverse_iterator(lower) );
} else {
walk_range( lower, upper );
}

return result;
}

optional<fc::time_point> producer_plugin_impl::calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const {
chain::controller& chain = chain_plug->chain();
const auto& hbs = chain.head_block_state();
Expand Down

0 comments on commit 3ed95b4

Please sign in to comment.