Skip to content

Commit

Permalink
#3373: Prefer generic function naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Sep 5, 2019
1 parent b946f52 commit 9ba73d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions libraries/chain/database.cpp
Expand Up @@ -4357,7 +4357,7 @@ void database::clear_expired_orders()
}

template< class AccountType >
void clear_expired_delegations_helper( database& db, const AccountType& account, const vesting_delegation_expiration_object& o )
void generic_clear_expired_delegations( database& db, const AccountType& account, const vesting_delegation_expiration_object& o )
{
const auto& gpo = db.get_dynamic_global_properties();
db.modify( account, [&]( AccountType& a )
Expand Down Expand Up @@ -4388,13 +4388,13 @@ void database::clear_expired_delegations()

if ( itr->vesting_shares.symbol.space() == asset_symbol_type::legacy_space )
{
clear_expired_delegations_helper( *this, get_account( itr->delegator ), *itr );
generic_clear_expired_delegations( *this, get_account( itr->delegator ), *itr );
}
else
{
auto key = boost::make_tuple( itr->delegator, itr->vesting_shares.symbol.get_paired_symbol() );
const auto& account = get< account_regular_balance_object, by_name_liquid_symbol >( key );
clear_expired_delegations_helper( *this, account, *itr );
generic_clear_expired_delegations( *this, account, *itr );
}

post_push_virtual_operation( vop );
Expand Down
16 changes: 4 additions & 12 deletions libraries/chain/steem_evaluator.cpp
Expand Up @@ -3144,7 +3144,7 @@ void claim_reward_balance2_evaluator::do_apply( const claim_reward_balance2_oper
}

template < class AccountType >
void delegate_vesting_shares_helper( database& _db, const AccountType& delegator, const AccountType& delegatee, const asset& vesting_shares )
void generic_delegate_vesting_shares_evaluator( database& _db, const AccountType& delegator, const AccountType& delegatee, const asset& vesting_shares )
{
auto delegation = _db.find< vesting_delegation_object, by_delegation >( boost::make_tuple( delegator.name, delegatee.name, vesting_shares.symbol ) );

Expand Down Expand Up @@ -3375,21 +3375,13 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_
{
const auto& delegator = _db.get_account( op.delegator );
const auto& delegatee = _db.get_account( op.delegatee );
delegate_vesting_shares_helper( _db, delegator, delegatee, op.vesting_shares );
generic_delegate_vesting_shares_evaluator( _db, delegator, delegatee, op.vesting_shares );
}
else
{
const auto* delegator = _db.find< account_regular_balance_object, by_name_liquid_symbol >( boost::make_tuple( op.delegator, op.vesting_shares.symbol.get_paired_symbol() ) );

if ( delegator == nullptr )
{
delegator = &_db.create< account_regular_balance_object >( [&]( account_regular_balance_object& account_balance )
{
account_balance.initialize_assets( op.vesting_shares.symbol.get_paired_symbol() );
account_balance.name = op.delegator;
account_balance.validate();
} );
}
FC_ASSERT( delegator != nullptr, "Account ${acc} does not have enough mana to delegate.", ("acc", op.delegator) );

const auto* delegatee = _db.find< account_regular_balance_object, by_name_liquid_symbol >( boost::make_tuple( op.delegatee, op.vesting_shares.symbol.get_paired_symbol() ) );

Expand All @@ -3403,7 +3395,7 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_
} );
}

delegate_vesting_shares_helper( _db, *delegator, *delegatee, op.vesting_shares );
generic_delegate_vesting_shares_evaluator( _db, *delegator, *delegatee, op.vesting_shares );
}
}

Expand Down

0 comments on commit 9ba73d0

Please sign in to comment.