Skip to content

Commit

Permalink
Merge remote-tracking branch 'graphene/develop' into bitshares at com…
Browse files Browse the repository at this point in the history
…mit e3478d2
  • Loading branch information
theoreticalbts committed Feb 23, 2016
2 parents 2a5c6a3 + e3478d2 commit 52c0b31
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

add_custom_target( build_hardfork_hpp
COMMAND cat-parts hardfork.d "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" )
COMMAND cat-parts "${CMAKE_CURRENT_SOURCE_DIR}/hardfork.d" "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" )
set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" PROPERTIES GENERATED TRUE )

add_dependencies( build_hardfork_hpp cat-parts )
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/evaluator.hpp>

namespace graphene { namespace chain {

Expand Down
10 changes: 10 additions & 0 deletions libraries/chain/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ database& generic_evaluator::db()const { return trx_state->db(); }
_fba.accumulated_fba_fees += core_fee_paid;
} );
}

share_type generic_evaluator::calculate_fee_for_operation(const operation& op) const
{
return db().current_fee_schedule().calculate_fee( op ).amount;
}
void generic_evaluator::db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account)
{
db().adjust_balance(fee_payer, fee_from_account);
}

} }
4 changes: 3 additions & 1 deletion libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* THE SOFTWARE.
*/
#pragma once
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/node_property_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/fork_database.hpp>
#include <graphene/chain/block_database.hpp>
#include <graphene/chain/genesis_state.hpp>
#include <graphene/chain/evaluator.hpp>

#include <graphene/db/object_database.hpp>
#include <graphene/db/object.hpp>
Expand All @@ -45,6 +45,8 @@
namespace graphene { namespace chain {
using graphene::db::abstract_object;
using graphene::db::object;
class op_evaluator;
class transaction_evaluation_state;

struct budget_record;

Expand Down
13 changes: 10 additions & 3 deletions libraries/chain/include/graphene/chain/evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ namespace graphene { namespace chain {
*/
void pay_fba_fee( uint64_t fba_id );

// the next two functions are helpers that allow template functions declared in this
// header to call db() without including database.hpp, which would
// cause a circular dependency
share_type calculate_fee_for_operation(const operation& op) const;
void db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account);

asset fee_from_account;
share_type core_fee_paid;
const account_object* fee_paying_account = nullptr;
Expand Down Expand Up @@ -143,10 +149,11 @@ namespace graphene { namespace chain {
prepare_fee(op.fee_payer(), op.fee);
if( !trx_state->skip_fee_schedule_check )
{
GRAPHENE_ASSERT( core_fee_paid >= db().current_fee_schedule().calculate_fee( op ).amount,
share_type required_fee = calculate_fee_for_operation(op);
GRAPHENE_ASSERT( core_fee_paid >= required_fee,
insufficient_fee,
"Insufficient Fee Paid",
("core_fee_paid",core_fee_paid)("required",db().current_fee_schedule().calculate_fee( op ).amount) );
("core_fee_paid",core_fee_paid)("required", required_fee) );
}

return eval->do_evaluate(op);
Expand All @@ -162,7 +169,7 @@ namespace graphene { namespace chain {

auto result = eval->do_apply(op);

db().adjust_balance(op.fee_payer(), -fee_from_account);
db_adjust_balance(op.fee_payer(), -fee_from_account);

return result;
}
Expand Down
10 changes: 10 additions & 0 deletions libraries/chain/include/graphene/chain/protocol/ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct graphene_extension_unpack_visitor
template< typename Stream, typename T >
void operator>>( Stream& s, graphene::chain::extension<T>& value )
{
value = graphene::chain::extension<T>();
graphene_extension_unpack_visitor<Stream, T> vtor( s, value.value );
fc::reflector<T>::visit( vtor );
FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here
Expand Down Expand Up @@ -168,6 +169,15 @@ struct graphene_extension_from_variant_visitor
template< typename T >
void from_variant( const fc::variant& var, graphene::chain::extension<T>& value )
{
value = graphene::chain::extension<T>();
if( var.is_null() )
return;
if( var.is_array() )
{
FC_ASSERT( var.size() == 0 );
return;
}

graphene_extension_from_variant_visitor<T> vtor( var.get_object(), value.value );
fc::reflector<T>::visit( vtor );
FC_ASSERT( vtor.count_left == 0 ); // unrecognized extension throws here
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/protocol/fee_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <algorithm>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/smart_ref_impl.hpp>

Expand Down
1 change: 1 addition & 0 deletions programs/build_helpers/cat-parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ int main( int argc, char** argv, char** envp )
}

{
boost::filesystem::create_directories(opath.parent_path());
boost::filesystem::ofstream ofs(opath);
ofs.write( new_data.c_str(), new_data.length() );
}
Expand Down
1 change: 1 addition & 0 deletions tests/tests/fee_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <graphene/chain/fba_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/exceptions.hpp>

#include <boost/test/unit_test.hpp>

Expand Down

0 comments on commit 52c0b31

Please sign in to comment.