Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AsyncGrpcCall.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "etl/InitialLoadObserverInterface.hpp"
23#include "util/log/Logger.hpp"
24
25#include <grpcpp/client_context.h>
26#include <grpcpp/support/status.h>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger_data.pb.h>
29#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
30
31#include <cstdint>
32#include <memory>
33#include <optional>
34#include <string>
35#include <vector>
36
37namespace etl::impl {
38
39class AsyncGrpcCall {
40public:
41 enum class CallStatus { More, Done, Errored };
42 using RequestType = org::xrpl::rpc::v1::GetLedgerDataRequest;
43 using ResponseType = org::xrpl::rpc::v1::GetLedgerDataResponse;
44 using StubType = org::xrpl::rpc::v1::XRPLedgerAPIService::Stub;
45
46private:
47 util::Logger log_{"ETL"};
48
49 std::unique_ptr<ResponseType> cur_;
50 std::unique_ptr<ResponseType> next_;
51
52 RequestType request_;
53 std::unique_ptr<grpc::ClientContext> context_;
54
55 grpc::Status status_;
56 unsigned char nextPrefix_;
57
58 std::string lastKey_;
59 std::optional<std::string> predecessorKey_;
60
61public:
62 AsyncGrpcCall(
63 uint32_t seq,
64 ripple::uint256 const& marker,
65 std::optional<ripple::uint256> const& nextMarker
66 );
67
68 static std::vector<AsyncGrpcCall>
69 makeAsyncCalls(uint32_t const sequence, uint32_t const numMarkers);
70
71 CallStatus
72 process(
73 std::unique_ptr<StubType>& stub,
74 grpc::CompletionQueue& cq,
76 bool abort
77 );
78
79 void
80 call(
81 std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>& stub,
82 grpc::CompletionQueue& cq
83 );
84
85 std::string
86 getMarkerPrefix();
87
88 std::string
89 getLastKey();
90};
91
92} // namespace etl::impl
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:96
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36