Make is_authorized_asset a free-floating method #566
The following sed commands were used to port existing call sites to the new interface:
sed -i -e 's/\([a-zA-Z0-9_]\+\)->is_authorized_asset[(] \([a-zA-Z0-9_*]\+\), d [)]/is_authorized_asset( d, *\1, \2 )/' libraries/chain/*.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[.]is_authorized_asset[(] \([a-zA-Z0-9_*]\+\), d [)]/is_authorized_asset( d, \1, \2 )/' libraries/chain/*.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[(]db[)][.]is_authorized_asset[(]\([a-zA-Z0-9_*]\+\)[(]db[)], db[)]/is_authorized_asset( db, \1(db), \2(db) )/' tests/tests/uia_tests.cpp
sed -i -e 's/\([a-zA-Z0-9_]\+\)[.]is_authorized_asset[(]\([a-zA-Z0-9_*]\+\), db[)]/is_authorized_asset( db, \1, \2 )/' tests/tests/uia_tests.cpp
No new functionality is added by this commit, it is simply re-organizing the existing code in a different place.
This commit is contained in:
parent
447018b319
commit
68a0ffa1aa
11 changed files with 137 additions and 58 deletions
|
|
@ -84,6 +84,8 @@ add_library( graphene_chain
|
|||
|
||||
block_database.cpp
|
||||
|
||||
is_authorized_asset.cpp
|
||||
|
||||
${HEADERS}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,35 +42,6 @@ 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 database& d) const
|
||||
{
|
||||
if( d.head_block_time() > HARDFORK_416_TIME )
|
||||
{
|
||||
if( !(asset_obj.options.flags & white_list) )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( const auto id : blacklisting_accounts )
|
||||
{
|
||||
if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( d.head_block_time() > HARDFORK_415_TIME )
|
||||
{
|
||||
if( asset_obj.options.whitelist_authorities.size() == 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( const auto id : whitelisting_accounts )
|
||||
{
|
||||
if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void account_balance_object::adjust_balance(const asset& delta)
|
||||
{
|
||||
assert(delta.asset_id == asset_type);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
|
@ -155,7 +156,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, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, *to_account, a ) );
|
||||
}
|
||||
|
||||
asset_dyn_data = &a.dynamic_asset_data_id(d);
|
||||
|
|
@ -191,7 +192,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, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, *from_account, a ) );
|
||||
}
|
||||
|
||||
asset_dyn_data = &a.dynamic_asset_data_id(d);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <graphene/chain/evaluator.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
#include <graphene/chain/transaction_evaluation_state.hpp>
|
||||
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
|
|
@ -61,7 +62,7 @@ database& generic_evaluator::db()const { return trx_state->db(); }
|
|||
|
||||
if( d.head_block_time() > HARDFORK_419_TIME )
|
||||
{
|
||||
FC_ASSERT( fee_paying_account->is_authorized_asset( *fee_asset, d ), "Account ${acct} '${name}' attempted to pay fee by using asset ${a} '${sym}', which is unauthorized due to whitelist / blacklist",
|
||||
FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *fee_asset ), "Account ${acct} '${name}' attempted to pay fee by using asset ${a} '${sym}', which is unauthorized due to whitelist / blacklist",
|
||||
("acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id)("sym", fee_asset->symbol) );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -233,12 +233,6 @@ namespace graphene { namespace chain {
|
|||
return !is_basic_account(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 database& d)const;
|
||||
|
||||
account_id_type get_id()const { return id; }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
class account_object;
|
||||
class asset_object;
|
||||
class database;
|
||||
|
||||
/**
|
||||
* @return true if the account is whitelisted and not blacklisted to transact in the provided asset; false
|
||||
* otherwise.
|
||||
*/
|
||||
|
||||
bool is_authorized_asset(const database& d, const account_object& acct, const asset_object& asset_obj);
|
||||
|
||||
} }
|
||||
65
libraries/chain/is_authorized_asset.cpp
Normal file
65
libraries/chain/is_authorized_asset.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
bool is_authorized_asset(
|
||||
const database& d,
|
||||
const account_object& acct,
|
||||
const asset_object& asset_obj)
|
||||
{
|
||||
if( d.head_block_time() > HARDFORK_416_TIME )
|
||||
{
|
||||
if( !(asset_obj.options.flags & white_list) )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( const auto id : acct.blacklisting_accounts )
|
||||
{
|
||||
if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( d.head_block_time() > HARDFORK_415_TIME )
|
||||
{
|
||||
if( asset_obj.options.whitelist_authorities.size() == 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( const auto id : acct.whitelisting_accounts )
|
||||
{
|
||||
if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
@ -23,11 +23,14 @@
|
|||
*/
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
#include <graphene/chain/market_object.hpp>
|
||||
|
||||
#include <graphene/chain/market_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/market_evaluator.hpp>
|
||||
#include <graphene/chain/market_object.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/market.hpp>
|
||||
|
||||
|
|
@ -51,13 +54,13 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o
|
|||
|
||||
if( d.head_block_time() <= HARDFORK_416_TIME )
|
||||
{
|
||||
if( _sell_asset->options.flags & white_list ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) );
|
||||
if( _receive_asset->options.flags & white_list ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) );
|
||||
if( _sell_asset->options.flags & white_list ) FC_ASSERT( is_authorized_asset( d, *_seller, *_sell_asset ) );
|
||||
if( _receive_asset->options.flags & white_list ) FC_ASSERT( is_authorized_asset( d, *_seller, *_receive_asset ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) );
|
||||
FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, *_seller, *_sell_asset ) );
|
||||
FC_ASSERT( is_authorized_asset( d, *_seller, *_receive_asset ) );
|
||||
}
|
||||
|
||||
FC_ASSERT( d.get_balance( *_seller, *_sell_asset ) >= op.amount_to_sell, "insufficient balance",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
||||
|
|
@ -42,14 +43,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, d ),
|
||||
is_authorized_asset( d, from_account, asset_type ),
|
||||
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, d ),
|
||||
is_authorized_asset( d, to_account, asset_type ),
|
||||
transfer_to_account_not_whitelisted,
|
||||
"'to' account ${to} is not whitelisted for asset ${asset}",
|
||||
("to",op.to)
|
||||
|
|
@ -60,7 +61,7 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
|
|||
if( d.head_block_time() <= HARDFORK_419_TIME )
|
||||
{
|
||||
if( fee_asset_type.options.flags & white_list )
|
||||
FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, from_account, asset_type ) );
|
||||
}
|
||||
// the above becomes no-op after hardfork because this check will then be performed in evaluator
|
||||
|
||||
|
|
@ -112,14 +113,14 @@ 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, d ) );
|
||||
FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, to_account, asset_type ) );
|
||||
FC_ASSERT( is_authorized_asset( d, from_account, asset_type ) );
|
||||
}
|
||||
|
||||
if( d.head_block_time() <= HARDFORK_419_TIME )
|
||||
{
|
||||
if( fee_asset_type.options.flags & white_list )
|
||||
FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, from_account, asset_type ) );
|
||||
}
|
||||
// the above becomes no-op after hardfork because this check will then be performed in evaluator
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
|
|
@ -75,16 +76,16 @@ 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, d ) );
|
||||
FC_ASSERT( from.is_authorized_asset( _asset, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, to, _asset ) );
|
||||
FC_ASSERT( is_authorized_asset( d, from, _asset ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const account_object& from = op.withdraw_to_account(d);
|
||||
const account_object& to = permit.authorized_account(d);
|
||||
FC_ASSERT( to.is_authorized_asset( _asset, d ) );
|
||||
FC_ASSERT( from.is_authorized_asset( _asset, d ) );
|
||||
FC_ASSERT( is_authorized_asset( d, to, _asset ) );
|
||||
FC_ASSERT( is_authorized_asset( d, from, _asset ) );
|
||||
}
|
||||
|
||||
return void_result();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/is_authorized_asset.hpp>
|
||||
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
|
|
@ -161,7 +162,7 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia )
|
|||
}
|
||||
PUSH_TX( db, trx, ~0 );
|
||||
|
||||
BOOST_CHECK(nathan_id(db).is_authorized_asset(uia_id(db), db));
|
||||
BOOST_CHECK(is_authorized_asset( db, nathan_id(db), uia_id(db) ));
|
||||
BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 1000);
|
||||
|
||||
// Make a whitelist, now it should fail
|
||||
|
|
@ -265,7 +266,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
|
|||
wop.account_to_list = nathan.id;
|
||||
trx.operations.back() = wop;
|
||||
PUSH_TX( db, trx, ~0 );
|
||||
BOOST_CHECK( !(nathan.is_authorized_asset(advanced, db)) );
|
||||
BOOST_CHECK( !(is_authorized_asset( db, nathan, advanced )) );
|
||||
|
||||
BOOST_TEST_MESSAGE( "Attempting to transfer from nathan after blacklisting, should fail" );
|
||||
op.amount = advanced.amount(50);
|
||||
|
|
@ -323,7 +324,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
|
|||
|
||||
trx.operations.back() = op;
|
||||
//Fail because nathan is blacklisted
|
||||
BOOST_CHECK(!nathan.is_authorized_asset(advanced, db));
|
||||
BOOST_CHECK(!is_authorized_asset( db, nathan, advanced ));
|
||||
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.
|
||||
|
|
@ -340,7 +341,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, db));
|
||||
BOOST_CHECK(!is_authorized_asset( db, nathan, advanced ));
|
||||
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
|
||||
|
||||
burn.payer = dan.id;
|
||||
|
|
|
|||
Loading…
Reference in a new issue