Implement hardfork logic for #415
This commit is contained in:
parent
d1f9216f85
commit
db045f453c
8 changed files with 30 additions and 25 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
@ -38,7 +39,7 @@ share_type cut_fee(share_type a, uint16_t p)
|
||||||
return r.to_uint64();
|
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 )
|
for( const auto id : blacklisting_accounts )
|
||||||
{
|
{
|
||||||
|
|
@ -46,8 +47,11 @@ bool account_object::is_authorized_asset(const asset_object& asset_obj) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( asset_obj.options.whitelist_authorities.size() == 0 )
|
if( d.head_block_time() > HARDFORK_415_TIME )
|
||||||
return true;
|
{
|
||||||
|
if( asset_obj.options.whitelist_authorities.size() == 0 )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for( const auto id : whitelisting_accounts )
|
for( const auto id : whitelisting_accounts )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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 )
|
void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
const asset_object& a = o.asset_to_issue.asset_id(d);
|
const asset_object& a = o.asset_to_issue.asset_id(d);
|
||||||
FC_ASSERT( o.issuer == a.issuer );
|
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 )
|
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);
|
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 )
|
void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
const asset_object& a = o.amount_to_reserve.asset_id(d);
|
const asset_object& a = o.amount_to_reserve.asset_id(d);
|
||||||
GRAPHENE_ASSERT(
|
GRAPHENE_ASSERT(
|
||||||
|
|
@ -172,7 +172,7 @@ void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation&
|
||||||
|
|
||||||
if( a.options.flags & white_list )
|
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);
|
asset_dyn_data = &a.dynamic_asset_data_id(d);
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @return true if this account is whitelisted and not blacklisted to transact in the provided asset; false
|
||||||
* otherwise.
|
* 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; }
|
account_id_type get_id()const { return id; }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,4 @@
|
||||||
|
|
||||||
#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
|
#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
|
||||||
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
|
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
|
||||||
|
#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_operation& op)
|
void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_operation& op)
|
||||||
{ try {
|
{ try {
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
FC_ASSERT( op.expiration >= d.head_block_time() );
|
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() )
|
if( _sell_asset->options.blacklist_markets.size() )
|
||||||
FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end() );
|
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( _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 ) );
|
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",
|
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) );
|
("balance",d.get_balance(*_seller,*_sell_asset))("amount_to_sell",op.amount_to_sell) );
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace graphene { namespace chain {
|
||||||
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
||||||
{ try {
|
{ try {
|
||||||
|
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
const account_object& from_account = op.from(d);
|
const account_object& from_account = op.from(d);
|
||||||
const account_object& to_account = op.to(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 )
|
if( asset_type.options.flags & white_list )
|
||||||
{
|
{
|
||||||
GRAPHENE_ASSERT(
|
GRAPHENE_ASSERT(
|
||||||
from_account.is_authorized_asset( asset_type ),
|
from_account.is_authorized_asset( asset_type, d ),
|
||||||
transfer_from_account_not_whitelisted,
|
transfer_from_account_not_whitelisted,
|
||||||
"'from' account ${from} is not whitelisted for asset ${asset}",
|
"'from' account ${from} is not whitelisted for asset ${asset}",
|
||||||
("from",op.from)
|
("from",op.from)
|
||||||
("asset",op.amount.asset_id)
|
("asset",op.amount.asset_id)
|
||||||
);
|
);
|
||||||
GRAPHENE_ASSERT(
|
GRAPHENE_ASSERT(
|
||||||
to_account.is_authorized_asset( asset_type ),
|
to_account.is_authorized_asset( asset_type, d ),
|
||||||
transfer_to_account_not_whitelisted,
|
transfer_to_account_not_whitelisted,
|
||||||
"'to' account ${to} is not whitelisted for asset ${asset}",
|
"'to' account ${to} is not whitelisted for asset ${asset}",
|
||||||
("to",op.to)
|
("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 )
|
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() )
|
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 )
|
void_result override_transfer_evaluator::do_evaluate( const override_transfer_operation& op )
|
||||||
{ try {
|
{ try {
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
const asset_object& asset_type = op.amount.asset_id(d);
|
const asset_object& asset_type = op.amount.asset_id(d);
|
||||||
GRAPHENE_ASSERT(
|
GRAPHENE_ASSERT(
|
||||||
|
|
@ -104,12 +104,12 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op
|
||||||
|
|
||||||
if( asset_type.options.flags & white_list )
|
if( asset_type.options.flags & white_list )
|
||||||
{
|
{
|
||||||
FC_ASSERT( to_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 ) );
|
FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fee_asset_type.options.flags & white_list )
|
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,
|
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) );
|
"", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) );
|
||||||
|
|
|
||||||
|
|
@ -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)
|
void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_permission_claim_evaluator::operation_type& op)
|
||||||
{ try {
|
{ try {
|
||||||
database& d = db();
|
const database& d = db();
|
||||||
|
|
||||||
const withdraw_permission_object& permit = op.withdraw_permission(d);
|
const withdraw_permission_object& permit = op.withdraw_permission(d);
|
||||||
FC_ASSERT(permit.expiration > d.head_block_time() );
|
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& from = op.withdraw_to_account(d);
|
||||||
const account_object& to = permit.authorized_account(d);
|
const account_object& to = permit.authorized_account(d);
|
||||||
FC_ASSERT( to.is_authorized_asset( _asset ) );
|
FC_ASSERT( to.is_authorized_asset( _asset, d ) );
|
||||||
FC_ASSERT( from.is_authorized_asset( _asset ) );
|
FC_ASSERT( from.is_authorized_asset( _asset, d ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return void_result();
|
return void_result();
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia )
|
||||||
trx.operations.back() = wop;
|
trx.operations.back() = wop;
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
|
|
||||||
BOOST_CHECK(nathan.is_authorized_asset(advanced));
|
BOOST_CHECK(nathan.is_authorized_asset(advanced, db));
|
||||||
trx.operations.back() = op;
|
trx.operations.back() = op;
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
|
|
||||||
|
|
@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
|
||||||
|
|
||||||
trx.operations.back() = op;
|
trx.operations.back() = op;
|
||||||
//Fail because nathan is blacklisted
|
//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);
|
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.
|
//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;
|
trx.operations.back() = op;
|
||||||
//Fail because nathan is not whitelisted
|
//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);
|
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
|
||||||
|
|
||||||
burn.payer = dan.id;
|
burn.payer = dan.id;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue