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