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 {
22class Invariants_test;
23} // namespace test
24
25class STLedgerEntry final : public STObject, public CountedObject<STLedgerEntry>
26{
29
30public:
35
39 explicit STLedgerEntry(Keylet const& k);
41 STLedgerEntry(SerialIter& sit, uint256 const& index);
42 STLedgerEntry(SerialIter&& sit, uint256 const& index);
43 STLedgerEntry(STObject const& object, uint256 const& index);
44
45 [[nodiscard]] SerializedTypeID
46 getSType() const override;
47
48 [[nodiscard]] std::string
49 getFullText() const override;
50
51 [[nodiscard]] std::string
52 getText() const override;
53
54 [[nodiscard]] json::Value
55 getJson(JsonOptions options = JsonOptions::Values::None) const override;
56
62 [[nodiscard]] uint256 const&
63 key() const;
64
65 [[nodiscard]] LedgerEntryType
66 getType() const;
67
68 // is this a ledger entry that can be threaded
69 [[nodiscard]] bool
70 isThreadedType(Rules const& rules) const;
71
72 bool
73 thread(
74 uint256 const& txID,
75 std::uint32_t ledgerSeq,
76 uint256& prevTxID,
77 std::uint32_t& prevLedgerID);
78
79private:
80 /* Make STObject comply with the template for this SLE type
81 Can throw
82 */
83 void
84 setSLEType();
85
86 friend test::Invariants_test; // this test wants access to the private
87 // type_
88
89 STBase*
90 copy(std::size_t n, void* buf) const override;
91 STBase*
92 move(std::size_t n, void* buf) override;
93
94 friend class detail::STVar;
95};
96
97using SLE = STLedgerEntry;
98
100 : STLedgerEntry(Keylet(type, key))
101{
102}
103
105 SerialIter&& sit, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
106 uint256 const& index)
107 : STLedgerEntry(sit, index)
108{
109}
110
116inline uint256 const&
118{
119 return key_;
120}
121
122inline LedgerEntryType
124{
125 return type_;
126}
127
128} // 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
LedgerEntryType type_
std::shared_ptr< STLedgerEntry > const & ref
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
bool thread(uint256 const &txID, std::uint32_t ledgerSeq, uint256 &prevTxID, std::uint32_t &prevLedgerID)
LedgerEntryType getType() const
SerializedTypeID getSType() const override
std::shared_ptr< STLedgerEntry const > const & 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
SerializedTypeID
Definition SField.h:94
LedgerEntryType
Identifiers for on-ledger objects.
BaseUInt< 256 > uint256
Definition base_uint.h:580
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