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 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()); - }; - }); -} -} } 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/restriction_predicate.hxx b/libraries/protocol/custom_authorities/restriction_predicate.hxx index 9d2757b787..0f35b2a4cf 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 @@ -60,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; @@ -74,6 +103,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; @@ -163,12 +193,34 @@ 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 && !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 + 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 { // Compare optional value against comparable type @@ -197,7 +249,7 @@ struct predicate_comparea? 1 : 0); + return f @@ -212,6 +264,42 @@ 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 && !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 { + // 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; @@ -397,6 +485,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 +561,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 +686,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 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, \ /* 21 */ flat_set, \ @@ -81,20 +81,17 @@ struct restriction { /* 25 */ flat_set, \ /* 26 */ flat_set, \ /* 27 */ flat_set, \ - /* 28 */ 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 + /* 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;