Skip to content

Commit

Permalink
Merge pull request #2661 from bitshares/fix-code-smells
Browse files Browse the repository at this point in the history
Fix code smells
  • Loading branch information
abitmore authored Oct 27, 2022
2 parents e7bd762 + 3193263 commit 74d72ba
Show file tree
Hide file tree
Showing 18 changed files with 706 additions and 680 deletions.
50 changes: 25 additions & 25 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ vector<flat_set<account_id_type>> database_api_impl::get_key_references( vector<

for( auto& key : keys )
{
address a1( pts_address(key, false, 56) );
address a2( pts_address(key, true, 56) );
address a1( pts_address(key, false) ); // version = 56 (default)
address a2( pts_address(key, true) ); // version = 56 (default)
address a3( pts_address(key, false, 0) );
address a4( pts_address(key, true, 0) );
address a5( key );
Expand Down Expand Up @@ -513,19 +513,14 @@ vector<optional<account_object>> database_api_impl::get_accounts( const vector<s
return result;
}

std::map<string,full_account> database_api::get_full_accounts( const vector<string>& names_or_ids,
optional<bool> subscribe )
std::map<string, full_account, std::less<>> database_api::get_full_accounts( const vector<string>& names_or_ids,
const optional<bool>& subscribe )
{
return my->get_full_accounts( names_or_ids, subscribe );
}

vector<account_statistics_object> database_api::get_top_voters(uint32_t limit)const
{
return my->get_top_voters( limit );
}

std::map<std::string, full_account> database_api_impl::get_full_accounts( const vector<std::string>& names_or_ids,
optional<bool> subscribe )
std::map<std::string, full_account, std::less<>> database_api_impl::get_full_accounts(
const vector<std::string>& names_or_ids, const optional<bool>& subscribe )
{
FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_get_full_accounts;
Expand All @@ -535,7 +530,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const

bool to_subscribe = get_whether_to_subscribe( subscribe );

std::map<std::string, full_account> results;
std::map<std::string, full_account, std::less<>> results;

for (const std::string& account_name_or_id : names_or_ids)
{
Expand Down Expand Up @@ -703,6 +698,11 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
return results;
}

vector<account_statistics_object> database_api::get_top_voters(uint32_t limit)const
{
return my->get_top_voters( limit );
}

vector<account_statistics_object> database_api_impl::get_top_voters(uint32_t limit)const
{
FC_ASSERT( _app_options, "Internal error" );
Expand Down Expand Up @@ -774,16 +774,16 @@ vector<optional<account_object>> database_api_impl::lookup_account_names(const v
return get_accounts( account_names, false );
}

map<string,account_id_type> database_api::lookup_accounts( const string& lower_bound_name,
map<string, account_id_type, std::less<>> database_api::lookup_accounts( const string& lower_bound_name,
uint32_t limit,
optional<bool> subscribe )const
const optional<bool>& subscribe )const
{
return my->lookup_accounts( lower_bound_name, limit, subscribe );
}

map<string,account_id_type> database_api_impl::lookup_accounts( const string& lower_bound_name,
map<string, account_id_type, std::less<>> database_api_impl::lookup_accounts( const string& lower_bound_name,
uint32_t limit,
optional<bool> subscribe )const
const optional<bool>& subscribe )const
{
FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_lookup_accounts;
Expand All @@ -792,7 +792,7 @@ map<string,account_id_type> database_api_impl::lookup_accounts( const string& lo
("configured_limit", configured_limit) );

const auto& accounts_by_name = _db.get_index_type<account_index>().indices().get<by_name>();
map<string,account_id_type> result;
map<string, account_id_type, std::less<>> result;

if( limit == 0 ) // shortcut to save a database query
return result;
Expand Down Expand Up @@ -2203,14 +2203,14 @@ fc::optional<witness_object> database_api_impl::get_witness_by_account(const std
return {};
}

map<string, witness_id_type> database_api::lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const
map<string, witness_id_type, std::less<>> database_api::lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const
{
return my->lookup_witness_accounts( lower_bound_name, limit );
}

map<string, witness_id_type> database_api_impl::lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const
map<string, witness_id_type, std::less<>> database_api_impl::lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const
{
FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_lookup_witness_accounts;
Expand All @@ -2226,7 +2226,7 @@ map<string, witness_id_type> database_api_impl::lookup_witness_accounts( const s
// records to return. This could be optimized, but we expect the
// number of witnesses to be few and the frequency of calls to be rare
// TODO optimize
std::map<std::string, witness_id_type> witnesses_by_account_name;
std::map<std::string, witness_id_type, std::less<>> witnesses_by_account_name;
for (const witness_object& witness : witnesses_by_id)
if (auto account_iter = _db.find(witness.witness_account))
if (account_iter->name >= lower_bound_name) // we can ignore anything below lower_bound_name
Expand Down Expand Up @@ -2294,13 +2294,13 @@ fc::optional<committee_member_object> database_api_impl::get_committee_member_by
return {};
}

map<string, committee_member_id_type> database_api::lookup_committee_member_accounts(
map<string, committee_member_id_type, std::less<>> database_api::lookup_committee_member_accounts(
const string& lower_bound_name, uint32_t limit )const
{
return my->lookup_committee_member_accounts( lower_bound_name, limit );
}

map<string, committee_member_id_type> database_api_impl::lookup_committee_member_accounts(
map<string, committee_member_id_type, std::less<>> database_api_impl::lookup_committee_member_accounts(
const string& lower_bound_name, uint32_t limit )const
{
FC_ASSERT( _app_options, "Internal error" );
Expand All @@ -2317,7 +2317,7 @@ map<string, committee_member_id_type> database_api_impl::lookup_committee_member
// records to return. This could be optimized, but we expect the
// number of committee_members to be few and the frequency of calls to be rare
// TODO optimize
std::map<std::string, committee_member_id_type> committee_members_by_account_name;
std::map<std::string, committee_member_id_type, std::less<>> committee_members_by_account_name;
for (const committee_member_object& committee_member : committee_members_by_id)
if (auto account_iter = _db.find(committee_member.committee_member_account))
if (account_iter->name >= lower_bound_name) // we can ignore anything below lower_bound_name
Expand Down
13 changes: 7 additions & 6 deletions libraries/app/database_api_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Accounts
vector<optional<account_object>> get_accounts( const vector<std::string>& account_names_or_ids,
optional<bool> subscribe )const;
std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids,
optional<bool> subscribe );
map<string, full_account, std::less<>> get_full_accounts( const vector<string>& names_or_ids,
const optional<bool>& subscribe );
vector<account_statistics_object> get_top_voters(uint32_t limit)const;
optional<account_object> get_account_by_name( string name )const;
vector<account_id_type> get_account_references( const std::string account_id_or_name )const;
vector<optional<account_object>> lookup_account_names(const vector<string>& account_names)const;
map<string,account_id_type> lookup_accounts( const string& lower_bound_name,
map<string, account_id_type, std::less<>> lookup_accounts( const string& lower_bound_name,
uint32_t limit,
optional<bool> subscribe )const;
const optional<bool>& subscribe )const;
uint64_t get_account_count()const;

// Balances
Expand Down Expand Up @@ -160,15 +160,16 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Witnesses
vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const;
fc::optional<witness_object> get_witness_by_account(const std::string& account_id_or_name)const;
map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const;
map<string, witness_id_type, std::less<>> lookup_witness_accounts(
const string& lower_bound_name, uint32_t limit )const;
uint64_t get_witness_count()const;

// Committee members
vector<optional<committee_member_object>> get_committee_members(
const vector<committee_member_id_type>& committee_member_ids )const;
fc::optional<committee_member_object> get_committee_member_by_account(
const std::string& account_id_or_name )const;
map<string, committee_member_id_type> lookup_committee_member_accounts(
map<string, committee_member_id_type, std::less<>> lookup_committee_member_accounts(
const string& lower_bound_name, uint32_t limit )const;
uint64_t get_committee_count()const;

Expand Down
33 changes: 18 additions & 15 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class database_api
/**
* @brief Get the objects corresponding to the provided IDs
* @param ids IDs of the objects to retrieve
* @param subscribe @a true to subscribe to the queried objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return The objects retrieved, in the order they are mentioned in ids
Expand Down Expand Up @@ -277,7 +277,7 @@ class database_api
/**
* @brief Get a list of accounts by names or IDs
* @param account_names_or_ids names or IDs of the accounts to retrieve
* @param subscribe @a true to subscribe to the queried account objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried account objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return The accounts corresponding to the provided names or IDs
Expand All @@ -292,7 +292,7 @@ class database_api
* @param names_or_ids Each item must be the name or ID of an account to retrieve,
* the quantity should not be greater than the configured value of
* @a api_limit_get_full_accounts
* @param subscribe @a true to subscribe to the queried full account objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried full account objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return Map of string from @p names_or_ids to the corresponding account
Expand All @@ -306,8 +306,9 @@ class database_api
* @a api_limit_get_full_accounts_lists option. Exceeded objects need to be queried with other APIs.
*
*/
std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids,
optional<bool> subscribe = optional<bool>() );
map<string, full_account, std::less<>> get_full_accounts(
const vector<string>& names_or_ids,
const optional<bool>& subscribe = optional<bool>() );

/**
* @brief Returns vector of voting power sorted by reverse vp_active
Expand Down Expand Up @@ -345,17 +346,17 @@ class database_api
* @param lower_bound_name Lower bound of the first name to return
* @param limit Maximum number of results to return, must not exceed the configured value of
* @a api_limit_lookup_accounts
* @param subscribe @a true to subscribe to the queried account objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried account objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return Map of account names to corresponding IDs
*
* @note In addition to the common auto-subscription rules,
* this API will subscribe to the returned account only if @p limit is 1.
*/
map<string,account_id_type> lookup_accounts( const string& lower_bound_name,
map<string, account_id_type, std::less<>> lookup_accounts( const string& lower_bound_name,
uint32_t limit,
optional<bool> subscribe = optional<bool>() )const;
const optional<bool>& subscribe = optional<bool>() )const;

//////////////
// Balances //
Expand Down Expand Up @@ -414,7 +415,7 @@ class database_api
/**
* @brief Get a list of assets by symbol names or IDs
* @param asset_symbols_or_ids symbol names or IDs of the assets to retrieve
* @param subscribe @a true to subscribe to the queried asset objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried asset objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return The assets corresponding to the provided symbol names or IDs
Expand Down Expand Up @@ -802,7 +803,7 @@ class database_api
* @param ids IDs of the liquidity pools,
* the quantity should not be greater than the configured value of
* @a api_limit_get_liquidity_pools
* @param subscribe @a true to subscribe to the queried objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @param with_statistics Whether to return statistics
Expand All @@ -821,7 +822,7 @@ class database_api
* @param asset_symbols_or_ids symbol names or IDs of the share assets,
* the quantity should not be greater than the configured value of
* @a api_limit_get_liquidity_pools
* @param subscribe @a true to subscribe to the queried objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @param with_statistics Whether to return statistics
Expand Down Expand Up @@ -1141,7 +1142,8 @@ class database_api
* @a api_limit_lookup_witness_accounts
* @return Map of witness names to corresponding IDs
*/
map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const;
map<string, witness_id_type, std::less<>> lookup_witness_accounts( const string& lower_bound_name,
uint32_t limit )const;

/**
* @brief Get the total number of witnesses registered with the blockchain
Expand Down Expand Up @@ -1176,8 +1178,9 @@ class database_api
* @a api_limit_lookup_committee_member_accounts
* @return Map of committee_member names to corresponding IDs
*/
map<string, committee_member_id_type> lookup_committee_member_accounts( const string& lower_bound_name,
uint32_t limit )const;
map<string, committee_member_id_type, std::less<>> lookup_committee_member_accounts(
const string& lower_bound_name,
uint32_t limit )const;

/**
* @brief Get the total number of committee registered with the blockchain
Expand Down Expand Up @@ -1370,7 +1373,7 @@ class database_api
/**
* @brief Get HTLC object
* @param id HTLC contract id
* @param subscribe @a true to subscribe to the queried HTLC objects; @a false to not subscribe;
* @param subscribe @a true to subscribe to the queried HTLC objects, @a false to not subscribe,
* @a null to subscribe or not subscribe according to current auto-subscription setting
* (see @ref set_auto_subscription)
* @return HTLC object for the id
Expand Down
11 changes: 7 additions & 4 deletions libraries/chain/balance_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ void_result balance_claim_evaluator::do_evaluate(const balance_claim_operation&
database& d = db();
balance = &op.balance_to_claim(d);

GRAPHENE_ASSERT(
bool is_balance_owner = (
op.balance_owner_key == balance->owner ||
pts_address(op.balance_owner_key, false, 56) == balance->owner ||
pts_address(op.balance_owner_key, true, 56) == balance->owner ||
pts_address(op.balance_owner_key, false) == balance->owner || // version = 56 (default)
pts_address(op.balance_owner_key, true) == balance->owner ); // version = 56 (default)
is_balance_owner = (
is_balance_owner ||
pts_address(op.balance_owner_key, false, 0) == balance->owner ||
pts_address(op.balance_owner_key, true, 0) == balance->owner,
pts_address(op.balance_owner_key, true, 0) == balance->owner );
GRAPHENE_ASSERT( is_balance_owner,
balance_claim_owner_mismatch,
"Balance owner key was specified as '${op}' but balance's actual owner is '${bal}'",
("op", op.balance_owner_key)
Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
Loading

0 comments on commit 74d72ba

Please sign in to comment.