Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Extraction.hpp
1#pragma once
2
3#include "etl/ExtractorInterface.hpp"
5#include "etl/Models.hpp"
6#include "etl/impl/LedgerFetcher.hpp"
7#include "util/log/Logger.hpp"
8
9#include <google/protobuf/repeated_ptr_field.h>
10#include <sys/types.h>
11#include <xrpl/basics/Slice.h>
12#include <xrpl/basics/base_uint.h>
13#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
14#include <xrpl/proto/org/xrpl/rpc/v1/ledger.pb.h>
15#include <xrpl/protocol/LedgerHeader.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/Serializer.h>
18#include <xrpl/protocol/TxMeta.h>
19
20#include <cstddef>
21#include <cstdint>
22#include <memory>
23#include <optional>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace etl::impl {
29
30using PBObjType = org::xrpl::rpc::v1::RawLedgerObject;
31using PBModType = PBObjType::ModificationType;
32using PBTxType = org::xrpl::rpc::v1::TransactionAndMetadata;
33using PBTxListType = google::protobuf::RepeatedPtrField<PBTxType>;
34using PBObjListType = google::protobuf::RepeatedPtrField<PBObjType>;
35using PBBookSuccessorType = org::xrpl::rpc::v1::BookSuccessor;
36using PBLedgerResponseType = org::xrpl::rpc::v1::GetLedgerResponse;
37
38[[nodiscard]] model::Object::ModType
39extractModType(PBModType type);
40
41[[nodiscard]] model::Transaction
42extractTx(PBTxType tx, uint32_t seq);
43
44[[nodiscard]] std::vector<model::Transaction>
45extractTxs(PBTxListType transactions, uint32_t seq);
46
47[[nodiscard]] model::Object
48extractObj(PBObjType obj);
49
50[[nodiscard]] std::vector<model::Object>
51extractObjs(PBObjListType objects);
52
53[[nodiscard]] model::BookSuccessor
54extractSuccessor(PBBookSuccessorType successor);
55
56[[nodiscard]] std::optional<std::vector<model::BookSuccessor>>
57maybeExtractSuccessors(PBLedgerResponseType const& data);
58
59// fetches the data in gRPC and transforms to local representation
60class Extractor : public ExtractorInterface {
61 std::shared_ptr<LedgerFetcherInterface> fetcher_;
62
63 util::Logger log_{"ETL"};
64
65private:
66 [[nodiscard]] static auto
67 unpack();
68
69public:
70 Extractor(std::shared_ptr<LedgerFetcherInterface> fetcher) : fetcher_(std::move(fetcher))
71 {
72 }
73
74 Extractor(Extractor const&) = delete;
75 Extractor(Extractor&&) = delete;
76 Extractor&
77 operator=(Extractor const&) = delete;
78 Extractor&
79 operator=(Extractor&&) = delete;
80
81 [[nodiscard]] std::optional<model::LedgerData>
82 extractLedgerWithDiff(uint32_t seq) override;
83
84 [[nodiscard]] std::optional<model::LedgerData>
85 extractLedgerOnly(uint32_t seq) override;
86};
87
88} // namespace etl::impl
std::optional< model::LedgerData > extractLedgerWithDiff(uint32_t seq) override
Extract diff data for a particular ledger.
Definition Extraction.cpp:182
std::optional< model::LedgerData > extractLedgerOnly(uint32_t seq) override
Extract data for a particular ledger.
Definition Extraction.cpp:198
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
An interface for the Extractor.
Definition ExtractorInterface.hpp:13
ModType
Modification type for the object.
Definition Models.hpp:90