BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
evaluator.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
28 
29 namespace graphene { namespace chain {
30 
31  class database;
32  class generic_evaluator;
33  class transaction_evaluation_state;
34  class account_object;
35  class account_statistics_object;
36  class asset_object;
37  class asset_dynamic_data_object;
38 
40  {
41  public:
42  virtual ~generic_evaluator(){}
43 
44  virtual int get_type()const = 0;
45  virtual operation_result start_evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply);
46 
52  virtual operation_result evaluate(const operation& op) = 0;
53  virtual operation_result apply(const operation& op) = 0;
54 
69  virtual void pay_fee();
70 
71  database& db()const;
72 
73  //void check_required_authorities(const operation& op);
74  protected:
85  void prepare_fee(account_id_type account_id, asset fee);
86 
99  virtual void convert_fee();
100 
102 
106  void pay_fba_fee( uint64_t fba_id );
107 
108  // the next two functions are helpers that allow template functions declared in this
109  // header to call db() without including database.hpp, which would
110  // cause a circular dependency
112  void db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account);
113 
118  const asset_object* fee_asset = nullptr;
121  };
122 
124  {
125  public:
126  virtual ~op_evaluator(){}
127  virtual operation_result evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply) = 0;
128  };
129 
130  template<typename T>
132  {
133  public:
134  virtual operation_result evaluate(transaction_evaluation_state& eval_state, const operation& op, bool apply = true) override
135  {
136  T eval;
137  return eval.start_evaluate(eval_state, op, apply);
138  }
139  };
140 
141  template<typename DerivedEvaluator>
143  {
144  public:
145  virtual int get_type()const override { return operation::tag<typename DerivedEvaluator::operation_type>::value; }
146 
147  virtual operation_result evaluate(const operation& o) final override
148  {
149  auto* eval = static_cast<DerivedEvaluator*>(this);
150  const auto& op = o.get<typename DerivedEvaluator::operation_type>();
151 
152  prepare_fee(op.fee_payer(), op.fee);
154  {
155  share_type required_fee = calculate_fee_for_operation(op);
156  GRAPHENE_ASSERT( core_fee_paid >= required_fee,
157  insufficient_fee,
158  "Insufficient Fee Paid",
159  ("core_fee_paid",core_fee_paid)("required", required_fee) );
160  }
161 
162  return eval->do_evaluate(op);
163  }
164 
165  virtual operation_result apply(const operation& o) final override
166  {
167  auto* eval = static_cast<DerivedEvaluator*>(this);
168  const auto& op = o.get<typename DerivedEvaluator::operation_type>();
169 
170  convert_fee();
171  pay_fee();
172 
173  auto result = eval->do_apply(op);
174 
175  db_adjust_balance(op.fee_payer(), -fee_from_account);
176 
177  return result;
178  }
179  };
180 } }
const asset_object * fee_asset
Definition: evaluator.hpp:118
void prepare_fee(account_id_type account_id, asset fee)
Fetch objects relevant to fee payer and set pointer members.
Definition: evaluator.cpp:51
void db_adjust_balance(const account_id_type &fee_payer, asset fee_from_account)
Definition: evaluator.cpp:124
This class represents an account on the object graphAccounts are the primary unit of authority on the...
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:48
const account_object * fee_paying_account
Definition: evaluator.hpp:116
object_id_type get_relative_id(object_id_type rel_id) const
virtual operation_result evaluate(const operation &op)=0
virtual int get_type() const =0
void pay_fba_fee(uint64_t fba_id)
Definition: evaluator.cpp:105
tracks the asset information that changes frequentlyBecause the asset_object is very large it doesn&#39;t...
share_type calculate_fee_for_operation(const operation &op) const
Definition: evaluator.cpp:120
virtual operation_result apply(const operation &o) final override
Definition: evaluator.hpp:165
const account_statistics_object * fee_paying_account_statistics
Definition: evaluator.hpp:117
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
virtual operation_result start_evaluate(transaction_evaluation_state &eval_state, const operation &op, bool apply)
Definition: evaluator.cpp:41
virtual operation_result apply(const operation &op)=0
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
virtual int get_type() const override
Definition: evaluator.hpp:145
virtual operation_result evaluate(const operation &o) final override
Definition: evaluator.hpp:147
const asset_dynamic_data_object * fee_asset_dyn_data
Definition: evaluator.hpp:119
virtual operation_result evaluate(transaction_evaluation_state &eval_state, const operation &op, bool apply=true) override
Definition: evaluator.hpp:134
transaction_evaluation_state * trx_state
Definition: evaluator.hpp:120