BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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/uint128.hpp>
28 
29 namespace graphene { namespace protocol {
30 
32  {
33  using result_type = uint64_t;
34 
37  calc_fee_visitor( const fee_schedule& p, const operation& op ):param(p),current_op(op.which())
38  { /* Nothing else to do */ }
39 
40  template<typename OpType>
41  result_type operator()( const OpType& op )const
42  {
43  try {
44  return op.calculate_fee( param.get<OpType>() ).value;
45  } catch (fc::assert_exception& e) {
46  fee_parameters params;
47  params.set_which(current_op);
48  auto itr = param.parameters.find(params);
49  if( itr != param.parameters.end() )
50  params = *itr;
51  return op.calculate_fee( params.get<typename OpType::fee_params_t>() ).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_params_t 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 ) );
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
GRAPHENE_MAX_SHARE_SUPPLY
constexpr int64_t GRAPHENE_MAX_SHARE_SUPPLY(1000000000000000LL)
fc::static_variant::tag_type
int64_t tag_type
Definition: static_variant.hpp:46
uint128.hpp
graphene::protocol::ticket_create_operation
Creates a new ticket.
Definition: ticket.hpp:47
graphene::protocol::fee_schedule
contains all of the parameters necessary to calculate the fee for any operation
Definition: fee_schedule.hpp:173
graphene::protocol::price
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:108
graphene::protocol::asset_create_operation::fee_params_t
Definition: asset_ops.hpp:194
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, samet_fund_create_operation, samet_fund_delete_operation, samet_fund_update_operation, samet_fund_borrow_operation, samet_fund_repay_operation, credit_offer_create_operation, credit_offer_delete_operation, credit_offer_update_operation, credit_offer_accept_operation, credit_deal_repay_operation, credit_deal_expired_operation, liquidity_pool_update_operation, credit_deal_update_operation, limit_order_update_operation >
graphene::protocol::calc_fee_visitor::current_op
const operation::tag_type current_op
Definition: fee_schedule_calc.cpp:36
fee_schedule.hpp
graphene::protocol::fee_schedule::exists
bool exists() const
Definition: fee_schedule.hpp:211
graphene::protocol::account_transfer_operation
transfers the account to another account while clearing the white list
Definition: account.hpp:267
graphene::protocol::calc_fee_visitor
Definition: fee_schedule_calc.cpp:31
graphene::protocol::transfer_operation::fee_params_t::price_per_kbyte
uint32_t price_per_kbyte
Definition: transfer.hpp:49
graphene::protocol::calc_fee_visitor::param
const fee_schedule & param
Definition: fee_schedule_calc.cpp:35
graphene::protocol::htlc_create_operation
Definition: htlc.hpp:45
graphene::protocol::htlc_create_operation::calculate_fee
share_type calculate_fee(const fee_params_t &fee_params, uint32_t fee_per_kb) const
Definition: htlc.cpp:37
graphene::protocol::asset::multiply_and_round_up
asset multiply_and_round_up(const price &p) const
Multiply and round up.
Definition: asset.cpp:77
graphene::protocol::fee_schedule::parameters
fee_parameters::flat_set_type parameters
Definition: fee_schedule.hpp:220
graphene::protocol::fee_schedule::get
const Operation::fee_params_t & get() const
Definition: fee_schedule.hpp:201
graphene::protocol::transfer_operation
Transfers an amount of one asset from one account to another.
Definition: transfer.hpp:45
graphene::protocol::calc_fee_visitor::operator()
result_type operator()(const OpType &op) const
Definition: fee_schedule_calc.cpp:41
graphene::protocol::asset_create_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k, const optional< uint64_t > &sub_asset_creation_fee) const
Definition: asset_ops.cpp:82
graphene::protocol::fee_schedule::scale
uint32_t scale
fee * scale / GRAPHENE_100_PERCENT
Definition: fee_schedule.hpp:221
graphene::protocol::calc_fee_visitor::result_type
uint64_t result_type
Definition: fee_schedule_calc.cpp:33
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::protocol::fee_parameters
transform_to_fee_parameters< operation >::type fee_parameters
Definition: fee_schedule.hpp:35
graphene::protocol::transfer_operation::fee_params_t
Definition: transfer.hpp:47
fc::static_variant::visit
visitor::result_type visit(visitor &v)
Definition: static_variant.hpp:256
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::protocol::fee_schedule::calculate_fee
asset calculate_fee(const operation &op) const
Definition: fee_schedule_calc.cpp:79
graphene::protocol::asset
Definition: asset.hpp:31
fc::safe::value
T value
Definition: safe.hpp:28
graphene::protocol::calc_fee_visitor::calc_fee_visitor
calc_fee_visitor(const fee_schedule &p, const operation &op)
Definition: fee_schedule_calc.cpp:37
GRAPHENE_100_PERCENT
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
graphene
Definition: api.cpp:48
graphene::protocol::asset_create_operation
Definition: asset_ops.hpp:192