Change static refs to member pointers of db class
This commit is contained in:
parent
36e318a503
commit
04102d549c
5 changed files with 28 additions and 19 deletions
|
|
@ -37,26 +37,22 @@ namespace graphene { namespace chain {
|
|||
|
||||
const asset_object& database::get_core_asset() const
|
||||
{
|
||||
static const asset_object& obj = get(asset_id_type());
|
||||
return obj;
|
||||
return *_p_core_asset_obj;
|
||||
}
|
||||
|
||||
const global_property_object& database::get_global_properties()const
|
||||
{
|
||||
static const global_property_object& obj = get( global_property_id_type() );
|
||||
return obj;
|
||||
return *_p_global_prop_obj;
|
||||
}
|
||||
|
||||
const chain_property_object& database::get_chain_properties()const
|
||||
{
|
||||
static const chain_property_object& obj = get( chain_property_id_type() );
|
||||
return obj;
|
||||
return *_p_chain_property_obj;
|
||||
}
|
||||
|
||||
const dynamic_global_property_object& database::get_dynamic_global_properties() const
|
||||
{
|
||||
static const dynamic_global_property_object& obj = get( dynamic_global_property_id_type() );
|
||||
return obj;
|
||||
return *_p_dyn_global_prop_obj;
|
||||
}
|
||||
|
||||
const fee_schedule& database::current_fee_schedule()const
|
||||
|
|
|
|||
|
|
@ -493,8 +493,9 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
a.dynamic_asset_data_id = dyn_asset.id;
|
||||
a.dividend_data_id = div_asset.id;
|
||||
});
|
||||
assert( asset_id_type(core_asset.id) == asset().asset_id );
|
||||
assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) );
|
||||
FC_ASSERT( asset_id_type(core_asset.id) == asset().asset_id );
|
||||
FC_ASSERT( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) );
|
||||
_p_core_asset_obj = &core_asset;
|
||||
|
||||
#ifdef _DEFAULT_DIVIDEND_ASSET
|
||||
// Create default dividend asset
|
||||
|
|
@ -527,7 +528,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
a.dynamic_asset_data_id = dyn_asset1.id;
|
||||
a.dividend_data_id = div_asset1.id;
|
||||
});
|
||||
assert( default_asset.id == asset_id_type(1) );
|
||||
FC_ASSERT( default_asset.id == asset_id_type(1) );
|
||||
#endif
|
||||
|
||||
// Create more special assets
|
||||
|
|
@ -560,14 +561,14 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
chain_id_type chain_id = genesis_state.compute_chain_id();
|
||||
|
||||
// Create global properties
|
||||
create<global_property_object>([&](global_property_object& p) {
|
||||
_p_global_prop_obj = & create<global_property_object>([&genesis_state](global_property_object& p) {
|
||||
p.parameters = genesis_state.initial_parameters;
|
||||
// Set fees to zero initially, so that genesis initialization needs not pay them
|
||||
// We'll fix it at the end of the function
|
||||
p.parameters.current_fees->zero_all_fees();
|
||||
|
||||
});
|
||||
create<dynamic_global_property_object>([&](dynamic_global_property_object& p) {
|
||||
_p_dyn_global_prop_obj = & create<dynamic_global_property_object>([&genesis_state](dynamic_global_property_object& p) {
|
||||
p.time = genesis_state.initial_timestamp;
|
||||
p.dynamic_flags = 0;
|
||||
p.witness_budget = 0;
|
||||
|
|
@ -580,7 +581,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
FC_ASSERT( (genesis_state.immutable_parameters.min_witness_count & 1) == 1, "min_witness_count must be odd" );
|
||||
FC_ASSERT( (genesis_state.immutable_parameters.min_committee_member_count & 1) == 1, "min_committee_member_count must be odd" );
|
||||
|
||||
create<chain_property_object>([&](chain_property_object& p)
|
||||
_p_chain_property_obj = & create<chain_property_object>([chain_id,&genesis_state](chain_property_object& p)
|
||||
{
|
||||
p.chain_id = chain_id;
|
||||
p.immutable_parameters = genesis_state.immutable_parameters;
|
||||
|
|
|
|||
|
|
@ -214,6 +214,13 @@ void database::open(
|
|||
|
||||
if( !find(global_property_id_type()) )
|
||||
init_genesis(genesis_loader());
|
||||
else
|
||||
{
|
||||
_p_core_asset_obj = &get( asset_id_type() );
|
||||
_p_global_prop_obj = &get( global_property_id_type() );
|
||||
_p_chain_property_obj = &get( chain_property_id_type() );
|
||||
_p_dyn_global_prop_obj = &get( dynamic_global_property_id_type() );
|
||||
}
|
||||
|
||||
fc::optional<block_id_type> last_block = _block_id_to_block.last_id();
|
||||
if( last_block.valid() )
|
||||
|
|
|
|||
|
|
@ -429,9 +429,7 @@ bool database::fill_order(const force_settlement_object& settle, const asset& pa
|
|||
bool database::check_call_orders( const asset_object& mia, bool enable_black_swan, bool for_new_limit_order,
|
||||
const asset_bitasset_data_object* bitasset_ptr )
|
||||
{ try {
|
||||
static const auto& dyn_prop = get_dynamic_global_properties();
|
||||
if( !mia.is_market_issued() ) return false;
|
||||
auto maint_time = dyn_prop.next_maintenance_time;
|
||||
|
||||
const asset_bitasset_data_object& bitasset = ( bitasset_ptr ? *bitasset_ptr : mia.bitasset_data(*this) );
|
||||
|
||||
|
|
@ -471,7 +469,6 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa
|
|||
auto head_time = head_block_time();
|
||||
auto head_num = head_block_num();
|
||||
|
||||
bool before_hardfork_615 = ( head_time < HARDFORK_615_TIME );
|
||||
bool after_hardfork_436 = ( head_time > HARDFORK_436_TIME );
|
||||
|
||||
while( !check_for_blackswan( mia, enable_black_swan, &bitasset ) && call_itr != call_end )
|
||||
|
|
@ -491,7 +488,7 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa
|
|||
|
||||
// would be margin called, but there is no matching order #436
|
||||
bool feed_protected = ( bitasset.current_feed.settlement_price > ~call_itr->call_price );
|
||||
if( feed_protected && (head_block_time() > HARDFORK_436_TIME) )
|
||||
if( feed_protected && after_hardfork_436 )
|
||||
return margin_called;
|
||||
|
||||
// would be margin called, but there is no matching order
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ namespace graphene { namespace chain {
|
|||
asset pay_market_fees( const asset_object& recv_asset, const asset& receives );
|
||||
|
||||
|
||||
///@}
|
||||
///@{
|
||||
/**
|
||||
* This method validates transactions without adding it to the pending state.
|
||||
* @return true if the transaction would validate
|
||||
|
|
@ -588,6 +588,14 @@ namespace graphene { namespace chain {
|
|||
bool _opened = false;
|
||||
/// Tracks assets affected by bitshares-core issue #453 before hard fork #615 in one block
|
||||
flat_set<asset_id_type> _issue_453_affected_assets;
|
||||
|
||||
/// Pointers to core asset object and global objects who will have immutable addresses after created
|
||||
///@{
|
||||
const asset_object* _p_core_asset_obj = nullptr;
|
||||
const global_property_object* _p_global_prop_obj = nullptr;
|
||||
const dynamic_global_property_object* _p_dyn_global_prop_obj = nullptr;
|
||||
const chain_property_object* _p_chain_property_obj = nullptr;
|
||||
///@}
|
||||
};
|
||||
|
||||
namespace detail
|
||||
|
|
|
|||
Loading…
Reference in a new issue