From cfa8a73636ade3bdb41410d6244c246c684678ee Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 4 May 2019 19:11:53 -0300 Subject: [PATCH 01/25] add by_authorized withdraw objects to get_full_accounts results --- libraries/app/database_api.cpp | 17 ++++++++++++----- .../chain/withdraw_permission_object.hpp | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 8227fa9f4a..cc81c7a41b 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -968,11 +968,18 @@ std::map database_api_impl::get_full_accounts( const }); // get withdraws permissions - auto withdraw_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(withdraw_range.first, withdraw_range.second, - [&acnt] (const withdraw_permission_object& withdraw) { - acnt.withdraws.emplace_back(withdraw); - }); + auto withdraw_indices = _db.get_index_type().indices(); + auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); + std::for_each(withdraw_from_range.first, withdraw_from_range.second, + [&acnt] (const withdraw_permission_object& withdraw) { + acnt.withdraws.emplace_back(withdraw); + }); + auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); + std::for_each(withdraw_authorized_range.first, withdraw_authorized_range.second, + [&acnt] (const withdraw_permission_object& withdraw) { + if ( std::find(acnt.withdraws.begin(), acnt.withdraws.end(), withdraw) == acnt.withdraws.end() ) + acnt.withdraws.emplace_back(withdraw); + }); // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); diff --git a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp index f202ee1b66..adc3a73a28 100644 --- a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp +++ b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp @@ -77,6 +77,8 @@ namespace graphene { namespace chain { ? withdrawal_limit.amount - claimed_this_period : 0, withdrawal_limit.asset_id ); } + + bool operator==(const withdraw_permission_object& in) { return this->id == in.id; } }; struct by_from; From cab48aef565104688d04a0810a4907b38473b3b3 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 6 May 2019 16:38:37 -0300 Subject: [PATCH 02/25] add api-limit-get-full-accounts to application, complete implementation of api-limit-get-htlc-by --- libraries/app/application.cpp | 7 +++++++ libraries/app/include/graphene/app/application.hpp | 1 + 2 files changed, 8 insertions(+) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 8f089c0b0b..85cbad4f93 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -343,6 +343,9 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-get-htlc-by")) { _app_options.api_limit_get_htlc_by = _options->at("api-limit-get-htlc-by").as(); } + if(_options->count("api-limit-get-full-accounts")) { + _app_options.api_limit_get_full_accounts = _options->at("api-limit-get-full-accounts").as(); + } } void application_impl::startup() @@ -1020,6 +1023,10 @@ void application::set_program_options(boost::program_options::options_descriptio "For asset_api::get_asset_holders to set its default limit value as 100") ("api-limit-get-key-references",boost::program_options::value()->default_value(100), "For database_api_impl::get_key_references to set its default limit value as 100") + ("api-limit-get-htlc-by",boost::program_options::value()->default_value(100), + "For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100") + ("api-limit-get-full-accounts",boost::program_options::value()->default_value(100), + "For database_api_impl::get_full_accounts to set its lists default limit values as 100") ; command_line_options.add(configuration_file_options); command_line_options.add_options() diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 226fc0053f..6fa094760d 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -48,6 +48,7 @@ namespace graphene { namespace app { uint64_t api_limit_get_asset_holders = 100; uint64_t api_limit_get_key_references = 100; uint64_t api_limit_get_htlc_by = 100; + uint64_t api_limit_get_full_accounts = 100; }; class application From ee0df87ec8bca801a1361990e3e3f1e456e42349 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 6 May 2019 18:37:42 -0300 Subject: [PATCH 03/25] add configurable limits to get_full_account lists --- libraries/app/database_api.cpp | 70 ++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index cc81c7a41b..0dafb0d640 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -921,78 +921,98 @@ std::map database_api_impl::get_full_accounts( const { acnt.cashback_balance = account->cashback_balance(_db); } + + uint64_t api_limit_get_full_accounts = _app_options->api_limit_get_full_accounts; + // Add the account's proposals auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { - acnt.proposals.reserve( required_approvals_itr->second.size() ); + acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts) ); for( auto proposal_id : required_approvals_itr->second ) + { acnt.proposals.push_back( proposal_id(_db) ); + if(acnt.proposals.size() >= api_limit_get_full_accounts) + break; + } } - // Add the account's balances const auto& balances = _db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >().get_account_balances( account->id ); for( const auto balance : balances ) + { acnt.balances.emplace_back( *balance.second ); + if(acnt.balances.size() >= api_limit_get_full_accounts) + break; + } // Add the account's vesting balances auto vesting_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(vesting_range.first, vesting_range.second, - [&acnt](const vesting_balance_object& balance) { - acnt.vesting_balances.emplace_back(balance); - }); + [&acnt, api_limit_get_full_accounts](const vesting_balance_object& balance) { + if(acnt.vesting_balances.size() < api_limit_get_full_accounts) + acnt.vesting_balances.emplace_back(balance); + }); // Add the account's orders auto order_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(order_range.first, order_range.second, - [&acnt] (const limit_order_object& order) { - acnt.limit_orders.emplace_back(order); - }); + [&acnt, api_limit_get_full_accounts] (const limit_order_object& order) { + if(acnt.limit_orders.size() < api_limit_get_full_accounts) + acnt.limit_orders.emplace_back(order); + }); auto call_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(call_range.first, call_range.second, - [&acnt] (const call_order_object& call) { - acnt.call_orders.emplace_back(call); - }); + [&acnt, api_limit_get_full_accounts] (const call_order_object& call) { + if(acnt.call_orders.size() < api_limit_get_full_accounts) + acnt.call_orders.emplace_back(call); + }); auto settle_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(settle_range.first, settle_range.second, - [&acnt] (const force_settlement_object& settle) { - acnt.settle_orders.emplace_back(settle); - }); + [&acnt, api_limit_get_full_accounts] (const force_settlement_object& settle) { + if(acnt.settle_orders.size() < api_limit_get_full_accounts) + acnt.settle_orders.emplace_back(settle); + }); // get assets issued by user auto asset_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(asset_range.first, asset_range.second, - [&acnt] (const asset_object& asset) { - acnt.assets.emplace_back(asset.id); - }); + [&acnt, api_limit_get_full_accounts] (const asset_object& asset) { + if(acnt.assets.size() < api_limit_get_full_accounts) + acnt.assets.emplace_back(asset.id); + }); // get withdraws permissions auto withdraw_indices = _db.get_index_type().indices(); auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); std::for_each(withdraw_from_range.first, withdraw_from_range.second, - [&acnt] (const withdraw_permission_object& withdraw) { - acnt.withdraws.emplace_back(withdraw); + [&acnt, api_limit_get_full_accounts] (const withdraw_permission_object& withdraw) { + if(acnt.withdraws.size() < api_limit_get_full_accounts) + acnt.withdraws.emplace_back(withdraw); }); auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); std::for_each(withdraw_authorized_range.first, withdraw_authorized_range.second, - [&acnt] (const withdraw_permission_object& withdraw) { - if ( std::find(acnt.withdraws.begin(), acnt.withdraws.end(), withdraw) == acnt.withdraws.end() ) + [&acnt, api_limit_get_full_accounts] (const withdraw_permission_object& withdraw) { + if((std::find(acnt.withdraws.begin(), acnt.withdraws.end(), withdraw) == acnt.withdraws.end()) or + (acnt.withdraws.size() < api_limit_get_full_accounts)) acnt.withdraws.emplace_back(withdraw); }); // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(htlc_from_range.first, htlc_from_range.second, - [&acnt] (const htlc_object& htlc) { - acnt.htlcs.emplace_back(htlc); + [&acnt, api_limit_get_full_accounts] (const htlc_object& htlc) { + if(acnt.htlcs.size() < api_limit_get_full_accounts) + acnt.htlcs.emplace_back(htlc); }); auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); std::for_each(htlc_to_range.first, htlc_to_range.second, - [&acnt] (const htlc_object& htlc) { - if ( std::find(acnt.htlcs.begin(), acnt.htlcs.end(), htlc) == acnt.htlcs.end() ) + [&acnt, api_limit_get_full_accounts] (const htlc_object& htlc) { + if ((std::find(acnt.htlcs.begin(), acnt.htlcs.end(), htlc) == acnt.htlcs.end()) or + (acnt.htlcs.size() < api_limit_get_full_accounts)) acnt.htlcs.emplace_back(htlc); }); + results[account_name_or_id] = acnt; } return results; From 31f28a26e653a275bf6101e0241a391842bda074 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 7 May 2019 18:14:39 -0300 Subject: [PATCH 04/25] remove operator== overload from htlc and withdraw objects --- libraries/chain/include/graphene/chain/htlc_object.hpp | 3 --- .../include/graphene/chain/withdraw_permission_object.hpp | 2 -- 2 files changed, 5 deletions(-) diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index da853877d3..5ba0918e9c 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -84,9 +84,6 @@ namespace graphene { namespace chain { typedef account_id_type result_type; const result_type& operator()(const htlc_object& o)const { return o.transfer.to; } }; - - bool operator==(const htlc_object& in) { return this->id == in.id; } - }; struct by_from_id; diff --git a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp index adc3a73a28..f202ee1b66 100644 --- a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp +++ b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp @@ -77,8 +77,6 @@ namespace graphene { namespace chain { ? withdrawal_limit.amount - claimed_this_period : 0, withdrawal_limit.asset_id ); } - - bool operator==(const withdraw_permission_object& in) { return this->id == in.id; } }; struct by_from; From 55098b8f686b56c0ca04c604ec0716235ef317fe Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 7 May 2019 18:15:26 -0300 Subject: [PATCH 05/25] add more_data struct to full_account --- .../app/include/graphene/app/full_account.hpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libraries/app/include/graphene/app/full_account.hpp b/libraries/app/include/graphene/app/full_account.hpp index 139eb5cc1e..58d0b26e6e 100644 --- a/libraries/app/include/graphene/app/full_account.hpp +++ b/libraries/app/include/graphene/app/full_account.hpp @@ -31,6 +31,19 @@ namespace graphene { namespace app { using namespace graphene::chain; + struct more_data + { + bool balances = false; + bool vesting_balances = false; + bool limit_orders = false; + bool call_orders = false; + bool settle_orders = false; + bool proposals = false; + bool assets = false; + bool withdraws = false; + bool htlcs = false; + }; + struct full_account { account_object account; @@ -49,10 +62,16 @@ namespace graphene { namespace app { vector assets; vector withdraws; vector htlcs; + more_data more_data_available; }; } } +FC_REFLECT( graphene::app::more_data, + (balances) (vesting_balances) (limit_orders) (call_orders) + (settle_orders) (proposals) (assets) (withdraws) (htlcs) + ) + FC_REFLECT( graphene::app::full_account, (account) (statistics) @@ -70,4 +89,5 @@ FC_REFLECT( graphene::app::full_account, (assets) (withdraws) (htlcs) + (more_data_available) ) From d10f970852039b786c32c7d4297b2301d2b5fc66 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 7 May 2019 18:16:35 -0300 Subject: [PATCH 06/25] change for_eachs to for, populate more_data flags, remove find --- libraries/app/database_api.cpp | 127 ++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 0dafb0d640..ba0dc97202 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -932,8 +932,10 @@ std::map database_api_impl::get_full_accounts( const for( auto proposal_id : required_approvals_itr->second ) { acnt.proposals.push_back( proposal_id(_db) ); - if(acnt.proposals.size() >= api_limit_get_full_accounts) + if(acnt.proposals.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.proposals = true; break; + } } } @@ -942,76 +944,103 @@ std::map database_api_impl::get_full_accounts( const for( const auto balance : balances ) { acnt.balances.emplace_back( *balance.second ); - if(acnt.balances.size() >= api_limit_get_full_accounts) + if(acnt.balances.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.balances = true; break; + } } // Add the account's vesting balances auto vesting_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(vesting_range.first, vesting_range.second, - [&acnt, api_limit_get_full_accounts](const vesting_balance_object& balance) { - if(acnt.vesting_balances.size() < api_limit_get_full_accounts) - acnt.vesting_balances.emplace_back(balance); - }); + for(auto itr = vesting_range.first; itr != vesting_range.second; ++itr) + { + acnt.vesting_balances.emplace_back(*itr); + if(acnt.vesting_balances.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.vesting_balances = true; + break; + } + } // Add the account's orders auto order_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(order_range.first, order_range.second, - [&acnt, api_limit_get_full_accounts] (const limit_order_object& order) { - if(acnt.limit_orders.size() < api_limit_get_full_accounts) - acnt.limit_orders.emplace_back(order); - }); + for(auto itr = order_range.first; itr != order_range.second; ++itr) + { + acnt.limit_orders.emplace_back(*itr); + if(acnt.limit_orders.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.limit_orders = true; + break; + } + } auto call_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(call_range.first, call_range.second, - [&acnt, api_limit_get_full_accounts] (const call_order_object& call) { - if(acnt.call_orders.size() < api_limit_get_full_accounts) - acnt.call_orders.emplace_back(call); - }); + for(auto itr = call_range.first; itr != call_range.second; ++itr) + { + acnt.call_orders.emplace_back(*itr); + if(acnt.call_orders.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.call_orders = true; + break; + } + } auto settle_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(settle_range.first, settle_range.second, - [&acnt, api_limit_get_full_accounts] (const force_settlement_object& settle) { - if(acnt.settle_orders.size() < api_limit_get_full_accounts) - acnt.settle_orders.emplace_back(settle); - }); + for(auto itr = settle_range.first; itr != settle_range.second; ++itr) + { + acnt.settle_orders.emplace_back(*itr); + if(acnt.settle_orders.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.settle_orders = true; + break; + } + } // get assets issued by user auto asset_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(asset_range.first, asset_range.second, - [&acnt, api_limit_get_full_accounts] (const asset_object& asset) { - if(acnt.assets.size() < api_limit_get_full_accounts) - acnt.assets.emplace_back(asset.id); - }); + for(auto itr = asset_range.first; itr != asset_range.second; ++itr) + { + acnt.assets.emplace_back(itr->id); + if(acnt.assets.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.assets = true; + break; + } + } // get withdraws permissions auto withdraw_indices = _db.get_index_type().indices(); auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); - std::for_each(withdraw_from_range.first, withdraw_from_range.second, - [&acnt, api_limit_get_full_accounts] (const withdraw_permission_object& withdraw) { - if(acnt.withdraws.size() < api_limit_get_full_accounts) - acnt.withdraws.emplace_back(withdraw); - }); + for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) + { + acnt.withdraws.emplace_back(*itr); + if(acnt.withdraws.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.withdraws = true; + break; + } + } auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); - std::for_each(withdraw_authorized_range.first, withdraw_authorized_range.second, - [&acnt, api_limit_get_full_accounts] (const withdraw_permission_object& withdraw) { - if((std::find(acnt.withdraws.begin(), acnt.withdraws.end(), withdraw) == acnt.withdraws.end()) or - (acnt.withdraws.size() < api_limit_get_full_accounts)) - acnt.withdraws.emplace_back(withdraw); - }); + for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) + { + acnt.withdraws.emplace_back(*itr); + if(acnt.withdraws.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.withdraws = true; + break; + } + } // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(htlc_from_range.first, htlc_from_range.second, - [&acnt, api_limit_get_full_accounts] (const htlc_object& htlc) { - if(acnt.htlcs.size() < api_limit_get_full_accounts) - acnt.htlcs.emplace_back(htlc); - }); + for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) + { + acnt.htlcs.emplace_back(*itr); + if(acnt.htlcs.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.htlcs = true; + break; + } + } auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); - std::for_each(htlc_to_range.first, htlc_to_range.second, - [&acnt, api_limit_get_full_accounts] (const htlc_object& htlc) { - if ((std::find(acnt.htlcs.begin(), acnt.htlcs.end(), htlc) == acnt.htlcs.end()) or - (acnt.htlcs.size() < api_limit_get_full_accounts)) - acnt.htlcs.emplace_back(htlc); - }); + for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) + { + acnt.htlcs.emplace_back(*itr); + if(acnt.htlcs.size() >= api_limit_get_full_accounts) { + acnt.more_data_available.htlcs = true; + break; + } + } results[account_name_or_id] = acnt; } From 3aba3f76d47e6e4b20707c69a51de43d5dc3f84b Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 11:33:20 -0300 Subject: [PATCH 07/25] have 2 limit options for get_full_accounts for vector accounts and list limits --- libraries/app/application.cpp | 7 ++++- libraries/app/database_api.cpp | 28 ++++++++++--------- .../app/include/graphene/app/application.hpp | 3 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 85cbad4f93..5dbfdfacc3 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -346,6 +346,9 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-get-full-accounts")) { _app_options.api_limit_get_full_accounts = _options->at("api-limit-get-full-accounts").as(); } + if(_options->count("api-limit-get-full-accounts-lists")) { + _app_options.api_limit_get_full_accounts_lists = _options->at("api-limit-get-full-accounts-lists").as(); + } } void application_impl::startup() @@ -1025,7 +1028,9 @@ void application::set_program_options(boost::program_options::options_descriptio "For database_api_impl::get_key_references to set its default limit value as 100") ("api-limit-get-htlc-by",boost::program_options::value()->default_value(100), "For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100") - ("api-limit-get-full-accounts",boost::program_options::value()->default_value(100), + ("api-limit-get-full-accounts",boost::program_options::value()->default_value(10), + "For database_api_impl::get_full_accounts to set its account default limit values as 10") + ("api-limit-get-full-accounts-lists",boost::program_options::value()->default_value(100), "For database_api_impl::get_full_accounts to set its lists default limit values as 100") ; command_line_options.add(configuration_file_options); diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index ba0dc97202..4fb1c4affb 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -889,6 +889,8 @@ std::map database_api::get_full_accounts( const vector database_api_impl::get_full_accounts( const vector& names_or_ids, bool subscribe) { + FC_ASSERT( names_or_ids.size() <= _app_options->api_limit_get_full_accounts ); + const auto& proposal_idx = _db.get_index_type(); const auto& pidx = dynamic_cast(proposal_idx); const auto& proposals_by_account = pidx.get_secondary_index(); @@ -922,17 +924,17 @@ std::map database_api_impl::get_full_accounts( const acnt.cashback_balance = account->cashback_balance(_db); } - uint64_t api_limit_get_full_accounts = _app_options->api_limit_get_full_accounts; + uint64_t api_limit_get_full_accounts_lists = _app_options->api_limit_get_full_accounts_lists; // Add the account's proposals auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { - acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts) ); + acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts_lists) ); for( auto proposal_id : required_approvals_itr->second ) { acnt.proposals.push_back( proposal_id(_db) ); - if(acnt.proposals.size() >= api_limit_get_full_accounts) { + if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.proposals = true; break; } @@ -944,7 +946,7 @@ std::map database_api_impl::get_full_accounts( const for( const auto balance : balances ) { acnt.balances.emplace_back( *balance.second ); - if(acnt.balances.size() >= api_limit_get_full_accounts) { + if(acnt.balances.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.balances = true; break; } @@ -955,7 +957,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = vesting_range.first; itr != vesting_range.second; ++itr) { acnt.vesting_balances.emplace_back(*itr); - if(acnt.vesting_balances.size() >= api_limit_get_full_accounts) { + if(acnt.vesting_balances.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.vesting_balances = true; break; } @@ -966,7 +968,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = order_range.first; itr != order_range.second; ++itr) { acnt.limit_orders.emplace_back(*itr); - if(acnt.limit_orders.size() >= api_limit_get_full_accounts) { + if(acnt.limit_orders.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.limit_orders = true; break; } @@ -975,7 +977,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = call_range.first; itr != call_range.second; ++itr) { acnt.call_orders.emplace_back(*itr); - if(acnt.call_orders.size() >= api_limit_get_full_accounts) { + if(acnt.call_orders.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.call_orders = true; break; } @@ -984,7 +986,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = settle_range.first; itr != settle_range.second; ++itr) { acnt.settle_orders.emplace_back(*itr); - if(acnt.settle_orders.size() >= api_limit_get_full_accounts) { + if(acnt.settle_orders.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.settle_orders = true; break; } @@ -995,7 +997,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = asset_range.first; itr != asset_range.second; ++itr) { acnt.assets.emplace_back(itr->id); - if(acnt.assets.size() >= api_limit_get_full_accounts) { + if(acnt.assets.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.assets = true; break; } @@ -1007,7 +1009,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) { acnt.withdraws.emplace_back(*itr); - if(acnt.withdraws.size() >= api_limit_get_full_accounts) { + if(acnt.withdraws.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.withdraws = true; break; } @@ -1016,7 +1018,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { acnt.withdraws.emplace_back(*itr); - if(acnt.withdraws.size() >= api_limit_get_full_accounts) { + if(acnt.withdraws.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.withdraws = true; break; } @@ -1027,7 +1029,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) { acnt.htlcs.emplace_back(*itr); - if(acnt.htlcs.size() >= api_limit_get_full_accounts) { + if(acnt.htlcs.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.htlcs = true; break; } @@ -1036,7 +1038,7 @@ std::map database_api_impl::get_full_accounts( const for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) { acnt.htlcs.emplace_back(*itr); - if(acnt.htlcs.size() >= api_limit_get_full_accounts) { + if(acnt.htlcs.size() >= api_limit_get_full_accounts_lists) { acnt.more_data_available.htlcs = true; break; } diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 6fa094760d..018d34e77c 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -48,7 +48,8 @@ namespace graphene { namespace app { uint64_t api_limit_get_asset_holders = 100; uint64_t api_limit_get_key_references = 100; uint64_t api_limit_get_htlc_by = 100; - uint64_t api_limit_get_full_accounts = 100; + uint64_t api_limit_get_full_accounts = 10; + uint64_t api_limit_get_full_accounts_lists = 100; }; class application From 2fd3db2c9d660c6ca51685f279b91989c107afa9 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 13:30:42 -0300 Subject: [PATCH 08/25] refactor get_proposed_transactions --- libraries/app/database_api.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 4fb1c4affb..0a5e993774 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -2362,22 +2362,24 @@ vector database_api::get_proposed_transactions( const std::stri return my->get_proposed_transactions( account_id_or_name ); } -/** TODO: add secondary index that will accelerate this process */ vector database_api_impl::get_proposed_transactions( const std::string account_id_or_name )const { - const auto& idx = _db.get_index_type(); + const auto& proposal_idx = _db.get_index_type(); + const auto& pidx = dynamic_cast(proposal_idx); + const auto& proposals_by_account = pidx.get_secondary_index(); + vector result; const account_id_type id = get_account_from_string(account_id_or_name)->id; - idx.inspect_all_objects( [&](const object& obj){ - const proposal_object& p = static_cast(obj); - if( p.required_active_approvals.find( id ) != p.required_active_approvals.end() ) - result.push_back(p); - else if ( p.required_owner_approvals.find( id ) != p.required_owner_approvals.end() ) - result.push_back(p); - else if ( p.available_active_approvals.find( id ) != p.available_active_approvals.end() ) - result.push_back(p); - }); + auto required_approvals_itr = proposals_by_account._account_to_proposals.find( id ); + if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) + { + result.reserve( required_approvals_itr->second.size() ); + for( auto proposal_id : required_approvals_itr->second ) + { + result.push_back( proposal_id(_db) ); + } + } return result; } From c20c3254dcc243ee15f6913446bf772dd8b71f81 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 15:34:12 -0300 Subject: [PATCH 09/25] separate htlc and withdraws in from and to --- libraries/app/database_api.cpp | 24 +++++++++---------- .../app/include/graphene/app/full_account.hpp | 20 ++++++++++------ tests/tests/htlc_tests.cpp | 4 ++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 0a5e993774..50aad0571e 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1008,18 +1008,18 @@ std::map database_api_impl::get_full_accounts( const auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) { - acnt.withdraws.emplace_back(*itr); - if(acnt.withdraws.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.withdraws = true; + acnt.withdraws_from.emplace_back(*itr); + if(acnt.withdraws_from.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.withdraws_from = true; break; } } auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { - acnt.withdraws.emplace_back(*itr); - if(acnt.withdraws.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.withdraws = true; + acnt.withdraws_authorized.emplace_back(*itr); + if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.withdraws_authorized = true; break; } } @@ -1028,18 +1028,18 @@ std::map database_api_impl::get_full_accounts( const auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) { - acnt.htlcs.emplace_back(*itr); - if(acnt.htlcs.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.htlcs = true; + acnt.htlcs_from.emplace_back(*itr); + if(acnt.htlcs_from.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.htlcs_from = true; break; } } auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) { - acnt.htlcs.emplace_back(*itr); - if(acnt.htlcs.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.htlcs = true; + acnt.htlcs_to.emplace_back(*itr); + if(acnt.htlcs_to.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.htlcs_to = true; break; } } diff --git a/libraries/app/include/graphene/app/full_account.hpp b/libraries/app/include/graphene/app/full_account.hpp index 58d0b26e6e..ebb1144cdb 100644 --- a/libraries/app/include/graphene/app/full_account.hpp +++ b/libraries/app/include/graphene/app/full_account.hpp @@ -40,8 +40,10 @@ namespace graphene { namespace app { bool settle_orders = false; bool proposals = false; bool assets = false; - bool withdraws = false; - bool htlcs = false; + bool withdraws_from = false; + bool withdraws_authorized = false; + bool htlcs_from = false; + bool htlcs_to = false; }; struct full_account @@ -60,8 +62,10 @@ namespace graphene { namespace app { vector settle_orders; vector proposals; vector assets; - vector withdraws; - vector htlcs; + vector withdraws_from; + vector withdraws_authorized; + vector htlcs_from; + vector htlcs_to; more_data more_data_available; }; @@ -69,7 +73,7 @@ namespace graphene { namespace app { FC_REFLECT( graphene::app::more_data, (balances) (vesting_balances) (limit_orders) (call_orders) - (settle_orders) (proposals) (assets) (withdraws) (htlcs) + (settle_orders) (proposals) (assets) (withdraws_from) (withdraws_authorized) (htlcs_from) (htlcs_to) ) FC_REFLECT( graphene::app::full_account, @@ -87,7 +91,9 @@ FC_REFLECT( graphene::app::full_account, (settle_orders) (proposals) (assets) - (withdraws) - (htlcs) + (withdraws_from) + (withdraws_authorized) + (htlcs_from) + (htlcs_to) (more_data_available) ) diff --git a/tests/tests/htlc_tests.cpp b/tests/tests/htlc_tests.cpp index 88b9bf73f9..6a22b6b00c 100644 --- a/tests/tests/htlc_tests.cpp +++ b/tests/tests/htlc_tests.cpp @@ -973,10 +973,10 @@ try { BOOST_CHECK_EQUAL( htlcs_dan[0].id.instance(), 2 ); auto full = db_api.get_full_accounts({alice.name}, false); - BOOST_CHECK_EQUAL( full[alice.name].htlcs.size(), 3 ); + BOOST_CHECK_EQUAL( full[alice.name].htlcs_from.size(), 3 ); full = db_api.get_full_accounts({bob.name}, false); - BOOST_CHECK_EQUAL( full[bob.name].htlcs.size(), 1 ); + BOOST_CHECK_EQUAL( full[bob.name].htlcs_to.size(), 1 ); } catch (fc::exception &e) { edump((e.to_detail_string())); From 445c6d4f7da16883a7bab304e05cb116d580de6e Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 17:18:17 -0300 Subject: [PATCH 10/25] move additional data computation outside loops --- libraries/app/database_api.cpp | 66 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 50aad0571e..57e8a7fa37 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -931,117 +931,117 @@ std::map database_api_impl::get_full_accounts( const if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts_lists) ); + if(required_approvals_itr->second.size() > api_limit_get_full_accounts_lists) + acnt.more_data_available.proposals = true; for( auto proposal_id : required_approvals_itr->second ) { acnt.proposals.push_back( proposal_id(_db) ); - if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.proposals = true; + if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) break; - } } } // Add the account's balances const auto& balances = _db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >().get_account_balances( account->id ); + if(balances.size() > api_limit_get_full_accounts_lists) + acnt.more_data_available.balances = true; for( const auto balance : balances ) { acnt.balances.emplace_back( *balance.second ); - if(acnt.balances.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.balances = true; + if(acnt.balances.size() >= api_limit_get_full_accounts_lists) break; - } } // Add the account's vesting balances auto vesting_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(vesting_range.first, vesting_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.vesting_balances = true; for(auto itr = vesting_range.first; itr != vesting_range.second; ++itr) { acnt.vesting_balances.emplace_back(*itr); - if(acnt.vesting_balances.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.vesting_balances = true; + if(acnt.vesting_balances.size() >= api_limit_get_full_accounts_lists) break; - } } // Add the account's orders auto order_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(order_range.first, order_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.limit_orders = true; for(auto itr = order_range.first; itr != order_range.second; ++itr) { acnt.limit_orders.emplace_back(*itr); - if(acnt.limit_orders.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.limit_orders = true; + if(acnt.limit_orders.size() >= api_limit_get_full_accounts_lists) break; - } } auto call_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(call_range.first, call_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.call_orders = true; for(auto itr = call_range.first; itr != call_range.second; ++itr) { acnt.call_orders.emplace_back(*itr); - if(acnt.call_orders.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.call_orders = true; + if(acnt.call_orders.size() >= api_limit_get_full_accounts_lists) break; - } } auto settle_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(settle_range.first, settle_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.settle_orders = true; for(auto itr = settle_range.first; itr != settle_range.second; ++itr) { acnt.settle_orders.emplace_back(*itr); - if(acnt.settle_orders.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.settle_orders = true; + if(acnt.settle_orders.size() >= api_limit_get_full_accounts_lists) break; - } } // get assets issued by user auto asset_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(asset_range.first, asset_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.assets = true; for(auto itr = asset_range.first; itr != asset_range.second; ++itr) { acnt.assets.emplace_back(itr->id); - if(acnt.assets.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.assets = true; + if(acnt.assets.size() >= api_limit_get_full_accounts_lists) break; - } } // get withdraws permissions auto withdraw_indices = _db.get_index_type().indices(); auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); + if(abs(distance(withdraw_from_range.first, withdraw_from_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.withdraws_from = true; for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) { acnt.withdraws_from.emplace_back(*itr); - if(acnt.withdraws_from.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.withdraws_from = true; + if(acnt.withdraws_from.size() >= api_limit_get_full_accounts_lists) break; - } } auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); + if(abs(distance(withdraw_authorized_range.first, withdraw_authorized_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.withdraws_authorized = true; for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { acnt.withdraws_authorized.emplace_back(*itr); - if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.withdraws_authorized = true; + if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) break; - } } // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(htlc_from_range.first, htlc_from_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.htlcs_from = true; for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) { acnt.htlcs_from.emplace_back(*itr); - if(acnt.htlcs_from.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.htlcs_from = true; + if(acnt.htlcs_from.size() >= api_limit_get_full_accounts_lists) break; - } } auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); + if(abs(distance(htlc_to_range.first, htlc_to_range.second)) > api_limit_get_full_accounts_lists) + acnt.more_data_available.htlcs_to = true; for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) { acnt.htlcs_to.emplace_back(*itr); - if(acnt.htlcs_to.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.htlcs_to = true; + if(acnt.htlcs_to.size() >= api_limit_get_full_accounts_lists) break; - } } results[account_name_or_id] = acnt; From 413b9cfe004bee5b57990bf7831f066f661f6101 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 20:31:24 -0300 Subject: [PATCH 11/25] add get_call_orders_by_account api call --- libraries/app/application.cpp | 5 ++++ libraries/app/database_api.cpp | 30 +++++++++++++++++-- .../app/include/graphene/app/application.hpp | 1 + .../app/include/graphene/app/database_api.hpp | 9 ++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 5dbfdfacc3..7f70fa6b66 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -349,6 +349,9 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-get-full-accounts-lists")) { _app_options.api_limit_get_full_accounts_lists = _options->at("api-limit-get-full-accounts-lists").as(); } + if(_options->count("api-limit-get-call-orders")) { + _app_options.api_limit_get_call_orders = _options->at("api-limit-get-call-orders").as(); + } } void application_impl::startup() @@ -1032,6 +1035,8 @@ void application::set_program_options(boost::program_options::options_descriptio "For database_api_impl::get_full_accounts to set its account default limit values as 10") ("api-limit-get-full-accounts-lists",boost::program_options::value()->default_value(100), "For database_api_impl::get_full_accounts to set its lists default limit values as 100") + ("api-limit-get-call-orders",boost::program_options::value()->default_value(300), + "For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300") ; command_line_options.add(configuration_file_options); command_line_options.add_options() diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 57e8a7fa37..b15199ba22 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -112,6 +112,7 @@ class database_api_impl : public std::enable_shared_from_this optional ostart_id, optional ostart_price ); vector get_call_orders(const std::string& a, uint32_t limit)const; + vector get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const; vector get_settle_orders(const std::string& a, uint32_t limit)const; vector get_margin_positions( const std::string account_id_or_name )const; vector get_collateral_bids(const std::string& asset, uint32_t limit, uint32_t start)const; @@ -1364,16 +1365,17 @@ vector database_api::get_call_orders(const std::string& a, ui vector database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const { - FC_ASSERT( limit <= 300 ); + uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; + FC_ASSERT( limit <= api_limit_get_call_orders ); const asset_object* mia = get_asset_from_string(a); const auto& call_index = _db.get_index_type().indices().get(); price index_price = price::min( mia->bitasset_data(_db).options.short_backing_asset, mia->get_id() ); - + vector< call_order_object> result; auto itr_min = call_index.lower_bound(index_price); auto itr_max = call_index.upper_bound(index_price.max()); - while( itr_min != itr_max && result.size() < limit ) + while( itr_min != itr_max && result.size() < limit ) { result.emplace_back(*itr_min); ++itr_min; @@ -1381,6 +1383,28 @@ vector database_api_impl::get_call_orders(const std::string& return result; } +vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const +{ + return my->get_call_orders_by_account( account_name_or_id, limit ); +} + +vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const +{ + uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; + FC_ASSERT( limit <= api_limit_get_call_orders ); + + vector< call_order_object> result; + const account_id_type account = get_account_from_string(account_name_or_id)->id; + auto call_range = _db.get_index_type().indices().get().equal_range(account); + for(auto itr = call_range.first; itr != call_range.second; ++itr) + { + result.emplace_back(*itr); + if(result.size() >= limit) + break; + } + return result; +} + vector database_api::get_settle_orders(const std::string& a, uint32_t limit)const { return my->get_settle_orders( a, limit ); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 018d34e77c..c22fba20a0 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -50,6 +50,7 @@ namespace graphene { namespace app { uint64_t api_limit_get_htlc_by = 100; uint64_t api_limit_get_full_accounts = 10; uint64_t api_limit_get_full_accounts_lists = 100; + uint64_t api_limit_get_call_orders = 300; }; class application diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index b5ecbf4625..8f9ee3fa28 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -444,6 +444,14 @@ class database_api */ vector get_call_orders(const std::string& a, uint32_t limit)const; + /** + * @brief Get call orders from a given account + * @param account_name_or_id Account name or ID to get objects from + * @param limit Maximum number of objects to retrieve + * @return The call orders of the account + */ + vector get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const; + /** * @brief Get forced settlement orders in a given asset * @param a Symbol or ID of asset being settled @@ -843,6 +851,7 @@ FC_API(graphene::app::database_api, (get_limit_orders) (get_account_limit_orders) (get_call_orders) + (get_call_orders_by_account) (get_settle_orders) (get_margin_positions) (get_collateral_bids) From 4eeb4d3c1a4db1de54b99cffb07be9966892556f Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 8 May 2019 20:36:14 -0300 Subject: [PATCH 12/25] remove unsigned warnings --- libraries/app/database_api.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index b15199ba22..c90894054a 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -955,7 +955,7 @@ std::map database_api_impl::get_full_accounts( const // Add the account's vesting balances auto vesting_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(vesting_range.first, vesting_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(vesting_range.first, vesting_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.vesting_balances = true; for(auto itr = vesting_range.first; itr != vesting_range.second; ++itr) { @@ -966,7 +966,7 @@ std::map database_api_impl::get_full_accounts( const // Add the account's orders auto order_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(order_range.first, order_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(order_range.first, order_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.limit_orders = true; for(auto itr = order_range.first; itr != order_range.second; ++itr) { @@ -975,7 +975,7 @@ std::map database_api_impl::get_full_accounts( const break; } auto call_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(call_range.first, call_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(call_range.first, call_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.call_orders = true; for(auto itr = call_range.first; itr != call_range.second; ++itr) { @@ -984,7 +984,7 @@ std::map database_api_impl::get_full_accounts( const break; } auto settle_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(settle_range.first, settle_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(settle_range.first, settle_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.settle_orders = true; for(auto itr = settle_range.first; itr != settle_range.second; ++itr) { @@ -995,7 +995,7 @@ std::map database_api_impl::get_full_accounts( const // get assets issued by user auto asset_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(asset_range.first, asset_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(asset_range.first, asset_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.assets = true; for(auto itr = asset_range.first; itr != asset_range.second; ++itr) { @@ -1007,7 +1007,7 @@ std::map database_api_impl::get_full_accounts( const // get withdraws permissions auto withdraw_indices = _db.get_index_type().indices(); auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); - if(abs(distance(withdraw_from_range.first, withdraw_from_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(withdraw_from_range.first, withdraw_from_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.withdraws_from = true; for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) { @@ -1016,7 +1016,7 @@ std::map database_api_impl::get_full_accounts( const break; } auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); - if(abs(distance(withdraw_authorized_range.first, withdraw_authorized_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(withdraw_authorized_range.first, withdraw_authorized_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.withdraws_authorized = true; for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { @@ -1027,7 +1027,7 @@ std::map database_api_impl::get_full_accounts( const // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(htlc_from_range.first, htlc_from_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(htlc_from_range.first, htlc_from_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.htlcs_from = true; for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) { @@ -1036,7 +1036,7 @@ std::map database_api_impl::get_full_accounts( const break; } auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); - if(abs(distance(htlc_to_range.first, htlc_to_range.second)) > api_limit_get_full_accounts_lists) + if((unsigned)abs(distance(htlc_to_range.first, htlc_to_range.second)) > api_limit_get_full_accounts_lists) acnt.more_data_available.htlcs_to = true; for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) { From bda09a0989d8b5c030792b1dc6ecc12217b43868 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 14:59:20 -0300 Subject: [PATCH 13/25] move additional data logic back to inside loops as suggested by abit --- libraries/app/database_api.cpp | 88 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index c90894054a..516298711e 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -932,117 +932,117 @@ std::map database_api_impl::get_full_accounts( const if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts_lists) ); - if(required_approvals_itr->second.size() > api_limit_get_full_accounts_lists) - acnt.more_data_available.proposals = true; for( auto proposal_id : required_approvals_itr->second ) { - acnt.proposals.push_back( proposal_id(_db) ); - if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) + if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.proposals = true; break; + } + acnt.proposals.push_back(proposal_id(_db)); } } // Add the account's balances const auto& balances = _db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >().get_account_balances( account->id ); - if(balances.size() > api_limit_get_full_accounts_lists) - acnt.more_data_available.balances = true; for( const auto balance : balances ) { - acnt.balances.emplace_back( *balance.second ); - if(acnt.balances.size() >= api_limit_get_full_accounts_lists) + if(acnt.balances.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.balances = true; break; + } + acnt.balances.emplace_back(*balance.second); } // Add the account's vesting balances auto vesting_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(vesting_range.first, vesting_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.vesting_balances = true; for(auto itr = vesting_range.first; itr != vesting_range.second; ++itr) { - acnt.vesting_balances.emplace_back(*itr); - if(acnt.vesting_balances.size() >= api_limit_get_full_accounts_lists) + if(acnt.vesting_balances.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.vesting_balances = true; break; + } + acnt.vesting_balances.emplace_back(*itr); } // Add the account's orders auto order_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(order_range.first, order_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.limit_orders = true; for(auto itr = order_range.first; itr != order_range.second; ++itr) { - acnt.limit_orders.emplace_back(*itr); - if(acnt.limit_orders.size() >= api_limit_get_full_accounts_lists) + if(acnt.limit_orders.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.limit_orders = true; break; + } + acnt.limit_orders.emplace_back(*itr); } auto call_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(call_range.first, call_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.call_orders = true; for(auto itr = call_range.first; itr != call_range.second; ++itr) { - acnt.call_orders.emplace_back(*itr); - if(acnt.call_orders.size() >= api_limit_get_full_accounts_lists) + if(acnt.call_orders.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.call_orders = true; break; + } + acnt.call_orders.emplace_back(*itr); } auto settle_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(settle_range.first, settle_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.settle_orders = true; for(auto itr = settle_range.first; itr != settle_range.second; ++itr) { - acnt.settle_orders.emplace_back(*itr); - if(acnt.settle_orders.size() >= api_limit_get_full_accounts_lists) + if(acnt.settle_orders.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.settle_orders = true; break; + } + acnt.settle_orders.emplace_back(*itr); } // get assets issued by user auto asset_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(asset_range.first, asset_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.assets = true; for(auto itr = asset_range.first; itr != asset_range.second; ++itr) { - acnt.assets.emplace_back(itr->id); - if(acnt.assets.size() >= api_limit_get_full_accounts_lists) + if(acnt.assets.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.assets = true; break; + } + acnt.assets.emplace_back(itr->id); } // get withdraws permissions auto withdraw_indices = _db.get_index_type().indices(); auto withdraw_from_range = withdraw_indices.get().equal_range(account->id); - if((unsigned)abs(distance(withdraw_from_range.first, withdraw_from_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.withdraws_from = true; for(auto itr = withdraw_from_range.first; itr != withdraw_from_range.second; ++itr) { - acnt.withdraws_from.emplace_back(*itr); - if(acnt.withdraws_from.size() >= api_limit_get_full_accounts_lists) + if(acnt.withdraws_from.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.withdraws_from = true; break; + } + acnt.withdraws_from.emplace_back(*itr); } auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); - if((unsigned)abs(distance(withdraw_authorized_range.first, withdraw_authorized_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.withdraws_authorized = true; for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { - acnt.withdraws_authorized.emplace_back(*itr); - if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) + if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.withdraws_authorized = true; break; + } + acnt.withdraws_authorized.emplace_back(*itr); } // get htlcs auto htlc_from_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(htlc_from_range.first, htlc_from_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.htlcs_from = true; for(auto itr = htlc_from_range.first; itr != htlc_from_range.second; ++itr) { - acnt.htlcs_from.emplace_back(*itr); - if(acnt.htlcs_from.size() >= api_limit_get_full_accounts_lists) + if(acnt.htlcs_from.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.htlcs_from = true; break; + } + acnt.htlcs_from.emplace_back(*itr); } auto htlc_to_range = _db.get_index_type().indices().get().equal_range(account->id); - if((unsigned)abs(distance(htlc_to_range.first, htlc_to_range.second)) > api_limit_get_full_accounts_lists) - acnt.more_data_available.htlcs_to = true; for(auto itr = htlc_to_range.first; itr != htlc_to_range.second; ++itr) { - acnt.htlcs_to.emplace_back(*itr); - if(acnt.htlcs_to.size() >= api_limit_get_full_accounts_lists) + if(acnt.htlcs_to.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.htlcs_to = true; break; + } + acnt.htlcs_to.emplace_back(*itr); } results[account_name_or_id] = acnt; From 66c0f40ae89130ce018ffb4c92a5d588d698c3d9 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 15:42:01 -0300 Subject: [PATCH 14/25] do proposal index in 1 line --- libraries/app/database_api.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 516298711e..0f6db31a87 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -892,10 +892,6 @@ std::map database_api_impl::get_full_accounts( const { FC_ASSERT( names_or_ids.size() <= _app_options->api_limit_get_full_accounts ); - const auto& proposal_idx = _db.get_index_type(); - const auto& pidx = dynamic_cast(proposal_idx); - const auto& proposals_by_account = pidx.get_secondary_index(); - std::map results; for (const std::string& account_name_or_id : names_or_ids) @@ -928,6 +924,8 @@ std::map database_api_impl::get_full_accounts( const uint64_t api_limit_get_full_accounts_lists = _app_options->api_limit_get_full_accounts_lists; // Add the account's proposals + const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); + const auto& proposals_by_account = proposal_idx.get_secondary_index(); auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { @@ -2388,9 +2386,8 @@ vector database_api::get_proposed_transactions( const std::stri vector database_api_impl::get_proposed_transactions( const std::string account_id_or_name )const { - const auto& proposal_idx = _db.get_index_type(); - const auto& pidx = dynamic_cast(proposal_idx); - const auto& proposals_by_account = pidx.get_secondary_index(); + const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); + const auto& proposals_by_account = proposal_idx.get_secondary_index(); vector result; const account_id_type id = get_account_from_string(account_id_or_name)->id; From 65d518021bd98250dcb928e29bae3b412072ed57 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 16:20:15 -0300 Subject: [PATCH 15/25] change to withdraws_to for consistency, wrap long line --- libraries/app/database_api.cpp | 9 +++++---- libraries/app/include/graphene/app/full_account.hpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 0f6db31a87..568e8c9626 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -941,7 +941,8 @@ std::map database_api_impl::get_full_accounts( const } // Add the account's balances - const auto& balances = _db.get_index_type< primary_index< account_balance_index > >().get_secondary_index< balances_by_account_index >().get_account_balances( account->id ); + const auto& balances = _db.get_index_type< primary_index< account_balance_index > >(). + get_secondary_index< balances_by_account_index >().get_account_balances( account->id ); for( const auto balance : balances ) { if(acnt.balances.size() >= api_limit_get_full_accounts_lists) { @@ -1016,11 +1017,11 @@ std::map database_api_impl::get_full_accounts( const auto withdraw_authorized_range = withdraw_indices.get().equal_range(account->id); for(auto itr = withdraw_authorized_range.first; itr != withdraw_authorized_range.second; ++itr) { - if(acnt.withdraws_authorized.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.withdraws_authorized = true; + if(acnt.withdraws_to.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.withdraws_to = true; break; } - acnt.withdraws_authorized.emplace_back(*itr); + acnt.withdraws_to.emplace_back(*itr); } // get htlcs diff --git a/libraries/app/include/graphene/app/full_account.hpp b/libraries/app/include/graphene/app/full_account.hpp index ebb1144cdb..84ffbab42c 100644 --- a/libraries/app/include/graphene/app/full_account.hpp +++ b/libraries/app/include/graphene/app/full_account.hpp @@ -41,7 +41,7 @@ namespace graphene { namespace app { bool proposals = false; bool assets = false; bool withdraws_from = false; - bool withdraws_authorized = false; + bool withdraws_to = false; bool htlcs_from = false; bool htlcs_to = false; }; @@ -63,7 +63,7 @@ namespace graphene { namespace app { vector proposals; vector assets; vector withdraws_from; - vector withdraws_authorized; + vector withdraws_to; vector htlcs_from; vector htlcs_to; more_data more_data_available; @@ -73,7 +73,7 @@ namespace graphene { namespace app { FC_REFLECT( graphene::app::more_data, (balances) (vesting_balances) (limit_orders) (call_orders) - (settle_orders) (proposals) (assets) (withdraws_from) (withdraws_authorized) (htlcs_from) (htlcs_to) + (settle_orders) (proposals) (assets) (withdraws_from) (withdraws_to) (htlcs_from) (htlcs_to) ) FC_REFLECT( graphene::app::full_account, @@ -92,7 +92,7 @@ FC_REFLECT( graphene::app::full_account, (proposals) (assets) (withdraws_from) - (withdraws_authorized) + (withdraws_to) (htlcs_from) (htlcs_to) (more_data_available) From 38c3cef72d6379b50b2268fe908a84d467ca6b93 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 17:50:53 -0300 Subject: [PATCH 16/25] add start argument to get_call_orders_by_account --- libraries/app/database_api.cpp | 24 +++++++++++-------- .../app/include/graphene/app/database_api.hpp | 4 +++- .../include/graphene/chain/market_object.hpp | 7 ++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 568e8c9626..f5f798f599 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -112,7 +112,8 @@ class database_api_impl : public std::enable_shared_from_this optional ostart_id, optional ostart_price ); vector get_call_orders(const std::string& a, uint32_t limit)const; - vector get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const; + vector get_call_orders_by_account(const std::string& account_name_or_id, + call_order_id_type start, uint32_t limit)const; vector get_settle_orders(const std::string& a, uint32_t limit)const; vector get_margin_positions( const std::string account_id_or_name )const; vector get_collateral_bids(const std::string& asset, uint32_t limit, uint32_t start)const; @@ -1382,24 +1383,27 @@ vector database_api_impl::get_call_orders(const std::string& return result; } -vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const +vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, + call_order_id_type start, uint32_t limit)const { - return my->get_call_orders_by_account( account_name_or_id, limit ); + return my->get_call_orders_by_account( account_name_or_id, start, limit ); } -vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const +vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, + call_order_id_type start, uint32_t limit)const { uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; FC_ASSERT( limit <= api_limit_get_call_orders ); - vector< call_order_object> result; + vector result; const account_id_type account = get_account_from_string(account_name_or_id)->id; - auto call_range = _db.get_index_type().indices().get().equal_range(account); - for(auto itr = call_range.first; itr != call_range.second; ++itr) + const auto& call_idx = _db.get_index_type().indices().get(); + auto call_index_end = call_idx.end(); + auto call_itr = call_idx.lower_bound(boost::make_tuple(account, start)); + while(call_itr != call_index_end && call_itr->borrower == account && result.size() < limit) { - result.emplace_back(*itr); - if(result.size() >= limit) - break; + result.push_back(*call_itr); + ++call_itr; } return result; } diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 8f9ee3fa28..3b901a1f01 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -447,10 +447,12 @@ class database_api /** * @brief Get call orders from a given account * @param account_name_or_id Account name or ID to get objects from + * @param start Withdraw permission objects(1.8.X) before this ID will be skipped in results. Pagination purposes. * @param limit Maximum number of objects to retrieve * @return The call orders of the account */ - vector get_call_orders_by_account(const std::string& account_name_or_id, uint32_t limit)const; + vector get_call_orders_by_account(const std::string& account_name_or_id, + call_order_id_type start, uint32_t limit)const; /** * @brief Get forced settlement orders in a given asset diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 168e2b6439..337151de21 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -196,6 +196,7 @@ class collateral_bid_object : public abstract_object struct by_collateral; struct by_account; struct by_price; +struct by_account_and_id; typedef multi_index_container< call_order_object, indexed_by< @@ -214,6 +215,12 @@ typedef multi_index_container< const_mem_fun< call_order_object, asset_id_type, &call_order_object::debt_type> > >, + ordered_unique< tag, + composite_key< call_order_object, + member< call_order_object, account_id_type, &call_order_object::borrower >, + member< object, object_id_type, &object::id > + > + >, ordered_unique< tag, composite_key< call_order_object, const_mem_fun< call_order_object, price, &call_order_object::collateralization >, From cd504f59c409bd3b9740435e9a94968791cf91a7 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 18:37:45 -0300 Subject: [PATCH 17/25] add get_settle_orders_by_account --- libraries/app/application.cpp | 5 +++ libraries/app/database_api.cpp | 31 ++++++++++++++++++- .../app/include/graphene/app/application.hpp | 1 + .../app/include/graphene/app/database_api.hpp | 11 +++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 7f70fa6b66..43498f50af 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -352,6 +352,9 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-get-call-orders")) { _app_options.api_limit_get_call_orders = _options->at("api-limit-get-call-orders").as(); } + if(_options->count("api-limit-get-settle-orders")) { + _app_options.api_limit_get_settle_orders = _options->at("api-limit-get-settle-orders").as(); + } } void application_impl::startup() @@ -1037,6 +1040,8 @@ void application::set_program_options(boost::program_options::options_descriptio "For database_api_impl::get_full_accounts to set its lists default limit values as 100") ("api-limit-get-call-orders",boost::program_options::value()->default_value(300), "For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300") + ("api-limit-get-settle-orders",boost::program_options::value()->default_value(300), + "For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300") ; command_line_options.add(configuration_file_options); command_line_options.add_options() diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index f5f798f599..e7eb42e572 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -115,6 +115,8 @@ class database_api_impl : public std::enable_shared_from_this vector get_call_orders_by_account(const std::string& account_name_or_id, call_order_id_type start, uint32_t limit)const; vector get_settle_orders(const std::string& a, uint32_t limit)const; + vector get_settle_orders_by_account(const std::string& account_name_or_id, + force_settlement_id_type start, uint32_t limit)const; vector get_margin_positions( const std::string account_id_or_name )const; vector get_collateral_bids(const std::string& asset, uint32_t limit, uint32_t start)const; @@ -1415,7 +1417,8 @@ vector database_api::get_settle_orders(const std::strin vector database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const { - FC_ASSERT( limit <= 300 ); + 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().indices().get(); @@ -1432,6 +1435,32 @@ vector database_api_impl::get_settle_orders(const std:: return result; } +vector database_api::get_settle_orders_by_account(const std::string& account_name_or_id, + force_settlement_id_type start, uint32_t limit)const +{ + return my->get_settle_orders_by_account( account_name_or_id, start, limit); +} + +vector database_api_impl::get_settle_orders_by_account(const std::string& account_name_or_id, + force_settlement_id_type start, uint32_t limit)const +{ + uint64_t api_limit_get_settle_orders = _app_options->api_limit_get_settle_orders; + FC_ASSERT( limit <= api_limit_get_settle_orders ); + + vector result; + const account_id_type account = get_account_from_string(account_name_or_id)->id; + const auto& settle_idx = _db.get_index_type().indices().get(); + auto settle_index_end = settle_idx.end(); + auto settle_itr = settle_idx.lower_bound(boost::make_tuple(account, start)); + while(settle_itr != settle_index_end && settle_itr->owner == account && result.size() < limit) + { + result.push_back(*settle_itr); + ++settle_itr; + } + return result; +} + + vector database_api::get_margin_positions( const std::string account_id_or_name )const { return my->get_margin_positions( account_id_or_name ); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index c22fba20a0..67edcb5374 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -51,6 +51,7 @@ namespace graphene { namespace app { uint64_t api_limit_get_full_accounts = 10; uint64_t api_limit_get_full_accounts_lists = 100; uint64_t api_limit_get_call_orders = 300; + uint64_t api_limit_get_settle_orders = 300; }; class application diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 3b901a1f01..27d7409ec7 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -462,6 +462,16 @@ class database_api */ vector get_settle_orders(const std::string& a, uint32_t limit)const; + /** + * @brief Get forced settlement orders of a given account + * @param account_name_or_id Account name or ID to get objects from + * @param start Withdraw permission objects(1.4.X) before this ID will be skipped in results. Pagination purposes. + * @param limit Maximum number of orders to retrieve + * @return The settle orders of the account + */ + vector get_settle_orders_by_account(const std::string& account_name_or_id, + force_settlement_id_type start, uint32_t limit)const; + /** * @brief Get collateral_bid_objects for a given asset * @param a Symbol or ID of asset @@ -855,6 +865,7 @@ FC_API(graphene::app::database_api, (get_call_orders) (get_call_orders_by_account) (get_settle_orders) + (get_settle_orders_by_account) (get_margin_positions) (get_collateral_bids) (subscribe_to_market) From ce709f9abc1ac31e920b6bbf85107dff9a0da3f6 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 9 May 2019 19:57:14 -0300 Subject: [PATCH 18/25] add get_assets_by_issuer api call --- libraries/app/application.cpp | 5 +++ libraries/app/database_api.cpp | 33 +++++++++++++++++-- .../app/include/graphene/app/application.hpp | 1 + .../app/include/graphene/app/database_api.hpp | 11 +++++++ .../include/graphene/chain/asset_object.hpp | 7 ++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 43498f50af..d6acc64453 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -355,6 +355,9 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-get-settle-orders")) { _app_options.api_limit_get_settle_orders = _options->at("api-limit-get-settle-orders").as(); } + if(_options->count("api-limit-get-assets")) { + _app_options.api_limit_get_assets = _options->at("api-limit-get-assets").as(); + } } void application_impl::startup() @@ -1042,6 +1045,8 @@ void application::set_program_options(boost::program_options::options_descriptio "For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300") ("api-limit-get-settle-orders",boost::program_options::value()->default_value(300), "For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300") + ("api-limit-get-assets",boost::program_options::value()->default_value(101), + "For database_api_impl::list_assets and get_assets_by_issuer to set its default limit values as 101") ; command_line_options.add(configuration_file_options); command_line_options.add_options() diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index e7eb42e572..44a7255976 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -103,6 +103,8 @@ class database_api_impl : public std::enable_shared_from_this vector list_assets(const string& lower_bound_symbol, uint32_t limit)const; vector> lookup_asset_symbols(const vector& symbols_or_ids)const; uint64_t get_asset_count()const; + vector get_assets_by_issuer(const std::string& issuer_name_or_id, + asset_id_type start, uint32_t limit)const; // Markets / feeds vector get_limit_orders(const std::string& a, const std::string& b, uint32_t limit)const; @@ -929,7 +931,7 @@ std::map database_api_impl::get_full_accounts( const // Add the account's proposals const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); const auto& proposals_by_account = proposal_idx.get_secondary_index(); - auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); + auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), api_limit_get_full_accounts_lists) ); @@ -1287,7 +1289,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 <= 101 ); + uint64_t api_limit_get_assets = _app_options->api_limit_get_assets; + FC_ASSERT( limit <= api_limit_get_assets ); + const auto& assets_by_symbol = _db.get_index_type().indices().get(); vector result; result.reserve(limit); @@ -1313,6 +1317,31 @@ uint64_t database_api_impl::get_asset_count()const return _db.get_index_type().indices().size(); } +vector database_api::get_assets_by_issuer(const std::string& issuer_name_or_id, + asset_id_type start, uint32_t limit)const +{ + return my->get_assets_by_issuer(issuer_name_or_id, start, limit); +} + +vector database_api_impl::get_assets_by_issuer(const std::string& issuer_name_or_id, + asset_id_type start, uint32_t limit)const +{ + uint64_t api_limit_get_assets = _app_options->api_limit_get_assets; + FC_ASSERT( limit <= api_limit_get_assets ); + + vector result; + const account_id_type account = get_account_from_string(issuer_name_or_id)->id; + const auto& asset_idx = _db.get_index_type().indices().get(); + auto asset_index_end = asset_idx.end(); + auto asset_itr = asset_idx.lower_bound(boost::make_tuple(account, start)); + while(asset_itr != asset_index_end && asset_itr->issuer == account && result.size() < limit) + { + result.push_back(*asset_itr); + ++asset_itr; + } + return result; +} + vector> database_api::lookup_asset_symbols(const vector& symbols_or_ids)const { return my->lookup_asset_symbols( symbols_or_ids ); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 67edcb5374..aa6854a0af 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -52,6 +52,7 @@ namespace graphene { namespace app { uint64_t api_limit_get_full_accounts_lists = 100; uint64_t api_limit_get_call_orders = 300; uint64_t api_limit_get_settle_orders = 300; + uint64_t api_limit_get_assets = 101; }; class application diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 27d7409ec7..8b33bfce6c 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -423,6 +423,16 @@ class database_api */ uint64_t get_asset_count()const; + /** + * @brief Get asset objects issued from a given account + * @param account_name_or_id Account name or ID to get objects from + * @param start Withdraw permission objects(1.3.X) before this ID will be skipped in results. Pagination purposes. + * @param limit Maximum number of orders to retrieve + * @return The assets issued by the account + */ + vector get_assets_by_issuer(const std::string& issuer_name_or_id, + asset_id_type start, uint32_t limit)const; + ///////////////////// // Markets / feeds // ///////////////////// @@ -856,6 +866,7 @@ FC_API(graphene::app::database_api, (list_assets) (lookup_asset_symbols) (get_asset_count) + (get_assets_by_issuer) (get_asset_id_from_string) // Markets / feeds diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 38081dc40f..516d325bff 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -294,6 +294,7 @@ namespace graphene { namespace chain { struct by_symbol; struct by_type; struct by_issuer; + struct by_issuer_and_id; typedef multi_index_container< asset_object, indexed_by< @@ -305,6 +306,12 @@ namespace graphene { namespace chain { const_mem_fun, member< object, object_id_type, &object::id > > + >, + ordered_unique< tag, + composite_key< asset_object, + member< asset_object, account_id_type, &asset_object::issuer >, + member< object, object_id_type, &object::id > + > > > > asset_object_multi_index_type; From ed53cb09fd677fa95d01cd3ad10b0d2fe0acd924 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 10:58:03 -0300 Subject: [PATCH 19/25] move back proposal index outside of the loop --- libraries/app/database_api.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 44a7255976..d7d3a5358d 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -897,6 +897,9 @@ std::map database_api_impl::get_full_accounts( const { FC_ASSERT( names_or_ids.size() <= _app_options->api_limit_get_full_accounts ); + const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); + const auto& proposals_by_account = proposal_idx.get_secondary_index(); + std::map results; for (const std::string& account_name_or_id : names_or_ids) @@ -929,8 +932,6 @@ std::map database_api_impl::get_full_accounts( const uint64_t api_limit_get_full_accounts_lists = _app_options->api_limit_get_full_accounts_lists; // Add the account's proposals - const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); - const auto& proposals_by_account = proposal_idx.get_secondary_index(); auto required_approvals_itr = proposals_by_account._account_to_proposals.find( account->id ); if( required_approvals_itr != proposals_by_account._account_to_proposals.end() ) { From 0968f95c2e8b761808bc3058ebfae44a21814dbc Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 11:15:15 -0300 Subject: [PATCH 20/25] fix c&p errors --- libraries/app/include/graphene/app/database_api.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 8b33bfce6c..341d95cafa 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -426,7 +426,7 @@ class database_api /** * @brief Get asset objects issued from a given account * @param account_name_or_id Account name or ID to get objects from - * @param start Withdraw permission objects(1.3.X) before this ID will be skipped in results. Pagination purposes. + * @param start Asset objects(1.3.X) before this ID will be skipped in results. Pagination purposes. * @param limit Maximum number of orders to retrieve * @return The assets issued by the account */ @@ -457,7 +457,7 @@ class database_api /** * @brief Get call orders from a given account * @param account_name_or_id Account name or ID to get objects from - * @param start Withdraw permission objects(1.8.X) before this ID will be skipped in results. Pagination purposes. + * @param start Call order objects(1.8.X) before this ID will be skipped in results. Pagination purposes. * @param limit Maximum number of objects to retrieve * @return The call orders of the account */ @@ -475,7 +475,7 @@ class database_api /** * @brief Get forced settlement orders of a given account * @param account_name_or_id Account name or ID to get objects from - * @param start Withdraw permission objects(1.4.X) before this ID will be skipped in results. Pagination purposes. + * @param start Force settlement objects(1.4.X) before this ID will be skipped in results. Pagination purposes. * @param limit Maximum number of orders to retrieve * @return The settle orders of the account */ From 89949957341c91acfa16053d90870bfb9a49dbea Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 11:54:13 -0300 Subject: [PATCH 21/25] remove by_issuer_and_id index --- libraries/app/database_api.cpp | 2 +- libraries/chain/include/graphene/chain/asset_object.hpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d7d3a5358d..c85accb83c 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1332,7 +1332,7 @@ vector database_api_impl::get_assets_by_issuer(const std::string& vector result; const account_id_type account = get_account_from_string(issuer_name_or_id)->id; - const auto& asset_idx = _db.get_index_type().indices().get(); + const auto& asset_idx = _db.get_index_type().indices().get(); auto asset_index_end = asset_idx.end(); auto asset_itr = asset_idx.lower_bound(boost::make_tuple(account, start)); while(asset_itr != asset_index_end && asset_itr->issuer == account && result.size() < limit) diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 516d325bff..1b98c5b4fd 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -294,20 +294,18 @@ namespace graphene { namespace chain { struct by_symbol; struct by_type; struct by_issuer; - struct by_issuer_and_id; typedef multi_index_container< asset_object, indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, member >, - ordered_non_unique< tag, member >, ordered_unique< tag, composite_key< asset_object, const_mem_fun, member< object, object_id_type, &object::id > > >, - ordered_unique< tag, + ordered_unique< tag, composite_key< asset_object, member< asset_object, account_id_type, &asset_object::issuer >, member< object, object_id_type, &object::id > From 976b56bbe3fac494490ef57277e11674c1a8e597 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 14:58:54 -0300 Subject: [PATCH 22/25] paginate get_call_orders_by_account by asset_id --- libraries/app/database_api.cpp | 8 ++++---- libraries/app/include/graphene/app/database_api.hpp | 4 ++-- libraries/chain/include/graphene/chain/market_object.hpp | 7 ------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index c85accb83c..158590f4c4 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -115,7 +115,7 @@ class database_api_impl : public std::enable_shared_from_this optional ostart_price ); vector get_call_orders(const std::string& a, uint32_t limit)const; vector get_call_orders_by_account(const std::string& account_name_or_id, - call_order_id_type start, uint32_t limit)const; + asset_id_type start, uint32_t limit)const; vector get_settle_orders(const std::string& a, uint32_t limit)const; vector get_settle_orders_by_account(const std::string& account_name_or_id, force_settlement_id_type start, uint32_t limit)const; @@ -1416,20 +1416,20 @@ vector database_api_impl::get_call_orders(const std::string& } vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, - call_order_id_type start, uint32_t limit)const + asset_id_type start, uint32_t limit)const { return my->get_call_orders_by_account( account_name_or_id, start, limit ); } vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, - call_order_id_type start, uint32_t limit)const + asset_id_type start, uint32_t limit)const { uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; FC_ASSERT( limit <= api_limit_get_call_orders ); vector result; const account_id_type account = get_account_from_string(account_name_or_id)->id; - const auto& call_idx = _db.get_index_type().indices().get(); + const auto& call_idx = _db.get_index_type().indices().get(); auto call_index_end = call_idx.end(); auto call_itr = call_idx.lower_bound(boost::make_tuple(account, start)); while(call_itr != call_index_end && call_itr->borrower == account && result.size() < limit) diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 341d95cafa..a95e09df70 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -457,12 +457,12 @@ class database_api /** * @brief Get call orders from a given account * @param account_name_or_id Account name or ID to get objects from - * @param start Call order objects(1.8.X) before this ID will be skipped in results. Pagination purposes. + * @param start Asset objects(1.3.X) before this ID will be skipped in results. Pagination purposes. * @param limit Maximum number of objects to retrieve * @return The call orders of the account */ vector get_call_orders_by_account(const std::string& account_name_or_id, - call_order_id_type start, uint32_t limit)const; + asset_id_type start, uint32_t limit)const; /** * @brief Get forced settlement orders in a given asset diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 337151de21..168e2b6439 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -196,7 +196,6 @@ class collateral_bid_object : public abstract_object struct by_collateral; struct by_account; struct by_price; -struct by_account_and_id; typedef multi_index_container< call_order_object, indexed_by< @@ -215,12 +214,6 @@ typedef multi_index_container< const_mem_fun< call_order_object, asset_id_type, &call_order_object::debt_type> > >, - ordered_unique< tag, - composite_key< call_order_object, - member< call_order_object, account_id_type, &call_order_object::borrower >, - member< object, object_id_type, &object::id > - > - >, ordered_unique< tag, composite_key< call_order_object, const_mem_fun< call_order_object, price, &call_order_object::collateralization >, From d07c3745a7aa2e5879f15af634e2e850c5df44a0 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 15:54:44 -0300 Subject: [PATCH 23/25] make start optional in htlc api calls --- libraries/app/database_api.cpp | 15 +++++++++++---- .../app/include/graphene/app/database_api.hpp | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 158590f4c4..f31ea5f3dd 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -2564,9 +2564,12 @@ fc::optional database_api_impl::get_htlc(htlc_id_type id) const return fc::optional(); } -vector database_api::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const +vector database_api::get_htlc_by_from(const std::string account_id_or_name, optional start, uint32_t limit)const { - return my->get_htlc_by_from(account_id_or_name, start, limit); + if(start.valid()) + return my->get_htlc_by_from(account_id_or_name, *start, limit); + else + return my->get_htlc_by_from(account_id_or_name, htlc_id_type(), limit); } vector database_api_impl::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const @@ -2587,9 +2590,13 @@ vector database_api_impl::get_htlc_by_from(const std::string accoun return result; } -vector database_api::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const +vector database_api::get_htlc_by_to(const std::string account_id_or_name, optional start, uint32_t limit)const { - return my->get_htlc_by_to(account_id_or_name, start, limit); + if(start.valid()) + return my->get_htlc_by_to(account_id_or_name, *start, limit); + else + return my->get_htlc_by_to(account_id_or_name, htlc_id_type(), limit); + } vector database_api_impl::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index a95e09df70..0bc1f5bffd 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -792,7 +792,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; + vector get_htlc_by_from(const std::string account_id_or_name, optional start, uint32_t limit) const; /** * @brief Get non expired HTLC objects using the receiver account @@ -801,7 +801,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; + vector get_htlc_by_to(const std::string account_id_or_name, optional start, uint32_t limit) const; private: std::shared_ptr< database_api_impl > my; From dbb1fed2fae7bb1f770303f492f03609b344a26f Mon Sep 17 00:00:00 2001 From: Alfredo Date: Fri, 10 May 2019 19:54:25 -0300 Subject: [PATCH 24/25] undo d07c374 --- libraries/app/database_api.cpp | 15 ++++----------- .../app/include/graphene/app/database_api.hpp | 4 ++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index f31ea5f3dd..158590f4c4 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -2564,12 +2564,9 @@ fc::optional database_api_impl::get_htlc(htlc_id_type id) const return fc::optional(); } -vector database_api::get_htlc_by_from(const std::string account_id_or_name, optional start, uint32_t limit)const +vector database_api::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const { - if(start.valid()) - return my->get_htlc_by_from(account_id_or_name, *start, limit); - else - return my->get_htlc_by_from(account_id_or_name, htlc_id_type(), limit); + return my->get_htlc_by_from(account_id_or_name, start, limit); } vector database_api_impl::get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const @@ -2590,13 +2587,9 @@ vector database_api_impl::get_htlc_by_from(const std::string accoun return result; } -vector database_api::get_htlc_by_to(const std::string account_id_or_name, optional start, uint32_t limit)const +vector database_api::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit)const { - if(start.valid()) - return my->get_htlc_by_to(account_id_or_name, *start, limit); - else - return my->get_htlc_by_to(account_id_or_name, htlc_id_type(), limit); - + return my->get_htlc_by_to(account_id_or_name, start, limit); } vector database_api_impl::get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 0bc1f5bffd..a95e09df70 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -792,7 +792,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_from(const std::string account_id_or_name, optional start, uint32_t limit) const; + vector get_htlc_by_from(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; /** * @brief Get non expired HTLC objects using the receiver account @@ -801,7 +801,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_to(const std::string account_id_or_name, optional start, uint32_t limit) const; + vector get_htlc_by_to(const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; private: std::shared_ptr< database_api_impl > my; From efc818160ced4bbc968353c79caef65ea03bc0de Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 13 May 2019 18:21:47 -0300 Subject: [PATCH 25/25] add test cases --- tests/tests/database_api_tests.cpp | 166 +++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/tests/tests/database_api_tests.cpp b/tests/tests/database_api_tests.cpp index 295eac45de..c4f5433100 100644 --- a/tests/tests/database_api_tests.cpp +++ b/tests/tests/database_api_tests.cpp @@ -1121,4 +1121,170 @@ BOOST_AUTO_TEST_CASE( api_limit_get_key_references ){ throw; } } + +BOOST_AUTO_TEST_CASE( api_limit_get_full_accounts ) { + + try { + graphene::app::database_api db_api(db, &(this->app.get_options())); + + const account_object& alice = create_account("alice"); + const account_object& bob = create_account("bob"); + const account_object& carl = create_account("carl"); + const account_object& dan = create_account("dan"); + const account_object& fred = create_account("fred"); + const account_object& henry = create_account("henry"); + const account_object& kevin = create_account("kevin"); + const account_object& laura = create_account("laura"); + const account_object& lucy = create_account("lucy"); + const account_object& martin = create_account("martin"); + const account_object& patty = create_account("patty"); + + vector accounts; + accounts.push_back(alice.name); + accounts.push_back(bob.name); + accounts.push_back(carl.name); + accounts.push_back(dan.name); + accounts.push_back(fred.name); + accounts.push_back(henry.name); + accounts.push_back(kevin.name); + accounts.push_back(laura.name); + accounts.push_back(lucy.name); + accounts.push_back(martin.name); + accounts.push_back(patty.name); + + GRAPHENE_CHECK_THROW(db_api.get_full_accounts(accounts, false), fc::exception); + + accounts.erase(accounts.begin()); + auto full_accounts = db_api.get_full_accounts(accounts, false); + BOOST_CHECK(full_accounts.size() == 10); + + // not an account + accounts.erase(accounts.begin()); + accounts.push_back("nosuchaccount"); + + // request fully fails even if 9 accounts are valid + GRAPHENE_CHECK_THROW(db_api.get_full_accounts(accounts, false), fc::exception); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( get_assets_by_issuer ) { + try { + graphene::app::database_api db_api(db, &(this->app.get_options())); + + create_bitasset("CNY"); + create_bitasset("EUR"); + create_bitasset("USD"); + + generate_block(); + + auto assets = db_api.get_assets_by_issuer("witness-account", asset_id_type(), 10); + + BOOST_CHECK(assets.size() == 3); + BOOST_CHECK(assets[0].symbol == "CNY"); + BOOST_CHECK(assets[1].symbol == "EUR"); + BOOST_CHECK(assets[2].symbol == "USD"); + + assets = db_api.get_assets_by_issuer("witness-account", asset_id_type(200), 100); + BOOST_CHECK(assets.size() == 0); + + GRAPHENE_CHECK_THROW(db_api.get_assets_by_issuer("nosuchaccount", asset_id_type(), 100), fc::exception); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( get_call_orders_by_account ) { + + try { + ACTORS((caller)(feedproducer)); + + graphene::app::database_api db_api(db, &(this->app.get_options())); + + const auto &usd = create_bitasset("USD", feedproducer_id); + const auto &cny = create_bitasset("CNY", feedproducer_id); + const auto &core = asset_id_type()(db); + + int64_t init_balance(1000000); + transfer(committee_account, caller_id, asset(init_balance)); + + update_feed_producers(usd, {feedproducer.id}); + update_feed_producers(cny, {feedproducer.id}); + + price_feed current_feed; + current_feed.maintenance_collateral_ratio = 1750; + current_feed.maximum_short_squeeze_ratio = 1100; + current_feed.settlement_price = usd.amount(1) / core.amount(5); + publish_feed(usd, feedproducer, current_feed); + + current_feed.maintenance_collateral_ratio = 1750; + current_feed.maximum_short_squeeze_ratio = 1100; + current_feed.settlement_price = cny.amount(1) / core.amount(5); + publish_feed(cny, feedproducer, current_feed); + + auto call1 = borrow(caller, usd.amount(1000), asset(15000)); + auto call2 = borrow(caller, cny.amount(1000), asset(15000)); + + auto calls = db_api.get_call_orders_by_account("caller", asset_id_type(), 100); + + BOOST_CHECK(calls.size() == 2); + BOOST_CHECK(calls[0].id == call1->id); + BOOST_CHECK(calls[1].id == call2->id); + + GRAPHENE_CHECK_THROW(db_api.get_call_orders_by_account("nosuchaccount", asset_id_type(), 100), fc::exception); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( get_settle_orders_by_account ) { + try { + ACTORS((creator)(settler)(caller)(feedproducer)); + + graphene::app::database_api db_api(db, &(this->app.get_options())); + + const auto &usd = create_bitasset("USD", creator_id); + const auto &core = asset_id_type()(db); + asset_id_type usd_id = usd.id; + + int64_t init_balance(1000000); + transfer(committee_account, settler_id, asset(init_balance)); + transfer(committee_account, caller_id, asset(init_balance)); + + update_feed_producers(usd, {feedproducer.id}); + + price_feed current_feed; + current_feed.maintenance_collateral_ratio = 1750; + current_feed.maximum_short_squeeze_ratio = 1100; + current_feed.settlement_price = usd.amount(1) / core.amount(5); + publish_feed(usd, feedproducer, current_feed); + + borrow(caller, usd.amount(1000), asset(15000)); + generate_block(); + + transfer(caller.id, settler.id, asset(200, usd_id)); + + auto result = force_settle( settler, usd_id(db).amount(4)); + generate_block(); + + auto settlements = db_api.get_settle_orders_by_account("settler", force_settlement_id_type(), 100); + + BOOST_CHECK(settlements.size() == 1); + BOOST_CHECK(settlements[0].id == result.get()); + + GRAPHENE_CHECK_THROW(db_api.get_settle_orders_by_account("nosuchaccount", force_settlement_id_type(), 100), fc::exception); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END()