diff --git a/include/bitcoin/network/impl/messages/rpc/dispatcher.ipp b/include/bitcoin/network/impl/messages/rpc/dispatcher.ipp index 276917bb7..9df8b3bcf 100644 --- a/include/bitcoin/network/impl/messages/rpc/dispatcher.ipp +++ b/include/bitcoin/network/impl/messages/rpc/dispatcher.ipp @@ -66,7 +66,10 @@ inline external_t CLASS::get_valued(const value_t& value) THROWS const auto& internal = value.value(); using type = internal_t; - if constexpr (is_shared_ptr) + if constexpr (is_same_type || + is_same_type) + return value; + else if constexpr (is_shared_ptr) return std::get(internal).as>(); else if constexpr (is_nullable) return { std::get(internal) }; diff --git a/include/bitcoin/network/messages/rpc/types.hpp b/include/bitcoin/network/messages/rpc/types.hpp index 5bd509303..44a770168 100644 --- a/include/bitcoin/network/messages/rpc/types.hpp +++ b/include/bitcoin/network/messages/rpc/types.hpp @@ -36,7 +36,7 @@ namespace rpc { /// --------------------------------------------------------------------------- struct optional_tag {}; -enum class empty { array, object }; +enum class empty { array, object, value }; /// Partial specializations for optional (values). template @@ -67,6 +67,18 @@ struct optional static const type default_value() NOEXCEPT { return {}; } }; +/// value_t : optional +template requires +is_same_type && (Default == empty::value) +struct optional +{ + using tag = optional_tag; + using type = value_t; + + /// value_t optional default is only/always empty. + static constexpr type default_value() NOEXCEPT { return {}; } +}; + /// int8_t : optional<42_i8> (int8_t) /// int16_t : optional<42_i16> (int16_t) /// int32_t : optional<42_i32> (int32_t) @@ -139,7 +151,7 @@ template requires is_same_type || is_same_type || is_same_type || is_same_type || is_same_type || is_integral_integer || - is_shared_ptr + is_same_type || is_shared_ptr struct nullable { using tag = nullable_tag;