folder reorg

This commit is contained in:
CJ Cobb
2021-06-07 22:56:44 -04:00
parent a2dddbcb8a
commit 58fe780714
45 changed files with 245 additions and 315 deletions

View File

@@ -36,7 +36,7 @@ add_executable (reporting_main
add_executable (reporting_tests add_executable (reporting_tests
unittests/main.cpp unittests/main.cpp
) )
add_library(reporting reporting/BackendInterface.h) add_library(reporting backend/BackendInterface.h)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps")
include(ExternalProject) include(ExternalProject)
message(${CMAKE_CURRENT_BINARY_DIR}) message(${CMAKE_CURRENT_BINARY_DIR})
@@ -67,17 +67,16 @@ include(Postgres)
target_sources(reporting PRIVATE target_sources(reporting PRIVATE
reporting/ETLSource.cpp backend/CassandraBackend.cpp
reporting/CassandraBackend.cpp backend/PostgresBackend.cpp
reporting/PostgresBackend.cpp backend/BackendIndexer.cpp
reporting/BackendIndexer.cpp backend/BackendInterface.cpp
reporting/BackendInterface.cpp backend/Pg.cpp
reporting/Pg.cpp backend/DBHelpers.cpp
reporting/P2pProxy.cpp etl/ETLSource.cpp
reporting/DBHelpers.cpp etl/ReportingETL.cpp
reporting/ReportingETL.cpp server/session.cpp
reporting/server/session.cpp server/SubscriptionManager.cpp
reporting/server/SubscriptionManager.cpp
handlers/AccountInfo.cpp handlers/AccountInfo.cpp
handlers/Tx.cpp handlers/Tx.cpp
handlers/RPCHelpers.cpp handlers/RPCHelpers.cpp

View File

@@ -2,9 +2,9 @@
#define RIPPLE_APP_REPORTING_BACKENDFACTORY_H_INCLUDED #define RIPPLE_APP_REPORTING_BACKENDFACTORY_H_INCLUDED
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
#include <reporting/CassandraBackend.h> #include <backend/CassandraBackend.h>
#include <reporting/PostgresBackend.h> #include <backend/PostgresBackend.h>
namespace Backend { namespace Backend {
std::unique_ptr<BackendInterface> std::unique_ptr<BackendInterface>

View File

@@ -1,4 +1,4 @@
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
namespace Backend { namespace Backend {
BackendIndexer::BackendIndexer(boost::json::object const& config) BackendIndexer::BackendIndexer(boost::json::object const& config)

View File

@@ -1,6 +1,6 @@
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
namespace Backend { namespace Backend {
bool bool
BackendInterface::finishWrites(uint32_t ledgerSequence) const BackendInterface::finishWrites(uint32_t ledgerSequence) const

View File

@@ -2,7 +2,7 @@
#define RIPPLE_APP_REPORTING_BACKENDINTERFACE_H_INCLUDED #define RIPPLE_APP_REPORTING_BACKENDINTERFACE_H_INCLUDED
#include <ripple/ledger/ReadView.h> #include <ripple/ledger/ReadView.h>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <reporting/DBHelpers.h> #include <backend/DBHelpers.h>
namespace std { namespace std {
template <> template <>
struct hash<ripple::uint256> struct hash<ripple::uint256>

View File

@@ -1,6 +1,6 @@
#include <functional> #include <functional>
#include <reporting/CassandraBackend.h> #include <backend/CassandraBackend.h>
#include <reporting/DBHelpers.h> #include <backend/DBHelpers.h>
#include <unordered_map> #include <unordered_map>
/* /*
namespace std { namespace std {

View File

@@ -31,8 +31,8 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
#include <reporting/DBHelpers.h> #include <backend/DBHelpers.h>
namespace Backend { namespace Backend {

View File

@@ -19,7 +19,7 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <memory> #include <memory>
#include <reporting/DBHelpers.h> #include <backend/DBHelpers.h>
static bool static bool
writeToLedgersDB(ripple::LedgerInfo const& info, PgQuery& pgQuery) writeToLedgersDB(ripple::LedgerInfo const& info, PgQuery& pgQuery)

View File

@@ -23,7 +23,7 @@
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/protocol/TxMeta.h> #include <ripple/protocol/TxMeta.h>
#include <boost/container/flat_set.hpp> #include <boost/container/flat_set.hpp>
#include <reporting/Pg.h> #include <backend/Pg.h>
/// Struct used to keep track of what to write to transactions and /// Struct used to keep track of what to write to transactions and
/// account_transactions tables in Postgres /// account_transactions tables in Postgres

View File

@@ -39,7 +39,7 @@
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <reporting/Pg.h> #include <backend/Pg.h>
#include <signal.h> #include <signal.h>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>

View File

@@ -1,6 +1,6 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <reporting/PostgresBackend.h> #include <backend/PostgresBackend.h>
namespace Backend { namespace Backend {
PostgresBackend::PostgresBackend(boost::json::object const& config) PostgresBackend::PostgresBackend(boost::json::object const& config)

View File

@@ -1,7 +1,7 @@
#ifndef RIPPLE_APP_REPORTING_POSTGRESBACKEND_H_INCLUDED #ifndef RIPPLE_APP_REPORTING_POSTGRESBACKEND_H_INCLUDED
#define RIPPLE_APP_REPORTING_POSTGRESBACKEND_H_INCLUDED #define RIPPLE_APP_REPORTING_POSTGRESBACKEND_H_INCLUDED
#include <boost/json.hpp> #include <boost/json.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
namespace Backend { namespace Backend {
class PostgresBackend : public BackendInterface class PostgresBackend : public BackendInterface

View File

@@ -19,15 +19,15 @@
*/ */
//============================================================================== //==============================================================================
#include <ripple/beast/net/IPEndpoint.h>
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <boost/asio/strand.hpp> #include <boost/asio/strand.hpp>
#include <boost/beast/http.hpp> #include <boost/beast/http.hpp>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <boost/json/src.hpp> #include <boost/json/src.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#include <ripple/beast/net/IPEndpoint.h> #include <etl/ETLSource.h>
#include <reporting/ETLSource.h> #include <etl/ReportingETL.h>
#include <reporting/ReportingETL.h>
// Create ETL source without grpc endpoint // Create ETL source without grpc endpoint
// Fetch ledger and load initial ledger will fail for this source // Fetch ledger and load initial ledger will fail for this source
@@ -578,13 +578,7 @@ ETLLoadBalancer::ETLLoadBalancer(
for (auto& entry : config) for (auto& entry : config)
{ {
std::unique_ptr<ETLSource> source = ETLSource::make_ETLSource( std::unique_ptr<ETLSource> source = ETLSource::make_ETLSource(
entry.as_object(), entry.as_object(), ioContext, backend, subscriptions, nwvl, *this);
ioContext,
backend,
subscriptions,
nwvl,
*this
);
sources_.push_back(std::move(source)); sources_.push_back(std::move(source));
BOOST_LOG_TRIVIAL(info) << __func__ << " : added etl source - " BOOST_LOG_TRIVIAL(info) << __func__ << " : added etl source - "
@@ -618,7 +612,7 @@ ETLLoadBalancer::fetchLedger(uint32_t ledgerSequence, bool getObjects)
auto [status, data] = auto [status, data] =
source->fetchLedger(ledgerSequence, getObjects); source->fetchLedger(ledgerSequence, getObjects);
response = std::move(data); response = std::move(data);
if (status.ok() && (response.validated()|| true)) if (status.ok() && (response.validated() || true))
{ {
BOOST_LOG_TRIVIAL(info) BOOST_LOG_TRIVIAL(info)
<< "Successfully fetched ledger = " << ledgerSequence << "Successfully fetched ledger = " << ledgerSequence
@@ -644,7 +638,7 @@ ETLLoadBalancer::fetchLedger(uint32_t ledgerSequence, bool getObjects)
} }
std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>
ETLLoadBalancer::getP2pForwardingStub() const ETLLoadBalancer::getRippledForwardingStub() const
{ {
if (sources_.size() == 0) if (sources_.size() == 0)
return nullptr; return nullptr;
@@ -653,7 +647,7 @@ ETLLoadBalancer::getP2pForwardingStub() const
auto numAttempts = 0; auto numAttempts = 0;
while (numAttempts < sources_.size()) while (numAttempts < sources_.size())
{ {
auto stub = sources_[sourceIdx]->getP2pForwardingStub(); auto stub = sources_[sourceIdx]->getRippledForwardingStub();
if (!stub) if (!stub)
{ {
sourceIdx = (sourceIdx + 1) % sources_.size(); sourceIdx = (sourceIdx + 1) % sources_.size();
@@ -666,7 +660,7 @@ ETLLoadBalancer::getP2pForwardingStub() const
} }
boost::json::object boost::json::object
ETLLoadBalancer::forwardToP2p(boost::json::object const& request) const ETLLoadBalancer::forwardToRippled(boost::json::object const& request) const
{ {
boost::json::object res; boost::json::object res;
if (sources_.size() == 0) if (sources_.size() == 0)
@@ -676,7 +670,7 @@ ETLLoadBalancer::forwardToP2p(boost::json::object const& request) const
auto numAttempts = 0; auto numAttempts = 0;
while (numAttempts < sources_.size()) while (numAttempts < sources_.size())
{ {
res = sources_[sourceIdx]->forwardToP2p(request); res = sources_[sourceIdx]->forwardToRippled(request);
if (!res.contains("forwarded") || res.at("forwarded") != true) if (!res.contains("forwarded") || res.at("forwarded") != true)
{ {
@@ -691,7 +685,7 @@ ETLLoadBalancer::forwardToP2p(boost::json::object const& request) const
} }
std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>
ETLSource::getP2pForwardingStub() const ETLSource::getRippledForwardingStub() const
{ {
if (!connected_) if (!connected_)
return nullptr; return nullptr;
@@ -712,7 +706,7 @@ ETLSource::getP2pForwardingStub() const
} }
boost::json::object boost::json::object
ETLSource::forwardToP2p(boost::json::object const& request) const ETLSource::forwardToRippled(boost::json::object const& request) const
{ {
BOOST_LOG_TRIVIAL(debug) << "Attempting to forward request to tx. " BOOST_LOG_TRIVIAL(debug) << "Attempting to forward request to tx. "
<< "request = " << boost::json::serialize(request); << "request = " << boost::json::serialize(request);
@@ -778,8 +772,7 @@ ETLSource::forwardToP2p(boost::json::object const& request) const
auto begin = static_cast<char const*>(buffer.data().data()); auto begin = static_cast<char const*>(buffer.data().data());
auto end = begin + buffer.data().size(); auto end = begin + buffer.data().size();
auto parsed = auto parsed = boost::json::parse(std::string(begin, end));
boost::json::parse(std::string(begin, end));
if (!parsed.is_object()) if (!parsed.is_object())
{ {
@@ -817,7 +810,7 @@ ETLLoadBalancer::execute(Func f, uint32_t ledgerSequence)
<< __func__ << " : " << __func__ << " : "
<< "Attempting to execute func. ledger sequence = " << "Attempting to execute func. ledger sequence = "
<< ledgerSequence << " - source = " << source->toString(); << ledgerSequence << " - source = " << source->toString();
if (source->hasLedger(ledgerSequence)|| true) if (source->hasLedger(ledgerSequence) || true)
{ {
bool res = f(source); bool res = f(source);
if (res) if (res)

View File

@@ -25,23 +25,23 @@
#include <boost/beast/core.hpp> #include <boost/beast/core.hpp>
#include <boost/beast/core/string.hpp> #include <boost/beast/core/string.hpp>
#include <boost/beast/websocket.hpp> #include <boost/beast/websocket.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
#include <reporting/server/SubscriptionManager.h> #include <server/SubscriptionManager.h>
#include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h" #include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h"
#include <grpcpp/grpcpp.h> #include <grpcpp/grpcpp.h>
#include <reporting/ETLHelpers.h> #include <etl/ETLHelpers.h>
class ETLLoadBalancer; class ETLLoadBalancer;
class SubscriptionManager; class SubscriptionManager;
/// This class manages a connection to a single ETL source. This is almost /// This class manages a connection to a single ETL source. This is almost
/// always a p2p node, but really could be another reporting node. This class /// always a rippled node, but really could be another reporting node. This
/// subscribes to the ledgers and transactions_proposed streams of the /// class subscribes to the ledgers and transactions_proposed streams of the
/// associated p2p node, and keeps track of which ledgers the p2p node has. This /// associated rippled node, and keeps track of which ledgers the rippled node
/// class also has methods for extracting said ledgers. Lastly this class /// has. This class also has methods for extracting said ledgers. Lastly this
/// forwards transactions received on the transactions_proposed streams to any /// class forwards transactions received on the transactions_proposed streams to
/// subscribers. /// any subscribers.
class ETLSource class ETLSource
{ {
@@ -316,13 +316,13 @@ public:
void void
close(bool startAgain); close(bool startAgain);
/// Get grpc stub to forward requests to p2p node /// Get grpc stub to forward requests to rippled node
/// @return stub to send requests to ETL source /// @return stub to send requests to ETL source
std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>
getP2pForwardingStub() const; getRippledForwardingStub() const;
boost::json::object boost::json::object
forwardToP2p(boost::json::object const& request) const; forwardToRippled(boost::json::object const& request) const;
}; };
/// This class is used to manage connections to transaction processing processes /// This class is used to manage connections to transaction processing processes
/// This class spawns a listener for each etl source, which listens to messages /// This class spawns a listener for each etl source, which listens to messages
@@ -420,16 +420,16 @@ public:
return ret; return ret;
} }
/// Randomly select a p2p node to forward a gRPC request to /// Randomly select a rippled node to forward a gRPC request to
/// @return gRPC stub to forward requests to p2p node /// @return gRPC stub to forward requests to rippled node
std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>
getP2pForwardingStub() const; getRippledForwardingStub() const;
/// Forward a JSON RPC request to a randomly selected p2p node /// Forward a JSON RPC request to a randomly selected rippled node
/// @param request JSON-RPC request /// @param request JSON-RPC request
/// @return response received from p2p node /// @return response received from rippled node
boost::json::object boost::json::object
forwardToP2p(boost::json::object const& request) const; forwardToRippled(boost::json::object const& request) const;
private: private:
/// f is a function that takes an ETLSource as an argument and returns a /// f is a function that takes an ETLSource as an argument and returns a

View File

@@ -18,8 +18,8 @@
//============================================================================== //==============================================================================
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <reporting/DBHelpers.h> #include <backend/DBHelpers.h>
#include <reporting/ReportingETL.h> #include <etl/ReportingETL.h>
#include <ripple/beast/core/CurrentThreadName.h> #include <ripple/beast/core/CurrentThreadName.h>
#include <boost/asio/connect.hpp> #include <boost/asio/connect.hpp>

View File

@@ -25,10 +25,9 @@
#include <boost/beast/core.hpp> #include <boost/beast/core.hpp>
#include <boost/beast/core/string.hpp> #include <boost/beast/core/string.hpp>
#include <boost/beast/websocket.hpp> #include <boost/beast/websocket.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
#include <reporting/ETLSource.h> #include <etl/ETLSource.h>
#include <reporting/Pg.h> #include <server/SubscriptionManager.h>
#include <reporting/server/SubscriptionManager.h>
#include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h" #include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h"
#include <grpcpp/grpcpp.h> #include <grpcpp/grpcpp.h>

View File

@@ -6,10 +6,8 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
#include <reporting/Pg.h>
void void
addChannel(boost::json::array& jsonLines, ripple::SLE const& line) addChannel(boost::json::array& jsonLines, ripple::SLE const& line)
@@ -17,7 +15,8 @@ addChannel(boost::json::array& jsonLines, ripple::SLE const& line)
boost::json::object jDst; boost::json::object jDst;
jDst["channel_id"] = ripple::to_string(line.key()); jDst["channel_id"] = ripple::to_string(line.key());
jDst["account"] = ripple::to_string(line.getAccountID(ripple::sfAccount)); jDst["account"] = ripple::to_string(line.getAccountID(ripple::sfAccount));
jDst["destination_account"] = ripple::to_string(line.getAccountID(ripple::sfDestination)); jDst["destination_account"] =
ripple::to_string(line.getAccountID(ripple::sfDestination));
jDst["amount"] = line[ripple::sfAmount].getText(); jDst["amount"] = line[ripple::sfAmount].getText();
jDst["balance"] = line[ripple::sfBalance].getText(); jDst["balance"] = line[ripple::sfBalance].getText();
if (publicKeyType(line[ripple::sfPublicKey])) if (publicKeyType(line[ripple::sfPublicKey]))
@@ -53,13 +52,13 @@ doAccountChannels(
return response; return response;
} }
if(!request.contains("account")) if (!request.contains("account"))
{ {
response["error"] = "Must contain account"; response["error"] = "Must contain account";
return response; return response;
} }
if(!request.at("account").is_string()) if (!request.at("account").is_string())
{ {
response["error"] = "Account must be a string"; response["error"] = "Account must be a string";
return response; return response;
@@ -98,7 +97,7 @@ doAccountChannels(
std::uint32_t limit = 200; std::uint32_t limit = 200;
if (request.contains("limit")) if (request.contains("limit"))
{ {
if(!request.at("limit").is_int64()) if (!request.at("limit").is_int64())
{ {
response["error"] = "limit must be integer"; response["error"] = "limit must be integer";
return response; return response;
@@ -115,7 +114,7 @@ doAccountChannels(
ripple::uint256 cursor = beast::zero; ripple::uint256 cursor = beast::zero;
if (request.contains("cursor")) if (request.contains("cursor"))
{ {
if(!request.at("cursor").is_string()) if (!request.at("cursor").is_string())
{ {
response["error"] = "limit must be string"; response["error"] = "limit must be string";
return response; return response;
@@ -151,13 +150,8 @@ doAccountChannels(
return true; return true;
}; };
auto nextCursor = auto nextCursor = traverseOwnedNodes(
traverseOwnedNodes( backend, accountID, *ledgerSequence, cursor, addToResponse);
backend,
accountID,
*ledgerSequence,
cursor,
addToResponse);
if (nextCursor) if (nextCursor)
response["next_cursor"] = ripple::strHex(*nextCursor); response["next_cursor"] = ripple::strHex(*nextCursor);

View File

@@ -6,10 +6,8 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
#include <reporting/Pg.h>
boost::json::object boost::json::object
doAccountCurrencies( doAccountCurrencies(
@@ -25,13 +23,13 @@ doAccountCurrencies(
return response; return response;
} }
if(!request.contains("account")) if (!request.contains("account"))
{ {
response["error"] = "Must contain account"; response["error"] = "Must contain account";
return response; return response;
} }
if(!request.at("account").is_string()) if (!request.at("account").is_string())
{ {
response["error"] = "Account must be a string"; response["error"] = "Account must be a string";
return response; return response;
@@ -49,7 +47,6 @@ doAccountCurrencies(
accountID = *parsed; accountID = *parsed;
std::set<std::string> send, receive; std::set<std::string> send, receive;
auto const addToResponse = [&](ripple::SLE const& sle) { auto const addToResponse = [&](ripple::SLE const& sle) {
if (sle.getType() == ripple::ltRIPPLE_STATE) if (sle.getType() == ripple::ltRIPPLE_STATE)
@@ -73,11 +70,7 @@ doAccountCurrencies(
}; };
traverseOwnedNodes( traverseOwnedNodes(
backend, backend, accountID, *ledgerSequence, beast::zero, addToResponse);
accountID,
*ledgerSequence,
beast::zero,
addToResponse);
response["send_currencies"] = boost::json::value(boost::json::array_kind); response["send_currencies"] = boost::json::value(boost::json::array_kind);
boost::json::array& jsonSend = response.at("send_currencies").as_array(); boost::json::array& jsonSend = response.at("send_currencies").as_array();
@@ -85,8 +78,10 @@ doAccountCurrencies(
for (auto const& currency : send) for (auto const& currency : send)
jsonSend.push_back(currency.c_str()); jsonSend.push_back(currency.c_str());
response["receive_currencies"] = boost::json::value(boost::json::array_kind); response["receive_currencies"] =
boost::json::array& jsonReceive = response.at("receive_currencies").as_array(); boost::json::value(boost::json::array_kind);
boost::json::array& jsonReceive =
response.at("receive_currencies").as_array();
for (auto const& currency : receive) for (auto const& currency : receive)
jsonReceive.push_back(currency.c_str()); jsonReceive.push_back(currency.c_str());

View File

@@ -21,7 +21,7 @@
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
// { // {
// account: <ident>, // account: <ident>,

View File

@@ -1,5 +1,5 @@
#include <ripple/app/paths/RippleState.h>
#include <ripple/app/ledger/Ledger.h> #include <ripple/app/ledger/Ledger.h>
#include <ripple/app/paths/RippleState.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/ErrorCodes.h> #include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
@@ -7,9 +7,8 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
void void
addLine( addLine(
@@ -39,13 +38,19 @@ addLine(
if (peerAccount and peerAccount != lineAccountIDPeer) if (peerAccount and peerAccount != lineAccountIDPeer)
return; return;
bool lineAuth = flags & (viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth); bool lineAuth =
bool lineAuthPeer = flags & (!viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth); flags & (viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
bool lineNoRipple = flags & (viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple); bool lineAuthPeer =
flags & (!viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
bool lineNoRipple =
flags & (viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
bool lineDefaultRipple = flags & ripple::lsfDefaultRipple; bool lineDefaultRipple = flags & ripple::lsfDefaultRipple;
bool lineNoRipplePeer = flags & (!viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple); bool lineNoRipplePeer = flags &
bool lineFreeze = flags & (viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze); (!viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
bool lineFreezePeer = flags & (!viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze); bool lineFreeze =
flags & (viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
bool lineFreezePeer =
flags & (!viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
ripple::STAmount const& saBalance(balance); ripple::STAmount const& saBalance(balance);
ripple::STAmount const& saLimit(lineLimit); ripple::STAmount const& saLimit(lineLimit);
@@ -89,13 +94,13 @@ doAccountLines(
return response; return response;
} }
if(!request.contains("account")) if (!request.contains("account"))
{ {
response["error"] = "Must contain account"; response["error"] = "Must contain account";
return response; return response;
} }
if(!request.at("account").is_string()) if (!request.at("account").is_string())
{ {
response["error"] = "Account must be a string"; response["error"] = "Account must be a string";
return response; return response;
@@ -134,7 +139,7 @@ doAccountLines(
std::uint32_t limit = 200; std::uint32_t limit = 200;
if (request.contains("limit")) if (request.contains("limit"))
{ {
if(!request.at("limit").is_int64()) if (!request.at("limit").is_int64())
{ {
response["error"] = "limit must be integer"; response["error"] = "limit must be integer";
return response; return response;
@@ -151,7 +156,7 @@ doAccountLines(
ripple::uint256 cursor = beast::zero; ripple::uint256 cursor = beast::zero;
if (request.contains("cursor")) if (request.contains("cursor"))
{ {
if(!request.at("cursor").is_string()) if (!request.at("cursor").is_string())
{ {
response["error"] = "limit must be string"; response["error"] = "limit must be string";
return response; return response;
@@ -167,7 +172,6 @@ doAccountLines(
cursor = ripple::uint256::fromVoid(bytes->data()); cursor = ripple::uint256::fromVoid(bytes->data());
} }
response["lines"] = boost::json::value(boost::json::array_kind); response["lines"] = boost::json::value(boost::json::array_kind);
boost::json::array& jsonLines = response.at("lines").as_array(); boost::json::array& jsonLines = response.at("lines").as_array();
@@ -185,13 +189,8 @@ doAccountLines(
return true; return true;
}; };
auto nextCursor = auto nextCursor = traverseOwnedNodes(
traverseOwnedNodes( backend, accountID, *ledgerSequence, cursor, addToResponse);
backend,
accountID,
*ledgerSequence,
cursor,
addToResponse);
if (nextCursor) if (nextCursor)
response["next_cursor"] = ripple::strHex(*nextCursor); response["next_cursor"] = ripple::strHex(*nextCursor);

View File

@@ -7,9 +7,8 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
std::unordered_map<std::string, ripple::LedgerEntryType> types{ std::unordered_map<std::string, ripple::LedgerEntryType> types{
{"state", ripple::ltRIPPLE_STATE}, {"state", ripple::ltRIPPLE_STATE},

View File

@@ -1,5 +1,5 @@
#include <ripple/app/paths/RippleState.h>
#include <ripple/app/ledger/Ledger.h> #include <ripple/app/ledger/Ledger.h>
#include <ripple/app/paths/RippleState.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/ErrorCodes.h> #include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
@@ -7,9 +7,8 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
void void
addOffer(boost::json::array& offersJson, ripple::SLE const& offer) addOffer(boost::json::array& offersJson, ripple::SLE const& offer)
@@ -72,13 +71,13 @@ doAccountOffers(
return response; return response;
} }
if(!request.contains("account")) if (!request.contains("account"))
{ {
response["error"] = "Must contain account"; response["error"] = "Must contain account";
return response; return response;
} }
if(!request.at("account").is_string()) if (!request.at("account").is_string())
{ {
response["error"] = "Account must be a string"; response["error"] = "Account must be a string";
return response; return response;
@@ -99,7 +98,7 @@ doAccountOffers(
std::uint32_t limit = 200; std::uint32_t limit = 200;
if (request.contains("limit")) if (request.contains("limit"))
{ {
if(!request.at("limit").is_int64()) if (!request.at("limit").is_int64())
{ {
response["error"] = "limit must be integer"; response["error"] = "limit must be integer";
return response; return response;
@@ -116,7 +115,7 @@ doAccountOffers(
ripple::uint256 cursor = beast::zero; ripple::uint256 cursor = beast::zero;
if (request.contains("cursor")) if (request.contains("cursor"))
{ {
if(!request.at("cursor").is_string()) if (!request.at("cursor").is_string())
{ {
response["error"] = "limit must be string"; response["error"] = "limit must be string";
return response; return response;
@@ -149,13 +148,8 @@ doAccountOffers(
return true; return true;
}; };
auto nextCursor = auto nextCursor = traverseOwnedNodes(
traverseOwnedNodes( backend, accountID, *ledgerSequence, cursor, addToResponse);
backend,
accountID,
*ledgerSequence,
cursor,
addToResponse);
if (nextCursor) if (nextCursor)
response["next_cursor"] = ripple::strHex(*nextCursor); response["next_cursor"] = ripple::strHex(*nextCursor);

View File

@@ -18,7 +18,7 @@
//============================================================================== //==============================================================================
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
// { // {
// account: account, // account: account,

View File

@@ -6,10 +6,9 @@
#include <ripple/protocol/jss.h> #include <ripple/protocol/jss.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendInterface.h>
#include <backend/DBHelpers.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/DBHelpers.h>
#include <reporting/Pg.h>
boost::json::object boost::json::object
doBookOffers( doBookOffers(
@@ -251,10 +250,10 @@ doBookOffers(
backend.fetchBookOffers(bookBase, *ledgerSequence, limit, cursor); backend.fetchBookOffers(bookBase, *ledgerSequence, limit, cursor);
auto end = std::chrono::system_clock::now(); auto end = std::chrono::system_clock::now();
BOOST_LOG_TRIVIAL(warning) << "Time loading books: " BOOST_LOG_TRIVIAL(warning)
<< ((end - start).count() / 1000000000.0); << "Time loading books: " << ((end - start).count() / 1000000000.0);
if(warning) if (warning)
response["warning"] = *warning; response["warning"] = *warning;
response["offers"] = boost::json::value(boost::json::array_kind); response["offers"] = boost::json::value(boost::json::array_kind);
@@ -270,13 +269,17 @@ doBookOffers(
{ {
ripple::SerialIter it{obj.blob.data(), obj.blob.size()}; ripple::SerialIter it{obj.blob.data(), obj.blob.size()};
ripple::SLE offer{it, obj.key}; ripple::SLE offer{it, obj.key};
ripple::uint256 bookDir = offer.getFieldH256(ripple::sfBookDirectory); ripple::uint256 bookDir =
offer.getFieldH256(ripple::sfBookDirectory);
boost::json::object offerJson = toJson(offer); boost::json::object offerJson = toJson(offer);
offerJson["quality"] = ripple::amountFromQuality(getQuality(bookDir)).getText(); offerJson["quality"] =
ripple::amountFromQuality(getQuality(bookDir)).getText();
jsonOffers.push_back(offerJson); jsonOffers.push_back(offerJson);
} }
catch (std::exception const& e) {} catch (std::exception const& e)
{
}
} }
end = std::chrono::system_clock::now(); end = std::chrono::system_clock::now();

View File

@@ -1,5 +1,5 @@
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
boost::json::object boost::json::object
doLedger(boost::json::object const& request, BackendInterface const& backend) doLedger(boost::json::object const& request, BackendInterface const& backend)

View File

@@ -21,7 +21,7 @@
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
// Get state nodes from a ledger // Get state nodes from a ledger
// Inputs: // Inputs:
// limit: integer, maximum number of entries // limit: integer, maximum number of entries

View File

@@ -2,7 +2,7 @@
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
// { // {
// ledger_hash : <ledger> // ledger_hash : <ledger>
// ledger_index : <ledger_index> // ledger_index : <ledger_index>

View File

@@ -1,5 +1,5 @@
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
boost::json::object boost::json::object
doLedgerRange( doLedgerRange(

View File

@@ -1,5 +1,5 @@
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
std::optional<ripple::AccountID> std::optional<ripple::AccountID>
accountFromStringStrict(std::string const& account) accountFromStringStrict(std::string const& account)

View File

@@ -5,7 +5,7 @@
#include <ripple/protocol/STLedgerEntry.h> #include <ripple/protocol/STLedgerEntry.h>
#include <ripple/protocol/STTx.h> #include <ripple/protocol/STTx.h>
#include <boost/json.hpp> #include <boost/json.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
std::optional<ripple::AccountID> std::optional<ripple::AccountID>
accountFromStringStrict(std::string const& account); accountFromStringStrict(std::string const& account);

View File

@@ -1,5 +1,5 @@
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
boost::json::object boost::json::object
doServerInfo( doServerInfo(
boost::json::object const& request, boost::json::object const& request,

View File

@@ -1,11 +1,11 @@
#include <boost/json.hpp> #include <boost/json.hpp>
#include <reporting/server/session.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <server/session.h>
static std::unordered_set<std::string> validStreams { static std::unordered_set<std::string> validStreams{
"ledger", "ledger",
"transactions", "transactions",
"transactions_proposed" }; "transactions_proposed"};
boost::json::value boost::json::value
validateStreams(boost::json::object const& request) validateStreams(boost::json::object const& request)
@@ -119,7 +119,7 @@ subscribeToAccounts(
auto accountID = accountFromStringStrict(s); auto accountID = accountFromStringStrict(s);
if(!accountID) if (!accountID)
{ {
assert(false); assert(false);
continue; continue;
@@ -143,7 +143,7 @@ unsubscribeToAccounts(
auto accountID = accountFromStringStrict(s); auto accountID = accountFromStringStrict(s);
if(!accountID) if (!accountID)
{ {
assert(false); assert(false);
continue; continue;
@@ -159,7 +159,8 @@ subscribeToAccountsProposed(
std::shared_ptr<session>& session, std::shared_ptr<session>& session,
SubscriptionManager& manager) SubscriptionManager& manager)
{ {
boost::json::array const& accounts = request.at("accounts_proposed").as_array(); boost::json::array const& accounts =
request.at("accounts_proposed").as_array();
for (auto const& account : accounts) for (auto const& account : accounts)
{ {
@@ -167,7 +168,7 @@ subscribeToAccountsProposed(
auto accountID = ripple::parseBase58<ripple::AccountID>(s); auto accountID = ripple::parseBase58<ripple::AccountID>(s);
if(!accountID) if (!accountID)
{ {
assert(false); assert(false);
continue; continue;
@@ -183,7 +184,8 @@ unsubscribeToAccountsProposed(
std::shared_ptr<session>& session, std::shared_ptr<session>& session,
SubscriptionManager& manager) SubscriptionManager& manager)
{ {
boost::json::array const& accounts = request.at("accounts_proposed").as_array(); boost::json::array const& accounts =
request.at("accounts_proposed").as_array();
for (auto const& account : accounts) for (auto const& account : accounts)
{ {
@@ -191,7 +193,7 @@ unsubscribeToAccountsProposed(
auto accountID = ripple::parseBase58<ripple::AccountID>(s); auto accountID = ripple::parseBase58<ripple::AccountID>(s);
if(!accountID) if (!accountID)
{ {
assert(false); assert(false);
continue; continue;
@@ -201,7 +203,6 @@ unsubscribeToAccountsProposed(
} }
} }
boost::json::object boost::json::object
doSubscribe( doSubscribe(
boost::json::object const& request, boost::json::object const& request,
@@ -214,7 +215,7 @@ doSubscribe(
{ {
boost::json::value error = validateStreams(request); boost::json::value error = validateStreams(request);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;
@@ -223,7 +224,6 @@ doSubscribe(
if (request.contains("accounts")) if (request.contains("accounts"))
{ {
if (!request.at("accounts").is_array()) if (!request.at("accounts").is_array())
{ {
response["error"] = "accounts must be array"; response["error"] = "accounts must be array";
@@ -233,7 +233,7 @@ doSubscribe(
boost::json::array accounts = request.at("accounts").as_array(); boost::json::array accounts = request.at("accounts").as_array();
boost::json::value error = validateAccounts(request, accounts); boost::json::value error = validateAccounts(request, accounts);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;
@@ -248,10 +248,11 @@ doSubscribe(
return response; return response;
} }
boost::json::array accounts = request.at("accounts_proposed").as_array(); boost::json::array accounts =
request.at("accounts_proposed").as_array();
boost::json::value error = validateAccounts(request, accounts); boost::json::value error = validateAccounts(request, accounts);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;
@@ -283,7 +284,7 @@ doUnsubscribe(
{ {
boost::json::value error = validateStreams(request); boost::json::value error = validateStreams(request);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;
@@ -295,7 +296,7 @@ doUnsubscribe(
boost::json::array accounts = request.at("accounts").as_array(); boost::json::array accounts = request.at("accounts").as_array();
boost::json::value error = validateAccounts(request, accounts); boost::json::value error = validateAccounts(request, accounts);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;
@@ -304,10 +305,11 @@ doUnsubscribe(
if (request.contains("accounts_proposed")) if (request.contains("accounts_proposed"))
{ {
boost::json::array accounts = request.at("accounts_proposed").as_array(); boost::json::array accounts =
request.at("accounts_proposed").as_array();
boost::json::value error = validateAccounts(request, accounts); boost::json::value error = validateAccounts(request, accounts);
if(!error.is_null()) if (!error.is_null())
{ {
response["error"] = error; response["error"] = error;
return response; return response;

View File

@@ -17,9 +17,8 @@
*/ */
//============================================================================== //==============================================================================
#include <backend/BackendInterface.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/BackendInterface.h>
#include <reporting/Pg.h>
// { // {
// transaction: <hex> // transaction: <hex>

View File

@@ -1,49 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2020 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <boost/json.hpp>
#include <reporting/server/session.h>
// We only forward requests where ledger_index is "current" or "closed"
// otherwise, attempt to handle here
bool
shouldForwardToP2p(boost::json::object const& request)
{
if(request.contains("forward") && request.at("forward").is_bool())
return request.at("forward").as_bool();
std::string strCommand = request.contains("command")
? request.at("command").as_string().c_str()
: request.at("method").as_string().c_str();
if (forwardCommands.find(strCommand) != forwardCommands.end())
return true;
if (request.contains("ledger_index"))
{
auto indexValue = request.at("ledger_index");
if (!indexValue.is_uint64())
{
std::string index = indexValue.as_string().c_str();
return index == "current" || index == "closed";
}
}
return false;
}

View File

@@ -1,31 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2020 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_APP_REPORTING_P2PPROXY_H_INCLUDED
#define RIPPLE_APP_REPORTING_P2PPROXY_H_INCLUDED
#include <boost/json.hpp>
/// Whether a request should be forwarded, based on request parameters
/// @param request request json
/// @return true if should be forwarded
bool
shouldForwardToP2p(boost::json::object const& request);
#endif

View File

@@ -1,5 +1,5 @@
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/server/SubscriptionManager.h> #include <server/SubscriptionManager.h>
void void
SubscriptionManager::subLedger(std::shared_ptr<session>& session) SubscriptionManager::subLedger(std::shared_ptr<session>& session)

View File

@@ -20,10 +20,10 @@
#ifndef SUBSCRIPTION_MANAGER_H #ifndef SUBSCRIPTION_MANAGER_H
#define SUBSCRIPTION_MANAGER_H #define SUBSCRIPTION_MANAGER_H
#include <reporting/server/session.h> #include <server/session.h>
#include <set>
#include <memory> #include <memory>
#include <set>
class session; class session;
@@ -41,10 +41,10 @@ class SubscriptionManager
std::array<subscriptions, finalEntry> streamSubscribers_; std::array<subscriptions, finalEntry> streamSubscribers_;
std::unordered_map<ripple::AccountID, subscriptions> accountSubscribers_; std::unordered_map<ripple::AccountID, subscriptions> accountSubscribers_;
std::unordered_map<ripple::AccountID, subscriptions> accountProposedSubscribers_; std::unordered_map<ripple::AccountID, subscriptions>
accountProposedSubscribers_;
public: public:
static std::shared_ptr<SubscriptionManager> static std::shared_ptr<SubscriptionManager>
make_SubscriptionManager() make_SubscriptionManager()
{ {
@@ -71,22 +71,32 @@ public:
unsubTransactions(std::shared_ptr<session>& session); unsubTransactions(std::shared_ptr<session>& session);
void void
pubTransaction(Backend::TransactionAndMetadata const& blob, std::uint32_t seq); pubTransaction(
Backend::TransactionAndMetadata const& blob,
std::uint32_t seq);
void void
subAccount(ripple::AccountID const& account, std::shared_ptr<session>& session); subAccount(
ripple::AccountID const& account,
std::shared_ptr<session>& session);
void void
unsubAccount(ripple::AccountID const& account, std::shared_ptr<session>& session); unsubAccount(
ripple::AccountID const& account,
std::shared_ptr<session>& session);
void void
forwardProposedTransaction(boost::json::object const& response); forwardProposedTransaction(boost::json::object const& response);
void void
subProposedAccount(ripple::AccountID const& account, std::shared_ptr<session>& session); subProposedAccount(
ripple::AccountID const& account,
std::shared_ptr<session>& session);
void void
unsubProposedAccount(ripple::AccountID const& account, std::shared_ptr<session>& session); unsubProposedAccount(
ripple::AccountID const& account,
std::shared_ptr<session>& session);
void void
subProposedTransactions(std::shared_ptr<session>& session); subProposedTransactions(std::shared_ptr<session>& session);
@@ -95,4 +105,4 @@ public:
unsubProposedTransactions(std::shared_ptr<session>& session); unsubProposedTransactions(std::shared_ptr<session>& session);
}; };
#endif //SUBSCRIPTION_MANAGER_H #endif // SUBSCRIPTION_MANAGER_H

View File

@@ -24,7 +24,7 @@
#include <boost/beast/core.hpp> #include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp> #include <boost/beast/websocket.hpp>
#include <reporting/server/SubscriptionManager.h> #include <server/SubscriptionManager.h>
#include <iostream> #include <iostream>

View File

@@ -1,5 +1,4 @@
#include <reporting/P2pProxy.h> #include <server/session.h>
#include <reporting/server/session.h>
void void
fail(boost::beast::error_code ec, char const* what) fail(boost::beast::error_code ec, char const* what)
@@ -7,6 +6,31 @@ fail(boost::beast::error_code ec, char const* what)
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
bool
shouldForwardToRippled(boost::json::object const& request)
{
if (request.contains("forward") && request.at("forward").is_bool())
return request.at("forward").as_bool();
std::string strCommand = request.contains("command")
? request.at("command").as_string().c_str()
: request.at("method").as_string().c_str();
if (forwardCommands.find(strCommand) != forwardCommands.end())
return true;
if (request.contains("ledger_index"))
{
auto indexValue = request.at("ledger_index");
if (!indexValue.is_uint64())
{
std::string index = indexValue.as_string().c_str();
return index == "current" || index == "closed";
}
}
return false;
}
std::pair<boost::json::object, uint32_t> std::pair<boost::json::object, uint32_t>
buildResponse( buildResponse(
boost::json::object const& request, boost::json::object const& request,
@@ -19,8 +43,8 @@ buildResponse(
BOOST_LOG_TRIVIAL(info) << "Received rpc command : " << request; BOOST_LOG_TRIVIAL(info) << "Received rpc command : " << request;
boost::json::object response; boost::json::object response;
if (shouldForwardToP2p(request)) if (shouldForwardToRippled(request))
return {balancer->forwardToP2p(request), 10}; return {balancer->forwardToRippled(request), 10};
switch (commandMap[command]) switch (commandMap[command])
{ {

View File

@@ -24,10 +24,10 @@
#include <boost/beast/core.hpp> #include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp> #include <boost/beast/websocket.hpp>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
#include <reporting/ETLSource.h> #include <etl/ETLSource.h>
#include <reporting/server/SubscriptionManager.h>
#include <server/DOSGuard.h> #include <server/DOSGuard.h>
#include <server/SubscriptionManager.h>
class session; class session;
class SubscriptionManager; class SubscriptionManager;

View File

@@ -23,15 +23,15 @@
#include <boost/log/expressions.hpp> #include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#include <algorithm> #include <algorithm>
#include <backend/BackendFactory.h>
#include <cstdlib> #include <cstdlib>
#include <etl/ReportingETL.h>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <reporting/BackendFactory.h> #include <server/listener.h>
#include <reporting/ReportingETL.h> #include <server/session.h>
#include <reporting/server/listener.h>
#include <reporting/server/session.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <thread> #include <thread>

View File

@@ -1,13 +1,13 @@
#include <algorithm> #include <algorithm>
#include <backend/DBHelpers.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <handlers/RPCHelpers.h> #include <handlers/RPCHelpers.h>
#include <reporting/DBHelpers.h>
#include <boost/log/core.hpp> #include <boost/log/core.hpp>
#include <boost/log/expressions.hpp> #include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#include <reporting/BackendFactory.h> #include <backend/BackendFactory.h>
#include <reporting/BackendInterface.h> #include <backend/BackendInterface.h>
// Demonstrate some basic assertions. // Demonstrate some basic assertions.
TEST(BackendTest, Basic) TEST(BackendTest, Basic)