From 3b3ad70c2f342974600ed2d40ddb942c601e5546 Mon Sep 17 00:00:00 2001 From: pravin-battu Date: Thu, 6 Aug 2020 09:51:47 -0300 Subject: [PATCH 1/4] websocket related changes --- libraries/app/application.cpp | 2 +- libraries/plugins/delayed_node/delayed_node_plugin.cpp | 2 +- programs/cli_wallet/main.cpp | 6 +++--- tests/cli/main.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 2c7553f5..db73124f 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -226,7 +226,7 @@ namespace detail { void new_connection( const fc::http::websocket_connection_ptr& c ) { - auto wsc = std::make_shared(*c, GRAPHENE_MAX_NESTED_OBJECTS); + auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); auto login = std::make_shared( std::ref(*_self) ); login->enable_api("database_api"); diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index d49129b0..3eadda34 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -65,7 +65,7 @@ void delayed_node_plugin::plugin_set_program_options(bpo::options_description& c void delayed_node_plugin::connect() { - my->client_connection = std::make_shared(*my->client.connect(my->remote_endpoint), GRAPHENE_MAX_NESTED_OBJECTS); + my->client_connection = std::make_shared(my->client.connect(my->remote_endpoint), GRAPHENE_MAX_NESTED_OBJECTS); my->database_api = my->client_connection->get_remote_api(0); my->client_connection_closed = my->client_connection->closed.connect([this] { connection_failed(); diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index b7abdabe..89b01dbf 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -176,7 +176,7 @@ int main( int argc, char** argv ) fc::http::websocket_client client; idump((wdata.ws_server)); auto con = client.connect( wdata.ws_server ); - auto apic = std::make_shared(*con, GRAPHENE_MAX_NESTED_OBJECTS); + auto apic = std::make_shared(con, GRAPHENE_MAX_NESTED_OBJECTS); auto remote_api = apic->get_remote_api< login_api >(1); edump((wdata.ws_user)(wdata.ws_password) ); @@ -215,7 +215,7 @@ int main( int argc, char** argv ) _websocket_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ std::cout << "here... \n"; wlog("." ); - auto wsc = std::make_shared(*c, GRAPHENE_MAX_NESTED_OBJECTS); + auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); c->set_session_data( wsc ); }); @@ -232,7 +232,7 @@ int main( int argc, char** argv ) if( options.count("rpc-tls-endpoint") ) { _websocket_tls_server->on_connection([&]( const fc::http::websocket_connection_ptr& c ){ - auto wsc = std::make_shared(*c, GRAPHENE_MAX_NESTED_OBJECTS); + auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); c->set_session_data( wsc ); }); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 9e7a4119..6fcdbaa0 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -226,7 +226,7 @@ public: wallet_data.ws_password = ""; websocket_connection = websocket_client.connect( wallet_data.ws_server ); - api_connection = std::make_shared(*websocket_connection, GRAPHENE_MAX_NESTED_OBJECTS); + api_connection = std::make_shared(websocket_connection, GRAPHENE_MAX_NESTED_OBJECTS); remote_login_api = api_connection->get_remote_api< graphene::app::login_api >(1); BOOST_CHECK(remote_login_api->login( wallet_data.ws_user, wallet_data.ws_password ) ); -- 2.45.2 From 50bfb4e2f0dd2764af2dcb4fccad16e432e55505 Mon Sep 17 00:00:00 2001 From: pravin-battu Date: Thu, 6 Aug 2020 13:58:14 -0300 Subject: [PATCH 2/4] updates main.cpp --- programs/cli_wallet/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index 89b01dbf..fda7f22d 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -209,9 +209,10 @@ int main( int argc, char** argv ) wallet_cli->set_prompt( locked ? "locked >>> " : "unlocked >>> " ); })); - auto _websocket_server = std::make_shared(); + std::shared_ptr _websocket_server; if( options.count("rpc-endpoint") ) { + _websocket_server = std::make_shared(); _websocket_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ std::cout << "here... \n"; wlog("." ); @@ -228,9 +229,10 @@ int main( int argc, char** argv ) if( options.count( "rpc-tls-certificate" ) ) cert_pem = options.at("rpc-tls-certificate").as(); - auto _websocket_tls_server = std::make_shared(cert_pem); + std::shared_ptr _websocket_tls_server; if( options.count("rpc-tls-endpoint") ) { + _websocket_tls_server = std::make_shared(cert_pem); _websocket_tls_server->on_connection([&]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); -- 2.45.2 From 211708d884362a1d2ef0786421d59e82947e9397 Mon Sep 17 00:00:00 2001 From: pravin-battu Date: Wed, 12 Aug 2020 10:07:35 -0300 Subject: [PATCH 3/4] Bump fc version for ws-updates --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index a76b9ff8..fb27454c 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit a76b9ff81c6887ebe1dc9fa03ef15e1433029c65 +Subproject commit fb27454cdf1626e5e108e42848bd1bcfe60c9540 -- 2.45.2 From 3bc34b3724dd84381615ff676de1a9e2bc556a9e Mon Sep 17 00:00:00 2001 From: pravin-battu Date: Tue, 15 Sep 2020 10:15:47 -0300 Subject: [PATCH 4/4] updated API error messages to have clear text format --- libraries/app/api.cpp | 19 ++++-- libraries/app/database_api.cpp | 72 +++++++++++++++++----- libraries/app/include/graphene/app/api.hpp | 4 ++ 3 files changed, 76 insertions(+), 19 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index c808a27c..47bf18d2 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -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 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 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 result; account_id_type account; try { @@ -795,7 +804,9 @@ namespace graphene { namespace app { asset_api::~asset_api() { } vector 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 >(); diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 6b14f2bc..d7c6b708 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -217,6 +217,18 @@ class database_api_impl : public std::enable_shared_from_this vector get_offer_history_by_item(const offer_history_id_type lower_id, const nft_id_type item, uint32_t limit) const; vector 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 database_api::lookup_accounts(const string& lower_bo map 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().indices().get(); map result; @@ -1065,7 +1079,9 @@ vector database_api::list_assets(const string& lower_bound_symbol, vector 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().indices().get(); vector 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 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 database_api::lookup_witness_accounts(const string& map 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().indices().get(); // we want to order witnesses by account name, but that name is in the account object @@ -1772,7 +1794,9 @@ map database_api::lookup_committee_member_acco map 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().indices().get(); // we want to order committee_members by account name, but that name is in the account object @@ -2674,7 +2698,9 @@ vector database_api::list_offers(const offer_id_type lower_id, uin vector 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().indices().get(); vector result; result.reserve(limit); @@ -2694,7 +2720,9 @@ vector database_api::list_sell_offers(const offer_id_type lower_id vector 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().indices().get(); vector result; result.reserve(limit); @@ -2720,7 +2748,9 @@ vector database_api::list_buy_offers(const offer_id_type lower_id, vector 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().indices().get(); vector result; result.reserve(limit); @@ -2747,7 +2777,9 @@ vector database_api::list_offer_history(const offer_histor vector 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().indices().get(); vector result; result.reserve(limit); @@ -2767,7 +2799,9 @@ vector database_api::get_offers_by_issuer(const offer_id_type lowe vector 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().indices().get(); vector result; result.reserve(limit); @@ -2791,7 +2825,9 @@ vector database_api::get_offers_by_item(const offer_id_type lower_ vector 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().indices().get(); vector result; result.reserve(limit); @@ -2826,7 +2862,9 @@ vector database_api::get_offer_history_by_bidder(const off vector 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().indices().get(); vector result; result.reserve(limit); @@ -2847,7 +2885,9 @@ vector database_api_impl::get_offer_history_by_issuer(cons vector 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().indices().get(); vector result; result.reserve(limit); @@ -2869,7 +2909,9 @@ vector database_api_impl::get_offer_history_by_item(const vector 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().indices().get(); vector result; result.reserve(limit); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 4adf73a3..e4329141 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -150,6 +150,9 @@ namespace graphene { namespace app { fc::time_point_sec start, fc::time_point_sec end )const; vector list_core_accounts()const; flat_set 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 get_all_asset_holders() const; + uint32_t api_limit_get_asset_holders = 100; private: graphene::app::application& _app; graphene::chain::database& _db; -- 2.45.2