Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/bitcoin/network/impl/messages/rpc/dispatcher.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ inline external_t<Argument> CLASS::get_valued(const value_t& value) THROWS
const auto& internal = value.value();
using type = internal_t<Argument>;

if constexpr (is_shared_ptr<type>)
if constexpr (is_same_type<Argument, value_t> ||
is_same_type<type, value_t>)
return value;
else if constexpr (is_shared_ptr<type>)
return std::get<any_t>(internal).as<pointer_t<type>>();
else if constexpr (is_nullable<Argument>)
return { std::get<type>(internal) };
Expand Down
16 changes: 14 additions & 2 deletions include/bitcoin/network/messages/rpc/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <auto Default>
Expand Down Expand Up @@ -67,6 +67,18 @@ struct optional<Default>
static const type default_value() NOEXCEPT { return {}; }
};

/// value_t : optional<empty::value>
template <auto Default> requires
is_same_type<decltype(Default), empty> && (Default == empty::value)
struct optional<Default>
{
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)
Expand Down Expand Up @@ -139,7 +151,7 @@ template <typename Type> requires
is_same_type<Type, object_t> || is_same_type<Type, array_t> ||
is_same_type<Type, string_t> || is_same_type<Type, boolean_t> ||
is_same_type<Type, number_t> || is_integral_integer<Type> ||
is_shared_ptr<Type>
is_same_type<Type, value_t> || is_shared_ptr<Type>
struct nullable
{
using tag = nullable_tag;
Expand Down
Loading