BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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_parameters_type... >;
34  };
36 
37  template<typename Operation>
38  class fee_helper {
39  public:
40  const typename Operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
41  {
42  auto itr = parameters.find( typename Operation::fee_parameters_type() );
43  FC_ASSERT( itr != parameters.end() );
44  return itr->template get<typename Operation::fee_parameters_type>();
45  }
46  };
47 
48  template<>
50  public:
51  const account_create_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
52  {
53  auto itr = parameters.find( account_create_operation::fee_parameters_type() );
54  FC_ASSERT( itr != parameters.end() );
56  }
57  typename account_create_operation::fee_parameters_type& get(fee_parameters::flat_set_type& parameters)const
58  {
59  auto itr = parameters.find( account_create_operation::fee_parameters_type() );
60  FC_ASSERT( itr != parameters.end() );
62  }
63  };
64 
65  template<>
67  public:
68  const bid_collateral_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
69  {
70  auto itr = parameters.find( bid_collateral_operation::fee_parameters_type() );
71  if ( itr != parameters.end() )
73 
74  static bid_collateral_operation::fee_parameters_type 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_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
84  {
85  auto itr = parameters.find( asset_update_issuer_operation::fee_parameters_type() );
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_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
99  {
100  auto itr = parameters.find( asset_claim_pool_operation::fee_parameters_type() );
101  if ( itr != parameters.end() )
103 
104  static asset_claim_pool_operation::fee_parameters_type 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_parameters_type& 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_parameters_type& 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_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
134  {
135  auto itr = parameters.find( htlc_create_operation::fee_parameters_type() );
136  if ( itr != parameters.end() )
138 
139  static htlc_create_operation::fee_parameters_type 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_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
148  {
149  auto itr = parameters.find( htlc_redeem_operation::fee_parameters_type() );
150  if ( itr != parameters.end() )
152 
153  static htlc_redeem_operation::fee_parameters_type htlc_redeem_operation_fee_dummy;
154  return htlc_redeem_operation_fee_dummy;
155  }
156  };
157  template<>
159  public:
160  const htlc_extend_operation::fee_parameters_type& cget(const fee_parameters::flat_set_type& parameters)const
161  {
162  auto itr = parameters.find( htlc_extend_operation::fee_parameters_type() );
163  if ( itr != parameters.end() )
165 
166  static htlc_extend_operation::fee_parameters_type htlc_extend_operation_fee_dummy;
167  return htlc_extend_operation_fee_dummy;
168  }
169  };
174  {
175  fee_schedule();
176 
177  static fee_schedule get_default();
178 
183  asset calculate_fee( const operation& op )const;
189  asset calculate_fee( const operation& op, const price& core_exchange_rate )const;
193  asset set_fee( operation& op, const price& core_exchange_rate = price::unit_price() )const;
194 
195  void zero_all_fees();
196 
200  void validate()const {}
201 
202  template<typename Operation>
203  const typename Operation::fee_parameters_type& get()const
204  {
205  return fee_helper<Operation>().cget(parameters);
206  }
207  template<typename Operation>
208  typename Operation::fee_parameters_type& get()
209  {
210  return fee_helper<Operation>().get(parameters);
211  }
212  template<typename Operation>
213  bool exists()const
214  {
215  auto itr = parameters.find(typename Operation::fee_parameters_type());
216  return itr != parameters.end();
217  }
218 
222  fee_parameters::flat_set_type parameters;
223  uint32_t scale = GRAPHENE_100_PERCENT;
224  private:
225  static void set_fee_parameters(fee_schedule& sched);
226  };
227 
229 
230 } } // graphene::protocol
231 
233 FC_REFLECT( graphene::protocol::fee_schedule, (parameters)(scale) )
234 
235 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::fee_schedule )
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
contains all of the parameters necessary to calculate the fee for any operation
Definition: api.cpp:56
const htlc_extend_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
transform_to_fee_parameters< operation >::type fee_parameters
const bid_collateral_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
Updates an existing ticket.
Definition: ticket.hpp:66
FC_REFLECT_TYPENAME(fc::log_message)
const asset_claim_pool_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
const Operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
const account_create_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:114
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
const htlc_create_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
const ticket_create_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
const htlc_redeem_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
Transfers BTS from the fee pool of a specified asset back to the issuer&#39;s balance.
Definition: asset_ops.hpp:554
const asset_update_issuer_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
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:128
Definition: api.hpp:15
Update issuer of an assetAn issuer has general administrative power of an asset and in some cases als...
Definition: asset_ops.hpp:518
fee_schedule fee_schedule_type
const ticket_update_operation::fee_parameters_type & cget(const fee_parameters::flat_set_type &parameters) const
fee_parameters::flat_set_type parameters