Skip to content

Commit

Permalink
issue fix for 782 and 783
Browse files Browse the repository at this point in the history
  • Loading branch information
manikey123 committed Feb 19, 2019
1 parent 8fea035 commit 05d13ed
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 18 deletions.
26 changes: 16 additions & 10 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
uint64_t api_limit_get_account_history=_app.get_options().api_limit_get_account_history;
FC_ASSERT( limit <= api_limit_get_account_history );
vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -353,7 +354,8 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
uint64_t api_limit_get_account_history_operations=_app.get_options().api_limit_get_account_history_operations;
FC_ASSERT(limit <= api_limit_get_account_history_operations);
vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -392,7 +394,8 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT(limit <= 100);
uint64_t api_limit_get_relative_account_history=_app.get_options().api_limit_get_relative_account_history;
FC_ASSERT(limit <= api_limit_get_relative_account_history);
vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -431,7 +434,8 @@ namespace graphene { namespace app {

history_operation_detail history_api::get_account_history_by_operations(const std::string account_id_or_name, vector<uint16_t> operation_types, uint32_t start, unsigned limit)
{
FC_ASSERT(limit <= 100);
uint64_t api_limit_get_account_history_by_operations=_app.get_options().api_limit_get_account_history_by_operations;
FC_ASSERT(limit <= api_limit_get_account_history_by_operations);
history_operation_detail result;
vector<operation_history_object> objs = get_relative_account_history(account_id_or_name, start, limit, limit + start - 1);
std::for_each(objs.begin(), objs.end(), [&](const operation_history_object &o) {
Expand Down Expand Up @@ -530,14 +534,15 @@ namespace graphene { namespace app {

// asset_api
asset_api::asset_api(graphene::app::application& app) :
_db( *app.chain_database()),
database_api( std::ref(*app.chain_database()), &(app.get_options())
_app(app),
_db( *app.chain_database()),
database_api( std::ref(*app.chain_database()), &(app.get_options())
) { }
asset_api::~asset_api() { }

vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
FC_ASSERT(limit <= 100);

uint64_t api_limit_get_asset_holders=_app.get_options().api_limit_get_asset_holders;
FC_ASSERT(limit <= api_limit_get_asset_holders);
asset_id_type asset_id = database_api.get_asset_id_from_string( asset );

const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
Expand Down Expand Up @@ -622,8 +627,9 @@ namespace graphene { namespace app {
optional<price> start,
uint32_t limit )const
{
FC_ASSERT( limit <= 101 );
auto plugin = _app.get_plugin<grouped_orders_plugin>( "grouped_orders" );
uint64_t api_limit_get_grouped_limit_orders=_app.get_options().api_limit_get_grouped_limit_orders;
FC_ASSERT( limit <= api_limit_get_grouped_limit_orders );
auto plugin = _app.get_plugin<graphene::grouped_orders::grouped_orders_plugin>( "grouped_orders" );
FC_ASSERT( plugin );
const auto& limit_groups = plugin->limit_order_groups();
vector< limit_order_group > result;
Expand Down
74 changes: 74 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,44 @@ void application_impl::set_dbg_init_key( graphene::chain::genesis_state_type& ge
genesis.initial_witness_candidates[i].block_signing_key = init_pubkey;
}


void application_impl::set_dgb_api_limit_api() {
if (_options->count("api-limit-get-account-history-operations")) {
_app_options.api_limit_get_account_history_operations = _options->at("api-limit-get-account-history-operations").as<uint64_t>();
}
if(_options->count("api-limit-get-account-history")){
_app_options.api_limit_get_account_history = _options->at("api-limit-get-account-history").as<uint64_t>();
}
if(_options->count("api-limit-get-grouped-limit-orders")){
_app_options.api_limit_get_grouped_limit_orders = _options->at("api-limit-get-grouped-limit-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-relative-account-history")){
_app_options.api_limit_get_relative_account_history = _options->at("api-limit-get-relative-account-history").as<uint64_t>();
}
if(_options->count("api-limit-get-account-history-by-operations")){
_app_options.api_limit_get_account_history_by_operations = _options->at("api-limit-get-account-history-by-operations").as<uint64_t>();
}
if(_options->count("api-limit-get-asset-holders")){
_app_options.api_limit_get_asset_holders = _options->at("api-limit-get-asset-holders").as<uint64_t>();
}
if(_options->count("api-limit-get-limit-orders")){
_app_options.api_limit_get_limit_orders = _options->at("api-limit-get-limit-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-key-references")){
_app_options.api_limit_get_key_references = _options->at("api-limit-get-key-references").as<uint64_t>();
}
if(_options->count("api-limit-get-call-orders")){
_app_options.api_limit_get_call_orders = _options->at("api-limit-get-call-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-settle-orders")){
_app_options.api_limit_get_settle_orders = _options->at("api-limit-get-settle-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-order-book")){
_app_options.api_limit_get_order_book = _options->at("api-limit-get-order-book").as<uint64_t>();
}

}

void application_impl::startup()
{ try {
fc::create_directories(_data_dir / "blockchain");
Expand Down Expand Up @@ -437,6 +475,8 @@ void application_impl::startup()
if ( _options->count("enable-subscribe-to-all") )
_app_options.enable_subscribe_to_all = _options->at( "enable-subscribe-to-all" ).as<bool>();

set_dgb_api_limit_api();

if( _active_plugins.find( "market_history" ) != _active_plugins.end() )
_app_options.has_market_history_plugin = true;

Expand Down Expand Up @@ -975,6 +1015,28 @@ void application::set_program_options(boost::program_options::options_descriptio
("enable-standby-votes-tracking", bpo::value<bool>()->implicit_value(true),
"Whether to enable tracking of votes of standby witnesses and committee members. "
"Set it to true to provide accurate data to API clients, set to false for slightly better performance.")
("api-limit-get-account-history-operations",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history_operations to set its default limit value as 100")
("api-limit-get-account-history",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history to set its default limit value as 100")
("api-limit-get-grouped-limit-orders",boost::program_options::value<uint64_t>()->default_value(101),
"For orders_api::get_grouped_limit_orders to set its default limit value as 101")
("api-limit-get-relative-account-history",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_relative_account_history to set its default limit value as 100")
("api-limit-get-account-history-by-operations",boost::program_options::value<uint64_t>()->default_value(100),
"For history_api::get_account_history_by_operations to set its default limit value as 100")
("api-limit-get-asset-holders",boost::program_options::value<uint64_t>()->default_value(100),
"For asset_api::get_asset_holders to set its default limit value as 100")
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_key_references to set its default limit value as 100")
("api-limit-get-limit-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_limit_orders to set its default limit value as 300")
("api-limit-get-call-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_call_orders to set its default limit value as 300")
("api-limit-get-settle-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_settle_orders to set its default limit value as 300")
("api-limit-get-order-book",boost::program_options::value<uint64_t>()->default_value(50),
"For database_api_impl::get_order_book to set its default limit value as 50")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down Expand Up @@ -1013,6 +1075,18 @@ void application::startup()
throw;
}
}
void application::set_dgb_api_limit_api()
{
try {
my->set_dgb_api_limit_api();
} catch ( const fc::exception& e ) {
elog( "${e}", ("e",e.to_detail_string()) );
throw;
} catch ( ... ) {
elog( "unexpected exception" );
throw;
}
}

std::shared_ptr<abstract_plugin> application::get_plugin(const string& name) const
{
Expand Down
1 change: 1 addition & 0 deletions libraries/app/application_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class application_impl : public net::node_delegate
}

void set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key );
void set_dgb_api_limit_api();

void startup();

Expand Down
25 changes: 19 additions & 6 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
}
vector<limit_order_object> get_limit_orders(const asset_id_type a, const asset_id_type b, const uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
FC_ASSERT( _app_options && _app_options->api_limit_get_limit_orders, "App needs to be passed");
uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders;
FC_ASSERT( limit <= api_limit_get_limit_orders );

const auto& limit_order_idx = _db.get_index_type<limit_order_index>();
const auto& limit_price_idx = limit_order_idx.indices().get<by_price>();
Expand Down Expand Up @@ -649,7 +651,6 @@ dynamic_global_property_object database_api_impl::get_dynamic_global_properties(

vector<vector<account_id_type>> database_api::get_key_references( vector<public_key_type> key )const
{
FC_ASSERT(key.size() <= 100, "Number of keys must be 100 or less");
return my->get_key_references( key );
}

Expand All @@ -658,6 +659,9 @@ vector<vector<account_id_type>> database_api::get_key_references( vector<public_
*/
vector<vector<account_id_type>> database_api_impl::get_key_references( vector<public_key_type> keys )const
{
FC_ASSERT( _app_options && _app_options->api_limit_get_key_references, "App needs to be passed");
uint64_t api_limit_get_key_references=_app_options->api_limit_get_key_references;
FC_ASSERT(keys.size() <= api_limit_get_key_references);
const auto& idx = _db.get_index_type<account_index>();
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
Expand Down Expand Up @@ -1255,7 +1259,9 @@ vector<limit_order_object> database_api::get_limit_orders(std::string a, std::st
*/
vector<limit_order_object> database_api_impl::get_limit_orders(const std::string& a, const std::string& b, uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
FC_ASSERT( _app_options && _app_options->api_limit_get_limit_orders, "App needs to be passed");
uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders;
FC_ASSERT( limit <= api_limit_get_limit_orders );

const asset_id_type asset_a_id = get_asset_from_string(a)->id;
const asset_id_type asset_b_id = get_asset_from_string(b)->id;
Expand All @@ -1270,7 +1276,9 @@ vector<call_order_object> database_api::get_call_orders(const std::string& a, ui

vector<call_order_object> database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
FC_ASSERT( _app_options && _app_options->api_limit_get_call_orders, "App needs to be passed");
uint64_t api_limit_get_call_orders=_app_options->api_limit_get_call_orders;
FC_ASSERT( limit <= api_limit_get_call_orders );

const asset_id_type asset_a_id = get_asset_from_string(a)->id;
const auto& call_index = _db.get_index_type<call_order_index>().indices().get<by_price>();
Expand All @@ -1295,7 +1303,9 @@ vector<force_settlement_object> database_api::get_settle_orders(const std::strin

vector<force_settlement_object> database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
FC_ASSERT( _app_options && _app_options->api_limit_get_settle_orders, "App needs to be passed");
uint64_t api_limit_get_settle_orders=_app_options->api_limit_get_settle_orders;
FC_ASSERT( limit <= api_limit_get_settle_orders );

const asset_id_type asset_a_id = get_asset_from_string(a)->id;
const auto& settle_index = _db.get_index_type<force_settlement_index>().indices().get<by_expiration>();
Expand Down Expand Up @@ -1464,7 +1474,10 @@ order_book database_api::get_order_book( const string& base, const string& quote
order_book database_api_impl::get_order_book( const string& base, const string& quote, unsigned limit )const
{
using boost::multiprecision::uint128_t;
FC_ASSERT( limit <= 50 );

FC_ASSERT( _app_options && _app_options->api_limit_get_order_book, "App needs to be passed");
uint64_t api_limit_get_order_book=_app_options->api_limit_get_order_book;
FC_ASSERT( limit <= api_limit_get_order_book );

order_book result;
result.base = base;
Expand Down
1 change: 1 addition & 0 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ namespace graphene { namespace app {
vector<asset_holders> get_all_asset_holders() const;

private:
graphene::app::application& _app;
graphene::chain::database& _db;
graphene::app::database_api database_api;
};
Expand Down
13 changes: 12 additions & 1 deletion libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ namespace graphene { namespace app {
public:
bool enable_subscribe_to_all = false;
bool has_market_history_plugin = false;
uint64_t api_limit_get_account_history_operations=100;
uint64_t api_limit_get_account_history=100;
uint64_t api_limit_get_grouped_limit_orders=101;
uint64_t api_limit_get_relative_account_history=100;
uint64_t api_limit_get_account_history_by_operations=100;
uint64_t api_limit_get_asset_holders=100;
uint64_t api_limit_get_key_references=100;
uint64_t api_limit_get_limit_orders=300;
uint64_t api_limit_get_call_orders=300;
uint64_t api_limit_get_settle_orders=300;
uint64_t api_limit_get_order_book=50;
};

class application
Expand Down Expand Up @@ -90,7 +101,7 @@ namespace graphene { namespace app {

net::node_ptr p2p_node();
std::shared_ptr<chain::database> chain_database()const;

void set_dgb_api_limit_api();
void set_block_production(bool producing_blocks);
fc::optional< api_access_info > get_api_access_info( const string& username )const;
void set_api_access_info(const string& username, api_access_info&& permissions);
Expand Down
Loading

0 comments on commit 05d13ed

Please sign in to comment.