From db045f453cd303d32b42142144b1363f8fd62f80 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 13:10:09 -0400 Subject: [PATCH] Implement hardfork logic for #415 --- libraries/chain/account_object.cpp | 10 +++++++--- libraries/chain/asset_evaluator.cpp | 8 ++++---- .../include/graphene/chain/account_object.hpp | 2 +- .../chain/include/graphene/chain/hardfork.hpp | 1 + libraries/chain/market_evaluator.cpp | 6 +++--- libraries/chain/transfer_evaluator.cpp | 16 ++++++++-------- .../chain/withdraw_permission_evaluator.cpp | 6 +++--- tests/tests/uia_tests.cpp | 6 +++--- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 839a4537..ef52056c 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace graphene { namespace chain { @@ -38,7 +39,7 @@ share_type cut_fee(share_type a, uint16_t p) return r.to_uint64(); } -bool account_object::is_authorized_asset(const asset_object& asset_obj) const +bool account_object::is_authorized_asset(const asset_object& asset_obj, const database& d) const { for( const auto id : blacklisting_accounts ) { @@ -46,8 +47,11 @@ bool account_object::is_authorized_asset(const asset_object& asset_obj) const return false; } - if( asset_obj.options.whitelist_authorities.size() == 0 ) - return true; + if( d.head_block_time() > HARDFORK_415_TIME ) + { + if( asset_obj.options.whitelist_authorities.size() == 0 ) + return true; + } for( const auto id : whitelisting_accounts ) { diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 2fe586da..03e07e66 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -126,7 +126,7 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o ) { try { - database& d = db(); + const database& d = db(); const asset_object& a = o.asset_to_issue.asset_id(d); FC_ASSERT( o.issuer == a.issuer ); @@ -136,7 +136,7 @@ void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o ) if( a.options.flags & white_list ) { - FC_ASSERT( to_account->is_authorized_asset( a ) ); + FC_ASSERT( to_account->is_authorized_asset( a, d ) ); } asset_dyn_data = &a.dynamic_asset_data_id(d); @@ -158,7 +158,7 @@ void_result asset_issue_evaluator::do_apply( const asset_issue_operation& o ) void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& o ) { try { - database& d = db(); + const database& d = db(); const asset_object& a = o.amount_to_reserve.asset_id(d); GRAPHENE_ASSERT( @@ -172,7 +172,7 @@ void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& if( a.options.flags & white_list ) { - FC_ASSERT( from_account->is_authorized_asset( a ) ); + FC_ASSERT( from_account->is_authorized_asset( a, d ) ); } asset_dyn_data = &a.dynamic_asset_data_id(d); diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 7c6dac90..5067292d 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -229,7 +229,7 @@ namespace graphene { namespace chain { * @return true if this account is whitelisted and not blacklisted to transact in the provided asset; false * otherwise. */ - bool is_authorized_asset(const asset_object& asset_obj)const; + bool is_authorized_asset(const asset_object& asset_obj, const database& d)const; account_id_type get_id()const { return id; } }; diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index 01907932..503e5f0b 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -22,3 +22,4 @@ #define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) +#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index a0eeac97..19f7742f 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -29,7 +29,7 @@ namespace graphene { namespace chain { void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_operation& op) { try { - database& d = db(); + const database& d = db(); FC_ASSERT( op.expiration >= d.head_block_time() ); @@ -42,8 +42,8 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o if( _sell_asset->options.blacklist_markets.size() ) FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end() ); - if( _sell_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset ) ); - if( _receive_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset ) ); + if( _sell_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) ); + if( _receive_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) ); FC_ASSERT( d.get_balance( *_seller, *_sell_asset ) >= op.amount_to_sell, "insufficient balance", ("balance",d.get_balance(*_seller,*_sell_asset))("amount_to_sell",op.amount_to_sell) ); diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 91e6eeb4..521f2f55 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -26,7 +26,7 @@ namespace graphene { namespace chain { void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) { try { - database& d = db(); + const database& d = db(); const account_object& from_account = op.from(d); const account_object& to_account = op.to(d); @@ -38,14 +38,14 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) if( asset_type.options.flags & white_list ) { GRAPHENE_ASSERT( - from_account.is_authorized_asset( asset_type ), + from_account.is_authorized_asset( asset_type, d ), transfer_from_account_not_whitelisted, "'from' account ${from} is not whitelisted for asset ${asset}", ("from",op.from) ("asset",op.amount.asset_id) ); GRAPHENE_ASSERT( - to_account.is_authorized_asset( asset_type ), + to_account.is_authorized_asset( asset_type, d ), transfer_to_account_not_whitelisted, "'to' account ${to} is not whitelisted for asset ${asset}", ("to",op.to) @@ -54,7 +54,7 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) } if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); if( asset_type.is_transfer_restricted() ) { @@ -87,7 +87,7 @@ void_result transfer_evaluator::do_apply( const transfer_operation& o ) void_result override_transfer_evaluator::do_evaluate( const override_transfer_operation& op ) { try { - database& d = db(); + const database& d = db(); const asset_object& asset_type = op.amount.asset_id(d); GRAPHENE_ASSERT( @@ -104,12 +104,12 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op if( asset_type.options.flags & white_list ) { - FC_ASSERT( to_account.is_authorized_asset( asset_type ) ); - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( to_account.is_authorized_asset( asset_type, d ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); } if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); FC_ASSERT( d.get_balance( from_account, asset_type ).amount >= op.amount.amount, "", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) ); diff --git a/libraries/chain/withdraw_permission_evaluator.cpp b/libraries/chain/withdraw_permission_evaluator.cpp index 620a2af7..17e96c45 100644 --- a/libraries/chain/withdraw_permission_evaluator.cpp +++ b/libraries/chain/withdraw_permission_evaluator.cpp @@ -53,7 +53,7 @@ object_id_type withdraw_permission_create_evaluator::do_apply(const operation_ty void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_permission_claim_evaluator::operation_type& op) { try { - database& d = db(); + const database& d = db(); const withdraw_permission_object& permit = op.withdraw_permission(d); FC_ASSERT(permit.expiration > d.head_block_time() ); @@ -69,8 +69,8 @@ void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_perm { const account_object& from = op.withdraw_to_account(d); const account_object& to = permit.authorized_account(d); - FC_ASSERT( to.is_authorized_asset( _asset ) ); - FC_ASSERT( from.is_authorized_asset( _asset ) ); + FC_ASSERT( to.is_authorized_asset( _asset, d ) ); + FC_ASSERT( from.is_authorized_asset( _asset, d ) ); } return void_result(); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 2ef816c9..924a91fd 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) trx.operations.back() = wop; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK(nathan.is_authorized_asset(advanced)); + BOOST_CHECK(nathan.is_authorized_asset(advanced, db)); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) trx.operations.back() = op; //Fail because nathan is blacklisted - BOOST_CHECK(!nathan.is_authorized_asset(advanced)); + BOOST_CHECK(!nathan.is_authorized_asset(advanced, db)); GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); //Remove nathan from committee's whitelist, add him to dan's. This should not authorize him to hold ADVANCED. @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) trx.operations.back() = op; //Fail because nathan is not whitelisted - BOOST_CHECK(!nathan.is_authorized_asset(advanced)); + BOOST_CHECK(!nathan.is_authorized_asset(advanced, db)); GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); burn.payer = dan.id;