Line data Source code
1 : // Copyright (c) 2023-2024 The Dash Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef BITCOIN_EVO_DMN_TYPES_H 6 : #define BITCOIN_EVO_DMN_TYPES_H 7 : 8 : #include <consensus/amount.h> 9 : 10 : #include <limits> 11 : #include <string_view> 12 : 13 : enum class MnType : uint16_t { 14 : Regular = 0, 15 : Evo = 1, 16 : COUNT, 17 : Invalid = std::numeric_limits<uint16_t>::max(), 18 : }; 19 : 20 : template<typename T> struct is_serializable_enum; 21 : template<> struct is_serializable_enum<MnType> : std::true_type {}; 22 : 23 : namespace dmn_types { 24 : 25 : struct mntype_struct 26 : { 27 : const int32_t voting_weight; 28 : const CAmount collat_amount; 29 : const std::string_view description; 30 : }; 31 : 32 : constexpr auto Regular = mntype_struct{ 33 : .voting_weight = 1, 34 : .collat_amount = 1000 * COIN, 35 : .description = "Regular", 36 : }; 37 : constexpr auto Evo = mntype_struct{ 38 : .voting_weight = 4, 39 : .collat_amount = 4000 * COIN, 40 : .description = "Evo", 41 : }; 42 : constexpr auto Invalid = mntype_struct{ 43 : .voting_weight = 0, 44 : .collat_amount = MAX_MONEY, 45 : .description = "Invalid", 46 : }; 47 : 48 107 : [[nodiscard]] static constexpr bool IsCollateralAmount(CAmount amount) 49 : { 50 107 : return amount == Regular.collat_amount || 51 91 : amount == Evo.collat_amount; 52 : } 53 : 54 : } // namespace dmn_types 55 : 56 2372091 : [[nodiscard]] constexpr dmn_types::mntype_struct GetMnType(MnType type) 57 : { 58 2372091 : switch (type) { 59 2189410 : case MnType::Regular: return dmn_types::Regular; 60 182681 : case MnType::Evo: return dmn_types::Evo; 61 0 : default: return dmn_types::Invalid; 62 : } 63 2372091 : } 64 : 65 6774 : [[nodiscard]] constexpr bool IsValidMnType(MnType type) { return type < MnType::COUNT; } 66 : 67 : #endif // BITCOIN_EVO_DMN_TYPES_H