Skip to content

Commit

Permalink
Merge cjs-collat-asset-container-pr into cjs-bsip87
Browse files Browse the repository at this point in the history
  • Loading branch information
christophersanborn committed May 3, 2020
2 parents 09a96da + 02f9da8 commit 9e8332a
Show file tree
Hide file tree
Showing 36 changed files with 3,597 additions and 614 deletions.
3 changes: 3 additions & 0 deletions docker/default_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ rpc-endpoint = 0.0.0.0:8090
# For database_api_impl::get_limit_orders to set max limit value
# api-limit-get-limit-orders = 300

# For database_api_impl::get_limit_orders_by_account to set max limit value
# api-limit-get-limit-orders-by-account = 101

# For database_api_impl::get_order_book to set max limit value
# api-limit-get-order-book = 50

Expand Down
83 changes: 58 additions & 25 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,12 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
uint64_t api_limit_get_account_history=_app.get_options().api_limit_get_account_history;
FC_ASSERT( limit <= api_limit_get_account_history );

const auto configured_limit = _app.get_options().api_limit_get_account_history;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -387,12 +391,16 @@ namespace graphene { namespace app {
int operation_type,
operation_history_id_type start,
operation_history_id_type stop,
unsigned limit) const
unsigned limit ) const
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
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);

const auto configured_limit = _app.get_options().api_limit_get_account_history_operations;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -427,12 +435,16 @@ namespace graphene { namespace app {
vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
uint64_t stop,
unsigned limit,
uint64_t start) const
uint64_t start ) const
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
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);

const auto configured_limit = _app.get_options().api_limit_get_relative_account_history;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<operation_history_object> result;
account_id_type account;
try {
Expand Down Expand Up @@ -469,24 +481,38 @@ namespace graphene { namespace app {
return hist->tracked_buckets();
}

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)
history_operation_detail history_api::get_account_history_by_operations( const std::string account_id_or_name,
flat_set<uint16_t> operation_types,
uint32_t start, unsigned limit )const
{
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);
const auto configured_limit = _app.get_options().api_limit_get_account_history_by_operations;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

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) {
if (operation_types.empty() || find(operation_types.begin(), operation_types.end(), o.op.which()) != operation_types.end()) {
result.operation_history_objs.push_back(o);
}
});
vector<operation_history_object> objs = get_relative_account_history( account_id_or_name, start, limit,
limit + start - 1 );
result.total_count = objs.size();

if( operation_types.empty() )
result.operation_history_objs = std::move(objs);
else
{
for( const operation_history_object &o : objs )
{
if( operation_types.find(o.op.which()) != operation_types.end() ) {
result.operation_history_objs.push_back(o);
}
}
}

result.total_count = objs.size();
return result;
return result;
}

vector<bucket_object> history_api::get_market_history( std::string asset_a, std::string asset_b,
uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const
uint32_t bucket_seconds,
fc::time_point_sec start, fc::time_point_sec end )const
{ try {
FC_ASSERT(_app.chain_database());
const auto& db = *_app.chain_database();
Expand Down Expand Up @@ -577,9 +603,13 @@ namespace graphene { namespace app {
) { }
asset_api::~asset_api() { }

vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
uint64_t api_limit_get_asset_holders=_app.get_options().api_limit_get_asset_holders;
FC_ASSERT(limit <= api_limit_get_asset_holders);
vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const
{
const auto configured_limit = _app.get_options().api_limit_get_asset_holders;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

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 >();
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
Expand Down Expand Up @@ -660,8 +690,11 @@ namespace graphene { namespace app {
optional<price> start,
uint32_t limit )const
{
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 );
const auto configured_limit = _app.get_options().api_limit_get_grouped_limit_orders;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

auto plugin = _app.get_plugin<graphene::grouped_orders::grouped_orders_plugin>( "grouped_orders" );
FC_ASSERT( plugin );
const auto& limit_groups = plugin->limit_order_groups();
Expand Down
5 changes: 5 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ void application_impl::set_api_limit() {
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-limit-orders-by-account")){
_app_options.api_limit_get_limit_orders_by_account = _options->at("api-limit-get-limit-orders-by-account").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>();
}
Expand Down Expand Up @@ -1079,6 +1082,8 @@ void application::set_program_options(boost::program_options::options_descriptio
"For database_api_impl::list_assets and get_assets_by_issuer to set max limit value")
("api-limit-get-limit-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_limit_orders to set max limit value")
("api-limit-get-limit-orders-by-account",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::get_limit_orders_by_account to set max limit value")
("api-limit-get-order-book",boost::program_options::value<uint64_t>()->default_value(50),
"For database_api_impl::get_order_book to set max limit value")
("api-limit-lookup-accounts",boost::program_options::value<uint64_t>()->default_value(1000),
Expand Down
Loading

0 comments on commit 9e8332a

Please sign in to comment.