updated API error messages to have clear text format

This commit is contained in:
pravin-battu 2020-09-15 10:15:47 -03:00
parent 149ec3d011
commit 3bc34b3724
3 changed files with 76 additions and 19 deletions

View file

@ -570,7 +570,10 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_get_account_history,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_account_history) );
vector<operation_history_object> result;
account_id_type account;
try {
@ -618,7 +621,10 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_get_account_history_operations,
"Number of querying history accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_account_history_operations) );
vector<operation_history_object> result;
account_id_type account;
try {
@ -658,7 +664,10 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT(limit <= 100);
FC_ASSERT( limit <= api_limit_get_relative_account_history,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_relative_account_history) );
vector<operation_history_object> result;
account_id_type account;
try {
@ -795,7 +804,9 @@ 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 {
FC_ASSERT(limit <= 100);
FC_ASSERT( limit <= api_limit_get_asset_holders,
"Number of querying asset holder accounts can not be greater than ${configured_limit}",
("configured_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 >();

View file

@ -217,6 +217,18 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<offer_history_object> get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const;
vector<offer_history_object> get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const;
uint32_t api_limit_get_lower_bound_symbol = 100;
uint32_t api_limit_get_limit_orders = 300;
uint32_t api_limit_get_limit_orders_by_account = 101;
uint32_t api_limit_get_order_book = 50;
uint32_t api_limit_all_offers_count = 100;
uint32_t api_limit_lookup_accounts = 1000;
uint32_t api_limit_lookup_witness_accounts = 1000;
uint32_t api_limit_lookup_committee_member_accounts = 1000;
uint32_t api_limit_get_trade_history = 100;
uint32_t api_limit_get_trade_history_by_sequence = 100;
//private:
const account_object* get_account_from_string( const std::string& name_or_id,
bool throw_if_not_found = true ) const;
@ -857,7 +869,9 @@ map<string,account_id_type> database_api::lookup_accounts(const string& lower_bo
map<string,account_id_type> database_api_impl::lookup_accounts(const string& lower_bound_name, uint32_t limit)const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= api_limit_lookup_accounts,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_lookup_accounts) );
const auto& accounts_by_name = _db.get_index_type<account_index>().indices().get<by_name>();
map<string,account_id_type> result;
@ -1065,7 +1079,9 @@ vector<asset_object> database_api::list_assets(const string& lower_bound_symbol,
vector<asset_object> database_api_impl::list_assets(const string& lower_bound_symbol, uint32_t limit)const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_get_lower_bound_symbol,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_lower_bound_symbol) );
const auto& assets_by_symbol = _db.get_index_type<asset_index>().indices().get<by_symbol>();
vector<asset_object> result;
result.reserve(limit);
@ -1515,7 +1531,9 @@ 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( limit <= api_limit_get_order_book,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_order_book) );
order_book result;
result.base = base;
@ -1577,7 +1595,9 @@ vector<market_trade> database_api_impl::get_trade_history( const string& base,
fc::time_point_sec stop,
unsigned limit )const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_get_trade_history,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_get_trade_history) );
auto assets = lookup_asset_symbols( {base, quote} );
FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) );
@ -1696,7 +1716,9 @@ map<string, witness_id_type> database_api::lookup_witness_accounts(const string&
map<string, witness_id_type> database_api_impl::lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= api_limit_lookup_witness_accounts,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_lookup_witness_accounts) );
const auto& witnesses_by_id = _db.get_index_type<witness_index>().indices().get<by_id>();
// we want to order witnesses by account name, but that name is in the account object
@ -1772,7 +1794,9 @@ map<string, committee_member_id_type> database_api::lookup_committee_member_acco
map<string, committee_member_id_type> database_api_impl::lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const
{
FC_ASSERT( limit <= 1000 );
FC_ASSERT( limit <= api_limit_lookup_committee_member_accounts,
"Number of querying accounts can not be greater than ${configured_limit}",
("configured_limit", api_limit_lookup_committee_member_accounts) );
const auto& committee_members_by_id = _db.get_index_type<committee_member_index>().indices().get<by_id>();
// we want to order committee_members by account name, but that name is in the account object
@ -2674,7 +2698,9 @@ vector<offer_object> database_api::list_offers(const offer_id_type lower_id, uin
vector<offer_object> database_api_impl::list_offers(const offer_id_type lower_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
vector<offer_object> result;
result.reserve(limit);
@ -2694,7 +2720,9 @@ vector<offer_object> database_api::list_sell_offers(const offer_id_type lower_id
vector<offer_object> database_api_impl::list_sell_offers(const offer_id_type lower_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
vector<offer_object> result;
result.reserve(limit);
@ -2720,7 +2748,9 @@ vector<offer_object> database_api::list_buy_offers(const offer_id_type lower_id,
vector<offer_object> database_api_impl::list_buy_offers(const offer_id_type lower_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
vector<offer_object> result;
result.reserve(limit);
@ -2747,7 +2777,9 @@ vector<offer_history_object> database_api::list_offer_history(const offer_histor
vector<offer_history_object> database_api_impl::list_offer_history(const offer_history_id_type lower_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
vector<offer_history_object> result;
result.reserve(limit);
@ -2767,7 +2799,9 @@ vector<offer_object> database_api::get_offers_by_issuer(const offer_id_type lowe
vector<offer_object> database_api_impl::get_offers_by_issuer(const offer_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
vector<offer_object> result;
result.reserve(limit);
@ -2791,7 +2825,9 @@ vector<offer_object> database_api::get_offers_by_item(const offer_id_type lower_
vector<offer_object> database_api_impl::get_offers_by_item(const offer_id_type lower_id, const nft_id_type item, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& offers_idx = _db.get_index_type<offer_index>().indices().get<by_id>();
vector<offer_object> result;
result.reserve(limit);
@ -2826,7 +2862,9 @@ vector<offer_history_object> database_api::get_offer_history_by_bidder(const off
vector<offer_history_object> database_api_impl::get_offer_history_by_issuer(const offer_history_id_type lower_id, const account_id_type issuer_account_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
vector<offer_history_object> result;
result.reserve(limit);
@ -2847,7 +2885,9 @@ vector<offer_history_object> database_api_impl::get_offer_history_by_issuer(cons
vector<offer_history_object> database_api_impl::get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
vector<offer_history_object> result;
result.reserve(limit);
@ -2869,7 +2909,9 @@ vector<offer_history_object> database_api_impl::get_offer_history_by_item(const
vector<offer_history_object> database_api_impl::get_offer_history_by_bidder(const offer_history_id_type lower_id, const account_id_type bidder_account_id, uint32_t limit) const
{
FC_ASSERT( limit <= 100 );
FC_ASSERT( limit <= api_limit_all_offers_count,
"Number of querying offers can not be greater than ${configured_limit}",
("configured_limit", api_limit_all_offers_count) );
const auto& oh_idx = _db.get_index_type<offer_history_index>().indices().get<by_id>();
vector<offer_history_object> result;
result.reserve(limit);

View file

@ -150,6 +150,9 @@ namespace graphene { namespace app {
fc::time_point_sec start, fc::time_point_sec end )const;
vector<account_balance_object> list_core_accounts()const;
flat_set<uint32_t> get_market_history_buckets()const;
uint32_t api_limit_get_account_history_operations = 100;
uint32_t api_limit_get_account_history = 100;
uint32_t api_limit_get_relative_account_history = 100;
private:
application& _app;
graphene::app::database_api database_api;
@ -354,6 +357,7 @@ namespace graphene { namespace app {
*/
vector<asset_holders> get_all_asset_holders() const;
uint32_t api_limit_get_asset_holders = 100;
private:
graphene::app::application& _app;
graphene::chain::database& _db;