From bc5c34bd67d7b8ef59df1a000a7f3ba0c12e1dff Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 14:58:52 -0500 Subject: [PATCH 01/10] [BSIP40] Add external serializations See https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r399386266 --- libraries/protocol/custom_authority.cpp | 7 +++++++ .../include/graphene/protocol/custom_authority.hpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/libraries/protocol/custom_authority.cpp b/libraries/protocol/custom_authority.cpp index f7217d01f2..1a7bc54f4d 100644 --- a/libraries/protocol/custom_authority.cpp +++ b/libraries/protocol/custom_authority.cpp @@ -98,3 +98,10 @@ void custom_authority_delete_operation::validate()const { } } } // graphene::protocol + +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_create_operation::fee_parameters_type) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_update_operation::fee_parameters_type) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_delete_operation::fee_parameters_type) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_create_operation) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_update_operation) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_delete_operation) diff --git a/libraries/protocol/include/graphene/protocol/custom_authority.hpp b/libraries/protocol/include/graphene/protocol/custom_authority.hpp index 7448c84aee..ead0c5597e 100644 --- a/libraries/protocol/include/graphene/protocol/custom_authority.hpp +++ b/libraries/protocol/include/graphene/protocol/custom_authority.hpp @@ -134,3 +134,10 @@ FC_REFLECT(graphene::protocol::custom_authority_update_operation, (fee)(account)(authority_to_update)(new_enabled)(new_valid_from) (new_valid_to)(new_auth)(restrictions_to_remove)(restrictions_to_add)(extensions)) FC_REFLECT(graphene::protocol::custom_authority_delete_operation, (fee)(account)(authority_to_delete)(extensions)) + +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_create_operation::fee_parameters_type) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_update_operation::fee_parameters_type) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_delete_operation::fee_parameters_type) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_create_operation) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_update_operation) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(graphene::protocol::custom_authority_delete_operation) From 3cd47d1813de536fd8fcc45485aac0a5cbdca4b5 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 17:36:00 -0500 Subject: [PATCH 02/10] [BSIP40] Add field support check See https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401052309 A compile error is now thrown if any operation field type is unsupported in use in any predicate with any argument type. See https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r400286103 Unsigned_int is now supported as an integral type --- .../restriction_predicate.hxx | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/libraries/protocol/custom_authorities/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index 9d2757b787..96a2120ac0 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.hxx +++ b/libraries/protocol/custom_authorities/restriction_predicate.hxx @@ -23,6 +23,7 @@ */ #include +#include #include @@ -50,7 +51,8 @@ template constexpr static bool is_flat_set = is_flat_set_impl::va // We use our own is_integral which does not consider bools integral (to disallow comparison between bool and ints) template constexpr static bool is_integral = !std::is_same::value && !std::is_same>::value && - (is_safe || std::is_integral::value); + (is_safe || std::is_integral::value || + std::is_same::value); // Metafunction to check if two types are comparable, which means not void_t, and either the same or both integral template @@ -74,6 +76,7 @@ const auto& to_num(const I& i) { return i; } template const auto& to_num(const fc::safe& i) { return i.value; } inline auto to_num(const fc::time_point_sec& t) { return t.sec_since_epoch(); } +inline auto to_num(const fc::unsigned_int& ui) { return ui.value; } namespace safenum = boost::safe_numerics::safe_compare; @@ -397,6 +400,14 @@ struct attribute_assertion> { }; } }; +template +struct attribute_assertion> { + static object_restriction_predicate> create(vector&& rs) { + return [p=restrictions_to_predicate(std::move(rs), false)](const shared_ptr& x) { + return p(*x); + }; + } +}; template struct variant_assertion { @@ -465,8 +476,59 @@ object_restriction_predicate make_predicate(ArgVariant arg) { }); } +// A template checking whether a predicate is valid with the provided field type and any restriction argument type +template +struct predicate_is_valid_for_field { + template + struct filter { + template + struct argument_filter { + constexpr static bool value = Predicate::template unwrap::valid; + }; + + constexpr static bool value = typelist::any; + }; +}; +// Specialization for reflected struct fields; they are always valid because we can use an attribute_assert on them +template +struct predicate_is_valid_for_field::is_defined::value>> { + template + struct filter { constexpr static bool value = true; }; +}; +// Specialization for extension fields; they are always valid because we can use an attribute_assert on them +template +struct predicate_is_valid_for_field, void> { + template + struct filter { constexpr static bool value = true; }; +}; +// Specialization for static variant fields; they are always valid because we can use a variant_assert on them +template +struct predicate_is_valid_for_field, void> { + template + struct filter { constexpr static bool value = true; }; +}; +// Specialization for shared_ptr fields; they are valid if the thing pointed to is +template +struct predicate_is_valid_for_field, void> + : public predicate_is_valid_for_field> {}; + +// Check if any predicate can be used with the provided field type and any known argument type +template +constexpr bool any_predicate_applies() { + using PredicateTypes = typelist::list, typelist::wrapped, + typelist::wrapped, typelist::wrapped, + typelist::wrapped, typelist::wrapped, + typelist::wrapped, typelist::wrapped, + typelist::wrapped, typelist::wrapped>; + return typelist::any::template filter>; +} + template object_restriction_predicate create_predicate_function(restriction_function func, restriction_argument arg) { + // This checks that all fields of all objects can be used with at least one predicate + static_assert(any_predicate_applies(), + "This new field type is not yet supported by Custom Active Authorities. Please add support for it."); + try { switch(func) { case restriction::func_eq: @@ -539,7 +601,7 @@ object_restriction_predicate create_field_predicate(restriction&& r, sho template object_restriction_predicate create_field_predicate(restriction&&, long) { FC_THROW_EXCEPTION(fc::assert_exception, "Invalid restriction references member of non-object type: ${O}", - ("O", fc::get_typename::name())); + ("O", fc::get_typename>::name())); } template From 738ac6f99771587f9b169fb791cbcc32d1a2813c Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 18:13:44 -0500 Subject: [PATCH 03/10] [BSIP40] Generate list_#.cpp files See https://github.com/bitshares/bitshares-core/pull/2093#discussion_r400238556 Add a cmake template file for the list_#.cpp files and autogenerate them from the template rather than having 12 almost identical copies of a file --- libraries/protocol/CMakeLists.txt | 20 ++++----- .../{list_1.cpp => list.cpp.in} | 4 +- .../protocol/custom_authorities/list_10.cpp | 41 ------------------ .../protocol/custom_authorities/list_11.cpp | 41 ------------------ .../protocol/custom_authorities/list_12.cpp | 41 ------------------ .../protocol/custom_authorities/list_2.cpp | 42 ------------------- .../protocol/custom_authorities/list_3.cpp | 42 ------------------- .../protocol/custom_authorities/list_4.cpp | 42 ------------------- .../protocol/custom_authorities/list_5.cpp | 42 ------------------- .../protocol/custom_authorities/list_6.cpp | 42 ------------------- .../protocol/custom_authorities/list_7.cpp | 42 ------------------- .../protocol/custom_authorities/list_8.cpp | 42 ------------------- .../protocol/custom_authorities/list_9.cpp | 42 ------------------- 13 files changed, 9 insertions(+), 474 deletions(-) rename libraries/protocol/custom_authorities/{list_1.cpp => list.cpp.in} (88%) delete mode 100644 libraries/protocol/custom_authorities/list_10.cpp delete mode 100644 libraries/protocol/custom_authorities/list_11.cpp delete mode 100644 libraries/protocol/custom_authorities/list_12.cpp delete mode 100644 libraries/protocol/custom_authorities/list_2.cpp delete mode 100644 libraries/protocol/custom_authorities/list_3.cpp delete mode 100644 libraries/protocol/custom_authorities/list_4.cpp delete mode 100644 libraries/protocol/custom_authorities/list_5.cpp delete mode 100644 libraries/protocol/custom_authorities/list_6.cpp delete mode 100644 libraries/protocol/custom_authorities/list_7.cpp delete mode 100644 libraries/protocol/custom_authorities/list_8.cpp delete mode 100644 libraries/protocol/custom_authorities/list_9.cpp diff --git a/libraries/protocol/CMakeLists.txt b/libraries/protocol/CMakeLists.txt index 8d6b096e84..72f2b40b00 100644 --- a/libraries/protocol/CMakeLists.txt +++ b/libraries/protocol/CMakeLists.txt @@ -37,24 +37,18 @@ list(APPEND CUSTOM_AUTHS_FILES custom_authorities/create_predicate_fwd_1.cpp custom_authorities/create_predicate_fwd_2.cpp custom_authorities/create_predicate_fwd_3.cpp - custom_authorities/restriction_predicate.cpp - custom_authorities/list_1.cpp - custom_authorities/list_2.cpp - custom_authorities/list_3.cpp - custom_authorities/list_4.cpp - custom_authorities/list_5.cpp - custom_authorities/list_6.cpp - custom_authorities/list_7.cpp - custom_authorities/list_8.cpp - custom_authorities/list_9.cpp - custom_authorities/list_10.cpp - custom_authorities/list_11.cpp - custom_authorities/list_12.cpp) + custom_authorities/restriction_predicate.cpp) + +foreach(LIST_NUM RANGE 1 12) + configure_file("custom_authorities/list.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/custom_authorities/list_${LIST_NUM}.cpp") + list(APPEND CUSTOM_AUTHS_FILES "${CMAKE_CURRENT_BINARY_DIR}/custom_authorities/list_${LIST_NUM}.cpp") +endforeach(LIST_NUM) file(GLOB CUSTOM_AUTHS_HEADERS "custom_authorities/*.hxx") add_library( graphene_protocol_custom_auths ${CUSTOM_AUTHS_FILES} ${CUSTOM_AUTHS_HEADERS} ) target_link_libraries( graphene_protocol_custom_auths fc ) +target_include_directories(graphene_protocol_custom_auths PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/custom_authorities") target_include_directories( graphene_protocol_custom_auths PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if( MSVC ) diff --git a/libraries/protocol/custom_authorities/list_1.cpp b/libraries/protocol/custom_authorities/list.cpp.in similarity index 88% rename from libraries/protocol/custom_authorities/list_1.cpp rename to libraries/protocol/custom_authorities/list.cpp.in index 7102fe2ecc..3416c9ebfc 100644 --- a/libraries/protocol/custom_authorities/list_1.cpp +++ b/libraries/protocol/custom_authorities/list.cpp.in @@ -28,8 +28,8 @@ namespace graphene { namespace protocol { using result_type = object_restriction_predicate; -result_type get_restriction_predicate_list_1(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_1::list(), idx, [&rs] (auto t) -> result_type { +result_type get_restriction_predicate_list_${LIST_NUM}(size_t idx, vector rs) { + return typelist::runtime::dispatch(operation_list_${LIST_NUM}::list(), idx, [&rs] (auto t) -> result_type { using Op = typename decltype(t)::type; return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { FC_ASSERT(op.which() == operation::tag::value, diff --git a/libraries/protocol/custom_authorities/list_10.cpp b/libraries/protocol/custom_authorities/list_10.cpp deleted file mode 100644 index 6bcd0a9a10..0000000000 --- a/libraries/protocol/custom_authorities/list_10.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_10(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_10::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_11.cpp b/libraries/protocol/custom_authorities/list_11.cpp deleted file mode 100644 index d626102113..0000000000 --- a/libraries/protocol/custom_authorities/list_11.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_11(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_11::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_12.cpp b/libraries/protocol/custom_authorities/list_12.cpp deleted file mode 100644 index 9a4cee9c2f..0000000000 --- a/libraries/protocol/custom_authorities/list_12.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_12(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_12::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_2.cpp b/libraries/protocol/custom_authorities/list_2.cpp deleted file mode 100644 index c42458dcf1..0000000000 --- a/libraries/protocol/custom_authorities/list_2.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_2(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_2::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_3.cpp b/libraries/protocol/custom_authorities/list_3.cpp deleted file mode 100644 index 9158d6e003..0000000000 --- a/libraries/protocol/custom_authorities/list_3.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_3(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_3::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_4.cpp b/libraries/protocol/custom_authorities/list_4.cpp deleted file mode 100644 index 2ff2fefb64..0000000000 --- a/libraries/protocol/custom_authorities/list_4.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_4(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_4::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_5.cpp b/libraries/protocol/custom_authorities/list_5.cpp deleted file mode 100644 index a1b93b9a44..0000000000 --- a/libraries/protocol/custom_authorities/list_5.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_5(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_5::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_6.cpp b/libraries/protocol/custom_authorities/list_6.cpp deleted file mode 100644 index e5d5962c0e..0000000000 --- a/libraries/protocol/custom_authorities/list_6.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_6(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_6::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_7.cpp b/libraries/protocol/custom_authorities/list_7.cpp deleted file mode 100644 index 9ac5c1bfcc..0000000000 --- a/libraries/protocol/custom_authorities/list_7.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_7(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_7::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_8.cpp b/libraries/protocol/custom_authorities/list_8.cpp deleted file mode 100644 index 32774e285b..0000000000 --- a/libraries/protocol/custom_authorities/list_8.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_8(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_8::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } diff --git a/libraries/protocol/custom_authorities/list_9.cpp b/libraries/protocol/custom_authorities/list_9.cpp deleted file mode 100644 index 27b2e069dd..0000000000 --- a/libraries/protocol/custom_authorities/list_9.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "restriction_predicate.hxx" -#include "sliced_lists.hxx" - -namespace graphene { namespace protocol { - -using result_type = object_restriction_predicate; - -result_type get_restriction_predicate_list_9(size_t idx, vector rs) { - return typelist::runtime::dispatch(operation_list_9::list(), idx, [&rs] (auto t) -> result_type { - using Op = typename decltype(t)::type; - return [p=restrictions_to_predicate(std::move(rs), true)] (const operation& op) { - FC_ASSERT(op.which() == operation::tag::value, - "Supplied operation is incorrect type for restriction predicate"); - return p(op.get()); - }; - }); -} -} } From 71de24bf97bdbcd5b6a65fdf8ebeba48247b7456 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 18:16:55 -0500 Subject: [PATCH 04/10] [BSIP40] Replace > with < See https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r400317820 --- libraries/protocol/custom_authorities/restriction_predicate.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/protocol/custom_authorities/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index 96a2120ac0..6b16f8b8a7 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.hxx +++ b/libraries/protocol/custom_authorities/restriction_predicate.hxx @@ -200,7 +200,7 @@ struct predicate_comparea? 1 : 0); + return f From b957a22ca6c35cafbf2d889aebe4e5275c3614f8 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 18:23:30 -0500 Subject: [PATCH 05/10] [BSIP40] Adjust argument types See: https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401581235 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401581502 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401582839 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401583091 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401588755 --- .../include/graphene/protocol/restriction.hpp | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/libraries/protocol/include/graphene/protocol/restriction.hpp b/libraries/protocol/include/graphene/protocol/restriction.hpp index 334cf63b03..a03736f400 100644 --- a/libraries/protocol/include/graphene/protocol/restriction.hpp +++ b/libraries/protocol/include/graphene/protocol/restriction.hpp @@ -62,39 +62,33 @@ struct restriction { /* 6 */ fc::sha256, \ /* 7 */ account_id_type, \ /* 8 */ asset_id_type, \ - /* 9 */ force_settlement_id_type, \ + /* 9 */ htlc_id_type, \ /* 10 */ committee_member_id_type, \ /* 11 */ witness_id_type, \ /* 12 */ limit_order_id_type, \ - /* 13 */ call_order_id_type, \ - /* 14 */ custom_id_type, \ - /* 15 */ proposal_id_type, \ - /* 16 */ withdraw_permission_id_type, \ - /* 17 */ vesting_balance_id_type, \ - /* 18 */ worker_id_type, \ - /* 19 */ balance_id_type, \ - /* 20 */ flat_set, \ - /* 21 */ flat_set, \ - /* 22 */ flat_set, \ - /* 23 */ flat_set, \ - /* 24 */ flat_set, \ - /* 25 */ flat_set, \ - /* 26 */ flat_set, \ - /* 27 */ flat_set, \ - /* 28 */ flat_set, \ - /* 29 */ flat_set, \ - /* 30 */ flat_set, \ - /* 31 */ flat_set, \ - /* 32 */ flat_set, \ - /* 33 */ flat_set, \ - /* 34 */ flat_set, \ - /* 35 */ flat_set, \ - /* 36 */ flat_set, \ - /* 37 */ flat_set, \ - /* 38 */ flat_set, \ - /* 39 */ vector, \ - /* 40 */ vector>, \ - /* 41 */ variant_assert_argument_type + /* 13 */ proposal_id_type, \ + /* 14 */ withdraw_permission_id_type, \ + /* 15 */ vesting_balance_id_type, \ + /* 16 */ balance_id_type, \ + /* 17 */ flat_set, \ + /* 18 */ flat_set, \ + /* 19 */ flat_set, \ + /* 20 */ flat_set, \ + /* 21 */ flat_set, \ + /* 22 */ flat_set, \ + /* 23 */ flat_set, \ + /* 24 */ flat_set, \ + /* 25 */ flat_set, \ + /* 26 */ flat_set, \ + /* 27 */ flat_set, \ + /* 28 */ flat_set, \ + /* 29 */ flat_set, \ + /* 30 */ flat_set, \ + /* 31 */ flat_set, \ + /* 32 */ flat_set, \ + /* 33 */ vector, \ + /* 34 */ vector>, \ + /* 35 */ variant_assert_argument_type using argument_type = fc::static_variant; From 56d7ef6d3e51be2e2a5709f14d9dc598e0160f76 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 18:55:53 -0500 Subject: [PATCH 06/10] [BSIP40] Remove support for unsupported operations See: https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401599873 --- .../restriction_predicate.cpp | 3 ++ .../custom_authorities/sliced_lists.hxx | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/libraries/protocol/custom_authorities/restriction_predicate.cpp b/libraries/protocol/custom_authorities/restriction_predicate.cpp index 10cc57709a..3375572316 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.cpp +++ b/libraries/protocol/custom_authorities/restriction_predicate.cpp @@ -56,6 +56,8 @@ restriction_predicate_function get_restriction_predicate(vector rs, return get_restriction_predicate_list_11(typelist::index_of(), std::move(rs)); if (typelist::contains()) return get_restriction_predicate_list_12(typelist::index_of(), std::move(rs)); + if (typelist::contains()) + FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported operation not allowed!" ); if (typelist::contains()) FC_THROW_EXCEPTION( fc::assert_exception, "Virtual operations not allowed!" ); @@ -66,6 +68,7 @@ restriction_predicate_function get_restriction_predicate(vector rs, operation_list_7::list, operation_list_8::list, operation_list_9::list, operation_list_10::list, operation_list_11::list, operation_list_12::list, + unsupported_operations_list::list, virtual_operations_list::list>, Op>(), ""); FC_THROW_EXCEPTION(fc::assert_exception, diff --git a/libraries/protocol/custom_authorities/sliced_lists.hxx b/libraries/protocol/custom_authorities/sliced_lists.hxx index f26b3b77ef..d1ffbfb70c 100644 --- a/libraries/protocol/custom_authorities/sliced_lists.hxx +++ b/libraries/protocol/custom_authorities/sliced_lists.hxx @@ -32,21 +32,58 @@ namespace typelist = fc::typelist; // 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>; using operation_list_2 = static_variant>; -using operation_list_3 = static_variant>; +static_assert(typelist::index_of() == 9, + "Custom Active Authorities do not support account_transfer_operation"); +using operation_list_3 = static_variant>; using operation_list_4 = static_variant>; using operation_list_5 = static_variant>; using operation_list_6 = static_variant>; using operation_list_7 = static_variant>; -using operation_list_8 = static_variant>; +using operation_list_8 = static_variant>; +static_assert(typelist::index_of() == 31, + "Custom Active Authorities do not support committee_member_update_global_parameters_operation"); using operation_list_9 = static_variant>; -using operation_list_10 = static_variant>; +using operation_list_10 = static_variant>; +static_assert(typelist::index_of() == 40, + "Custom Active Authorities do not support blind_transfer_operation"); +static_assert(typelist::index_of() == 41, + "Custom Active Authorities do not support transfer_from_blind_operation"); +static_assert(typelist::index_of() == 42, + "Custom Active Authorities do not support asset_settle_cancel_operation"); using operation_list_11 = static_variant ::add // 43 ::add // 45 - ::add_list> + ::add // 47 + ::add // 49 + ::add // 50 ::add // 52 ::finalize>; -using operation_list_12 = static_variant>; +static_assert(typelist::index_of() == 44, + "Custom Active Authorities do not support fba_distribute_operation"); +static_assert(typelist::index_of() == 46, + "Custom Active Authorities do not support execute_bid_operation"); +static_assert(typelist::index_of() == 48, + "Custom Active Authorities do not support asset_update_issuer_operation"); +static_assert(typelist::index_of() == 51, + "Custom Active Authorities do not support htlc_redeemed_operation"); +static_assert(typelist::index_of() == 53, + "Custom Active Authorities do not support htlc_refund_operation"); +static_assert(typelist::index_of() == 54, + "Custom Active Authorities do not support custom_authority_create_operation"); +static_assert(typelist::index_of() == 55, + "Custom Active Authorities do not support custom_authority_update_operation"); +static_assert(typelist::index_of() == 56, + "Custom Active Authorities do not support custom_authority_delete_operation"); +using operation_list_12 = static_variant>; +using unsupported_operations_list = static_variant; using virtual_operations_list = static_variant Date: Wed, 17 Jun 2020 19:07:38 -0500 Subject: [PATCH 07/10] [BSIP40] Add some hash argument types See: https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401604111 I can still get away with reordering the list like this because it's never been released yet. --- .../include/graphene/protocol/restriction.hpp | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/libraries/protocol/include/graphene/protocol/restriction.hpp b/libraries/protocol/include/graphene/protocol/restriction.hpp index a03736f400..c77e0b8495 100644 --- a/libraries/protocol/include/graphene/protocol/restriction.hpp +++ b/libraries/protocol/include/graphene/protocol/restriction.hpp @@ -59,36 +59,39 @@ struct restriction { /* 3 */ string, \ /* 4 */ time_point_sec, \ /* 5 */ public_key_type, \ - /* 6 */ fc::sha256, \ - /* 7 */ account_id_type, \ - /* 8 */ asset_id_type, \ - /* 9 */ htlc_id_type, \ - /* 10 */ committee_member_id_type, \ - /* 11 */ witness_id_type, \ - /* 12 */ limit_order_id_type, \ - /* 13 */ proposal_id_type, \ - /* 14 */ withdraw_permission_id_type, \ - /* 15 */ vesting_balance_id_type, \ - /* 16 */ balance_id_type, \ - /* 17 */ flat_set, \ - /* 18 */ flat_set, \ - /* 19 */ flat_set, \ - /* 20 */ flat_set, \ - /* 21 */ flat_set, \ - /* 22 */ flat_set, \ - /* 23 */ flat_set, \ - /* 24 */ flat_set, \ - /* 25 */ flat_set, \ - /* 26 */ flat_set, \ - /* 27 */ flat_set, \ - /* 28 */ flat_set, \ - /* 29 */ flat_set, \ - /* 30 */ flat_set, \ - /* 31 */ flat_set, \ - /* 32 */ flat_set, \ - /* 33 */ vector, \ - /* 34 */ vector>, \ - /* 35 */ variant_assert_argument_type + /* 6 */ fc::sha1, \ + /* 7 */ fc::sha256, \ + /* 8 */ fc::ripemd160, \ + /* 9 */ fc::hash160, \ + /* 10 */ account_id_type, \ + /* 11 */ asset_id_type, \ + /* 12 */ htlc_id_type, \ + /* 13 */ committee_member_id_type, \ + /* 14 */ witness_id_type, \ + /* 15 */ limit_order_id_type, \ + /* 16 */ proposal_id_type, \ + /* 17 */ withdraw_permission_id_type, \ + /* 18 */ vesting_balance_id_type, \ + /* 19 */ balance_id_type, \ + /* 20 */ flat_set, \ + /* 21 */ flat_set, \ + /* 22 */ flat_set, \ + /* 23 */ flat_set, \ + /* 24 */ flat_set, \ + /* 25 */ flat_set, \ + /* 26 */ flat_set, \ + /* 27 */ flat_set, \ + /* 28 */ flat_set, \ + /* 29 */ flat_set, \ + /* 30 */ flat_set, \ + /* 31 */ flat_set, \ + /* 32 */ flat_set, \ + /* 33 */ flat_set, \ + /* 34 */ flat_set, \ + /* 35 */ flat_set, \ + /* 36 */ vector, \ + /* 37 */ vector>, \ + /* 38 */ variant_assert_argument_type using argument_type = fc::static_variant; From 4e81e2b1a3d29521c227e6de9aa3b26f84140142 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 20:04:38 -0500 Subject: [PATCH 08/10] [BSIP40] Stringified and variant comparisons Now allows ==, !=, <, <=, >, >= for stringish types (including hashes and vectors), container size vs int, and static_variant.which() values vs int. vector is no longer considered a container, but is considered stringish See: https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401604111 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401635775 https://github.com/bitshares/bitshares-core/pull/ 2093#discussion_r401642590 --- .../restriction_predicate.hxx | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/libraries/protocol/custom_authorities/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index 6b16f8b8a7..2dede89e19 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.hxx +++ b/libraries/protocol/custom_authorities/restriction_predicate.hxx @@ -62,10 +62,37 @@ constexpr static bool comparable_types = !std::is_same::value && // Metafunction to check if type is a container template struct is_container_impl : std::false_type {}; +template<> +struct is_container_impl> : std::false_type {}; template struct is_container_impl().size())>> : std::true_type {}; template constexpr static bool is_container = is_container_impl::value; +// Metafunction to check if type is string-like +template +struct is_stringish_impl : std::false_type {}; +template<> +struct is_stringish_impl : std::true_type {}; +template<> +struct is_stringish_impl> : std::true_type {}; +template<> +struct is_stringish_impl : std::true_type {}; +template<> +struct is_stringish_impl : std::true_type {}; +template<> +struct is_stringish_impl : std::true_type {}; +template<> +struct is_stringish_impl : std::true_type {}; +template constexpr static bool is_stringish = is_stringish_impl::value; + +// Convert stringish types to strings +inline const string& to_string(const string& str) { return str; } +inline string to_string(const std::vector& vec) { return string(vec.begin(), vec.end()); } +inline string to_string(const fc::sha1& hash) { return hash.str(); } +inline string to_string(const fc::sha256& hash) { return hash.str(); } +inline string to_string(const fc::ripemd160& hash) { return hash.str(); } +inline string to_string(const fc::hash160& hash) { return hash.str(); } + // Type alias for a predicate on a particular field type template using object_restriction_predicate = std::function; @@ -166,11 +193,26 @@ struct predicate_eq && is_i constexpr bool operator()(const Field& f, const Argument& a) const { return safenum::equal(to_num(f), to_num(a)); } }; template +struct predicate_eq && is_stringish && + !std::is_same::value>> { + // Converting comparison, stringish types + constexpr static bool valid = true; + bool operator()(const Field& f, const Argument& a) const { return to_string(f) == to_string(a); } +}; +template struct predicate_eq && is_integral>> { // Compare container size against int constexpr static bool valid = true; bool operator()(const Field& f, const Argument& a) const { return safenum::equal(f.size(), to_num(a)); } }; +template +struct predicate_eq, Argument, std::enable_if_t>> { + // Compare static_variant.which() against int + constexpr static bool valid = true; + bool operator()(const static_variant& f, const Argument& a) const { + return safenum::equal(f.which(), to_num(a)); + } +}; template struct predicate_eq, Argument, std::enable_if_t>> : predicate_eq { @@ -215,6 +257,33 @@ struct predicate_compare && } }; template +struct predicate_compare && is_stringish && + !std::is_same::value>> { + // Converting comparison, stringish types + constexpr static bool valid = true; + constexpr int8_t operator()(const Field& f, const Argument& a) const { + auto sf = to_string(f); + auto sa = to_string(a); + return sf < sa? -1 : (sa < sf? 1 : 0); + } +}; +template +struct predicate_compare && is_integral>> + : public predicate_compare { + // Compare container size against int + using base = predicate_compare; + constexpr static bool valid = true; + bool operator()(const Field& f, const Argument& a) const { return base::operator()(f.size(), a); } +}; +template +struct predicate_compare, Argument, std::enable_if_t>> + : public predicate_compare { + // Compare static_variant.which() against int + using base = predicate_compare; + constexpr static bool valid = true; + bool operator()(const static_variant& f, const Argument& a) const { return base::operator()(f.which(), a); } +}; +template struct predicate_compare, Argument, void> : predicate_compare { // Compare optional value against comparable type constexpr static bool valid = true; From 0ac5399d632d26bacc0973f1a8e09fa6e8966958 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 20:33:26 -0500 Subject: [PATCH 09/10] Bump fc --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index 73a7f08f00..77fc2fe60d 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 73a7f08f00456b0984cd431dd8f55bd901282e15 +Subproject commit 77fc2fe60d762e49fe3a33398b1488ad24ac516d From c4acdf4c0ef89e3630619d13be725ba8a85de35e Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 22:41:21 -0500 Subject: [PATCH 10/10] [BSIP40] Fix test Add support for innteger comparisons against a stringish that is not a container, necessary because vector is no longer a container but only stringish. --- .../custom_authorities/restriction_predicate.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/protocol/custom_authorities/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index 2dede89e19..0f35b2a4cf 100644 --- a/libraries/protocol/custom_authorities/restriction_predicate.hxx +++ b/libraries/protocol/custom_authorities/restriction_predicate.hxx @@ -205,6 +205,13 @@ struct predicate_eq && is_ constexpr static bool valid = true; bool operator()(const Field& f, const Argument& a) const { return safenum::equal(f.size(), to_num(a)); } }; +template +struct predicate_eq && !is_container + && is_integral>> { + // Compare stringish size against int + constexpr static bool valid = true; + bool operator()(const Field& f, const Argument& a) const { return safenum::equal(to_string(f).size(), to_num(a)); } +}; template struct predicate_eq, Argument, std::enable_if_t>> { // Compare static_variant.which() against int @@ -275,6 +282,15 @@ struct predicate_compare & constexpr static bool valid = true; bool operator()(const Field& f, const Argument& a) const { return base::operator()(f.size(), a); } }; +template +struct predicate_compare && !is_container + && is_integral>> + : public predicate_compare { + // Compare stringish size against int + using base = predicate_compare; + constexpr static bool valid = true; + bool operator()(const Field& f, const Argument& a) const { return base::operator()(to_string(f).size(), a); } +}; template struct predicate_compare, Argument, std::enable_if_t>> : public predicate_compare {