1#include <test/jtx/JSONRPCClient.h>
3#include <xrpl/json/json_reader.h>
4#include <xrpl/json/to_string.h>
5#include <xrpl/protocol/jss.h>
6#include <xrpl/server/Port.h>
8#include <boost/asio.hpp>
9#include <boost/beast/http/dynamic_body.hpp>
10#include <boost/beast/http/message.hpp>
11#include <boost/beast/http/read.hpp>
12#include <boost/beast/http/string_body.hpp>
13#include <boost/beast/http/write.hpp>
22 static boost::asio::ip::tcp::endpoint
36 using namespace boost::asio::ip;
37 if (pp.
ip && pp.
ip->is_unspecified())
38 *pp.
ip = pp.
ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
41 Throw<std::runtime_error>(
"Use fixConfigPorts with auto ports");
45 Throw<std::runtime_error>(
"Missing HTTP port");
49 template <
class ConstBufferSequence>
56 buffer_copy(buffer(&s[0], s.
size()), b);
60 boost::asio::ip::tcp::endpoint
ep_;
61 boost::asio::io_context
ios_;
63 boost::beast::multi_buffer
bin_;
64 boost::beast::multi_buffer
bout_;
89 using namespace boost::beast::http;
91 using namespace std::string_literals;
93 request<string_body> req;
94 req.method(boost::beast::http::verb::post);
97 req.insert(
"Content-Type",
"application/json; charset=UTF-8");
101 req.insert(
"Host", ostr.
str());
105 jr[jss::method] = cmd;
108 jr[jss::jsonrpc] =
"2.0";
109 jr[jss::ripplerpc] =
"2.0";
119 req.prepare_payload();
122 response<dynamic_body> res;
128 if (jv[
"result"].isMember(
"error"))
129 jv[
"error"] = jv[
"result"][
"error"];
130 if (jv[
"result"].isMember(
"status"))
131 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 std::string buffer_string(ConstBufferSequence const &b)
unsigned version() const override
Get RPC 1.0 or RPC 2.0.
boost::asio::ip::tcp::endpoint ep_
boost::asio::ip::tcp::socket stream_
boost::beast::multi_buffer bout_
JSONRPCClient(Config const &cfg, unsigned rpc_version)
boost::beast::multi_buffer bin_
boost::asio::io_context ios_
static boost::asio::ip::tcp::endpoint getEndpoint(BasicConfig const &cfg)
~JSONRPCClient() override
Json::Value invoke(std::string const &cmd, Json::Value const ¶ms) override
Submit a command synchronously.
@ 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::set< std::string, boost::beast::iless > protocol
std::optional< boost::asio::ip::address > ip
std::optional< std::uint16_t > port