Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Nov 8, 2022
1 parent 40913fe commit ecdcd1b
Show file tree
Hide file tree
Showing 25 changed files with 176 additions and 130 deletions.
2 changes: 1 addition & 1 deletion libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ FC_API(graphene::app::crypto_api,
)
FC_API(graphene::app::asset_api,
(get_asset_holders)
(get_asset_holders_count)
(get_asset_holders_count)
(get_all_asset_holders)
)
FC_API(graphene::app::orders_api,
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/graphene/app/api_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ FC_REFLECT( graphene::app::order, (price)(quote)(base)(id)(owner_id)(owner_name)
FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) )
FC_REFLECT( graphene::app::market_ticker,
(time)(base)(quote)(latest)(lowest_ask)(lowest_ask_base_size)(lowest_ask_quote_size)
(highest_bid)(highest_bid_base_size)(highest_bid_quote_size)(percent_change)(base_volume)(quote_volume)(mto_id) )
(highest_bid)(highest_bid_base_size)(highest_bid_quote_size)(percent_change)(base_volume)(quote_volume)
(mto_id) )
FC_REFLECT( graphene::app::market_volume, (time)(base)(quote)(base_volume)(quote_volume) )
FC_REFLECT( graphene::app::market_trade, (sequence)(date)(price)(amount)(value)(type)
(side1_account_id)(side2_account_id) )
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ static extendable_operation_result pay_settle_from_gs_fund( database& d,

asset settled_amount = ( op.amount.amount == mia_dyn.current_supply )
? asset( bitasset.settlement_fund, bitasset.options.short_backing_asset )
: op.amount * bitasset.settlement_price; // round down, favors global settlement fund
: ( op.amount * bitasset.settlement_price ); // round down, favors global settlement fund
if( op.amount.amount != mia_dyn.current_supply )
{
// should be strictly < except for PM with zero outcome since in that case bitasset.settlement_fund is zero
Expand Down
11 changes: 5 additions & 6 deletions libraries/chain/db_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ void database::debug_dump()

void debug_apply_update( database& db, const fc::variant_object& vo )
{
static const uint8_t
db_action_nil = 0,
db_action_create = 1,
db_action_write = 2,
db_action_update = 3,
db_action_delete = 4;
constexpr uint8_t db_action_nil = 0;
constexpr uint8_t db_action_create = 1;
constexpr uint8_t db_action_write = 2;
constexpr uint8_t db_action_update = 3;
constexpr uint8_t db_action_delete = 4;

// "_action" : "create" object must not exist, unspecified fields take defaults
// "_action" : "write" object may exist, is replaced entirely, unspecified fields take defaults
Expand Down
18 changes: 11 additions & 7 deletions libraries/chain/include/graphene/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ namespace graphene { namespace chain {
uint64_t vp_committee = 0; ///< the final voting power for the committees.
uint64_t vp_witness = 0; ///< the final voting power for the witnesses.
uint64_t vp_worker = 0; ///< the final voting power for the workers.
/// timestamp of the last count of votes.
/// if there is no statistics, the date is less than `_db.get_dynamic_global_properties().last_vote_tally_time`.
time_point_sec vote_tally_time;
/// Timestamp of the last count of votes.
/// If there is no statistics,
/// the date is less than `_db.get_dynamic_global_properties().last_vote_tally_time`.
time_point_sec vote_tally_time;
///@}

/// Whether this account owns some CORE asset and is voting
Expand Down Expand Up @@ -160,7 +161,8 @@ namespace graphene { namespace chain {
account_id_type owner;
asset_id_type asset_type;
share_type balance;
bool maintenance_flag = false; ///< Whether need to process this balance object in maintenance interval
/// Whether need to process this balance object in maintenance interval
bool maintenance_flag = false;

asset get_balance()const { return asset(balance, asset_type); }
void adjust_balance(const asset& delta);
Expand Down Expand Up @@ -364,8 +366,10 @@ namespace graphene { namespace chain {
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;

const map< asset_id_type, const account_balance_object* >& get_account_balances( const account_id_type& acct )const;
const account_balance_object* get_account_balance( const account_id_type& acct, const asset_id_type& asset )const;
const map< asset_id_type, const account_balance_object* >& get_account_balances(
const account_id_type& acct )const;
const account_balance_object* get_account_balance( const account_id_type& acct,
const asset_id_type& asset )const;

private:
static const uint8_t bits;
Expand Down Expand Up @@ -428,7 +432,7 @@ namespace graphene { namespace chain {

struct by_maintenance_seq;
struct by_voting_power_active;

/**
* @ingroup object_index
*/
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace graphene { namespace chain {
{ return db.get(dynamic_asset_data_id); }

/**
* The total amount of an asset that is reserved for future issuance.
* The total amount of an asset that is reserved for future issuance.
*/
template<class DB>
share_type reserved( const DB& db )const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ typedef multi_index_container<
blinded_balance_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_commitment>, member<blinded_balance_object, commitment_type, &blinded_balance_object::commitment> >
ordered_unique< tag<by_commitment>,
member<blinded_balance_object, commitment_type, &blinded_balance_object::commitment> >
>
> blinded_balance_object_multi_index_type;
typedef generic_index<blinded_balance_object, blinded_balance_object_multi_index_type> blinded_balance_index;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ namespace graphene { namespace chain {
* to newly created VBID and return it.
*
* Otherwise, credit amount to ovbid.
*
*
* @return ID of newly created VBO, but only if VBO was created.
*/
optional< vesting_balance_id_type > deposit_lazy_vesting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace graphene { namespace chain {
time_point_sec time;
witness_id_type current_witness;
time_point_sec next_maintenance_time;
time_point_sec last_vote_tally_time;
time_point_sec last_vote_tally_time;
time_point_sec last_budget_time;
share_type witness_budget;
share_type total_pob;
Expand Down
9 changes: 4 additions & 5 deletions libraries/chain/include/graphene/chain/htlc_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace graphene { namespace chain {

/**
* @brief database object to store HTLCs
*
*
* This object is stored in the database while an HTLC is active. The HTLC will
* become inactive at expiration or when unlocked via the preimage.
*/
Expand All @@ -47,7 +47,7 @@ namespace graphene { namespace chain {
asset_id_type asset_id;
} transfer;
struct condition_info {
struct hash_lock_info {
struct hash_lock_info {
htlc_hash preimage_hash;
uint16_t preimage_size;
} hash_lock;
Expand Down Expand Up @@ -91,13 +91,13 @@ namespace graphene { namespace chain {
indexed_by<
ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,

ordered_unique< tag< by_expiration >,
ordered_unique< tag< by_expiration >,
composite_key< htlc_object,
htlc_object::timelock_extractor,
member< object, object_id_type, &object::id > > >,

ordered_unique< tag< by_from_id >,
composite_key< htlc_object,
composite_key< htlc_object,
htlc_object::from_extractor,
member< object, object_id_type, &object::id > > >,

Expand All @@ -106,7 +106,6 @@ namespace graphene { namespace chain {
htlc_object::to_extractor,
member< object, object_id_type, &object::id > > >
>

> htlc_object_index_type;

typedef generic_index< htlc_object, htlc_object_index_type > htlc_index;
Expand Down
5 changes: 2 additions & 3 deletions libraries/chain/include/graphene/chain/proposal_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace graphene { namespace chain {
class database;

/**
* @brief tracks the approval of a partially approved transaction
* @brief tracks the approval of a partially approved transaction
* @ingroup object
* @ingroup protocol
*/
Expand All @@ -56,7 +56,7 @@ class proposal_object : public abstract_object<proposal_object, protocol_ids, pr

/**
* @brief tracks all of the proposal objects that requrie approval of
* an individual account.
* an individual account.
*
* @ingroup object
* @ingroup protocol
Expand Down Expand Up @@ -88,7 +88,6 @@ typedef boost::multi_index_container<
proposal_object,
indexed_by<
ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
//ordered_non_unique< tag< by_expiration >, member< proposal_object, time_point_sec, &proposal_object::expiration_time > >
ordered_unique<tag<by_expiration>,
composite_key<proposal_object,
member<proposal_object, time_point_sec, &proposal_object::expiration_time>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef multi_index_container<
special_authority_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_account>, member< special_authority_object, account_id_type, &special_authority_object::account> >
ordered_unique< tag<by_account>,
member< special_authority_object, account_id_type, &special_authority_object::account> >
>
> special_authority_multi_index_type;

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/graphene/chain/ticket_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class ticket_object : public abstract_object<ticket_object, protocol_ids, ticket
return _seconds_to_downgrade[ static_cast<uint8_t>(i) ];
}
static uint8_t value_multiplier( ticket_type i, ticket_version version ) {
static constexpr uint32_t _value_multiplier_v1[] = { 1, 2, 4, 8, 8, 0 };
static constexpr uint32_t _value_multiplier_v2[] = { 0, 2, 4, 8, 8, 0 };
static constexpr uint8_t _value_multiplier_v1[] = { 1, 2, 4, 8, 8, 0 };
static constexpr uint8_t _value_multiplier_v2[] = { 0, 2, 4, 8, 8, 0 };
return ( version == ticket_v1 ? _value_multiplier_v1[ static_cast<uint8_t>(i) ]
: _value_multiplier_v2[ static_cast<uint8_t>(i) ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,37 @@ namespace graphene { namespace chain {
asset withdrawal_limit;
/// The duration of a withdrawal period in seconds
uint32_t withdrawal_period_sec = 0;
/***
* The beginning of the next withdrawal period
* WARNING: Due to caching, this value does not always represent the start of the next or current period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
*/
/**
* The beginning of the next withdrawal period.
* WARNING: Due to caching, this value does not always represent the start of the next or current period,
* because it is only updated after a withdrawal operation such as claim.
* For the latest current period, use current_period().
*/
time_point_sec period_start_time;
/// The time at which this withdraw permission expires
time_point_sec expiration;

/***
* Tracks the total amount
* WARNING: Due to caching, this value does not always represent the total amount claimed during the current period; it may represent what was claimed during the last claimed period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
*/
/**
* Tracks the total amount
* WARNING: Due to caching, this value does not always represent the total amount claimed during the
* current period, it may represent what was claimed during the last claimed period, because it is only
* updated after a withdrawal operation such as claim.
* For the latest current period, use current_period().
*/
share_type claimed_this_period;

/***
* Determine how much is still available to be claimed during the period that contains a time of interest. This object and function is mainly intended to be used with the "current" time as a parameter. The current time can be obtained from the time of the current head of the blockchain.
*/
/***
* Determine how much is still available to be claimed during the period that contains a time of interest.
* This object and function is mainly intended to be used with the "current" time as a parameter.
* The current time can be obtained from the time of the current head of the blockchain.
*/
asset available_this_period( fc::time_point_sec current_time )const
{
if( current_time >= period_start_time + withdrawal_period_sec )
return withdrawal_limit;
return asset(
( withdrawal_limit.amount > claimed_this_period )
? withdrawal_limit.amount - claimed_this_period
: 0, withdrawal_limit.asset_id );
return asset( ( withdrawal_limit.amount > claimed_this_period ) ?
( withdrawal_limit.amount - claimed_this_period ) : 0,
withdrawal_limit.asset_id );
}
};

Expand Down
6 changes: 3 additions & 3 deletions libraries/net/include/graphene/net/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* our peers and save a copy in a cache were we will find it if
* a peer requests it. We expire out old items out of the cache
* after this number of blocks go by.
*
*
* Recently lowered from 30 to match the default expiration time
* the web wallet imposes on transactions.
*/
Expand All @@ -92,12 +92,12 @@
* is being flooded -- typically transactions will be fetched as soon
* as we find out about them, so only one item will be requested
* at a time.
*
*
* No tests have been done to find the optimal value for this
* parameter, so consider increasing or decreasing it if performance
* during flooding is lacking.
*/
#define GRAPHENE_NET_MAX_ITEMS_PER_PEER_DURING_NORMAL_OPERATION 1
#define GRAPHENE_NET_MAX_ITEMS_PER_PEER_DURING_NORMAL_OPERATION 1

/**
* Instead of fetching all item IDs from a peer, then fetching all blocks
Expand Down
10 changes: 5 additions & 5 deletions libraries/net/include/graphene/net/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace graphene { namespace net {
using message_hash_type = fc::ripemd160;

/**
* Abstracts the process of packing/unpacking a message for a
* Abstracts the process of packing/unpacking a message for a
* particular channel.
*/
struct message : public message_header
Expand All @@ -71,7 +71,7 @@ namespace graphene { namespace net {
* Assumes that T::type specifies the message type
*/
template<typename T>
message( const T& m )
message( const T& m )
{
msg_type = T::type;
data = fc::raw::pack(m);
Expand All @@ -88,7 +88,7 @@ namespace graphene { namespace net {
* opposite process from the constructor.
*/
template<typename T>
T as()const
T as()const
{
try {
FC_ASSERT( msg_type.value() == T::type );
Expand All @@ -105,8 +105,8 @@ namespace graphene { namespace net {
fc::raw::unpack( ds, tmp );
}
return tmp;
} FC_RETHROW_EXCEPTIONS( warn,
"error unpacking network message as a '${type}' ${x} !=? ${msg_type}",
} FC_RETHROW_EXCEPTIONS( warn,
"error unpacking network message as a '${type}' ${x} !=? ${msg_type}",
("type", fc::get_typename<T>::name() )
("x", T::type)
("msg_type", msg_type.value())
Expand Down
9 changes: 5 additions & 4 deletions libraries/net/include/graphene/net/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace graphene { namespace net {
* @throws exception if error validating the item, otherwise the item is
* safe to broadcast on.
*/
virtual bool handle_block( const graphene::net::block_message& blk_msg, bool sync_mode,
virtual bool handle_block( const graphene::net::block_message& blk_msg, bool sync_mode,
std::vector<message_hash_type>& contained_transaction_msg_ids ) = 0;

/**
Expand Down Expand Up @@ -130,13 +130,14 @@ namespace graphene { namespace net {
* &c.
* the last item in the list will be the hash of the most recent block on our preferred chain
*/
virtual std::vector<item_hash_t> get_blockchain_synopsis(const item_hash_t& reference_point,
uint32_t number_of_blocks_after_reference_point) = 0;
virtual std::vector<item_hash_t> get_blockchain_synopsis(const item_hash_t& reference_point,
uint32_t number_of_blocks_after_reference_point) = 0;

/**
* Call this after the call to handle_message succeeds.
*
* @param item_type the type of the item we're synchronizing, will be the same as item passed to the sync_from() call
* @param item_type the type of the item we're synchronizing, will be the same as item passed to the
* sync_from() call
* @param item_count the number of items known to the node that haven't been sent to handle_item() yet.
* After `item_count` more calls to handle_item(), the node will be in sync
*/
Expand Down
Loading

0 comments on commit ecdcd1b

Please sign in to comment.