20#include <test/jtx/JSONRPCClient.h>
22#include <xrpl/json/json_reader.h>
23#include <xrpl/json/to_string.h>
24#include <xrpl/protocol/jss.h>
25#include <xrpl/server/Port.h>
27#include <boost/asio.hpp>
28#include <boost/beast/http/dynamic_body.hpp>
29#include <boost/beast/http/message.hpp>
30#include <boost/beast/http/read.hpp>
31#include <boost/beast/http/string_body.hpp>
32#include <boost/beast/http/write.hpp>
41 static boost::asio::ip::tcp::endpoint
55 using namespace boost::asio::ip;
56 if (pp.
ip && pp.
ip->is_unspecified())
57 *pp.
ip = pp.
ip->is_v6() ? address{address_v6::loopback()}
58 : address{address_v4::loopback()};
61 Throw<std::runtime_error>(
"Use fixConfigPorts with auto ports");
65 Throw<std::runtime_error>(
"Missing HTTP port");
69 template <
class ConstBufferSequence>
76 buffer_copy(buffer(&s[0], s.
size()), b);
80 boost::asio::ip::tcp::endpoint
ep_;
81 boost::asio::io_context
ios_;
83 boost::beast::multi_buffer
bin_;
84 boost::beast::multi_buffer
bout_;
109 using namespace boost::beast::http;
111 using namespace std::string_literals;
113 request<string_body> req;
114 req.method(boost::beast::http::verb::post);
117 req.insert(
"Content-Type",
"application/json; charset=UTF-8");
121 req.insert(
"Host", ostr.
str());
125 jr[jss::method] = cmd;
128 jr[jss::jsonrpc] =
"2.0";
129 jr[jss::ripplerpc] =
"2.0";
139 req.prepare_payload();
142 response<dynamic_body> res;
148 if (jv[
"result"].isMember(
"error"))
149 jv[
"error"] = jv[
"result"][
"error"];
150 if (jv[
"result"].isMember(
"status"))
151 jv[
"status"] = jv[
"result"][
"status"];
Unserialize a JSON document into a Value.
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Value & append(Value const &value)
Append value to array at the end.
Holds unparsed configuration information.
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
std::vector< std::string > const & values() const
Returns all the values in the section.
static boost::asio::ip::tcp::endpoint getEndpoint(BasicConfig const &cfg)
unsigned version() const override
Get RPC 1.0 or RPC 2.0.
~JSONRPCClient() override
boost::asio::io_context ios_
boost::asio::ip::tcp::socket stream_
boost::asio::ip::tcp::endpoint ep_
boost::beast::multi_buffer bout_
JSONRPCClient(Config const &cfg, unsigned rpc_version)
Json::Value invoke(std::string const &cmd, Json::Value const ¶ms) override
Submit a command synchronously.
static std::string buffer_string(ConstBufferSequence const &b)
boost::beast::multi_buffer bin_
@ arrayValue
array value (ordered list)
std::unique_ptr< AbstractClient > makeJSONRPCClient(Config const &cfg, unsigned rpc_version)
Returns a client using JSON-RPC over HTTP/S.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void parse_Port(ParsedPort &port, Section const §ion, std::ostream &log)
std::string to_string(base_uint< Bits, Tag > const &a)
std::optional< std::uint16_t > port
std::set< std::string, boost::beast::iless > protocol
std::optional< boost::asio::ip::address > ip