19 #include <ripple/json/json_reader.h>
20 #include <ripple/json/to_string.h>
21 #include <ripple/protocol/jss.h>
22 #include <ripple/server/Port.h>
23 #include <boost/asio.hpp>
24 #include <boost/beast/http/dynamic_body.hpp>
25 #include <boost/beast/http/message.hpp>
26 #include <boost/beast/http/read.hpp>
27 #include <boost/beast/http/string_body.hpp>
28 #include <boost/beast/http/write.hpp>
30 #include <test/jtx/JSONRPCClient.h>
37 static boost::asio::ip::tcp::endpoint
51 using namespace boost::asio::ip;
52 if (pp.
ip && pp.
ip->is_unspecified())
53 *pp.
ip = pp.
ip->is_v6() ? address{address_v6::loopback()}
54 : address{address_v4::loopback()};
57 Throw<std::runtime_error>(
"Missing HTTP port");
61 template <
class ConstBufferSequence>
68 buffer_copy(buffer(&s[0], s.
size()), b);
72 boost::asio::ip::tcp::endpoint
ep_;
73 boost::asio::io_service
ios_;
75 boost::beast::multi_buffer
bin_;
76 boost::beast::multi_buffer
bout_;
101 using namespace boost::beast::http;
103 using namespace std::string_literals;
105 request<string_body> req;
106 req.method(boost::beast::http::verb::post);
109 req.insert(
"Content-Type",
"application/json; charset=UTF-8");
113 req.insert(
"Host", ostr.
str());
117 jr[jss::method] = cmd;
120 jr[jss::jsonrpc] =
"2.0";
121 jr[jss::ripplerpc] =
"2.0";
131 req.prepare_payload();
134 response<dynamic_body> res;
140 if (jv[
"result"].isMember(
"error"))
141 jv[
"error"] = jv[
"result"][
"error"];
142 if (jv[
"result"].isMember(
"status"))
143 jv[
"status"] = jv[
"result"][
"status"];
157 return std::make_unique<JSONRPCClient>(cfg, rpc_version);
JSONRPCClient(Config const &cfg, unsigned rpc_version)
@ 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.
boost::asio::ip::tcp::endpoint ep_
static boost::asio::ip::tcp::endpoint getEndpoint(BasicConfig const &cfg)
void parse_Port(ParsedPort &port, Section const §ion, std::ostream &log)
Unserialize a JSON document into a Value.
boost::beast::multi_buffer bout_
Json::Value invoke(std::string const &cmd, Json::Value const ¶ms) override
Submit a command synchronously.
std::vector< std::string > const & values() const
Returns all the values in the section.
unsigned version() const override
Get RPC 1.0 or RPC 2.0.
Value & append(const Value &value)
Append value to array at the end.
boost::beast::multi_buffer bin_
boost::asio::io_service ios_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< boost::asio::ip::address > ip
std::optional< std::uint16_t > port
~JSONRPCClient() override
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
boost::asio::ip::tcp::socket stream_
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
static std::string buffer_string(ConstBufferSequence const &b)
std::set< std::string, boost::beast::iless > protocol
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.