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