Skip to content

Commit

Permalink
Merge pull request #2142 from bitshares/fix-4.0
Browse files Browse the repository at this point in the history
Fix 4.0 issues
  • Loading branch information
abitmore committed Apr 16, 2020
2 parents 70cc85f + c921ffd commit e836204
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
3 changes: 3 additions & 0 deletions libraries/app/application.cpp
Expand Up @@ -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<boost::filesystem::path>();
Expand Down
47 changes: 34 additions & 13 deletions libraries/app/database_api.cpp
Expand Up @@ -335,6 +335,10 @@ vector<flat_set<account_id_type>> database_api::get_key_references( vector<publi
*/
vector<flat_set<account_id_type>> database_api_impl::get_key_references( vector<public_key_type> 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<account_index>();
Expand Down Expand Up @@ -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<account_index>();
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
Expand Down Expand Up @@ -454,9 +463,6 @@ std::map<std::string, full_account> 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<graphene::chain::required_approval_index>();

bool to_subscribe = get_whether_to_subscribe( subscribe );

std::map<std::string, full_account> results;
Expand Down Expand Up @@ -492,19 +498,26 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
size_t api_limit_get_full_accounts_lists = static_cast<size_t>(
_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));
}
}

Expand Down Expand Up @@ -641,6 +654,10 @@ vector<account_id_type> database_api::get_account_references( const std::string

vector<account_id_type> 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<account_index>();
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
Expand Down Expand Up @@ -2153,6 +2170,10 @@ vector<proposal_object> database_api::get_proposed_transactions( const std::stri

vector<proposal_object> 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<graphene::chain::required_approval_index>();

Expand Down
3 changes: 3 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Expand Up @@ -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;
Expand Down
Expand Up @@ -51,13 +51,12 @@ struct account_storage_object : public abstract_object<account_storage_object>
optional<variant> value;
};

struct by_custom_id;
struct by_account_catalog_key;

typedef multi_index_container<
account_storage_object,
indexed_by<
ordered_unique< tag<by_custom_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_account_catalog_key>,
composite_key< account_storage_object,
member< account_storage_object, account_id_type, &account_storage_object::account >,
Expand Down
16 changes: 14 additions & 2 deletions tests/tests/database_api_tests.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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<num_keys1; i++ )
{
private_key_type privkey = generate_private_key(std::string("key_") + std::to_string(i));
Expand Down

0 comments on commit e836204

Please sign in to comment.