rippled
Loading...
Searching...
No Matches
LedgerFormats.h
1#pragma once
2
3#include <xrpl/protocol/KnownFormats.h>
4
5#include <map>
6#include <string>
7#include <vector>
8
9namespace xrpl {
33
34#pragma push_macro("LEDGER_ENTRY")
35#undef LEDGER_ENTRY
36
37#define LEDGER_ENTRY(tag, value, ...) tag = value,
38
39#include <xrpl/protocol/detail/ledger_entries.macro>
40
41#undef LEDGER_ENTRY
42#pragma pop_macro("LEDGER_ENTRY")
43
44 //---------------------------------------------------------------------------
54 ltANY = 0,
55
66 ltCHILD = 0x1CD2,
67
68 //---------------------------------------------------------------------------
75 ltNICKNAME [[deprecated("This object type is not supported and should not be used.")]] = 0x006e,
76
83 ltCONTRACT [[deprecated("This object type is not supported and should not be used.")]] = 0x0063,
84
91 ltGENERATOR_MAP [[deprecated("This object type is not supported and should not be used.")]] =
92 0x0067,
93};
94
105#pragma push_macro("XMACRO")
106#pragma push_macro("TO_VALUE")
107#pragma push_macro("VALUE_TO_MAP")
108#pragma push_macro("NULL_NAME")
109#pragma push_macro("TO_MAP")
110#pragma push_macro("ALL_LEDGER_FLAGS")
111
112#undef XMACRO
113#undef TO_VALUE
114#undef VALUE_TO_MAP
115#undef NULL_NAME
116#undef TO_MAP
117
118#undef ALL_LEDGER_FLAGS
119
120// clang-format off
121
122#define XMACRO(LEDGER_OBJECT, LSF_FLAG, LSF_FLAG2) \
123 LEDGER_OBJECT(AccountRoot, \
124 LSF_FLAG(lsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \
125 LSF_FLAG(lsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \
126 LSF_FLAG(lsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \
127 LSF_FLAG(lsfDisallowXRP, 0x00080000) /* True, to disallow sending XRP. */ \
128 LSF_FLAG(lsfDisableMaster, 0x00100000) /* True, force regular key */ \
129 LSF_FLAG(lsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \
130 LSF_FLAG(lsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \
131 LSF_FLAG(lsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \
132 LSF_FLAG(lsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \
133 LSF_FLAG(lsfDisallowIncomingNFTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \
134 LSF_FLAG(lsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \
135 LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \
136 LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \
137 LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \
138 LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \
139 \
140 LEDGER_OBJECT(Offer, \
141 LSF_FLAG(lsfPassive, 0x00010000) \
142 LSF_FLAG(lsfSell, 0x00020000) /* True, offer was placed as a sell. */ \
143 LSF_FLAG(lsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \
144 \
145 LEDGER_OBJECT(RippleState, \
146 LSF_FLAG(lsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \
147 LSF_FLAG(lsfHighReserve, 0x00020000) \
148 LSF_FLAG(lsfLowAuth, 0x00040000) \
149 LSF_FLAG(lsfHighAuth, 0x00080000) \
150 LSF_FLAG(lsfLowNoRipple, 0x00100000) \
151 LSF_FLAG(lsfHighNoRipple, 0x00200000) \
152 LSF_FLAG(lsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \
153 LSF_FLAG(lsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \
154 LSF_FLAG(lsfAMMNode, 0x01000000) /* True, trust line to AMM. */ \
155 /* Used by client apps to identify payments via AMM. */ \
156 LSF_FLAG(lsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \
157 LSF_FLAG(lsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \
158 \
159 LEDGER_OBJECT(SignerList, \
160 LSF_FLAG(lsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \
161 \
162 LEDGER_OBJECT(DirNode, \
163 LSF_FLAG(lsfNFTokenBuyOffers, 0x00000001) \
164 LSF_FLAG(lsfNFTokenSellOffers, 0x00000002)) \
165 \
166 LEDGER_OBJECT(NFTokenOffer, \
167 LSF_FLAG(lsfSellNFToken, 0x00000001)) \
168 \
169 LEDGER_OBJECT(MPTokenIssuance, \
170 LSF_FLAG(lsfMPTLocked, 0x00000001) /* Also used in ltMPTOKEN */ \
171 LSF_FLAG(lsfMPTCanLock, 0x00000002) \
172 LSF_FLAG(lsfMPTRequireAuth, 0x00000004) \
173 LSF_FLAG(lsfMPTCanEscrow, 0x00000008) \
174 LSF_FLAG(lsfMPTCanTrade, 0x00000010) \
175 LSF_FLAG(lsfMPTCanTransfer, 0x00000020) \
176 LSF_FLAG(lsfMPTCanClawback, 0x00000040)) \
177 \
178 LEDGER_OBJECT(MPTokenIssuanceMutable, \
179 LSF_FLAG(lsmfMPTCanMutateCanLock, 0x00000002) \
180 LSF_FLAG(lsmfMPTCanMutateRequireAuth, 0x00000004) \
181 LSF_FLAG(lsmfMPTCanMutateCanEscrow, 0x00000008) \
182 LSF_FLAG(lsmfMPTCanMutateCanTrade, 0x00000010) \
183 LSF_FLAG(lsmfMPTCanMutateCanTransfer, 0x00000020) \
184 LSF_FLAG(lsmfMPTCanMutateCanClawback, 0x00000040) \
185 LSF_FLAG(lsmfMPTCanMutateMetadata, 0x00010000) \
186 LSF_FLAG(lsmfMPTCanMutateTransferFee, 0x00020000)) \
187 \
188 LEDGER_OBJECT(MPToken, \
189 LSF_FLAG2(lsfMPTLocked, 0x00000001) \
190 LSF_FLAG(lsfMPTAuthorized, 0x00000002)) \
191 \
192 LEDGER_OBJECT(Credential, \
193 LSF_FLAG(lsfAccepted, 0x00010000)) \
194 \
195 LEDGER_OBJECT(Vault, \
196 LSF_FLAG(lsfVaultPrivate, 0x00010000)) \
197 \
198 LEDGER_OBJECT(Loan, \
199 LSF_FLAG(lsfLoanDefault, 0x00010000) \
200 LSF_FLAG(lsfLoanImpaired, 0x00020000) \
201 LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */
202
203// clang-format on
204
205// Create all the flag values as an enum.
206//
207// example:
208// enum LedgerSpecificFlags {
209// lsfPasswordSpent = 0x00010000,
210// lsfRequireDestTag = 0x00020000,
211// ...
212// };
213#define TO_VALUE(name, value) name = value,
214#define NULL_NAME(name, values) values
215#define NULL_OUTPUT(name, value)
216enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
217
218// Create getter functions for each set of flags using Meyer's singleton pattern.
219// This avoids static initialization order fiasco while still providing efficient access.
220// This is used below in `getAllLedgerFlags()` to generate the server_definitions RPC output.
221//
222// example:
223// inline LedgerFlagMap const& getAccountRootFlags() {
224// static LedgerFlagMap const flags = {
225// {"lsfPasswordSpent", 0x00010000},
226// {"lsfRequireDestTag", 0x00020000},
227// ...};
228// return flags;
229// }
231#define VALUE_TO_MAP(name, value) {#name, value},
232#define TO_MAP(name, values) \
233 inline LedgerFlagMap const& get##name##Flags() \
234 { \
235 static LedgerFlagMap const flags = {values}; \
236 return flags; \
237 }
238XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP)
239
240// Create a getter function for all ledger flag maps using Meyer's singleton pattern.
241// This is used to generate the server_definitions RPC output.
242//
243// example:
244// inline std::vector<std::pair<std::string, LedgerFlagMap>> const& getAllLedgerFlags() {
245// static std::vector<std::pair<std::string, LedgerFlagMap>> const flags = {
246// {"AccountRoot", getAccountRootFlags()},
247// ...};
248// return flags;
249// }
250#define ALL_LEDGER_FLAGS(name, values) {#name, get##name##Flags()},
253{
255 XMACRO(ALL_LEDGER_FLAGS, NULL_OUTPUT, NULL_OUTPUT)};
256 return flags;
257}
258
259#undef XMACRO
260#undef TO_VALUE
261#undef VALUE_TO_MAP
262#undef NULL_NAME
263#undef NULL_OUTPUT
264#undef TO_MAP
265#undef ALL_LEDGER_FLAGS
266
267#pragma pop_macro("XMACRO")
268#pragma pop_macro("TO_VALUE")
269#pragma pop_macro("VALUE_TO_MAP")
270#pragma pop_macro("NULL_NAME")
271#pragma pop_macro("TO_MAP")
272#pragma pop_macro("ALL_LEDGER_FLAGS")
273
274//------------------------------------------------------------------------------
275
278class LedgerFormats : public KnownFormats<LedgerEntryType, LedgerFormats>
279{
280private:
285
286public:
287 static LedgerFormats const&
288 getInstance();
289
290 // Fields shared by all ledger entry formats:
291 static std::vector<SOElement> const&
293};
294
295} // namespace xrpl
Manages a list of known formats.
Holds the list of known ledger entry formats.
static std::vector< SOElement > const & getCommonFields()
LedgerFormats()
Create the object.
static LedgerFormats const & getInstance()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LedgerSpecificFlags
std::vector< std::pair< std::string, LedgerFlagMap > > const & getAllLedgerFlags()
LedgerEntryType
Identifiers for on-ledger objects.
@ ltGENERATOR_MAP
A legacy, deprecated type.
@ ltNICKNAME
A legacy, deprecated type.
@ ltCONTRACT
A legacy, deprecated type.
@ ltANY
A special type, matching any ledger entry type.
@ ltCHILD
A special type, matching any ledger type except directory nodes.