BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
fee_schedule.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #include <algorithm>
26 
27 #include <fc/io/raw.hpp>
28 
29 #define MAX_FEE_STABILIZATION_ITERATION 4
30 
31 namespace graphene { namespace protocol {
32 
34  {
35  }
36 
38  {
39  fee_schedule result;
40  for( size_t i = 0; i < fee_parameters().count(); ++i )
41  {
42  fee_parameters x; x.set_which(i);
43  result.parameters.insert(x);
44  }
45  return result;
46  }
47 
49  {
50  typedef void result_type;
52 
53  set_fee_visitor( asset f ):_fee(f){}
54 
55  template<typename OpType>
56  void operator()( OpType& op )const
57  {
58  op.fee = _fee;
59  }
60  };
61 
63  {
64  typedef void result_type;
65 
66  template<typename ParamType>
67  result_type operator()( ParamType& op )const
68  {
69  memset( (char*)&op, 0, sizeof(op) );
70  }
71  };
72 
74  {
75  *this = get_default();
76  for( fee_parameters& i : parameters )
77  i.visit( zero_fee_visitor() );
78  this->scale = 0;
79  }
80 
81  asset fee_schedule::set_fee( operation& op, const price& core_exchange_rate )const
82  {
83  auto f = calculate_fee( op, core_exchange_rate );
84  auto f_max = f;
85  for( size_t i=0; i<MAX_FEE_STABILIZATION_ITERATION; i++ )
86  {
87  op.visit( set_fee_visitor( f_max ) );
88  auto f2 = calculate_fee( op, core_exchange_rate );
89  if( f == f2 )
90  break;
91  f_max = std::max( f_max, f2 );
92  f = f2;
93  if( i == 0 )
94  {
95  // no need for warnings on later iterations
96  wlog( "set_fee requires multiple iterations to stabilize with core_exchange_rate ${p} on operation ${op}",
97  ("p", core_exchange_rate) ("op", op) );
98  }
99  }
100  return f_max;
101  }
102 
103 } } // graphene::protocol
contains all of the parameters necessary to calculate the fee for any operation
Definition: api.cpp:56
#define MAX_FEE_STABILIZATION_ITERATION
fc::static_variant< transfer_operation, limit_order_create_operation, limit_order_cancel_operation, call_order_update_operation, fill_order_operation, account_create_operation, account_update_operation, account_whitelist_operation, account_upgrade_operation, account_transfer_operation, asset_create_operation, asset_update_operation, asset_update_bitasset_operation, asset_update_feed_producers_operation, asset_issue_operation, asset_reserve_operation, asset_fund_fee_pool_operation, asset_settle_operation, asset_global_settle_operation, asset_publish_feed_operation, witness_create_operation, witness_update_operation, proposal_create_operation, proposal_update_operation, proposal_delete_operation, withdraw_permission_create_operation, withdraw_permission_update_operation, withdraw_permission_claim_operation, withdraw_permission_delete_operation, committee_member_create_operation, committee_member_update_operation, committee_member_update_global_parameters_operation, vesting_balance_create_operation, vesting_balance_withdraw_operation, worker_create_operation, custom_operation, assert_operation, balance_claim_operation, override_transfer_operation, transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, asset_settle_cancel_operation, asset_claim_fees_operation, fba_distribute_operation, bid_collateral_operation, execute_bid_operation, asset_claim_pool_operation, asset_update_issuer_operation, htlc_create_operation, htlc_redeem_operation, htlc_redeemed_operation, htlc_extend_operation, htlc_refund_operation, custom_authority_create_operation, custom_authority_update_operation, custom_authority_delete_operation, ticket_create_operation, ticket_update_operation, liquidity_pool_create_operation, liquidity_pool_delete_operation, liquidity_pool_deposit_operation, liquidity_pool_withdraw_operation, liquidity_pool_exchange_operation >
static fee_schedule get_default()
transform_to_fee_parameters< operation >::type fee_parameters
visitor::result_type visit(visitor &v)
#define wlog(FORMAT,...)
Definition: logger.hpp:123
void operator()(OpType &op) const
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:114
result_type operator()(ParamType &op) const
asset set_fee(operation &op, const price &core_exchange_rate=price::unit_price()) const
asset calculate_fee(const operation &op) const
uint32_t scale
fee * scale / GRAPHENE_100_PERCENT
fee_parameters::flat_set_type parameters