Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerUtils.hpp
1#pragma once
2
3#include <fmt/format.h>
4#include <rpcspec/LedgerTypes.hpp>
5#include <xrpl/basics/Slice.h>
6#include <xrpl/basics/StringUtilities.h>
7#include <xrpl/basics/strHex.h>
8#include <xrpl/protocol/LedgerFormats.h>
9#include <xrpl/protocol/LedgerHeader.h>
10#include <xrpl/protocol/jss.h>
11
12#include <algorithm>
13#include <array>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <unordered_set>
18#include <vector>
19
20namespace util {
21
26 static constexpr auto const& kLedgerTypes = rpc::spec::kLedgerTypesTable;
27
28public:
33 static constexpr auto
35 {
36 std::array<std::string_view, std::size(kLedgerTypes)> res{};
37 std::ranges::transform(kLedgerTypes, std::begin(res), [](auto const& item) {
38 return item.rpcName;
39 });
40 return res;
41 }
42
48 static constexpr auto
50 {
51 constexpr auto kFilter = [](auto const& item) {
52 return item.category == rpc::spec::LedgerCategory::DeletionBlocker;
53 };
54
55 constexpr auto kDeletionBlockersCount =
56 std::count_if(std::begin(kLedgerTypes), std::end(kLedgerTypes), kFilter);
57 std::array<xrpl::LedgerEntryType, kDeletionBlockersCount> res{};
58 auto it = std::begin(res);
59 std::ranges::for_each(kLedgerTypes, [&](auto const& item) {
60 if (kFilter(item)) {
61 *it = item.type;
62 ++it;
63 }
64 });
65 return res;
66 }
67};
68
75inline xrpl::LedgerHeader
77{
78 return xrpl::deserializeHeader(data, /* hasHash = */ true);
79}
80
87inline std::string
88toString(xrpl::LedgerHeader const& info)
89{
90 return fmt::format(
91 "LedgerHeader {{Sequence: {}, Hash: {}, TxHash: {}, AccountHash: {}, ParentHash: {}}}",
92 info.seq,
93 xrpl::strHex(info.hash),
94 strHex(info.txHash),
95 xrpl::strHex(info.accountHash),
96 strHex(info.parentHash)
97 );
98}
99
100} // namespace util
A helper class that provides lists of different ledger type category.
Definition LedgerUtils.hpp:25
static constexpr auto getDeletionBlockerLedgerTypes()
Returns a list of all account deletion blocker's type as string.
Definition LedgerUtils.hpp:49
static constexpr auto getLedgerEntryTypeStrList()
Returns a list of all ledger entry type as string.
Definition LedgerUtils.hpp:34
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
This namespace contains various utilities.
Definition HandlerRegistry.hpp:24
std::string toString(xrpl::LedgerHeader const &info)
A helper function that converts a xrpl::LedgerHeader to a string representation.
Definition LedgerUtils.hpp:88
xrpl::LedgerHeader deserializeHeader(xrpl::Slice data)
Deserializes a xrpl::LedgerHeader from xrpl::Slice of data.
Definition LedgerUtils.hpp:76