BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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( fee_asset->get_id() != asset_id_type() )
83  {
87  });
88  }
89  }
90 
92  { try {
93  database& d = db();
95  {
97  });
98  } FC_CAPTURE_AND_RETHROW() } // GCOVR_EXCL_LINE
99 
100  void generic_evaluator::pay_fba_fee( uint64_t fba_id )
101  {
102  database& d = db();
103  const fba_accumulator_object& fba = d.get( fba_accumulator_id_type( fba_id ) );
104  if( !fba.is_configured(d) )
105  {
107  return;
108  }
109  d.modify( fba, [&]( fba_accumulator_object& _fba )
110  {
112  } );
113  }
114 
116  {
117  return db().current_fee_schedule().calculate_fee( op ).amount;
118  }
119  void generic_evaluator::db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account)
120  {
121  db().adjust_balance(fee_payer, fee_from_account);
122  }
123 
124 } }
graphene::chain::asset_dynamic_data_object::fee_pool
share_type fee_pool
in core asset
Definition: asset_object.hpp:65
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
fc::typelist::apply
typename impl::apply< List, Delegate >::type apply
Apply a list of types as arguments to another template.
Definition: typelist.hpp:142
fc::to_pretty_string
std::string to_pretty_string(int64_t)
Definition: string.cpp:26
graphene::db::object::id
object_id_type id
Definition: object.hpp:69
is_authorized_asset.hpp
graphene::chain::transaction_evaluation_state::db
database & db() const
Definition: transaction_evaluation_state.hpp:44
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
asset_object.hpp
graphene::db::object_database::get
const T & get(const object_id_type &id) const
Definition: object_database.hpp:119
graphene::chain::generic_evaluator::fee_paying_account_statistics
const account_statistics_object * fee_paying_account_statistics
Definition: evaluator.hpp:117
database.hpp
fc::static_variant< void_result, object_id_type, asset, generic_operation_result, generic_exchange_operation_result, extendable_operation_result >
graphene::chain::generic_evaluator::fee_asset
const asset_object * fee_asset
Definition: evaluator.hpp:118
graphene::chain::global_property_object::parameters
chain_parameters parameters
Definition: global_property_object.hpp:44
graphene::chain::transaction_evaluation_state
Definition: transaction_evaluation_state.hpp:37
graphene::chain::generic_evaluator::apply
virtual operation_result apply(const operation &op)=0
graphene::protocol::asset_options::core_exchange_rate
price core_exchange_rate
Definition: asset_ops.hpp:72
fee_schedule.hpp
graphene::chain::database::adjust_balance
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account's balance in a given asset by a delta.
Definition: db_balance.cpp:54
graphene::chain::asset_object::symbol
string symbol
Ticker symbol for this asset, i.e. "USD".
Definition: asset_object.hpp:131
graphene::chain::asset_object::dynamic_asset_data_id
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...
Definition: asset_object.hpp:140
graphene::chain::generic_evaluator::pay_fee
virtual void pay_fee()
Definition: evaluator.cpp:91
graphene::chain::generic_evaluator::fee_from_account
asset fee_from_account
Definition: evaluator.hpp:114
graphene::chain::fba_accumulator_object::is_configured
bool is_configured(const database &db) const
Definition: fba_object.cpp:31
graphene::chain::asset_dynamic_data_object::accumulated_fees
share_type accumulated_fees
fees accumulate to be paid out over time
Definition: asset_object.hpp:63
graphene::chain::generic_evaluator::pay_fba_fee
void pay_fba_fee(uint64_t fba_id)
Definition: evaluator.cpp:100
graphene::chain::account_statistics_object
Definition: account_object.hpp:46
graphene::chain::generic_evaluator::convert_fee
virtual void convert_fee()
Definition: evaluator.cpp:80
graphene::chain::database::current_fee_schedule
const fee_schedule & current_fee_schedule() const
Definition: db_getter.cpp:62
graphene::chain::asset_dynamic_data_object
tracks the asset information that changes frequently
Definition: asset_object.hpp:56
evaluator.hpp
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
account_object.hpp
graphene::chain::generic_evaluator::db_adjust_balance
void db_adjust_balance(const account_id_type &fee_payer, asset fee_from_account)
Definition: evaluator.cpp:119
graphene::chain::fba_accumulator_object::accumulated_fba_fees
share_type accumulated_fba_fees
Definition: fba_object.hpp:41
graphene::chain::generic_evaluator::fee_asset_dyn_data
const asset_dynamic_data_object * fee_asset_dyn_data
Definition: evaluator.hpp:119
graphene::chain::is_authorized_asset
bool is_authorized_asset(const database &d, const account_object &acct, const asset_object &asset_obj)
Definition: is_authorized_asset.hpp:43
committee_member_object.hpp
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
graphene::protocol::chain_parameters::cashback_vesting_threshold
share_type cashback_vesting_threshold
the maximum cashback that can be received without vesting
Definition: chain_parameters.hpp:70
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::chain::account_object::name
string name
The account's name. This name must be unique among all account names on the graph....
Definition: account_object.hpp:209
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::chain::generic_evaluator::calculate_fee_for_operation
share_type calculate_fee_for_operation(const operation &op) const
Definition: evaluator.cpp:115
graphene::chain::generic_evaluator::evaluate
virtual operation_result evaluate(const operation &op)=0
transaction_evaluation_state.hpp
graphene::chain::account_object::statistics
account_statistics_id_type statistics
Definition: account_object.hpp:229
graphene::db::abstract_object::get_id
object_id< SpaceID, TypeID > get_id() const
Definition: object.hpp:113
graphene::chain::fba_accumulator_object
Definition: fba_object.hpp:37
graphene::chain::database::get_global_properties
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
graphene::protocol::fee_schedule::calculate_fee
asset calculate_fee(const operation &op) const
Definition: fee_schedule_calc.cpp:79
graphene::chain::generic_evaluator::prepare_fee
void prepare_fee(account_id_type account_id, asset fee)
Fetch objects relevant to fee payer and set pointer members.
Definition: evaluator.cpp:51
graphene::chain::generic_evaluator::fee_paying_account
const account_object * fee_paying_account
Definition: evaluator.hpp:116
graphene::protocol::asset
Definition: asset.hpp:31
graphene::chain::asset_object::options
asset_options options
Definition: asset_object.hpp:137
graphene::chain::generic_evaluator::start_evaluate
virtual operation_result start_evaluate(transaction_evaluation_state &eval_state, const operation &op, bool apply)
Definition: evaluator.cpp:41
graphene::chain::generic_evaluator::core_fee_paid
share_type core_fee_paid
Definition: evaluator.hpp:115
fba_object.hpp
graphene::chain::account_statistics_object::pay_fee
void pay_fee(share_type core_fee, share_type cashback_vesting_threshold)
Definition: account_object.cpp:100
graphene
Definition: api.cpp:48
exceptions.hpp
market_evaluator.hpp
graphene::db::object_database::modify
void modify(const T &obj, const Lambda &m)
Definition: object_database.hpp:99
graphene::chain::generic_evaluator::trx_state
transaction_evaluation_state * trx_state
Definition: evaluator.hpp:120
fc::safe
Definition: safe.hpp:26