mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 11:45:53 +00:00
partial refactor of CassandraBackend
This commit is contained in:
@@ -54,18 +54,13 @@ std::unordered_map<std::string, RPCCommand> commandMap{
|
||||
boost::json::object
|
||||
doAccountInfo(
|
||||
boost::json::object const& request,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& postgres);
|
||||
BackendInterface const& backend);
|
||||
boost::json::object
|
||||
doTx(
|
||||
boost::json::object const& request,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool);
|
||||
doTx(boost::json::object const& request, BackendInterface const& backend);
|
||||
boost::json::object
|
||||
doAccountTx(
|
||||
boost::json::object const& request,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool);
|
||||
BackendInterface const& backend);
|
||||
boost::json::object
|
||||
doLedgerData(
|
||||
boost::json::object const& request,
|
||||
@@ -73,14 +68,12 @@ doLedgerData(
|
||||
boost::json::object
|
||||
doBookOffers(
|
||||
boost::json::object const& request,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool);
|
||||
BackendInterface const& backend);
|
||||
|
||||
boost::json::object
|
||||
buildResponse(
|
||||
boost::json::object const& request,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool)
|
||||
BackendInterface const& backend)
|
||||
{
|
||||
std::string command = request.at("command").as_string().c_str();
|
||||
BOOST_LOG_TRIVIAL(info) << "Received rpc command : " << request;
|
||||
@@ -88,10 +81,10 @@ buildResponse(
|
||||
switch (commandMap[command])
|
||||
{
|
||||
case tx:
|
||||
return doTx(request, backend, pgPool);
|
||||
return doTx(request, backend);
|
||||
break;
|
||||
case account_tx:
|
||||
return doAccountTx(request, backend, pgPool);
|
||||
return doAccountTx(request, backend);
|
||||
break;
|
||||
case ledger:
|
||||
break;
|
||||
@@ -99,10 +92,10 @@ buildResponse(
|
||||
return doLedgerData(request, backend);
|
||||
break;
|
||||
case account_info:
|
||||
return doAccountInfo(request, backend, pgPool);
|
||||
return doAccountInfo(request, backend);
|
||||
break;
|
||||
case book_offers:
|
||||
return doBookOffers(request, backend, pgPool);
|
||||
return doBookOffers(request, backend);
|
||||
break;
|
||||
default:
|
||||
BOOST_LOG_TRIVIAL(error) << "Unknown command: " << command;
|
||||
@@ -123,15 +116,13 @@ class session : public std::enable_shared_from_this<session>
|
||||
boost::beast::flat_buffer buffer_;
|
||||
std::string response_;
|
||||
BackendInterface const& backend_;
|
||||
std::shared_ptr<PgPool>& pgPool_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
explicit session(
|
||||
boost::asio::ip::tcp::socket&& socket,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool)
|
||||
: ws_(std::move(socket)), backend_(backend), pgPool_(pgPool)
|
||||
BackendInterface const& backend)
|
||||
: ws_(std::move(socket)), backend_(backend)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -207,7 +198,7 @@ public:
|
||||
boost::json::value raw = boost::json::parse(msg);
|
||||
// BOOST_LOG_TRIVIAL(debug) << __func__ << " parsed";
|
||||
boost::json::object request = raw.as_object();
|
||||
auto response = buildResponse(request, backend_, pgPool_);
|
||||
auto response = buildResponse(request, backend_);
|
||||
BOOST_LOG_TRIVIAL(debug) << __func__ << response;
|
||||
response_ = boost::json::serialize(response);
|
||||
|
||||
@@ -243,15 +234,13 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
boost::asio::io_context& ioc_;
|
||||
boost::asio::ip::tcp::acceptor acceptor_;
|
||||
BackendInterface const& backend_;
|
||||
std::shared_ptr<PgPool>& pgPool_;
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
boost::asio::ip::tcp::endpoint endpoint,
|
||||
BackendInterface const& backend,
|
||||
std::shared_ptr<PgPool>& pgPool)
|
||||
: ioc_(ioc), acceptor_(ioc), backend_(backend), pgPool_(pgPool)
|
||||
BackendInterface const& backend)
|
||||
: ioc_(ioc), acceptor_(ioc), backend_(backend)
|
||||
{
|
||||
boost::beast::error_code ec;
|
||||
|
||||
@@ -316,8 +305,7 @@ private:
|
||||
else
|
||||
{
|
||||
// Create the session and run it
|
||||
std::make_shared<session>(std::move(socket), backend_, pgPool_)
|
||||
->run();
|
||||
std::make_shared<session>(std::move(socket), backend_)->run();
|
||||
}
|
||||
|
||||
// Accept another connection
|
||||
@@ -423,8 +411,7 @@ main(int argc, char* argv[])
|
||||
std::make_shared<listener>(
|
||||
ioc,
|
||||
boost::asio::ip::tcp::endpoint{address, port},
|
||||
etl.getFlatMapBackend(),
|
||||
etl.getPgPool())
|
||||
etl.getFlatMapBackend())
|
||||
->run();
|
||||
|
||||
// Run the I/O service on the requested number of threads
|
||||
|
||||
Reference in New Issue
Block a user