2015-06-08 15:50:35 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Any modified source or binaries are used only with the BitShares network.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
2015-06-08 15:50:35 +00:00
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2015-06-08 15:50:35 +00:00
|
|
|
*/
|
|
|
|
|
#include <graphene/chain/database.hpp>
|
|
|
|
|
#include <graphene/chain/evaluator.hpp>
|
2015-07-08 18:26:59 +00:00
|
|
|
#include <graphene/chain/exceptions.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <graphene/chain/transaction_evaluation_state.hpp>
|
2015-07-08 18:26:59 +00:00
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
#include <graphene/chain/asset_object.hpp>
|
|
|
|
|
#include <graphene/chain/account_object.hpp>
|
2015-07-13 20:06:02 +00:00
|
|
|
#include <graphene/chain/committee_member_object.hpp>
|
2015-07-08 20:39:23 +00:00
|
|
|
#include <graphene/chain/market_evaluator.hpp>
|
|
|
|
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
#include <fc/uint128.hpp>
|
|
|
|
|
|
|
|
|
|
namespace graphene { namespace chain {
|
2015-06-30 20:42:41 +00:00
|
|
|
database& generic_evaluator::db()const { return trx_state->db(); }
|
|
|
|
|
|
2015-06-08 15:50:35 +00:00
|
|
|
operation_result generic_evaluator::start_evaluate( transaction_evaluation_state& eval_state, const operation& op, bool apply )
|
2015-06-30 19:11:26 +00:00
|
|
|
{ try {
|
2015-06-08 15:50:35 +00:00
|
|
|
trx_state = &eval_state;
|
2015-07-16 22:13:11 +00:00
|
|
|
//check_required_authorities(op);
|
2015-06-08 15:50:35 +00:00
|
|
|
auto result = evaluate( op );
|
|
|
|
|
|
|
|
|
|
if( apply ) result = this->apply( op );
|
|
|
|
|
return result;
|
2015-06-30 19:11:26 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW() }
|
2015-06-08 15:50:35 +00:00
|
|
|
|
|
|
|
|
void generic_evaluator::prepare_fee(account_id_type account_id, asset fee)
|
|
|
|
|
{
|
|
|
|
|
fee_from_account = fee;
|
|
|
|
|
FC_ASSERT( fee.amount >= 0 );
|
|
|
|
|
fee_paying_account = &account_id(db());
|
|
|
|
|
fee_paying_account_statistics = &fee_paying_account->statistics(db());
|
|
|
|
|
|
|
|
|
|
fee_asset = &fee.asset_id(db());
|
|
|
|
|
fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(db());
|
|
|
|
|
|
|
|
|
|
if( fee_from_account.asset_id == asset_id_type() )
|
|
|
|
|
core_fee_paid = fee_from_account.amount;
|
|
|
|
|
else {
|
|
|
|
|
asset fee_from_pool = fee_from_account * fee_asset->options.core_exchange_rate;
|
|
|
|
|
FC_ASSERT( fee_from_pool.asset_id == asset_id_type() );
|
|
|
|
|
core_fee_paid = fee_from_pool.amount;
|
2015-07-09 20:05:57 +00:00
|
|
|
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}",
|
|
|
|
|
("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)) );
|
2015-06-08 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void generic_evaluator::pay_fee()
|
|
|
|
|
{ try {
|
|
|
|
|
if( fee_asset->get_id() != asset_id_type() )
|
2015-06-09 20:46:00 +00:00
|
|
|
db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) {
|
2015-06-08 15:50:35 +00:00
|
|
|
d.accumulated_fees += fee_from_account.amount;
|
|
|
|
|
d.fee_pool -= core_fee_paid;
|
|
|
|
|
});
|
2015-06-09 20:46:00 +00:00
|
|
|
db().modify(*fee_paying_account_statistics, [&](account_statistics_object& s) {
|
2015-06-11 17:54:42 +00:00
|
|
|
if( core_fee_paid > db().get_global_properties().parameters.cashback_vesting_threshold )
|
|
|
|
|
s.pending_fees += core_fee_paid;
|
|
|
|
|
else
|
|
|
|
|
s.pending_vested_fees += core_fee_paid;
|
2015-06-08 15:50:35 +00:00
|
|
|
});
|
|
|
|
|
} FC_CAPTURE_AND_RETHROW() }
|
|
|
|
|
|
|
|
|
|
} }
|