Skip to content

Commit

Permalink
Merge branch 'master' into muse
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Nov 2, 2015
2 parents d99bba6 + 0985516 commit 43a7243
Show file tree
Hide file tree
Showing 34 changed files with 655 additions and 114 deletions.
1 change: 1 addition & 0 deletions libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct get_impacted_account_visitor
_impacted.insert( op.to );
}

void operator()( const asset_claim_fees_operation& op ){}
void operator()( const limit_order_create_operation& op ) {}
void operator()( const limit_order_cancel_operation& op )
{
Expand Down
36 changes: 32 additions & 4 deletions libraries/chain/account_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/hardfork.hpp>
#include <fc/uint128.hpp>

namespace graphene { namespace chain {
Expand All @@ -38,12 +39,32 @@ 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
{
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( 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;
{
if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() )
return true;
}

return false;
}

Expand All @@ -53,7 +74,6 @@ void account_balance_object::adjust_balance(const asset& delta)
balance += delta.amount;
}


void account_statistics_object::process_fees(const account_object& a, database& d) const
{
if( pending_fees > 0 || pending_vested_fees > 0 )
Expand Down Expand Up @@ -128,20 +148,28 @@ set<account_id_type> account_member_index::get_account_members(const account_obj
set<account_id_type> result;
for( auto auth : a.owner.account_auths )
result.insert(auth.first);
for( auto auth : a.active.account_auths )
result.insert(auth.first);
return result;
}
set<public_key_type> account_member_index::get_key_members(const account_object& a)const
{
set<public_key_type> result;
for( auto auth : a.owner.key_auths )
result.insert(auth.first);
for( auto auth : a.active.key_auths )
result.insert(auth.first);
result.insert( a.options.memo_key );
return result;
}
set<address> account_member_index::get_address_members(const account_object& a)const
{
set<address> result;
for( auto auth : a.owner.address_auths )
result.insert(auth.first);
for( auto auth : a.active.address_auths )
result.insert(auth.first);
result.insert( a.options.memo_key );
return result;
}

Expand Down
72 changes: 58 additions & 14 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,36 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
for( auto id : op.common_options.blacklist_authorities )
d.get_object(id);

auto& asset_indx = db().get_index_type<asset_index>().indices().get<by_symbol>();
auto& asset_indx = d.get_index_type<asset_index>().indices().get<by_symbol>();
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr == asset_indx.end() );

auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos ) {
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
if( d.head_block_time() <= HARDFORK_409_TIME )
{
auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos )
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
}
}
else
{
auto dotpos = op.symbol.rfind( '.' );
if( dotpos != std::string::npos )
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( prefix );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
}
}


core_fee_paid -= core_fee_paid.value/2;

Expand Down Expand Up @@ -126,7 +142,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 );
Expand All @@ -136,7 +152,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);
Expand All @@ -158,7 +174,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(
Expand All @@ -172,7 +188,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);
Expand Down Expand Up @@ -514,4 +530,32 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope
return void_result();
} FC_CAPTURE_AND_RETHROW((o)) }



void_result asset_claim_fees_evaluator::do_evaluate( const asset_claim_fees_operation& o )
{ try {
FC_ASSERT( db().head_block_time() > HARDFORK_413_TIME );
FC_ASSERT( o.amount_to_claim.asset_id(db()).issuer == o.issuer, "Asset fees may only be claimed by the issuer" );
return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }


void_result asset_claim_fees_evaluator::do_apply( const asset_claim_fees_operation& o )
{ try {
database& d = db();

const asset_object& a = o.amount_to_claim.asset_id(d);
const asset_dynamic_data_object& addo = a.dynamic_asset_data_id(d);
FC_ASSERT( o.amount_to_claim.amount <= addo.accumulated_fees, "Attempt to claim more fees than have accumulated", ("addo",addo) );

d.modify( addo, [&]( asset_dynamic_data_object& _addo ) {
_addo.accumulated_fees -= o.amount_to_claim.amount;
});

d.adjust_balance( o.issuer, o.amount_to_claim );

return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }


} } // graphene::chain
2 changes: 1 addition & 1 deletion libraries/chain/confidential_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void_result transfer_to_blind_evaluator::do_evaluate( const transfer_to_blind_op
const auto& atype = o.amount.asset_id(db());
FC_ASSERT( atype.allow_confidential() );
FC_ASSERT( !atype.is_transfer_restricted() );
FC_ASSERT( !atype.enforce_white_list() );
FC_ASSERT( !(atype.options.flags & white_list) );

for( const auto& out : o.outputs )
{
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void database::initialize_evaluators()
register_evaluator<transfer_to_blind_evaluator>();
register_evaluator<transfer_from_blind_evaluator>();
register_evaluator<blind_transfer_evaluator>();
register_evaluator<asset_claim_fees_evaluator>();
}

void database::initialize_indexes()
Expand Down
4 changes: 3 additions & 1 deletion libraries/chain/db_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ void database::close(bool rewind)
{
try
{
while( true )
uint32_t cutoff = get_dynamic_global_properties().last_irreversible_block_num;

while( head_block_num() > cutoff )
{
// elog("pop");
block_id_type popped_block_id = head_block_id();
Expand Down
10 changes: 6 additions & 4 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,13 @@ void database::clear_expired_orders()

void database::update_expired_feeds()
{
auto& asset_idx = get_index_type<asset_index>().indices();
for( const asset_object& a : asset_idx )
auto& asset_idx = get_index_type<asset_index>().indices().get<by_type>();
auto itr = asset_idx.lower_bound( true /** market issued */ );
while( itr != asset_idx.end() )
{
if( !a.is_market_issued() )
continue;
const asset_object& a = *itr;
++itr;
assert( a.is_market_issued() );

const asset_bitasset_data_object& b = a.bitasset_data(*this);
if( b.feed_is_expired(head_block_time()) )
Expand Down
19 changes: 14 additions & 5 deletions libraries/chain/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>

#include <graphene/chain/asset_object.hpp>
Expand All @@ -46,17 +47,25 @@ database& generic_evaluator::db()const { return trx_state->db(); }

void generic_evaluator::prepare_fee(account_id_type account_id, asset fee)
{
const database& d = db();
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_paying_account = &account_id(d);
fee_paying_account_statistics = &fee_paying_account->statistics(d);

fee_asset = &fee.asset_id(db());
fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(db());
fee_asset = &fee.asset_id(d);
fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d);

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",
("acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id)("sym", fee_asset->symbol) );
}

if( fee_from_account.asset_id == asset_id_type() )
core_fee_paid = fee_from_account.amount;
else {
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;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/graphene/chain/asset_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,13 @@ namespace graphene { namespace chain {
std::map<std::pair<asset_id_type,asset_id_type>,price_feed> median_feed_values;
};

class asset_claim_fees_evaluator : public evaluator<asset_claim_fees_evaluator>
{
public:
typedef asset_claim_fees_operation operation_type;

void_result do_evaluate( const asset_claim_fees_operation& o );
void_result do_apply( const asset_claim_fees_operation& o );
};

} } // graphene::chain
10 changes: 4 additions & 6 deletions libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ namespace graphene { namespace chain {
/// @return true if symbol is a valid ticker symbol; false otherwise.
static bool is_valid_symbol( const string& symbol );

/// @return true if accounts must be on a whitelist in order to hold this asset; false otherwise.
bool enforce_white_list()const { return options.flags & white_list; }
/// @return true if this is a market-issued asset; false otherwise.
bool is_market_issued()const { return bitasset_data_id.valid(); }
/// @return true if users may request force-settlement of this market-issued asset; false otherwise
Expand Down Expand Up @@ -213,7 +211,6 @@ namespace graphene { namespace chain {
void update_median_feeds(time_point_sec current_time);
};


struct by_feed_expiration;
typedef multi_index_container<
asset_bitasset_data_object,
Expand All @@ -227,17 +224,19 @@ namespace graphene { namespace chain {
typedef flat_index<asset_bitasset_data_object> asset_bitasset_data_index;

struct by_symbol;
struct by_type;
typedef multi_index_container<
asset_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_symbol>, member<asset_object, string, &asset_object::symbol> >
ordered_unique< tag<by_symbol>, member<asset_object, string, &asset_object::symbol> >,
ordered_non_unique< tag<by_type>, const_mem_fun<asset_object, bool, &asset_object::is_market_issued> >
>
> asset_object_multi_index_type;
typedef generic_index<asset_object, asset_object_multi_index_type> asset_index;


} } // graphene::chain

FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_object, (graphene::db::object),
(current_supply)(confidential_supply)(accumulated_fees)(fee_pool) )

Expand All @@ -260,4 +259,3 @@ FC_REFLECT_DERIVED( graphene::chain::asset_object, (graphene::db::object),
(dynamic_asset_data_id)
(bitasset_data_id)
)

Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::
(time)
(current_witness)
(next_maintenance_time)
(last_budget_time)
(witness_budget)
(accounts_registered_this_interval)
(recently_missed_count)
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/include/graphene/chain/hardfork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@

#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
#define HARDFORK_409_TIME (fc::time_point_sec( 1446652800 ))
#define HARDFORK_413_TIME (fc::time_point_sec( 1446652800 ))
#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 ))
#define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 ))
#define HARDFORK_419_TIME (fc::time_point_sec( 1446652800 ))
Loading

0 comments on commit 43a7243

Please sign in to comment.