19 #include <test/jtx/JSONRPCClient.h>
20 #include <ripple/json/json_reader.h>
21 #include <ripple/json/to_string.h>
22 #include <ripple/protocol/jss.h>
23 #include <ripple/server/Port.h>
24 #include <boost/beast/http/message.hpp>
25 #include <boost/beast/http/dynamic_body.hpp>
26 #include <boost/beast/http/string_body.hpp>
27 #include <boost/beast/http/read.hpp>
28 #include <boost/beast/http/write.hpp>
29 #include <boost/asio.hpp>
38 boost::asio::ip::tcp::endpoint
52 using namespace boost::asio::ip;
53 if(pp.
ip && pp.
ip->is_unspecified())
54 *pp.
ip = pp.
ip->is_v6() ? address{address_v6::loopback()} : address{address_v4::loopback()};
55 return { *pp.
ip, *pp.
port };
57 Throw<std::runtime_error>(
"Missing HTTP port");
61 template <
class ConstBufferSequence>
69 buffer_copy(buffer(&s[0], s.
size()), b);
73 boost::asio::ip::tcp::endpoint
ep_;
74 boost::asio::io_service
ios_;
76 boost::beast::multi_buffer
bin_;
77 boost::beast::multi_buffer
bout_;
106 using namespace boost::beast::http;
108 using namespace std::string_literals;
110 request<string_body> req;
111 req.method(boost::beast::http::verb::post);
114 req.insert(
"Content-Type",
"application/json; charset=UTF-8");
115 req.insert(
"Host",
ep_);
118 jr[jss::method] = cmd;
121 jr[jss::jsonrpc] =
"2.0";
122 jr[jss::ripplerpc] =
"2.0";
132 req.prepare_payload();
135 response<dynamic_body> res;
141 if(jv[
"result"].isMember(
"error"))
142 jv[
"error"] = jv[
"result"][
"error"];
143 if(jv[
"result"].isMember(
"status"))
144 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)
boost::optional< boost::asio::ip::address > ip
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)
std::string to_string(ListDisposition disposition)
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.
boost::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_
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.