BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
fee_schedule_calc.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 
26 
27 #include <fc/io/raw.hpp>
28 #include <fc/uint128.hpp>
29 
30 #define MAX_FEE_STABILIZATION_ITERATION 4
31 
32 namespace graphene { namespace protocol {
33 
35  {
36  typedef uint64_t result_type;
37 
39  const int current_op;
40  calc_fee_visitor( const fee_schedule& p, const operation& op ):param(p),current_op(op.which()){}
41 
42  template<typename OpType>
43  result_type operator()( const OpType& op )const
44  {
45  try {
46  return op.calculate_fee( param.get<OpType>() ).value;
47  } catch (fc::assert_exception& e) {
48  fee_parameters params; params.set_which(current_op);
49  auto itr = param.parameters.find(params);
50  if( itr != param.parameters.end() ) params = *itr;
51  return op.calculate_fee( params.get<typename OpType::fee_parameters_type>() ).value;
52  }
53  }
54  };
55 
56  template<>
58  {
59  //TODO: refactor for performance (see https://github.com/bitshares/bitshares-core/issues/2150)
64  }
65 
66  template<>
68  {
69  //TODO: refactor for performance (see https://github.com/bitshares/bitshares-core/issues/2150)
70  optional<uint64_t> sub_asset_creation_fee;
72  sub_asset_creation_fee = param.get<account_transfer_operation>().fee;
73  asset_create_operation::fee_parameters_type old_asset_creation_fee_params;
75  old_asset_creation_fee_params = param.get<asset_create_operation>();
76  return op.calculate_fee( old_asset_creation_fee_params, sub_asset_creation_fee ).value;
77  }
78 
80  {
81  uint64_t required_fee = op.visit( calc_fee_visitor( *this, op ) );
82  if( scale != GRAPHENE_100_PERCENT )
83  {
84  auto scaled = fc::uint128_t(required_fee) * scale;
85  scaled /= GRAPHENE_100_PERCENT;
87  "Required fee after scaling would exceed maximum possible supply" );
88  required_fee = static_cast<uint64_t>(scaled);
89  }
90  return asset( required_fee );
91  }
92 
93  asset fee_schedule::calculate_fee( const operation& op, const price& core_exchange_rate )const
94  {
95  return calculate_fee( op ).multiply_and_round_up( core_exchange_rate );
96  }
97 
98 } } // graphene::protocol
99 
contains all of the parameters necessary to calculate the fee for any operation
Definition: api.cpp:56
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 >
transform_to_fee_parameters< operation >::type fee_parameters
visitor::result_type visit(visitor &v)
calc_fee_visitor(const fee_schedule &p, const operation &op)
#define GRAPHENE_MAX_SHARE_SUPPLY
Definition: config.hpp:38
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
share_type calculate_fee(const fee_parameters_type &k, optional< uint64_t > sub_asset_creation_fee) const
Definition: asset_ops.cpp:82
Transfers an amount of one asset from one account to another.
Definition: transfer.hpp:45
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:114
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:74
share_type calculate_fee(const fee_parameters_type &fee_params, uint32_t fee_per_kb) const
Definition: htlc.cpp:37
result_type operator()(const OpType &op) const
const Operation::fee_parameters_type & get() const
asset calculate_fee(const operation &op) const
transfers the account to another account while clearing the white listIn theory an account can be tra...
Definition: account.hpp:266
T value
Definition: safe.hpp:22
fee_parameters::flat_set_type parameters
asset multiply_and_round_up(const price &p) const
Multiply and round up.
Definition: asset.cpp:78