Skip to content

Commit

Permalink
Update coding style, fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Aug 18, 2021
1 parent d9180f0 commit 183b80f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita
FC_ASSERT( !current_bitasset_data.has_individual_settlement(),
"Unable to update BDSM when the individual bad debt settlement pool is not empty" );
else if( bdsm_type::individual_settlement_to_order == old_bdsm )
FC_ASSERT( nullptr == d.find_bad_debt_settlement_order( op.asset_to_update ),
FC_ASSERT( !d.find_bad_debt_settlement_order( op.asset_to_update ),
"Unable to update BDSM when there exists a bad debt settlement order" );

// Since we do not allow updating in some cases (above), only check no_settlement here
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const call_order_object* database::find_least_collateralized_short( const asset_
if( call_itr != call_collateral_index.end() ) // no call order
call_ptr = &(*call_itr);
}
if( nullptr == call_ptr )
if( !call_ptr )
return nullptr;
if( call_ptr->debt_type() != bitasset.asset_id ) // no call order
return nullptr;
Expand Down
29 changes: 14 additions & 15 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void database::globally_settle_asset_impl( const asset_object& mia,

// Move the (individual) bad-debt settlement order to the GS fund
const limit_order_object* limit_ptr = find_bad_debt_settlement_order( bitasset.asset_id );
if( limit_ptr != nullptr )
if( limit_ptr )
{
collateral_gathered.amount += limit_ptr->for_sale;
remove( *limit_ptr );
Expand Down Expand Up @@ -200,7 +200,7 @@ void database::individually_settle( const asset_bitasset_data_object& bitasset,
else // settle to order
{
const limit_order_object* limit_ptr = find_bad_debt_settlement_order( bitasset.asset_id );
if( limit_ptr != nullptr )
if( limit_ptr )
{
modify( *limit_ptr, [&order,&fund_receives]( limit_order_object& obj ) {
obj.for_sale += fund_receives.amount;
Expand Down Expand Up @@ -360,8 +360,8 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
// if there is any CORE fee to deduct, redirect it to referral program
if( core_cancel_fee.amount > 0 )
{
seller_acc_stats = &order.seller( *this ).statistics( *this );
modify( *seller_acc_stats, [&]( account_statistics_object& obj ) {
seller_acc_stats = &get_account_stats_by_owner( order.seller );
modify( *seller_acc_stats, [&core_cancel_fee, this]( account_statistics_object& obj ) {
obj.pay_fee( core_cancel_fee.amount, get_global_properties().parameters.cashback_vesting_threshold );
} );
deferred_fee -= core_cancel_fee.amount;
Expand All @@ -382,7 +382,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
share_type cancel_fee_amount = static_cast<int64_t>(fee128);
// cancel_fee should be positive, pay it to asset's accumulated_fees
fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) {
modify( *fee_asset_dyn_data, [&cancel_fee_amount](asset_dynamic_data_object& addo) {
addo.accumulated_fees += cancel_fee_amount;
});
// cancel_fee should be no more than deferred_paid_fee
Expand All @@ -397,9 +397,9 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
auto refunded = order.amount_for_sale();
if( refunded.asset_id == asset_id_type() )
{
if( seller_acc_stats == nullptr )
seller_acc_stats = &order.seller( *this ).statistics( *this );
modify( *seller_acc_stats, [&]( account_statistics_object& obj ) {
if( !seller_acc_stats )
seller_acc_stats = &get_account_stats_by_owner( order.seller );
modify( *seller_acc_stats, [&refunded]( account_statistics_object& obj ) {
obj.total_core_in_orders -= refunded.amount;
});
}
Expand All @@ -418,7 +418,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
{
adjust_balance(order.seller, deferred_paid_fee);
// be here, must have: fee_asset != CORE
if( fee_asset_dyn_data == nullptr )
if( !fee_asset_dyn_data )
fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) {
addo.fee_pool += deferred_fee;
Expand Down Expand Up @@ -498,7 +498,7 @@ bool database::apply_order_before_hardfork_625(const limit_order_object& new_ord
check_call_orders(receive_asset); // the other side, same as above

const limit_order_object* updated_order_object = find< limit_order_object >( order_id );
if( updated_order_object == nullptr )
if( !updated_order_object )
return true;
if( head_block_time() <= HARDFORK_555_TIME )
return false;
Expand Down Expand Up @@ -694,7 +694,7 @@ bool database::apply_order(const limit_order_object& new_order_object)
}

const limit_order_object* updated_order_object = find< limit_order_object >( order_id );
if( updated_order_object == nullptr )
if( !updated_order_object )
return true;

// before #555 we would have done maybe_cull_small_order() logic as a result of fill_order()
Expand Down Expand Up @@ -1106,8 +1106,7 @@ asset database::match_impl( const force_settlement_object& settle,
{
call_pays.amount = call.collateral;
match_price = call_debt / call_collateral;
fill_price = ( margin_call_pays_ratio != nullptr ) ? ( match_price / (*margin_call_pays_ratio) )
: match_price;
fill_price = margin_call_pays_ratio ? ( match_price / (*margin_call_pays_ratio) ) : match_price;
}
settle_receives = call_receives.multiply_and_round_up( fill_price );
}
Expand Down Expand Up @@ -1175,7 +1174,7 @@ asset database::match_impl( const force_settlement_object& settle,
// price changed, update call_receives // round up to mitigate rounding issues (hf core-342)
call_receives = call_pays.multiply_and_round_up( match_price ); // round up
// update fill price and settle_receives
if( margin_call_pays_ratio != nullptr ) // check to be defensive
if( margin_call_pays_ratio ) // check to be defensive
{
fill_price = match_price / (*margin_call_pays_ratio);
settle_receives = call_receives * fill_price; // round down here, in favor of call order
Expand Down Expand Up @@ -1961,7 +1960,7 @@ asset database::pay_market_fees(const account_object* seller, const asset_object
asset reward = recv_asset.amount(0);

auto is_rewards_allowed = [&recv_asset, seller]() {
if (seller == nullptr)
if ( !seller )
return false;
const auto &white_list = recv_asset.options.extensions.value.whitelist_market_fee_sharing;
return ( !white_list || (*white_list).empty()
Expand Down

0 comments on commit 183b80f

Please sign in to comment.