BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
evaluator.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  */
27 #include <graphene/chain/hardfork.hpp>
30 
37 
38 namespace graphene { namespace chain {
40 
42  { try {
43  trx_state = &eval_state;
44  //check_required_authorities(op);
45  auto result = evaluate( op );
46 
47  if( apply ) result = this->apply( op );
48  return result;
50 
51  void generic_evaluator::prepare_fee(account_id_type account_id, asset fee)
52  {
53  const database& d = db();
54  fee_from_account = fee;
55  FC_ASSERT( fee.amount >= 0 );
56  fee_paying_account = &account_id(d);
58 
59  fee_asset = &fee.asset_id(d);
61 
63  "Account ${acct} '${name}' attempted to pay fee by using asset ${a} '${sym}', "
64  "which is unauthorized due to whitelist / blacklist",
65  ( "acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id)
66  ("sym", fee_asset->symbol) );
67 
68  if( fee_from_account.asset_id == asset_id_type() )
70  else
71  {
73  FC_ASSERT( fee_from_pool.asset_id == asset_id_type() );
74  core_fee_paid = fee_from_pool.amount;
75  FC_ASSERT( core_fee_paid <= fee_asset_dyn_data->fee_pool, "Fee pool balance of '${b}' is less than the ${r} required to convert ${c}",
76  ("r", db().to_pretty_string( fee_from_pool))("b",db().to_pretty_string(fee_asset_dyn_data->fee_pool))("c",db().to_pretty_string(fee)) );
77  }
78  }
79 
81  {
82  if( !trx_state->skip_fee ) {
83  if( fee_asset->get_id() != asset_id_type() )
84  {
88  });
89  }
90  }
91  }
92 
94  { try {
95  if( !trx_state->skip_fee ) {
96  database& d = db();
99  {
101  });
102  }
104 
105  void generic_evaluator::pay_fba_fee( uint64_t fba_id )
106  {
107  database& d = db();
108  const fba_accumulator_object& fba = d.get( fba_accumulator_id_type( fba_id ) );
109  if( !fba.is_configured(d) )
110  {
112  return;
113  }
114  d.modify( fba, [&]( fba_accumulator_object& _fba )
115  {
117  } );
118  }
119 
121  {
122  return db().current_fee_schedule().calculate_fee( op ).amount;
123  }
124  void generic_evaluator::db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account)
125  {
126  db().adjust_balance(fee_payer, fee_from_account);
127  }
128 
129 } }
const asset_object * fee_asset
Definition: evaluator.hpp:118
void modify(const T &obj, const Lambda &m)
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account&#39;s balance in a given asset by a delta.
Definition: db_balance.cpp:54
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
bool is_authorized_asset(const database &d, const account_object &acct, const asset_object &asset_obj)
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:48
asset calculate_fee(const operation &op) const
const account_object * fee_paying_account
Definition: evaluator.hpp:116
bool is_configured(const database &db) const
Definition: fba_object.cpp:31
virtual operation_result evaluate(const operation &op)=0
const fee_schedule & current_fee_schedule() const
Definition: db_getter.cpp:62
std::string to_pretty_string(int64_t)
Definition: string.cpp:26
object_id< SpaceID, TypeID > get_id() const
Definition: object.hpp:113
const T & get(const object_id_type &id) const
object_id_type id
Definition: object.hpp:69
asset_dynamic_data_id_type dynamic_asset_data_id
Current supply, fee pool, and collected fees are stored in a separate object as they change frequentl...
string symbol
Ticker symbol for this asset, i.e. "USD".
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
string name
The account&#39;s name. This name must be unique among all account names on the graph. May not be empty.
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 cashback_vesting_threshold
the maximum cashback that can be received without vesting
share_type calculate_fee_for_operation(const operation &op) const
Definition: evaluator.cpp:120
void pay_fee(share_type core_fee, share_type cashback_vesting_threshold)
const account_statistics_object * fee_paying_account_statistics
Definition: evaluator.hpp:117
share_type accumulated_fees
fees accumulate to be paid out over time
virtual operation_result start_evaluate(transaction_evaluation_state &eval_state, const operation &op, bool apply)
Definition: evaluator.cpp:41
asset_id_type asset_id
Definition: asset.hpp:37
virtual operation_result apply(const operation &op)=0
account_statistics_id_type statistics
const asset_dynamic_data_object * fee_asset_dyn_data
Definition: evaluator.hpp:119
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
transaction_evaluation_state * trx_state
Definition: evaluator.hpp:120