Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fee_helper refactor #2156

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
&& global_properties.parameters.account_fee_scale_bitshifts != 0 )
{
d.modify(global_properties, [](global_property_object& p) {
p.parameters.get_mutable_fees().get<account_create_operation>().basic_fee <<= p.parameters.account_fee_scale_bitshifts;
p.parameters.get_mutable_fees().mutable_get<account_create_operation>().basic_fee <<= p.parameters.account_fee_scale_bitshifts;
});
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g

modify(gpo, [&dgpo](global_property_object& p) {
// Remove scaling of account registration fee
p.parameters.get_mutable_fees().get<account_create_operation>().basic_fee >>= p.parameters.account_fee_scale_bitshifts *
p.parameters.get_mutable_fees().mutable_get<account_create_operation>().basic_fee >>= p.parameters.account_fee_scale_bitshifts *
(dgpo.accounts_registered_this_interval / p.parameters.accounts_per_fee_scale);

if( p.pending_parameters )
Expand Down
86 changes: 22 additions & 64 deletions libraries/protocol/include/graphene/protocol/fee_schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,116 +37,74 @@ namespace graphene { namespace protocol {
template<typename Operation>
class fee_helper {
public:
const typename Operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
const typename Operation::fee_parameters_type& get(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( typename Operation::fee_parameters_type() );
FC_ASSERT( itr != parameters.end() );
return itr->template get<typename Operation::fee_parameters_type>();
}
};
if( itr != parameters.end() )
return itr->template get<typename Operation::fee_parameters_type>();

template<>
class fee_helper<account_create_operation> {
public:
const account_create_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( account_create_operation::fee_parameters_type() );
FC_ASSERT( itr != parameters.end() );
return itr->get<account_create_operation::fee_parameters_type>();
static typename Operation::fee_parameters_type dummy;
return dummy;
}
typename account_create_operation::fee_parameters_type& get(fee_parameters::flat_set_type& parameters)const
typename Operation::fee_parameters_type& mutable_get(fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( account_create_operation::fee_parameters_type() );
FC_ASSERT( itr != parameters.end() );
return itr->get<account_create_operation::fee_parameters_type>();
auto itr = parameters.find( typename Operation::fee_parameters_type() );
if( itr != parameters.end() )
return itr->template get<typename Operation::fee_parameters_type >();

static typename Operation::fee_parameters_type dummy = get(parameters);
parameters.insert(dummy);
return dummy;
}
};

template<>
class fee_helper<bid_collateral_operation> {
public:
const bid_collateral_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
const bid_collateral_operation::fee_parameters_type& get(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( bid_collateral_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<bid_collateral_operation::fee_parameters_type>();

static bid_collateral_operation::fee_parameters_type bid_collateral_dummy;
bid_collateral_dummy.fee = fee_helper<call_order_update_operation>().cget(parameters).fee;
bid_collateral_dummy.fee = fee_helper<call_order_update_operation>().get(parameters).fee;
return bid_collateral_dummy;
}
};

template<>
class fee_helper<asset_update_issuer_operation> {
public:
const asset_update_issuer_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
const asset_update_issuer_operation::fee_parameters_type& get(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( asset_update_issuer_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<asset_update_issuer_operation::fee_parameters_type>();

static asset_update_issuer_operation::fee_parameters_type dummy;
dummy.fee = fee_helper<asset_update_operation>().cget(parameters).fee;
dummy.fee = fee_helper<asset_update_operation>().get(parameters).fee;
return dummy;
}
};

template<>
class fee_helper<asset_claim_pool_operation> {
public:
const asset_claim_pool_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
const asset_claim_pool_operation::fee_parameters_type& get(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( asset_claim_pool_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<asset_claim_pool_operation::fee_parameters_type>();

static asset_claim_pool_operation::fee_parameters_type asset_claim_pool_dummy;
asset_claim_pool_dummy.fee = fee_helper<asset_fund_fee_pool_operation>().cget(parameters).fee;
asset_claim_pool_dummy.fee = fee_helper<asset_fund_fee_pool_operation>().get(parameters).fee;
return asset_claim_pool_dummy;
}
};

template<>
class fee_helper<htlc_create_operation> {
public:
const htlc_create_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( htlc_create_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<htlc_create_operation::fee_parameters_type>();

static htlc_create_operation::fee_parameters_type htlc_create_operation_fee_dummy;
return htlc_create_operation_fee_dummy;
}
};

template<>
class fee_helper<htlc_redeem_operation> {
public:
const htlc_redeem_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( htlc_redeem_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<htlc_redeem_operation::fee_parameters_type>();

static htlc_redeem_operation::fee_parameters_type htlc_redeem_operation_fee_dummy;
return htlc_redeem_operation_fee_dummy;
}
};
template<>
class fee_helper<htlc_extend_operation> {
public:
const htlc_extend_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
{
auto itr = parameters.find( htlc_extend_operation::fee_parameters_type() );
if ( itr != parameters.end() )
return itr->get<htlc_extend_operation::fee_parameters_type>();

static htlc_extend_operation::fee_parameters_type htlc_extend_operation_fee_dummy;
return htlc_extend_operation_fee_dummy;
}
};
/**
* @brief contains all of the parameters necessary to calculate the fee for any operation
*/
Expand Down Expand Up @@ -182,12 +140,12 @@ namespace graphene { namespace protocol {
template<typename Operation>
const typename Operation::fee_parameters_type& get()const
{
return fee_helper<Operation>().cget(parameters);
return fee_helper<Operation>().get(parameters);
}
template<typename Operation>
typename Operation::fee_parameters_type& get()
typename Operation::fee_parameters_type& mutable_get()
{
return fee_helper<Operation>().get(parameters);
return fee_helper<Operation>().mutable_get(parameters);
}
template<typename Operation>
bool exists()const
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/fee_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ BOOST_AUTO_TEST_CASE( account_create_fee_scaling )
db.modify(global_property_id_type()(db), [](global_property_object& gpo)
{
gpo.parameters.get_mutable_fees() = fee_schedule::get_default();
gpo.parameters.get_mutable_fees().get<account_create_operation>().basic_fee = 1;
gpo.parameters.get_mutable_fees().mutable_get<account_create_operation>().basic_fee = 1;
});

for( int i = db.get_dynamic_global_properties().accounts_registered_this_interval; i < accounts_per_scale; ++i )
Expand Down