View in context in the libbitcoin Slack #general mirror.
boost::json does in fact provide full streaming capability to/from its DOM, it becomes very attractive to allow the network layer to simply parse/serialize to/from the json DOM for both the json-rpc request/response classes, and the contained request::params/response::result objects. These objects we defined as (tiny bit simplified):
namespace libbitcoin {
namespace network {
namespace json {
/// Enumeration of JSON-RPC protocol versions.
enum class version
{
/// Undefined version (not set).
undefined,
/// JSON-RPC 1.0 (bitcoin core).
v1,
/// JSON-RPC 2.0 (electrum daemon, electrum protocol, stratum v1).
v2,
/// Determine the version from the jsonrpc element.
any,
/// The jsonrpc value is invalid.
invalid
};
/// Forward declaration.
struct value_t;
struct null_t {};
using code_t = int64_t;
using boolean_t = bool;
using number_t = double;
using string_t = std::string;
using array_t = std::vector<value_t>;
using object_t = std::unordered_map<string_t, value_t>;
using identity_t = std::variant
<
null_t,
code_t,
string_t
>;
using id_option = std::optional<identity_t>;
struct value_t
{
using type = std::variant
<
null_t,
boolean_t,
number_t,
string_t,
array_t,
object_t
>;
type inner{};
};
using value_option = std::optional<value_t>;
using params_t = std::variant
<
array_t,
object_t
>;
using params_option = std::optional<params_t>;
struct BCT_API result_t
{
code_t code{};
string_t message{};
value_option data{};
};
using error_option = std::optional<result_t>;
struct BCT_API response_t
{
version jsonrpc{ version::undefined };
id_option id{};
error_option error{};
value_option result{};
};
struct BCT_API request_t
{
version jsonrpc{ version::undefined };
id_option id{};
string_t method{};
params_option params{};
};
} // namespace json
} // namespace network
} // namespace libbitcoin (edited)