BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
fee_schedule.hpp
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 #pragma once
26 
27 namespace graphene { namespace protocol {
28 
29  template<typename T> struct transform_to_fee_parameters;
30  template<typename ...T>
32  {
33  using type = fc::static_variant< typename T::fee_params_t... >;
34  };
36 
37  template<typename Operation>
38  class fee_helper {
39  public:
40  const typename Operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
41  {
42  auto itr = parameters.find( typename Operation::fee_params_t() );
43  FC_ASSERT( itr != parameters.end() );
44  return itr->template get<typename Operation::fee_params_t>();
45  }
46  };
47 
48  template<>
50  public:
51  const account_create_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
52  {
53  auto itr = parameters.find( account_create_operation::fee_params_t() );
54  FC_ASSERT( itr != parameters.end() );
55  return itr->get<account_create_operation::fee_params_t>();
56  }
57  typename account_create_operation::fee_params_t& get(fee_parameters::flat_set_type& parameters)const
58  {
59  auto itr = parameters.find( account_create_operation::fee_params_t() );
60  FC_ASSERT( itr != parameters.end() );
61  return itr->get<account_create_operation::fee_params_t>();
62  }
63  };
64 
65  template<>
67  public:
68  const bid_collateral_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
69  {
70  auto itr = parameters.find( bid_collateral_operation::fee_params_t() );
71  if ( itr != parameters.end() )
72  return itr->get<bid_collateral_operation::fee_params_t>();
73 
74  static bid_collateral_operation::fee_params_t bid_collateral_dummy;
75  bid_collateral_dummy.fee = fee_helper<call_order_update_operation>().cget(parameters).fee;
76  return bid_collateral_dummy;
77  }
78  };
79 
80  template<>
82  public:
83  const asset_update_issuer_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
84  {
85  auto itr = parameters.find( asset_update_issuer_operation::fee_params_t() );
86  if ( itr != parameters.end() )
88 
90  dummy.fee = fee_helper<asset_update_operation>().cget(parameters).fee;
91  return dummy;
92  }
93  };
94 
95  template<>
97  public:
98  const asset_claim_pool_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
99  {
100  auto itr = parameters.find( asset_claim_pool_operation::fee_params_t() );
101  if ( itr != parameters.end() )
102  return itr->get<asset_claim_pool_operation::fee_params_t>();
103 
104  static asset_claim_pool_operation::fee_params_t asset_claim_pool_dummy;
105  asset_claim_pool_dummy.fee = fee_helper<asset_fund_fee_pool_operation>().cget(parameters).fee;
106  return asset_claim_pool_dummy;
107  }
108  };
109 
110  template<>
112  public:
113  const ticket_create_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
114  {
116  return param;
117  }
118  };
119 
120  template<>
122  public:
123  const ticket_update_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
124  {
126  return param;
127  }
128  };
129 
130  template<>
132  public:
133  const htlc_create_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
134  {
135  auto itr = parameters.find( htlc_create_operation::fee_params_t() );
136  if ( itr != parameters.end() )
137  return itr->get<htlc_create_operation::fee_params_t>();
138 
139  static htlc_create_operation::fee_params_t htlc_create_operation_fee_dummy;
140  return htlc_create_operation_fee_dummy;
141  }
142  };
143 
144  template<>
146  public:
147  const htlc_redeem_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
148  {
149  auto itr = parameters.find( htlc_redeem_operation::fee_params_t() );
150  if ( itr != parameters.end() )
151  return itr->get<htlc_redeem_operation::fee_params_t>();
152 
153  static htlc_redeem_operation::fee_params_t htlc_redeem_operation_fee_dummy;
154  return htlc_redeem_operation_fee_dummy;
155  }
156  };
157  template<>
159  public:
160  const htlc_extend_operation::fee_params_t& cget(const fee_parameters::flat_set_type& parameters)const
161  {
162  auto itr = parameters.find( htlc_extend_operation::fee_params_t() );
163  if ( itr != parameters.end() )
164  return itr->get<htlc_extend_operation::fee_params_t>();
165 
166  static htlc_extend_operation::fee_params_t htlc_extend_operation_fee_dummy;
167  return htlc_extend_operation_fee_dummy;
168  }
169  };
174  {
175  static const fee_schedule& get_default();
176 
181  asset calculate_fee( const operation& op )const;
187  asset calculate_fee( const operation& op, const price& core_exchange_rate )const;
191  asset set_fee( operation& op, const price& core_exchange_rate = price::unit_price() )const;
192 
193  void zero_all_fees();
194 
198  void validate()const {}
199 
200  template<typename Operation>
201  const typename Operation::fee_params_t& get()const
202  {
204  }
205  template<typename Operation>
206  typename Operation::fee_params_t& get()
207  {
208  return fee_helper<Operation>().get(parameters);
209  }
210  template<typename Operation>
211  bool exists()const
212  {
213  auto itr = parameters.find(typename Operation::fee_params_t());
214  return itr != parameters.end();
215  }
216 
220  fee_parameters::flat_set_type parameters;
222  private:
223  static fee_schedule get_default_impl();
224  };
225 
227 
228 } } // graphene::protocol
229 
231 FC_REFLECT( graphene::protocol::fee_schedule, (parameters)(scale) )
232 
graphene::protocol::htlc_redeem_operation::fee_params_t
Definition: htlc.hpp:92
graphene::protocol::fee_helper< asset_update_issuer_operation >::cget
const asset_update_issuer_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:83
graphene::protocol::ticket_create_operation
Creates a new ticket.
Definition: ticket.hpp:47
graphene::protocol::bid_collateral_operation
Definition: market.hpp:241
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
fc::static_variant
Definition: raw_fwd.hpp:27
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::protocol::htlc_redeem_operation
Definition: htlc.hpp:90
graphene::protocol::fee_helper< asset_claim_pool_operation >::cget
const asset_claim_pool_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:98
fc
Definition: api.hpp:15
graphene::protocol::fee_schedule::validate
void validate() const
Definition: fee_schedule.hpp:198
graphene::protocol::asset_update_issuer_operation
Update issuer of an asset.
Definition: asset_ops.hpp:565
graphene::protocol::fee_schedule::exists
bool exists() const
Definition: fee_schedule.hpp:211
graphene::protocol::htlc_extend_operation::fee_params_t
Definition: htlc.hpp:155
graphene::protocol::asset_update_issuer_operation::fee_params_t
Definition: asset_ops.hpp:567
graphene::protocol::bid_collateral_operation::fee_params_t
Definition: market.hpp:244
graphene::protocol::htlc_create_operation
Definition: htlc.hpp:45
graphene::protocol::asset_claim_pool_operation::fee_params_t
Definition: asset_ops.hpp:603
graphene::protocol::price::unit_price
static price unit_price(asset_id_type a=asset_id_type())
The unit price for an asset type A is defined to be a price such that for any asset m,...
Definition: asset.hpp:122
graphene::protocol::ticket_create_operation::fee_params_t
Definition: ticket.hpp:49
operations.hpp
graphene::protocol::fee_schedule::get
Operation::fee_params_t & get()
Definition: fee_schedule.hpp:206
graphene::protocol::fee_schedule::set_fee
asset set_fee(operation &op, const price &core_exchange_rate=price::unit_price()) const
Definition: fee_schedule_set_fee.cpp:43
graphene::protocol::account_create_operation
Definition: account.hpp:81
graphene::protocol::ticket_update_operation
Updates an existing ticket.
Definition: ticket.hpp:66
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::fee_helper::cget
const Operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:40
graphene::protocol::fee_schedule::scale
uint32_t scale
fee * scale / GRAPHENE_100_PERCENT
Definition: fee_schedule.hpp:221
graphene::protocol::fee_helper< ticket_update_operation >::cget
const ticket_update_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:123
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::protocol::ticket_update_operation::fee_params_t
Definition: ticket.hpp:68
graphene::protocol::transform_to_fee_parameters
Definition: fee_schedule.hpp:29
graphene::protocol::asset_update_issuer_operation::fee_params_t::fee
uint64_t fee
Definition: asset_ops.hpp:568
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::bid_collateral_operation::fee_params_t::fee
uint64_t fee
Definition: market.hpp:244
graphene::protocol::fee_helper< htlc_create_operation >::cget
const htlc_create_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:133
graphene::protocol::htlc_create_operation::fee_params_t
Definition: htlc.hpp:47
graphene::protocol::fee_schedule::zero_all_fees
void zero_all_fees()
Definition: fee_schedule.cpp:59
graphene::protocol::fee_helper< account_create_operation >::get
account_create_operation::fee_params_t & get(fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:57
graphene::protocol::fee_parameters
transform_to_fee_parameters< operation >::type fee_parameters
Definition: fee_schedule.hpp:35
graphene::protocol::account_create_operation::fee_params_t
Definition: account.hpp:91
graphene::protocol::fee_helper< htlc_extend_operation >::cget
const htlc_extend_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:160
graphene::protocol::fee_helper< htlc_redeem_operation >::cget
const htlc_redeem_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:147
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
graphene::protocol::htlc_extend_operation
Definition: htlc.hpp:153
graphene::protocol::fee_helper< ticket_create_operation >::cget
const ticket_create_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:113
graphene::protocol::asset_claim_pool_operation::fee_params_t::fee
uint64_t fee
Definition: asset_ops.hpp:604
graphene::protocol::fee_helper< bid_collateral_operation >::cget
const bid_collateral_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:68
graphene::protocol::fee_schedule::calculate_fee
asset calculate_fee(const operation &op) const
Definition: fee_schedule_calc.cpp:79
graphene::protocol::fee_helper
Definition: fee_schedule.hpp:38
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::fee_helper< account_create_operation >::cget
const account_create_operation::fee_params_t & cget(const fee_parameters::flat_set_type &parameters) const
Definition: fee_schedule.hpp:51
graphene::protocol::fee_schedule::get_default
static const fee_schedule & get_default()
Definition: fee_schedule.cpp:42
GRAPHENE_100_PERCENT
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
graphene
Definition: api.cpp:48
graphene::protocol::asset_claim_pool_operation
Transfers BTS from the fee pool of a specified asset back to the issuer's balance.
Definition: asset_ops.hpp:601