xrpld
Loading...
Searching...
No Matches
STLedgerEntry.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/protocol/Keylet.h>
7#include <xrpl/protocol/LedgerFormats.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/STBase.h>
10#include <xrpl/protocol/STObject.h>
11#include <xrpl/protocol/Serializer.h>
12
13#include <cstddef>
14#include <cstdint>
15#include <memory>
16#include <string>
17
18namespace xrpl {
19
20class Rules;
21namespace test {
23} // namespace test
24
28class STLedgerEntry final : public STObject, public CountedObject<STLedgerEntry>
29{
32
33public:
38
42 explicit STLedgerEntry(Keylet const& k);
44 STLedgerEntry(SerialIter& sit, UInt256 const& index);
45 STLedgerEntry(SerialIter&& sit, UInt256 const& index);
46 STLedgerEntry(STObject const& object, UInt256 const& index);
47
48 [[nodiscard]] SerializedTypeID
49 getSType() const override;
50
51 [[nodiscard]] std::string
52 getFullText() const override;
53
54 [[nodiscard]] std::string
55 getText() const override;
56
57 [[nodiscard]] json::Value
58 getJson(JsonOptions options = JsonOptions::Values::None) const override;
59
65 [[nodiscard]] UInt256 const&
66 key() const;
67
68 [[nodiscard]] LedgerEntryType
69 getType() const;
70
71 // is this a ledger entry that can be threaded
72 [[nodiscard]] bool
73 isThreadedType(Rules const& rules) const;
74
75 bool
76 thread(
77 UInt256 const& txID,
78 std::uint32_t ledgerSeq,
79 UInt256& prevTxID,
80 std::uint32_t& prevLedgerID);
81
82private:
83 /* Make STObject comply with the template for this SLE type
84 Can throw
85 */
86 void
87 setSLEType();
88
89 friend test::InvariantsMisc_test; // this test wants access to the
90 // private type_
91
92 STBase*
93 copy(std::size_t n, void* buf) const override;
94 STBase*
95 move(std::size_t n, void* buf) override;
96
97 friend class detail::STVar;
98};
99
100using SLE = STLedgerEntry;
101
106
108 SerialIter&& sit, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
109 UInt256 const& index)
110 : STLedgerEntry(sit, index)
111{
112}
113
119inline UInt256 const&
121{
122 return key_;
123}
124
125inline LedgerEntryType
127{
128 return type_;
129}
130
131} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
Rules controlling protocol behavior.
Definition Rules.h:40
A type which can be exported to a well known binary format.
Definition STBase.h:129
A serialized ledger entry, commonly abbreviated "SLE".
LedgerEntryType type_
bool thread(UInt256 const &txID, std::uint32_t ledgerSeq, UInt256 &prevTxID, std::uint32_t &prevLedgerID)
UInt256 const & key() const
Returns the 'key' (or 'index') of this item.
std::shared_ptr< STLedgerEntry > pointer
std::string getFullText() const override
STBase * copy(std::size_t n, void *buf) const override
LedgerEntryType getType() const
SerializedTypeID getSType() const override
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
STLedgerEntry(Keylet const &k)
Create an empty object with the given key and type.
std::string getText() const override
bool isThreadedType(Rules const &rules) const
STBase * move(std::size_t n, void *buf) override
json::Value getJson(JsonOptions options=JsonOptions::Values::None) const override
std::shared_ptr< STLedgerEntry const > const_pointer
STObject(STObject const &)=default
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
STLedgerEntry SLE
BaseUInt< 256 > UInt256
Definition base_uint.h:580
SerializedTypeID
Definition SField.h:94
LedgerEntryType
Identifiers for on-ledger objects.
Note, should be treated as flags that can be | and &.
Definition STBase.h:22
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20