Skip to content

Commit

Permalink
Compat with FC TNT Updates
Browse files Browse the repository at this point in the history
This adds compatibility to bitshares/hardfork for bitshares/bitshares-fc#191
  • Loading branch information
nathanielhourt committed Mar 23, 2020
1 parent ca565a7 commit 3c4a161
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
57 changes: 30 additions & 27 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 Expand Up @@ -590,14 +593,14 @@ object_restriction_predicate<Object> restrictions_to_predicate(vector<restrictio
}

// 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, 5>>;
using operation_list_2 = static_variant<typelist::slice<operation::list, 5, 10>>;
using operation_list_3 = static_variant<typelist::slice<operation::list, 10, 20>>;
using operation_list_4 = static_variant<typelist::slice<operation::list, 20, 30>>;
using operation_list_5 = static_variant<typelist::slice<operation::list, 30, 35>>;
using operation_list_6 = static_variant<typelist::slice<operation::list, 35, 40>>;
using operation_list_7 = static_variant<typelist::slice<operation::list, 40, 50>>;
using operation_list_8 = static_variant<typelist::slice<operation::list, 50>>;
using operation_list_1 = to_sv<typelist::slice<operation::list, 0, 5>>;
using operation_list_2 = to_sv<typelist::slice<operation::list, 5, 10>>;
using operation_list_3 = to_sv<typelist::slice<operation::list, 10, 20>>;
using operation_list_4 = to_sv<typelist::slice<operation::list, 20, 30>>;
using operation_list_5 = to_sv<typelist::slice<operation::list, 30, 35>>;
using operation_list_6 = to_sv<typelist::slice<operation::list, 35, 40>>;
using operation_list_7 = to_sv<typelist::slice<operation::list, 40, 50>>;
using operation_list_8 = to_sv<typelist::slice<operation::list, 50>>;

object_restriction_predicate<operation> get_restriction_predicate_list_1(size_t idx, vector<restriction> rs);
object_restriction_predicate<operation> get_restriction_predicate_list_2(size_t idx, vector<restriction> rs);
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 @@ -35,14 +35,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

0 comments on commit 3c4a161

Please sign in to comment.