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

Compat with FC TNT Updates w/o TNT #2118

Open
wants to merge 1 commit into
base: hardfork
Choose a base branch
from
Open
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
41 changes: 22 additions & 19 deletions libraries/protocol/custom_authorities/restriction_predicate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ template<typename I>
const auto& to_num(const fc::safe<I>& i) { return i.value; }
inline auto to_num(const fc::time_point_sec& t) { return t.sec_since_epoch(); }

// Shorthand to convert a typelist into a static_variant of that typelist
template<typename List>
using to_sv = typelist::apply<List, static_variant>;

namespace safenum = boost::safe_numerics::safe_compare;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -127,7 +131,7 @@ using comparable_types_list = typelist::list<int64_t, string, time_point_sec, ac
proposal_id_type, withdraw_permission_id_type,
vesting_balance_id_type, worker_id_type, balance_id_type>;
// Valid for list functions (in, not_in, has_all, has_none)
struct make_flat_set { template<typename T> struct transform { using type = flat_set<T>; }; };
template<typename T> struct make_flat_set { using type = flat_set<T>; };
using list_types_list = typelist::transform<typelist::concat<typelist::list<bool, public_key_type, fc::sha256>,
comparable_types_list>,
make_flat_set>;
Expand Down Expand Up @@ -256,9 +260,15 @@ template<typename Field, typename Element>
struct predicate_in<fc::optional<Field>, flat_set<Element>, std::enable_if_t<comparable_types<Field, Element>>> {
// Check for optional value
constexpr static bool valid = true;
template<typename F = Field, std::enable_if_t<!std::is_same<F, share_type>::value, bool> = true>
bool operator()(const fc::optional<Field>& f, const flat_set<Element>& c) const {
if (!f.valid()) return predicate_result::Rejection(predicate_result::null_optional);
return c.count(*f) != 0;
return c.count(*f) != 0;
}
template<typename F = Field, std::enable_if_t<std::is_same<F, share_type>::value, bool> = true>
bool operator()(const fc::optional<share_type>& f, const flat_set<Element>& c) const {
if (!f.valid()) return predicate_result::Rejection(predicate_result::null_optional);
return c.count(Element(f->value)) != 0;
}
};
template<typename Container, typename Element>
Expand Down Expand Up @@ -470,32 +480,25 @@ object_restriction_predicate<Field> create_predicate_function(restriction_functi
try {
switch(func) {
case restriction::func_eq:
return make_predicate<predicate_eq, Field>(static_variant<equality_types_list>::import_from(std::move(arg)));
return make_predicate<predicate_eq, Field>(to_sv<equality_types_list>::import_from(std::move(arg)));
case restriction::func_ne:
return make_predicate<predicate_ne, Field>(static_variant<equality_types_list>::import_from(std::move(arg)));
return make_predicate<predicate_ne, Field>(to_sv<equality_types_list>::import_from(std::move(arg)));
case restriction::func_lt:
return make_predicate<predicate_lt, Field>(static_variant<comparable_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_lt, Field>(to_sv<comparable_types_list>::import_from(std::move(arg)));
case restriction::func_le:
return make_predicate<predicate_le, Field>(static_variant<comparable_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_le, Field>(to_sv<comparable_types_list>::import_from(std::move(arg)));
case restriction::func_gt:
return make_predicate<predicate_gt, Field>(static_variant<comparable_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_gt, Field>(to_sv<comparable_types_list>::import_from(std::move(arg)));
case restriction::func_ge:
return make_predicate<predicate_ge, Field>(static_variant<comparable_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_ge, Field>(to_sv<comparable_types_list>::import_from(std::move(arg)));
case restriction::func_in:
return make_predicate<predicate_in, Field>(static_variant<list_types_list>::import_from(std::move(arg)));
return make_predicate<predicate_in, Field>(to_sv<list_types_list>::import_from(std::move(arg)));
case restriction::func_not_in:
return make_predicate<predicate_not_in, Field>(static_variant<list_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_not_in, Field>(to_sv<list_types_list>::import_from(std::move(arg)));
case restriction::func_has_all:
return make_predicate<predicate_has_all, Field>(static_variant<list_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_has_all, Field>(to_sv<list_types_list>::import_from(std::move(arg)));
case restriction::func_has_none:
return make_predicate<predicate_has_none, Field>(static_variant<list_types_list>
::import_from(std::move(arg)));
return make_predicate<predicate_has_none, Field>(to_sv<list_types_list>::import_from(std::move(arg)));
case restriction::func_attr:
FC_ASSERT(arg.which() == restriction_argument::tag<vector<restriction>>::value,
"Argument type for attribute assertion must be restriction list");
Expand Down
32 changes: 18 additions & 14 deletions libraries/protocol/custom_authorities/sliced_lists.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@
namespace graphene { namespace protocol {
namespace typelist = fc::typelist;

// Shorthand to convert a typelist into a static_variant of that typelist
template<typename List>
using to_sv = typelist::apply<List, static_variant>;

// To make the build gentler on RAM, break the operation list into several pieces to build over several files
using operation_list_1 = static_variant<typelist::slice<operation::list, 0, 4>>;
using operation_list_2 = static_variant<typelist::slice<operation::list, 5, 9>>;
using operation_list_3 = static_variant<typelist::slice<operation::list, 9, 15>>;
using operation_list_4 = static_variant<typelist::slice<operation::list, 15, 22>>;
using operation_list_5 = static_variant<typelist::slice<operation::list, 22, 29>>;
using operation_list_6 = static_variant<typelist::slice<operation::list, 29, 34>>;
using operation_list_7 = static_variant<typelist::slice<operation::list, 34, 42>>;
using operation_list_8 = static_variant<typelist::builder<>
::add<asset_claim_fees_operation> // 43
::add<bid_collateral_operation> // 45
::add_list<typelist::slice<operation::list, 47, 51>>
::add<htlc_extend_operation> // 52
::finalize>;
using operation_list_9 = static_variant<typelist::slice<operation::list, 54>>;
using operation_list_1 = to_sv<typelist::slice<operation::list, 0, 4>>;
using operation_list_2 = to_sv<typelist::slice<operation::list, 5, 9>>;
using operation_list_3 = to_sv<typelist::slice<operation::list, 9, 15>>;
using operation_list_4 = to_sv<typelist::slice<operation::list, 15, 22>>;
using operation_list_5 = to_sv<typelist::slice<operation::list, 22, 29>>;
using operation_list_6 = to_sv<typelist::slice<operation::list, 29, 34>>;
using operation_list_7 = to_sv<typelist::slice<operation::list, 34, 42>>;
using operation_list_8 = to_sv<typelist::builder<>
::add<asset_claim_fees_operation> // 43
::add<bid_collateral_operation> // 45
::add_list<typelist::slice<operation::list, 47, 51>>
::add<htlc_extend_operation> // 52
::finalize>;
using operation_list_9 = to_sv<typelist::slice<operation::list, 54>>;
using virtual_operations_list = static_variant<fill_order_operation, // 4
asset_settle_cancel_operation, // 42
fba_distribute_operation, // 44
Expand Down
2 changes: 1 addition & 1 deletion libraries/protocol/include/graphene/protocol/object_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ struct reflector<graphene::db::object_id<SpaceID,TypeID> >
{
typedef graphene::db::object_id<SpaceID,TypeID> type;
typedef std::true_type is_defined;
using native_members = typelist::list<fc::field_reflection<0, type, unsigned_int, &type::instance>>;
using native_members = typelist::list<fc::field_reflector<0, type, unsigned_int, &type::instance>>;
using inherited_members = typelist::list<>;
using members = native_members;
using base_classes = typelist::list<>;
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/custom_authority_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@

using namespace graphene::chain;
using namespace graphene::chain::test;
namespace TL = fc::typelist;

namespace graphene { namespace protocol {
bool operator==(const restriction& a, const restriction& b) {
if (std::tie(a.member_index, a.restriction_type) != std::tie(b.member_index, b.restriction_type))
return false;
if (a.argument.is_type<void_t>())
return b.argument.is_type<void_t>();
using Value_Argument = static_variant<fc::typelist::slice<restriction::argument_type::list, 1>>;
using Value_Argument = TL::apply<TL::slice<restriction::argument_type::list, 1>, static_variant>;
return Value_Argument::import_from(a.argument) == Value_Argument::import_from(b.argument);
}
} }
Expand Down