From 81666aafa7df1e2113f7689bee0b267ddb4005a4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 16 Apr 2020 16:13:42 +0000 Subject: [PATCH 1/3] Update by_custom_id to by_id For custom_operations plugin --- .../include/graphene/custom_operations/custom_objects.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp index 616448a369..ceea704342 100644 --- a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp +++ b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp @@ -51,13 +51,12 @@ struct account_storage_object : public abstract_object optional value; }; -struct by_custom_id; struct by_account_catalog_key; typedef multi_index_container< account_storage_object, indexed_by< - ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< account_storage_object, member< account_storage_object, account_id_type, &account_storage_object::account >, From 9c7860ef381ceb833b5c23df73fc18e651a87fb6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 16 Apr 2020 16:31:18 +0000 Subject: [PATCH 2/3] Check api_helper_indexes plugin for several APIs --- libraries/app/application.cpp | 3 ++ libraries/app/database_api.cpp | 47 ++++++++++++++----- .../app/include/graphene/app/application.hpp | 3 ++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index de5bf8a334..672bed4dc8 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -510,6 +510,9 @@ void application_impl::startup() if( _active_plugins.find( "market_history" ) != _active_plugins.end() ) _app_options.has_market_history_plugin = true; + if( _active_plugins.find( "api_helper_indexes" ) != _active_plugins.end() ) + _app_options.has_api_helper_indexes_plugin = true; + if( _options->count("api-access") ) { fc::path api_access_file = _options->at("api-access").as(); diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 62e952c7ea..5cc9dcede7 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -335,6 +335,10 @@ vector> database_api::get_key_references( vector> database_api_impl::get_key_references( vector keys )const { + // api_helper_indexes plugin is required for accessing the secondary index + FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, + "api_helper_indexes plugin is not enabled on this server." ); + uint64_t api_limit_get_key_references=_app_options->api_limit_get_key_references; FC_ASSERT(keys.size() <= api_limit_get_key_references); const auto& idx = _db.get_index_type(); @@ -399,6 +403,11 @@ bool database_api_impl::is_public_key_registered(string public_key) const // An invalid public key was detected return false; } + + // api_helper_indexes plugin is required for accessing the secondary index + FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, + "api_helper_indexes plugin is not enabled on this server." ); + const auto& idx = _db.get_index_type(); const auto& aidx = dynamic_cast(idx); const auto& refs = aidx.get_secondary_index(); @@ -454,9 +463,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< primary_index< proposal_index > >(); - const auto& proposals_by_account = proposal_idx.get_secondary_index(); - bool to_subscribe = get_whether_to_subscribe( subscribe ); std::map results; @@ -492,19 +498,26 @@ std::map database_api_impl::get_full_accounts( const size_t api_limit_get_full_accounts_lists = static_cast( _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() ) + // Add the account's proposals (if the data is available) + if( _app_options && _app_options->has_api_helper_indexes_plugin ) { - acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), - api_limit_get_full_accounts_lists) ); - for( auto proposal_id : required_approvals_itr->second ) + const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); + const auto& proposals_by_account = proposal_idx.get_secondary_index< + graphene::chain::required_approval_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() ) { - if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) { - acnt.more_data_available.proposals = true; - break; + acnt.proposals.reserve( std::min(required_approvals_itr->second.size(), + api_limit_get_full_accounts_lists) ); + for( auto proposal_id : required_approvals_itr->second ) + { + if(acnt.proposals.size() >= api_limit_get_full_accounts_lists) { + acnt.more_data_available.proposals = true; + break; + } + acnt.proposals.push_back(proposal_id(_db)); } - acnt.proposals.push_back(proposal_id(_db)); } } @@ -641,6 +654,10 @@ vector database_api::get_account_references( const std::string vector database_api_impl::get_account_references( const std::string account_id_or_name )const { + // api_helper_indexes plugin is required for accessing the secondary index + FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, + "api_helper_indexes plugin is not enabled on this server." ); + const auto& idx = _db.get_index_type(); const auto& aidx = dynamic_cast(idx); const auto& refs = aidx.get_secondary_index(); @@ -2153,6 +2170,10 @@ vector database_api::get_proposed_transactions( const std::stri vector database_api_impl::get_proposed_transactions( const std::string account_id_or_name )const { + // api_helper_indexes plugin is required for accessing the secondary index + FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, + "api_helper_indexes plugin is not enabled on this server." ); + const auto& proposal_idx = _db.get_index_type< primary_index< proposal_index > >(); const auto& proposals_by_account = proposal_idx.get_secondary_index(); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index b9c37fb6c6..d0f81960db 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -39,7 +39,10 @@ namespace graphene { namespace app { { public: bool enable_subscribe_to_all = false; + + bool has_api_helper_indexes_plugin = false; bool has_market_history_plugin = false; + uint64_t api_limit_get_account_history_operations = 100; uint64_t api_limit_get_account_history = 100; uint64_t api_limit_get_grouped_limit_orders = 101; From c921ffdb92407ff5a0d97061f70cb92be5fbe9d6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 16 Apr 2020 17:12:35 +0000 Subject: [PATCH 3/3] Fix test cases --- tests/tests/database_api_tests.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/tests/database_api_tests.cpp b/tests/tests/database_api_tests.cpp index 31f03e7781..98febcf2af 100644 --- a/tests/tests/database_api_tests.cpp +++ b/tests/tests/database_api_tests.cpp @@ -66,7 +66,12 @@ BOOST_AUTO_TEST_CASE(is_registered) /*** * Assert */ - graphene::app::database_api db_api(db); + graphene::app::database_api db_api1(db); + BOOST_CHECK_THROW( db_api1.is_public_key_registered((string) nathan_public), fc::exception ); + + graphene::app::application_options opt = app.get_options(); + opt.has_api_helper_indexes_plugin = true; + graphene::app::database_api db_api( db, &opt ); BOOST_CHECK(db_api.is_public_key_registered((string) nathan_public)); BOOST_CHECK(db_api.is_public_key_registered((string) dan_public)); @@ -1365,7 +1370,14 @@ BOOST_AUTO_TEST_CASE( api_limit_get_key_references ){ vector< private_key_type > numbered_private_keys; vector< public_key_type > numbered_key_id; numbered_private_keys.reserve( num_keys ); - graphene::app::database_api db_api( db, &( app.get_options() )); + + graphene::app::database_api db_api1( db, &( app.get_options() )); + BOOST_CHECK_THROW( db_api1.get_key_references(numbered_key_id), fc::exception ); + + graphene::app::application_options opt = app.get_options(); + opt.has_api_helper_indexes_plugin = true; + graphene::app::database_api db_api( db, &opt ); + for( int i=0; i