xrpld
Loading...
Searching...
No Matches
LedgerEntryBase.h
1#pragma once
2
3#include <xrpl/protocol/LedgerFormats.h>
4#include <xrpl/protocol/SField.h>
5#include <xrpl/protocol/STLedgerEntry.h>
6#include <xrpl/protocol_autogen/STObjectValidation.h>
7#include <xrpl/protocol_autogen/Utils.h>
8
9#include <optional>
10#include <string>
11
12namespace xrpl::ledger_entries {
13
24{
25public:
30 explicit LedgerEntryBase(SLE::const_pointer sle) : sle_(std::move(sle))
31 {
32 }
33
38 [[nodiscard]]
39 bool
40 validate() const
41 {
42 if (!sle_->isFieldPresent(sfLedgerEntryType))
43 {
44 return false; // LCOV_EXCL_LINE
45 }
46 auto ledgerEntryType = static_cast<LedgerEntryType>(sle_->getFieldU16(sfLedgerEntryType));
48 *sle_, LedgerFormats::getInstance().findByType(ledgerEntryType)->getSOTemplate());
49 }
50
55 [[nodiscard]]
57 getType() const
58 {
59 return sle_->getType();
60 }
61
68 [[nodiscard]]
69 uint256 const&
70 getKey() const
71 {
72 return sle_->key();
73 }
74
75 // Common field getters (from LedgerFormats.cpp commonFields)
76
83 [[nodiscard]]
86 {
87 if (sle_->isFieldPresent(sfLedgerIndex))
88 {
89 return sle_->at(sfLedgerIndex);
90 }
91 return std::nullopt;
92 }
93
98 [[nodiscard]]
99 bool
101 {
102 return sle_->isFieldPresent(sfLedgerIndex);
103 }
104
112 [[nodiscard]]
113 uint16_t
115 {
116 return sle_->at(sfLedgerEntryType);
117 }
118
126 [[nodiscard]]
128 getFlags() const
129 {
130 return sle_->at(sfFlags);
131 }
132
139 [[nodiscard]]
140 bool
142 {
143 return sle_->isFlag(f);
144 }
145
153 [[nodiscard]]
155 getSle() const
156 {
157 return sle_;
158 }
159
160protected:
163};
164
165} // namespace xrpl::ledger_entries
static LedgerFormats const & getInstance()
std::shared_ptr< STLedgerEntry const > const_pointer
uint16_t getLedgerEntryType() const
Get the ledger entry type field (sfLedgerEntryType).
LedgerEntryBase(SLE::const_pointer sle)
Construct a ledger entry wrapper from an existing SLE object.
SLE::const_pointer getSle() const
Get the underlying SLE object.
LedgerEntryType getType() const
Get the ledger entry type.
bool isFlag(std::uint32_t f) const
Check if a specific flag is set.
bool validate() const
Validate the ledger entry.
uint256 const & getKey() const
Get the key (index) of this ledger entry.
std::optional< uint256 > getLedgerIndex() const
Get the ledger index (sfLedgerIndex).
bool hasLedgerIndex() const
Check if the ledger entry has a ledger index.
std::uint32_t getFlags() const
Get the flags field (sfFlags).
SLE::const_pointer sle_
The underlying serialized ledger entry being wrapped.
STL namespace.
bool validateSTObject(STObject const &obj, SOTemplate const &format)
LedgerEntryType
Identifiers for on-ledger objects.
BaseUInt< 256 > uint256
Definition base_uint.h:562