From 3c5f118b5904c48e1af5f810be5460dd7f1fee4a Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Thu, 18 Apr 2024 07:43:48 +0200 Subject: [PATCH] Fix: Add Tx Flags To Server Definitions (#304) --- src/magic/magic_enum.h | 166 ++++++++++-------- src/ripple/protocol/TxFlags.h | 116 +++++++----- src/ripple/protocol/jss.h | 90 +++++----- src/ripple/rpc/handlers/ServerDefinitions.cpp | 82 ++++++++- src/test/rpc/ServerDefinitions_test.cpp | 14 +- 5 files changed, 301 insertions(+), 167 deletions(-) diff --git a/src/magic/magic_enum.h b/src/magic/magic_enum.h index 095183d63..78b1d17cf 100644 --- a/src/magic/magic_enum.h +++ b/src/magic/magic_enum.h @@ -5,11 +5,11 @@ // | | | | (_| | (_| | | (__ | |____| | | | |_| | | | | | | | |____|_| |_| // |_| |_|\__,_|\__, |_|\___| |______|_| |_|\__,_|_| |_| |_| \_____| // __/ | https://github.com/Neargye/magic_enum -// |___/ version 0.9.3 +// |___/ version 0.9.5 // // Licensed under the MIT License . // SPDX-License-Identifier: MIT -// Copyright (c) 2019 - 2023 Daniil Goncharov . +// Copyright (c) 2019 - 2024 Daniil Goncharov . // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,7 @@ #define MAGIC_ENUM_VERSION_MAJOR 0 #define MAGIC_ENUM_VERSION_MINOR 9 -#define MAGIC_ENUM_VERSION_PATCH 3 +#define MAGIC_ENUM_VERSION_PATCH 5 #include #include @@ -60,7 +60,7 @@ #if defined(MAGIC_ENUM_NO_ASSERT) # define MAGIC_ENUM_ASSERT(...) static_cast(0) -#else +#elif !defined(MAGIC_ENUM_ASSERT) # include # define MAGIC_ENUM_ASSERT(...) assert((__VA_ARGS__)) #endif @@ -69,9 +69,11 @@ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-warning-option" # pragma clang diagnostic ignored "-Wenum-constexpr-conversion" +# pragma clang diagnostic ignored "-Wuseless-cast" // suppresses 'static_cast('\0')' for char_type = char (common on Linux). #elif defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // May be used uninitialized 'return {};'. +# pragma GCC diagnostic ignored "-Wuseless-cast" // suppresses 'static_cast('\0')' for char_type = char (common on Linux). #elif defined(_MSC_VER) # pragma warning(push) # pragma warning(disable : 26495) // Variable 'static_str::chars_' is uninitialized. @@ -164,14 +166,11 @@ namespace customize { // If need another range for specific enum type, add specialization enum_range for necessary enum type. template struct enum_range { - static_assert(std::is_enum_v, "magic_enum::customize::enum_range requires enum type."); static constexpr int min = MAGIC_ENUM_RANGE_MIN; static constexpr int max = MAGIC_ENUM_RANGE_MAX; - static_assert(max > min, "magic_enum::customize::enum_range requires max > min."); }; static_assert(MAGIC_ENUM_RANGE_MAX > MAGIC_ENUM_RANGE_MIN, "MAGIC_ENUM_RANGE_MAX must be greater than MAGIC_ENUM_RANGE_MIN."); -static_assert((MAGIC_ENUM_RANGE_MAX - MAGIC_ENUM_RANGE_MIN) < (std::numeric_limits::max)(), "MAGIC_ENUM_RANGE must be less than UINT16_MAX."); namespace detail { @@ -216,9 +215,9 @@ namespace detail { template struct supported #if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED || defined(MAGIC_ENUM_NO_CHECK_SUPPORT) - : std::true_type {}; + : std::true_type {}; #else - : std::false_type {}; + : std::false_type {}; #endif template , std::enable_if_t, int> = 0> @@ -423,10 +422,20 @@ constexpr auto n() noexcept { constexpr auto name_ptr = MAGIC_ENUM_GET_TYPE_NAME_BUILTIN(E); constexpr auto name = name_ptr ? str_view{name_ptr, std::char_traits::length(name_ptr)} : str_view{}; #elif defined(__clang__) - auto name = str_view{__PRETTY_FUNCTION__ + 34, sizeof(__PRETTY_FUNCTION__) - 36}; + str_view name; + if constexpr (sizeof(__PRETTY_FUNCTION__) == sizeof(__FUNCTION__)) { + static_assert(always_false_v, "magic_enum::detail::n requires __PRETTY_FUNCTION__."); + return str_view{}; + } else { + name.size_ = sizeof(__PRETTY_FUNCTION__) - 36; + name.str_ = __PRETTY_FUNCTION__ + 34; + } #elif defined(__GNUC__) auto name = str_view{__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1}; - if (name.str_[name.size_ - 1] == ']') { + if constexpr (sizeof(__PRETTY_FUNCTION__) == sizeof(__FUNCTION__)) { + static_assert(always_false_v, "magic_enum::detail::n requires __PRETTY_FUNCTION__."); + return str_view{}; + } else if (name.str_[name.size_ - 1] == ']') { name.size_ -= 50; name.str_ += 49; } else { @@ -489,7 +498,14 @@ constexpr auto n() noexcept { constexpr auto name_ptr = MAGIC_ENUM_GET_ENUM_NAME_BUILTIN(V); auto name = name_ptr ? str_view{name_ptr, std::char_traits::length(name_ptr)} : str_view{}; #elif defined(__clang__) - auto name = str_view{__PRETTY_FUNCTION__ + 34, sizeof(__PRETTY_FUNCTION__) - 36}; + str_view name; + if constexpr (sizeof(__PRETTY_FUNCTION__) == sizeof(__FUNCTION__)) { + static_assert(always_false_v, "magic_enum::detail::n requires __PRETTY_FUNCTION__."); + return str_view{}; + } else { + name.size_ = sizeof(__PRETTY_FUNCTION__) - 36; + name.str_ = __PRETTY_FUNCTION__ + 34; + } if (name.size_ > 22 && name.str_[0] == '(' && name.str_[1] == 'a' && name.str_[10] == ' ' && name.str_[22] == ':') { name.size_ -= 23; name.str_ += 23; @@ -499,7 +515,10 @@ constexpr auto n() noexcept { } #elif defined(__GNUC__) auto name = str_view{__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1}; - if (name.str_[name.size_ - 1] == ']') { + if constexpr (sizeof(__PRETTY_FUNCTION__) == sizeof(__FUNCTION__)) { + static_assert(always_false_v, "magic_enum::detail::n requires __PRETTY_FUNCTION__."); + return str_view{}; + } else if (name.str_[name.size_ - 1] == ']') { name.size_ -= 55; name.str_ += 54; } else { @@ -698,7 +717,7 @@ constexpr void valid_count(bool* valid, std::size_t& count) noexcept { } \ } - MAGIC_ENUM_FOR_EACH_256(MAGIC_ENUM_V); + MAGIC_ENUM_FOR_EACH_256(MAGIC_ENUM_V) if constexpr ((I + 256) < Size) { valid_count(valid, count); @@ -750,7 +769,6 @@ constexpr auto values() noexcept { constexpr auto max = reflected_max(); constexpr auto range_size = max - min + 1; static_assert(range_size > 0, "magic_enum::enum_range requires valid size."); - static_assert(range_size < (std::numeric_limits::max)(), "magic_enum::enum_range requires valid size."); return values(); } @@ -807,7 +825,8 @@ inline constexpr auto max_v = (count_v > 0) ? static_cast(values_v constexpr auto names(std::index_sequence) noexcept { - return std::array{{enum_name_v[I]>...}}; + constexpr auto names = std::array{{enum_name_v[I]>...}}; + return names; } template @@ -818,7 +837,8 @@ using names_t = decltype((names_v)); template constexpr auto entries(std::index_sequence) noexcept { - return std::array, sizeof...(I)>{{{values_v[I], enum_name_v[I]>}...}}; + constexpr auto entries = std::array, sizeof...(I)>{{{values_v[I], enum_name_v[I]>}...}}; + return entries; } template @@ -845,17 +865,16 @@ constexpr bool is_sparse() noexcept { template > inline constexpr bool is_sparse_v = is_sparse(); -template > -constexpr U values_ors() noexcept { - static_assert(S == enum_subtype::flags, "magic_enum::detail::values_ors requires valid subtype."); - - auto ors = U{0}; - for (std::size_t i = 0; i < count_v; ++i) { - ors |= static_cast(values_v[i]); - } +template +struct is_reflected +#if defined(MAGIC_ENUM_NO_CHECK_REFLECTED_ENUM) + : std::true_type {}; +#else + : std::bool_constant && (count_v != 0)> {}; +#endif - return ors; -} +template +inline constexpr bool is_reflected_v = is_reflected, S>{}; template struct enable_if_enum {}; @@ -1156,6 +1175,7 @@ template > template > [[nodiscard]] constexpr auto enum_value(std::size_t index) noexcept -> detail::enable_if_t> { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); if constexpr (detail::is_sparse_v) { return MAGIC_ENUM_ASSERT(index < detail::count_v), detail::values_v[index]; @@ -1170,6 +1190,7 @@ template > template > [[nodiscard]] constexpr auto enum_value() noexcept -> detail::enable_if_t> { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); static_assert(I < detail::count_v, "magic_enum::enum_value out of range."); return enum_value(I); @@ -1178,7 +1199,10 @@ template > [[nodiscard]] constexpr auto enum_values() noexcept -> detail::enable_if_t> { - return detail::values_v, S>; + using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); + + return detail::values_v; } // Returns integer value from enum value. @@ -1199,11 +1223,9 @@ template > [[nodiscard]] constexpr auto enum_index(E value) noexcept -> detail::enable_if_t> { using D = std::decay_t; using U = underlying_type_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); - if constexpr (detail::count_v == 0) { - static_cast(value); - return {}; // Empty enum. - } else if constexpr (detail::is_sparse_v || (S == detail::enum_subtype::flags)) { + if constexpr (detail::is_sparse_v || (S == detail::enum_subtype::flags)) { #if defined(MAGIC_ENUM_ENABLE_HASH) return detail::constexpr_switch<&detail::values_v, detail::case_call_t::index>( [](std::size_t i) { return optional{i}; }, @@ -1231,14 +1253,17 @@ template > template [[nodiscard]] constexpr auto enum_index(E value) noexcept -> detail::enable_if_t> { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); return enum_index(value); } // Obtains index in enum values from static storage enum variable. template >> -[[nodiscard]] constexpr auto enum_index() noexcept -> detail::enable_if_t { - constexpr auto index = enum_index, S>(V); +[[nodiscard]] constexpr auto enum_index() noexcept -> detail::enable_if_t {\ + using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); + constexpr auto index = enum_index(V); static_assert(index, "magic_enum::enum_index enum value does not have a index."); return *index; @@ -1259,6 +1284,7 @@ template template > [[nodiscard]] constexpr auto enum_name(E value) noexcept -> detail::enable_if_t { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); if (const auto i = enum_index(value)) { return detail::names_v[*i]; @@ -1271,6 +1297,7 @@ template > template [[nodiscard]] constexpr auto enum_name(E value) -> detail::enable_if_t { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); return enum_name(value); } @@ -1278,13 +1305,19 @@ template // Returns std::array with names, sorted by enum value. template > [[nodiscard]] constexpr auto enum_names() noexcept -> detail::enable_if_t> { - return detail::names_v, S>; + using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); + + return detail::names_v; } // Returns std::array with pairs (value, name), sorted by enum value. template > [[nodiscard]] constexpr auto enum_entries() noexcept -> detail::enable_if_t> { - return detail::entries_v, S>; + using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); + + return detail::entries_v; } // Allows you to write magic_enum::enum_cast("bar", magic_enum::case_insensitive); @@ -1295,31 +1328,27 @@ inline constexpr auto case_insensitive = detail::case_insensitive<>{}; template > [[nodiscard]] constexpr auto enum_cast(underlying_type_t value) noexcept -> detail::enable_if_t>> { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); - if constexpr (detail::count_v == 0) { - static_cast(value); - return {}; // Empty enum. - } else { - if constexpr (detail::is_sparse_v || (S == detail::enum_subtype::flags)) { + if constexpr (detail::is_sparse_v || (S == detail::enum_subtype::flags)) { #if defined(MAGIC_ENUM_ENABLE_HASH) - return detail::constexpr_switch<&detail::values_v, detail::case_call_t::value>( - [](D v) { return optional{v}; }, - static_cast(value), - detail::default_result_type_lambda>); + return detail::constexpr_switch<&detail::values_v, detail::case_call_t::value>( + [](D v) { return optional{v}; }, + static_cast(value), + detail::default_result_type_lambda>); #else - for (std::size_t i = 0; i < detail::count_v; ++i) { - if (value == static_cast>(enum_value(i))) { - return static_cast(value); - } - } - return {}; // Invalid value or out of range. -#endif - } else { - if (value >= detail::min_v && value <= detail::max_v) { + for (std::size_t i = 0; i < detail::count_v; ++i) { + if (value == static_cast>(enum_value(i))) { return static_cast(value); } - return {}; // Invalid value or out of range. } + return {}; // Invalid value or out of range. +#endif + } else { + if (value >= detail::min_v && value <= detail::max_v) { + return static_cast(value); + } + return {}; // Invalid value or out of range. } } @@ -1328,26 +1357,23 @@ template > template , typename BinaryPredicate = std::equal_to<>> [[nodiscard]] constexpr auto enum_cast(string_view value, [[maybe_unused]] BinaryPredicate p = {}) noexcept(detail::is_nothrow_invocable()) -> detail::enable_if_t>, BinaryPredicate> { using D = std::decay_t; + static_assert(detail::is_reflected_v, "magic_enum requires enum implementation and valid max and min."); - if constexpr (detail::count_v == 0) { - static_cast(value); - return {}; // Empty enum. #if defined(MAGIC_ENUM_ENABLE_HASH) - } else if constexpr (detail::is_default_predicate()) { - return detail::constexpr_switch<&detail::names_v, detail::case_call_t::index>( - [](std::size_t i) { return optional{detail::values_v[i]}; }, - value, - detail::default_result_type_lambda>, - [&p](string_view lhs, string_view rhs) { return detail::cmp_equal(lhs, rhs, p); }); + if constexpr (detail::is_default_predicate()) { + return detail::constexpr_switch<&detail::names_v, detail::case_call_t::index>( + [](std::size_t i) { return optional{detail::values_v[i]}; }, + value, + detail::default_result_type_lambda>, + [&p](string_view lhs, string_view rhs) { return detail::cmp_equal(lhs, rhs, p); }); + } #endif - } else { - for (std::size_t i = 0; i < detail::count_v; ++i) { - if (detail::cmp_equal(value, detail::names_v[i], p)) { - return enum_value(i); - } + for (std::size_t i = 0; i < detail::count_v; ++i) { + if (detail::cmp_equal(value, detail::names_v[i], p)) { + return enum_value(i); } - return {}; // Invalid value or out of range. } + return {}; // Invalid value or out of range. } // Checks whether enum contains value with such value. diff --git a/src/ripple/protocol/TxFlags.h b/src/ripple/protocol/TxFlags.h index b27104a67..b12558200 100644 --- a/src/ripple/protocol/TxFlags.h +++ b/src/ripple/protocol/TxFlags.h @@ -55,80 +55,98 @@ namespace ripple { // wrapped lines // clang-format off // Universal Transaction flags: -constexpr std::uint32_t tfFullyCanonicalSig = 0x80000000; +enum UniversalFlags : uint32_t { + tfFullyCanonicalSig = 0x80000000, +}; constexpr std::uint32_t tfUniversal = tfFullyCanonicalSig; constexpr std::uint32_t tfUniversalMask = ~tfUniversal; // AccountSet flags: -constexpr std::uint32_t tfRequireDestTag = 0x00010000; -constexpr std::uint32_t tfOptionalDestTag = 0x00020000; -constexpr std::uint32_t tfRequireAuth = 0x00040000; -constexpr std::uint32_t tfOptionalAuth = 0x00080000; -constexpr std::uint32_t tfDisallowXRP = 0x00100000; -constexpr std::uint32_t tfAllowXRP = 0x00200000; +enum AccountSetFlags : uint32_t { + tfRequireDestTag = 0x00010000, + tfOptionalDestTag = 0x00020000, + tfRequireAuth = 0x00040000, + tfOptionalAuth = 0x00080000, + tfDisallowXRP = 0x00100000, + tfAllowXRP = 0x00200000, +}; constexpr std::uint32_t tfAccountSetMask = ~(tfUniversal | tfRequireDestTag | tfOptionalDestTag | tfRequireAuth | tfOptionalAuth | tfDisallowXRP | tfAllowXRP); // AccountSet SetFlag/ClearFlag values -constexpr std::uint32_t asfRequireDest = 1; -constexpr std::uint32_t asfRequireAuth = 2; -constexpr std::uint32_t asfDisallowXRP = 3; -constexpr std::uint32_t asfDisableMaster = 4; -constexpr std::uint32_t asfAccountTxnID = 5; -constexpr std::uint32_t asfNoFreeze = 6; -constexpr std::uint32_t asfGlobalFreeze = 7; -constexpr std::uint32_t asfDefaultRipple = 8; -constexpr std::uint32_t asfDepositAuth = 9; -constexpr std::uint32_t asfAuthorizedNFTokenMinter = 10; -constexpr std::uint32_t asfTshCollect = 11; -constexpr std::uint32_t asfDisallowIncomingNFTokenOffer = 12; -constexpr std::uint32_t asfDisallowIncomingCheck = 13; -constexpr std::uint32_t asfDisallowIncomingPayChan = 14; -constexpr std::uint32_t asfDisallowIncomingTrustline = 15; -constexpr std::uint32_t asfDisallowIncomingRemit = 16; +enum AccountFlags : uint32_t { + asfRequireDest = 1, + asfRequireAuth = 2, + asfDisallowXRP = 3, + asfDisableMaster = 4, + asfAccountTxnID = 5, + asfNoFreeze = 6, + asfGlobalFreeze = 7, + asfDefaultRipple = 8, + asfDepositAuth = 9, + asfAuthorizedNFTokenMinter = 10, + asfTshCollect = 11, + asfDisallowIncomingNFTokenOffer = 12, + asfDisallowIncomingCheck = 13, + asfDisallowIncomingPayChan = 14, + asfDisallowIncomingTrustline = 15, + asfDisallowIncomingRemit = 16, +}; // OfferCreate flags: -constexpr std::uint32_t tfPassive = 0x00010000; -constexpr std::uint32_t tfImmediateOrCancel = 0x00020000; -constexpr std::uint32_t tfFillOrKill = 0x00040000; -constexpr std::uint32_t tfSell = 0x00080000; +enum OfferCreateFlags : uint32_t { + tfPassive = 0x00010000, + tfImmediateOrCancel = 0x00020000, + tfFillOrKill = 0x00040000, + tfSell = 0x00080000, +}; constexpr std::uint32_t tfOfferCreateMask = ~(tfUniversal | tfPassive | tfImmediateOrCancel | tfFillOrKill | tfSell); // Payment flags: -constexpr std::uint32_t tfNoRippleDirect = 0x00010000; -constexpr std::uint32_t tfPartialPayment = 0x00020000; -constexpr std::uint32_t tfLimitQuality = 0x00040000; +enum PaymentFlags : uint32_t { + tfNoRippleDirect = 0x00010000, + tfPartialPayment = 0x00020000, + tfLimitQuality = 0x00040000, +}; constexpr std::uint32_t tfPaymentMask = ~(tfUniversal | tfPartialPayment | tfLimitQuality | tfNoRippleDirect); // TrustSet flags: -constexpr std::uint32_t tfSetfAuth = 0x00010000; -constexpr std::uint32_t tfSetNoRipple = 0x00020000; -constexpr std::uint32_t tfClearNoRipple = 0x00040000; -constexpr std::uint32_t tfSetFreeze = 0x00100000; -constexpr std::uint32_t tfClearFreeze = 0x00200000; +enum TrustSetFlags : uint32_t { + tfSetfAuth = 0x00010000, + tfSetNoRipple = 0x00020000, + tfClearNoRipple = 0x00040000, + tfSetFreeze = 0x00100000, + tfClearFreeze = 0x00200000, +}; constexpr std::uint32_t tfTrustSetMask = ~(tfUniversal | tfSetfAuth | tfSetNoRipple | tfClearNoRipple | tfSetFreeze | tfClearFreeze); // EnableAmendment flags: -constexpr std::uint32_t tfGotMajority = 0x00010000; -constexpr std::uint32_t tfLostMajority = 0x00020000; -constexpr std::uint32_t tfTestSuite = 0x80000000; +enum EnableAmendmentFlags : std::uint32_t { + tfGotMajority = 0x00010000, + tfLostMajority = 0x00020000, + tfTestSuite = 0x80000000, +}; // PaymentChannelClaim flags: -constexpr std::uint32_t tfRenew = 0x00010000; -constexpr std::uint32_t tfClose = 0x00020000; +enum PaymentChannelClaimFlags : uint32_t { + tfRenew = 0x00010000, + tfClose = 0x00020000, +}; constexpr std::uint32_t tfPayChanClaimMask = ~(tfUniversal | tfRenew | tfClose); // NFTokenMint flags: -constexpr std::uint32_t const tfBurnable = 0x00000001; -constexpr std::uint32_t const tfOnlyXRP = 0x00000002; -constexpr std::uint32_t const tfTrustLine = 0x00000004; -constexpr std::uint32_t const tfTransferable = 0x00000008; -constexpr std::uint32_t const tfStrongTSH = 0x00008000; +enum NFTokenMintFlags : uint32_t { + tfBurnable = 0x00000001, + tfOnlyXRP = 0x00000002, + tfTrustLine = 0x00000004, + tfTransferable = 0x00000008, + tfStrongTSH = 0x00008000, +}; constexpr std::uint32_t const tfNFTokenMintOldMask = ~(tfUniversal | tfBurnable | tfOnlyXRP | tfTrustLine | tfTransferable | tfStrongTSH); @@ -151,7 +169,9 @@ constexpr std::uint32_t const tfNFTokenMintMask = ~(tfUniversal | tfBurnable | tfOnlyXRP | tfTransferable | tfStrongTSH); // NFTokenCreateOffer flags: -constexpr std::uint32_t const tfSellNFToken = 0x00000001; +enum NFTokenCreateOfferFlags : uint32_t { + tfSellNFToken = 0x00000001, +}; constexpr std::uint32_t const tfNFTokenCreateOfferMask = ~(tfUniversal | tfSellNFToken); @@ -166,7 +186,9 @@ constexpr std::uint32_t const tfURITokenMintMask = ~(tfUniversal | tfBurnable); constexpr std::uint32_t const tfURITokenNonMintMask = ~tfUniversal; // ClaimReward flags: -constexpr std::uint32_t const tfOptOut = 0x00000001; +enum ClaimRewardFlags : uint32_t { + tfOptOut = 0x00000001, +}; // clang-format on diff --git a/src/ripple/protocol/jss.h b/src/ripple/protocol/jss.h index 31cf8385b..b5ed722e2 100644 --- a/src/ripple/protocol/jss.h +++ b/src/ripple/protocol/jss.h @@ -665,50 +665,52 @@ JSS(trusted); // out: UnlList JSS(trusted_validator_keys); // out: ValidatorList JSS(tx); // out: STTx, AccountTx* JSS(txroot); -JSS(tx_blob); // in/out: Submit, - // in: TransactionSign, AccountTx* -JSS(tx_hash); // in: TransactionEntry -JSS(tx_json); // in/out: TransactionSign - // out: TransactionEntry -JSS(tx_signing_hash); // out: TransactionSign -JSS(tx_unsigned); // out: TransactionSign -JSS(txn_count); // out: NetworkOPs -JSS(txr_tx_cnt); // out: protocol message tx's count -JSS(txr_tx_sz); // out: protocol message tx's size -JSS(txr_have_txs_cnt); // out: protocol message have tx count -JSS(txr_have_txs_sz); // out: protocol message have tx size -JSS(txr_get_ledger_cnt); // out: protocol message get ledger count -JSS(txr_get_ledger_sz); // out: protocol message get ledger size -JSS(txr_ledger_data_cnt); // out: protocol message ledger data count -JSS(txr_ledger_data_sz); // out: protocol message ledger data size -JSS(txr_transactions_cnt); // out: protocol message get object count -JSS(txr_transactions_sz); // out: protocol message get object size -JSS(txr_selected_cnt); // out: selected peers count -JSS(txr_suppressed_cnt); // out: suppressed peers count -JSS(txr_not_enabled_cnt); // out: peers with tx reduce-relay disabled count -JSS(txr_missing_tx_freq); // out: missing tx frequency average -JSS(txs); // out: TxHistory -JSS(type); // in: AccountObjects - // out: NetworkOPs RPC server_definitions - // OverlayImpl, Logic -JSS(TRANSACTION_RESULTS); // out: RPC server_definitions -JSS(TRANSACTION_TYPES); // out: RPC server_definitions -JSS(TYPES); // out: RPC server_definitions -JSS(type_hex); // out: STPathSet -JSS(unl); // out: UnlList -JSS(unlimited); // out: Connection.h -JSS(uptime); // out: GetCounts -JSS(uri); // out: ValidatorSites -JSS(uri_token); // in: LedgerEntry -JSS(url); // in/out: Subscribe, Unsubscribe -JSS(url_password); // in: Subscribe -JSS(url_username); // in: Subscribe -JSS(urlgravatar); // -JSS(username); // in: Subscribe -JSS(validated); // out: NetworkOPs, RPCHelpers, AccountTx* - // Tx -JSS(validator_list_expires); // out: NetworkOps, ValidatorList -JSS(validator_list); // out: NetworkOps, ValidatorList +JSS(tx_blob); // in/out: Submit, + // in: TransactionSign, AccountTx* +JSS(tx_hash); // in: TransactionEntry +JSS(tx_json); // in/out: TransactionSign + // out: TransactionEntry +JSS(tx_signing_hash); // out: TransactionSign +JSS(tx_unsigned); // out: TransactionSign +JSS(txn_count); // out: NetworkOPs +JSS(txr_tx_cnt); // out: protocol message tx's count +JSS(txr_tx_sz); // out: protocol message tx's size +JSS(txr_have_txs_cnt); // out: protocol message have tx count +JSS(txr_have_txs_sz); // out: protocol message have tx size +JSS(txr_get_ledger_cnt); // out: protocol message get ledger count +JSS(txr_get_ledger_sz); // out: protocol message get ledger size +JSS(txr_ledger_data_cnt); // out: protocol message ledger data count +JSS(txr_ledger_data_sz); // out: protocol message ledger data size +JSS(txr_transactions_cnt); // out: protocol message get object count +JSS(txr_transactions_sz); // out: protocol message get object size +JSS(txr_selected_cnt); // out: selected peers count +JSS(txr_suppressed_cnt); // out: suppressed peers count +JSS(txr_not_enabled_cnt); // out: peers with tx reduce-relay disabled count +JSS(txr_missing_tx_freq); // out: missing tx frequency average +JSS(txs); // out: TxHistory +JSS(type); // in: AccountObjects + // out: NetworkOPs RPC server_definitions + // OverlayImpl, Logic +JSS(TRANSACTION_RESULTS); // out: RPC server_definitions +JSS(TRANSACTION_TYPES); // out: RPC server_definitions +JSS(TYPES); // out: RPC server_definitions +JSS(TRANSACTION_FLAGS); // out: RPC server_definitions +JSS(TRANSACTION_FLAGS_INDICIES); // out: RPC server_definitions +JSS(type_hex); // out: STPathSet +JSS(unl); // out: UnlList +JSS(unlimited); // out: Connection.h +JSS(uptime); // out: GetCounts +JSS(uri); // out: ValidatorSites +JSS(uri_token); // in: LedgerEntry +JSS(url); // in/out: Subscribe, Unsubscribe +JSS(url_password); // in: Subscribe +JSS(url_username); // in: Subscribe +JSS(urlgravatar); // +JSS(username); // in: Subscribe +JSS(validated); // out: NetworkOPs, RPCHelpers, AccountTx* + // Tx +JSS(validator_list_expires); // out: NetworkOps, ValidatorList +JSS(validator_list); // out: NetworkOps, ValidatorList JSS(validators); JSS(validated_hash); // out: NetworkOPs JSS(validated_ledger); // out: NetworkOPs diff --git a/src/ripple/rpc/handlers/ServerDefinitions.cpp b/src/ripple/rpc/handlers/ServerDefinitions.cpp index a7954b99a..871afe6d7 100644 --- a/src/ripple/rpc/handlers/ServerDefinitions.cpp +++ b/src/ripple/rpc/handlers/ServerDefinitions.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#define MAGIC_ENUM_NO_CHECK_REFLECTED_ENUM + #include #include #include @@ -26,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +44,21 @@ static constexpr int max = 20000; \ }; +#define MAGIC_ENUM_16(x) \ + template <> \ + struct magic_enum::customize::enum_range \ + { \ + static constexpr int min = -128; \ + static constexpr int max = 127; \ + }; + +#define MAGIC_ENUM_FLAG(x) \ + template <> \ + struct magic_enum::customize::enum_range \ + { \ + static constexpr bool is_flags = true; \ + }; + MAGIC_ENUM(ripple::SerializedTypeID); MAGIC_ENUM(ripple::LedgerEntryType); MAGIC_ENUM(ripple::TELcodes); @@ -49,22 +67,45 @@ MAGIC_ENUM(ripple::TEFcodes); MAGIC_ENUM(ripple::TERcodes); MAGIC_ENUM(ripple::TEScodes); MAGIC_ENUM(ripple::TECcodes); +MAGIC_ENUM_16(ripple::TxType); +MAGIC_ENUM_FLAG(ripple::UniversalFlags); +MAGIC_ENUM_FLAG(ripple::AccountSetFlags); +MAGIC_ENUM_FLAG(ripple::OfferCreateFlags); +MAGIC_ENUM_FLAG(ripple::PaymentFlags); +MAGIC_ENUM_FLAG(ripple::TrustSetFlags); +MAGIC_ENUM_FLAG(ripple::EnableAmendmentFlags); +MAGIC_ENUM_FLAG(ripple::PaymentChannelClaimFlags); +MAGIC_ENUM_FLAG(ripple::NFTokenMintFlags); +MAGIC_ENUM_FLAG(ripple::NFTokenCreateOfferFlags); +MAGIC_ENUM_FLAG(ripple::ClaimRewardFlags); +MAGIC_ENUM_16(ripple::AccountFlags); namespace ripple { class Definitions { private: - Json::Value - generate() - { - // RH TODO: probably a better way to do this? #define STR(x) \ ([&] { \ std::ostringstream ss; \ return ss << (x), ss.str(); \ }()) + template + void + addFlagsToJson(Json::Value& json, std::string const& key) + { + for (auto const& entry : magic_enum::enum_entries()) + { + const auto name = entry.second; + json[jss::TRANSACTION_FLAGS][key][STR(name)] = + static_cast(entry.first); + } + } + + Json::Value + generate() + { Json::Value ret{Json::objectValue}; ret[jss::TYPES] = Json::objectValue; @@ -368,6 +409,39 @@ class Definitions ret[jss::TRANSACTION_TYPES][type_name] = type_value; } + // Transaction Flags: + ret[jss::TRANSACTION_FLAGS] = Json::objectValue; + addFlagsToJson(ret, "Universal"); + addFlagsToJson(ret, "AccountSet"); + addFlagsToJson(ret, "OfferCreate"); + addFlagsToJson(ret, "Payment"); + addFlagsToJson(ret, "TrustSet"); + addFlagsToJson(ret, "EnableAmendment"); + addFlagsToJson(ret, "PaymentChannelClaim"); + addFlagsToJson(ret, "NFTokenMint"); + addFlagsToJson(ret, "NFTokenCreateOffer"); + addFlagsToJson(ret, "ClaimReward"); + struct FlagData + { + std::string name; + std::uint32_t value; + }; + std::array uriTokenMintFlags{{{"tfBurnable", tfBurnable}}}; + for (auto const& entry : uriTokenMintFlags) + { + ret[jss::TRANSACTION_FLAGS]["URITokenMint"][entry.name] = + static_cast(entry.value); + } + + // Transaction Indicies Flags: + ret[jss::TRANSACTION_FLAGS_INDICIES] = Json::objectValue; + for (auto const& entry : magic_enum::enum_entries()) + { + const auto name = entry.second; + ret[jss::TRANSACTION_FLAGS_INDICIES]["AccountSet"][STR(name)] = + static_cast(entry.first); + } + ret[jss::native_currency_code] = systemCurrencyCode(); // generate hash diff --git a/src/test/rpc/ServerDefinitions_test.cpp b/src/test/rpc/ServerDefinitions_test.cpp index 7727f3934..82388aaf0 100644 --- a/src/test/rpc/ServerDefinitions_test.cpp +++ b/src/test/rpc/ServerDefinitions_test.cpp @@ -57,12 +57,16 @@ class ServerDefinitions_test : public beast::unit_test::suite { Env env(*this); auto const result = env.rpc("server_definitions"); + std::cout << "RESULT: " << result << "\n"; BEAST_EXPECT(!result[jss::result].isMember(jss::error)); BEAST_EXPECT(result[jss::result].isMember(jss::FIELDS)); BEAST_EXPECT(result[jss::result].isMember(jss::LEDGER_ENTRY_TYPES)); BEAST_EXPECT( result[jss::result].isMember(jss::TRANSACTION_RESULTS)); BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES)); + BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_FLAGS)); + BEAST_EXPECT( + result[jss::result].isMember(jss::TRANSACTION_FLAGS_INDICIES)); BEAST_EXPECT(result[jss::result].isMember(jss::TYPES)); BEAST_EXPECT(result[jss::result].isMember(jss::hash)); BEAST_EXPECT(result[jss::result][jss::status] == "success"); @@ -70,7 +74,7 @@ class ServerDefinitions_test : public beast::unit_test::suite } void - testDefitionsHash(FeatureBitset features) + testDefinitionsHash(FeatureBitset features) { testcase("Definitions Hash"); @@ -92,6 +96,9 @@ class ServerDefinitions_test : public beast::unit_test::suite BEAST_EXPECT( !result[jss::result].isMember(jss::TRANSACTION_RESULTS)); BEAST_EXPECT(!result[jss::result].isMember(jss::TRANSACTION_TYPES)); + BEAST_EXPECT(!result[jss::result].isMember(jss::TRANSACTION_FLAGS)); + BEAST_EXPECT( + !result[jss::result].isMember(jss::TRANSACTION_FLAGS_INDICIES)); BEAST_EXPECT(!result[jss::result].isMember(jss::TYPES)); BEAST_EXPECT(result[jss::result].isMember(jss::hash)); } @@ -113,6 +120,9 @@ class ServerDefinitions_test : public beast::unit_test::suite BEAST_EXPECT( result[jss::result].isMember(jss::TRANSACTION_RESULTS)); BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_TYPES)); + BEAST_EXPECT(result[jss::result].isMember(jss::TRANSACTION_FLAGS)); + BEAST_EXPECT( + result[jss::result].isMember(jss::TRANSACTION_FLAGS_INDICIES)); BEAST_EXPECT(result[jss::result].isMember(jss::TYPES)); BEAST_EXPECT(result[jss::result].isMember(jss::hash)); } @@ -330,7 +340,7 @@ class ServerDefinitions_test : public beast::unit_test::suite testServerDefinitions(FeatureBitset features) { testDefinitions(features); - testDefitionsHash(features); + testDefinitionsHash(features); } void