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 "etlng/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 etlng::impl {
38
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(uint32_t seq, ripple::uint256 const& marker, std::optional<ripple::uint256> const& nextMarker);
63
64 static std::vector<AsyncGrpcCall>
65 makeAsyncCalls(uint32_t const sequence, uint32_t const numMarkers);
66
67 CallStatus
68 process(
69 std::unique_ptr<StubType>& stub,
70 grpc::CompletionQueue& cq,
72 bool abort
73 );
74
75 void
76 call(std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub>& stub, grpc::CompletionQueue& cq);
77
78 std::string
79 getMarkerPrefix();
80
81 std::string
82 getLastKey();
83};
84
85} // namespace etlng::impl
Definition AsyncGrpcCall.hpp:39
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36