Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code smells #2510

Merged
merged 4 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions libraries/chain/asset_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <fc/io/raw.hpp>
#include <fc/uint128.hpp>

using namespace graphene::chain;
namespace graphene { namespace chain {

share_type asset_bitasset_data_object::max_force_settlement_volume(share_type current_supply) const
{
Expand All @@ -44,8 +44,8 @@ share_type asset_bitasset_data_object::max_force_settlement_volume(share_type cu
return static_cast<uint64_t>(volume);
}

void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_point_sec current_time,
time_point_sec next_maintenance_time )
void asset_bitasset_data_object::update_median_feeds( time_point_sec current_time,
time_point_sec next_maintenance_time )
{
bool after_core_hardfork_1270 = ( next_maintenance_time > HARDFORK_CORE_1270_TIME ); // call price caching issue
current_feed_publication_time = current_time;
Expand All @@ -65,7 +65,8 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin
if( effective_feeds.size() < options.minimum_feeds )
{
//... don't calculate a median, and set a null feed
feed_cer_updated = false; // new median cer is null, won't update asset_object anyway, set to false for better performance
feed_cer_updated = false; // new median cer is null, won't update asset_object anyway,
// set to false for better performance
current_feed_publication_time = current_time;
median_feed = price_feed_with_icr();
if( after_core_hardfork_1270 )
Expand All @@ -76,7 +77,7 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin
return;
}

if( 1u == effective_feeds.size() )
if( 1U == effective_feeds.size() )
{
if( median_feed.core_exchange_rate != effective_feeds.front().get().core_exchange_rate )
feed_cer_updated = true;
Expand Down Expand Up @@ -218,6 +219,8 @@ string asset_object::amount_to_string(share_type amount) const
return result;
}

} } // namespace graphene::chain

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

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE_2281.hf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#ifndef HARDFORK_CORE_2281_TIME
// Jan 1 2030, midnight; this is a dummy date until a hardfork date is scheduled
#define HARDFORK_CORE_2281_TIME (fc::time_point_sec( 1893456000 ))
#define HARDFORK_CORE_2281_PASSED(now) (now > HARDFORK_CORE_2281_TIME)
#define HARDFORK_CORE_2281_PASSED(next_maintenance_time) (next_maintenance_time > HARDFORK_CORE_2281_TIME)
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE_2282.hf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#ifndef HARDFORK_CORE_2282_TIME
// Jan 1 2030, midnight; this is a dummy date until a hardfork date is scheduled
#define HARDFORK_CORE_2282_TIME (fc::time_point_sec( 1893456000 ))
#define HARDFORK_CORE_2282_PASSED(now) (now > HARDFORK_CORE_2282_TIME)
#define HARDFORK_CORE_2282_PASSED(next_maintenance_time) (next_maintenance_time > HARDFORK_CORE_2282_TIME)
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE_2290.hf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#ifndef HARDFORK_CORE_2290_TIME
// Jan 1 2030, midnight; this is a dummy date until a hardfork date is scheduled
#define HARDFORK_CORE_2290_TIME (fc::time_point_sec( 1893456000 ))
#define HARDFORK_CORE_2290_PASSED(now) (now > HARDFORK_CORE_2290_TIME)
#define HARDFORK_CORE_2290_PASSED(next_maintenance_time) (next_maintenance_time > HARDFORK_CORE_2290_TIME)
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE_2467.hf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#ifndef HARDFORK_CORE_2467_TIME
// Jan 1 2030, midnight; this is a dummy date until a hardfork date is scheduled
#define HARDFORK_CORE_2467_TIME (fc::time_point_sec( 1893456000 ))
#define HARDFORK_CORE_2467_PASSED(now) (now > HARDFORK_CORE_2467_TIME)
#define HARDFORK_CORE_2467_PASSED(next_maintenance_time) (next_maintenance_time > HARDFORK_CORE_2467_TIME)
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE_2481.hf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#ifndef HARDFORK_CORE_2481_TIME
// Jan 1 2030, midnight; this is a dummy date until a hardfork date is scheduled
#define HARDFORK_CORE_2481_TIME (fc::time_point_sec( 1893456000 ))
#define HARDFORK_CORE_2481_PASSED(now) (now > HARDFORK_CORE_2481_TIME)
#define HARDFORK_CORE_2481_PASSED(next_maintenance_time) (next_maintenance_time > HARDFORK_CORE_2481_TIME)
#endif
71 changes: 36 additions & 35 deletions libraries/chain/include/graphene/chain/hardfork_visitor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
/*
* Copyright (c) 2019 Contributors
*
Expand All @@ -22,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once

#include <graphene/protocol/operations.hpp>

Expand All @@ -33,8 +33,6 @@
#include <functional>

namespace graphene { namespace chain {
using namespace protocol;
namespace TL { using namespace fc::typelist; }

/**
* @brief The hardfork_visitor struct checks whether a given operation type has been hardforked in or not
Expand All @@ -45,66 +43,69 @@ namespace TL { using namespace fc::typelist; }
*/
struct hardfork_visitor {
using result_type = bool;
using first_unforked_op = custom_authority_create_operation;
using BSIP_40_ops = TL::list<custom_authority_create_operation, custom_authority_update_operation,
custom_authority_delete_operation>;
using hf2103_ops = TL::list<ticket_create_operation, ticket_update_operation>;
using liquidity_pool_ops = TL::list< liquidity_pool_create_operation,
liquidity_pool_delete_operation,
liquidity_pool_deposit_operation,
liquidity_pool_withdraw_operation,
liquidity_pool_exchange_operation >;
using samet_fund_ops = TL::list< samet_fund_create_operation,
samet_fund_delete_operation,
samet_fund_update_operation,
samet_fund_borrow_operation,
samet_fund_repay_operation >;
using credit_offer_ops = TL::list< credit_offer_create_operation,
credit_offer_delete_operation,
credit_offer_update_operation,
credit_offer_accept_operation,
credit_deal_repay_operation,
credit_deal_expired_operation >;
using first_unforked_op = protocol::custom_authority_create_operation;
using BSIP_40_ops = fc::typelist::list< protocol::custom_authority_create_operation,
protocol::custom_authority_update_operation,
protocol::custom_authority_delete_operation>;
using hf2103_ops = fc::typelist::list< protocol::ticket_create_operation,
protocol::ticket_update_operation>;
using liquidity_pool_ops = fc::typelist::list< protocol::liquidity_pool_create_operation,
protocol::liquidity_pool_delete_operation,
protocol::liquidity_pool_deposit_operation,
protocol::liquidity_pool_withdraw_operation,
protocol::liquidity_pool_exchange_operation >;
using samet_fund_ops = fc::typelist::list< protocol::samet_fund_create_operation,
protocol::samet_fund_delete_operation,
protocol::samet_fund_update_operation,
protocol::samet_fund_borrow_operation,
protocol::samet_fund_repay_operation >;
using credit_offer_ops = fc::typelist::list< protocol::credit_offer_create_operation,
protocol::credit_offer_delete_operation,
protocol::credit_offer_update_operation,
protocol::credit_offer_accept_operation,
protocol::credit_deal_repay_operation,
protocol::credit_deal_expired_operation >;
fc::time_point_sec now;

hardfork_visitor(fc::time_point_sec now) : now(now) {}
/// @note using head block time for all operations
explicit hardfork_visitor(const fc::time_point_sec& head_block_time) : now(head_block_time) {}

/// The real visitor implementations. Future operation types get added in here.
/// @{
template<typename Op>
std::enable_if_t<operation::tag<Op>::value < operation::tag<first_unforked_op>::value, bool>
std::enable_if_t<operation::tag<Op>::value < protocol::operation::tag<first_unforked_op>::value, bool>
visit() { return true; }
template<typename Op>
std::enable_if_t<TL::contains<BSIP_40_ops, Op>(), bool>
std::enable_if_t<fc::typelist::contains<BSIP_40_ops, Op>(), bool>
visit() { return HARDFORK_BSIP_40_PASSED(now); }
template<typename Op>
std::enable_if_t<TL::contains<hf2103_ops, Op>(), bool>
std::enable_if_t<fc::typelist::contains<hf2103_ops, Op>(), bool>
visit() { return HARDFORK_CORE_2103_PASSED(now); }
template<typename Op>
std::enable_if_t<TL::contains<liquidity_pool_ops, Op>(), bool>
std::enable_if_t<fc::typelist::contains<liquidity_pool_ops, Op>(), bool>
visit() { return HARDFORK_LIQUIDITY_POOL_PASSED(now); }
template<typename Op>
std::enable_if_t<TL::contains<samet_fund_ops, Op>(), bool>
std::enable_if_t<fc::typelist::contains<samet_fund_ops, Op>(), bool>
visit() { return HARDFORK_CORE_2351_PASSED(now); }
template<typename Op>
std::enable_if_t<TL::contains<credit_offer_ops, Op>(), bool>
std::enable_if_t<fc::typelist::contains<credit_offer_ops, Op>(), bool>
visit() { return HARDFORK_CORE_2362_PASSED(now); }
/// @}

/// typelist::runtime::dispatch adaptor
template<class W, class Op=typename W::type>
std::enable_if_t<TL::contains<operation::list, Op>(), bool>
std::enable_if_t<fc::typelist::contains<protocol::operation::list, Op>(), bool>
operator()(W) { return visit<Op>(); }
/// static_variant::visit adaptor
template<class Op>
std::enable_if_t<TL::contains<operation::list, Op>(), bool>
std::enable_if_t<fc::typelist::contains<protocol::operation::list, Op>(), bool>
operator()(const Op&) { return visit<Op>(); }
/// Tag adaptor
bool visit(operation::tag_type tag) {
return TL::runtime::dispatch(operation::list(), (size_t)tag, *this);
bool visit(protocol::operation::tag_type tag) const {
return fc::typelist::runtime::dispatch(protocol::operation::list(), (size_t)tag, *this);
}
/// operation adaptor
bool visit(const operation& op) {
bool visit(const protocol::operation& op) const {
return visit(op.which());
}
};
Expand Down