mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-15 09:15:51 +00:00
71 lines
2.9 KiB
C++
71 lines
2.9 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of clio: https://github.com/XRPLF/clio
|
|
Copyright (c) 2024, the clio developers.
|
|
|
|
Permission to use, copy, modify, and 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.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#pragma once
|
|
|
|
#include "data/BackendInterface.hpp"
|
|
#include "util/log/Logger.hpp"
|
|
|
|
#include <grpcpp/support/status.h>
|
|
#include <org/xrpl/rpc/v1/get_ledger.pb.h>
|
|
#include <ripple/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
namespace etl::impl {
|
|
|
|
class GrpcSource {
|
|
util::Logger log_;
|
|
std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> stub_;
|
|
std::shared_ptr<BackendInterface> backend_;
|
|
|
|
public:
|
|
GrpcSource(std::string const& ip, std::string const& grpcPort, std::shared_ptr<BackendInterface> backend);
|
|
|
|
/**
|
|
* @brief Fetch data for a specific ledger.
|
|
*
|
|
* This function will continuously try to fetch data for the specified ledger until the fetch succeeds, the ledger
|
|
* is found in the database, or the server is shutting down.
|
|
*
|
|
* @param sequence Sequence of the ledger to fetch
|
|
* @param getObjects Whether to get the account state diff between this ledger and the prior one; defaults to true
|
|
* @param getObjectNeighbors Whether to request object neighbors; defaults to false
|
|
* @return A std::pair of the response status and the response itself
|
|
*/
|
|
std::pair<grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse>
|
|
fetchLedger(uint32_t sequence, bool getObjects = true, bool getObjectNeighbors = false);
|
|
|
|
/**
|
|
* @brief Download a ledger in full.
|
|
*
|
|
* @param sequence Sequence of the ledger to download
|
|
* @param numMarkers Number of markers to generate for async calls
|
|
* @param cacheOnly Only insert into cache, not the DB; defaults to false
|
|
* @return A std::pair of the data and a bool indicating whether the download was successful
|
|
*/
|
|
std::pair<std::vector<std::string>, bool>
|
|
loadInitialLedger(uint32_t sequence, uint32_t numMarkers, bool cacheOnly = false);
|
|
};
|
|
|
|
} // namespace etl::impl
|