xrpld
Loading...
Searching...
No Matches
LedgerFormats.h
1#pragma once
2
3// NOLINTBEGIN(readability-identifier-naming)
4
5#include <xrpl/protocol/KnownFormats.h>
6
7#include <map>
8#include <string>
9#include <vector>
10
11namespace xrpl {
34// Protocol-critical, hundreds of usages
35// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
37
38#pragma push_macro("LEDGER_ENTRY")
39#undef LEDGER_ENTRY
40
41#define LEDGER_ENTRY(tag, value, ...) tag = value,
42
43#include <xrpl/protocol/detail/ledger_entries.macro>
44
45#undef LEDGER_ENTRY
46#pragma pop_macro("LEDGER_ENTRY")
47
48 //---------------------------------------------------------------------------
58 ltANY = 0,
59
70 ltCHILD = 0x1CD2,
71
72 //---------------------------------------------------------------------------
79 ltNICKNAME [[deprecated("This object type is not supported and should not be used.")]] = 0x006e,
80
87 ltCONTRACT [[deprecated("This object type is not supported and should not be used.")]] = 0x0063,
88
95 ltGENERATOR_MAP [[deprecated("This object type is not supported and should not be used.")]] =
96 0x0067,
97};
98
109#pragma push_macro("XMACRO")
110#pragma push_macro("TO_VALUE")
111#pragma push_macro("VALUE_TO_MAP")
112#pragma push_macro("NULL_NAME")
113#pragma push_macro("TO_MAP")
114#pragma push_macro("ALL_LEDGER_FLAGS")
115
116#undef XMACRO
117#undef TO_VALUE
118#undef VALUE_TO_MAP
119#undef NULL_NAME
120#undef TO_MAP
121
122#undef ALL_LEDGER_FLAGS
123
124// clang-format off
125
126#define XMACRO(LEDGER_OBJECT, LSF_FLAG, LSF_FLAG2) \
127 LEDGER_OBJECT(AccountRoot, \
128 LSF_FLAG(lsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \
129 LSF_FLAG(lsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \
130 LSF_FLAG(lsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \
131 LSF_FLAG(lsfDisallowXRP, 0x00080000) /* True, to disallow sending XRP. */ \
132 LSF_FLAG(lsfDisableMaster, 0x00100000) /* True, force regular key */ \
133 LSF_FLAG(lsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \
134 LSF_FLAG(lsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \
135 LSF_FLAG(lsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \
136 LSF_FLAG(lsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \
137 LSF_FLAG(lsfDisallowIncomingNFTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \
138 LSF_FLAG(lsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \
139 LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \
140 LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \
141 LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \
142 LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \
143 \
144 LEDGER_OBJECT(Offer, \
145 LSF_FLAG(lsfPassive, 0x00010000) \
146 LSF_FLAG(lsfSell, 0x00020000) /* True, offer was placed as a sell. */ \
147 LSF_FLAG(lsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \
148 \
149 LEDGER_OBJECT(RippleState, \
150 LSF_FLAG(lsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \
151 LSF_FLAG(lsfHighReserve, 0x00020000) \
152 LSF_FLAG(lsfLowAuth, 0x00040000) \
153 LSF_FLAG(lsfHighAuth, 0x00080000) \
154 LSF_FLAG(lsfLowNoRipple, 0x00100000) \
155 LSF_FLAG(lsfHighNoRipple, 0x00200000) \
156 LSF_FLAG(lsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \
157 LSF_FLAG(lsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \
158 LSF_FLAG(lsfAMMNode, 0x01000000) /* True, trust line to AMM. */ \
159 /* Used by client apps to identify payments via AMM. */ \
160 LSF_FLAG(lsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \
161 LSF_FLAG(lsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \
162 \
163 LEDGER_OBJECT(SignerList, \
164 LSF_FLAG(lsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \
165 \
166 LEDGER_OBJECT(DirNode, \
167 LSF_FLAG(lsfNFTokenBuyOffers, 0x00000001) \
168 LSF_FLAG(lsfNFTokenSellOffers, 0x00000002)) \
169 \
170 LEDGER_OBJECT(NFTokenOffer, \
171 LSF_FLAG(lsfSellNFToken, 0x00000001)) \
172 \
173 LEDGER_OBJECT(MPTokenIssuance, \
174 LSF_FLAG(lsfMPTLocked, 0x00000001) /* Also used in ltMPTOKEN */ \
175 LSF_FLAG(lsfMPTCanLock, 0x00000002) \
176 LSF_FLAG(lsfMPTRequireAuth, 0x00000004) \
177 LSF_FLAG(lsfMPTCanEscrow, 0x00000008) \
178 LSF_FLAG(lsfMPTCanTrade, 0x00000010) \
179 LSF_FLAG(lsfMPTCanTransfer, 0x00000020) \
180 LSF_FLAG(lsfMPTCanClawback, 0x00000040) \
181 LSF_FLAG(lsfMPTCanHoldConfidentialBalance, 0x00000080)) \
182 \
183 LEDGER_OBJECT(MPTokenIssuanceMutable, \
184 LSF_FLAG(lsmfMPTCanEnableCanLock, 0x00000002) \
185 LSF_FLAG(lsmfMPTCanEnableRequireAuth, 0x00000004) \
186 LSF_FLAG(lsmfMPTCanEnableCanEscrow, 0x00000008) \
187 LSF_FLAG(lsmfMPTCanEnableCanTrade, 0x00000010) \
188 LSF_FLAG(lsmfMPTCanEnableCanTransfer, 0x00000020) \
189 LSF_FLAG(lsmfMPTCanEnableCanClawback, 0x00000040) \
190 LSF_FLAG(lsmfMPTCannotEnableCanHoldConfidentialBalance, 0x00000080) \
191 LSF_FLAG(lsmfMPTCanMutateMetadata, 0x00010000) \
192 LSF_FLAG(lsmfMPTCanMutateTransferFee, 0x00020000)) \
193 \
194 LEDGER_OBJECT(MPToken, \
195 LSF_FLAG2(lsfMPTLocked, 0x00000001) \
196 LSF_FLAG(lsfMPTAuthorized, 0x00000002) \
197 LSF_FLAG(lsfMPTAMM, 0x00000004)) \
198 \
199 LEDGER_OBJECT(Credential, \
200 LSF_FLAG(lsfAccepted, 0x00010000)) \
201 \
202 LEDGER_OBJECT(Vault, \
203 LSF_FLAG(lsfVaultPrivate, 0x00010000)) \
204 \
205 LEDGER_OBJECT(Loan, \
206 LSF_FLAG(lsfLoanDefault, 0x00010000) \
207 LSF_FLAG(lsfLoanImpaired, 0x00020000) \
208 LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */
209
210// clang-format on
211
212// Create all the flag values as an enum.
213//
214// example:
215// enum LedgerSpecificFlags {
216// lsfPasswordSpent = 0x00010000,
217// lsfRequireDestTag = 0x00020000,
218// ...
219// };
220#define TO_VALUE(name, value) name = (value),
221#define NULL_NAME(name, values) values
222#define NULL_OUTPUT(name, value)
223// Bitwise flag enum
224// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
225enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
226
227// Create getter functions for each set of flags using Meyer's singleton pattern.
228// This avoids static initialization order fiasco while still providing efficient access.
229// This is used below in `getAllLedgerFlags()` to generate the server_definitions RPC output.
230//
231// example:
232// inline LedgerFlagMap const& getAccountRootFlags() {
233// static LedgerFlagMap const flags = {
234// {"lsfPasswordSpent", 0x00010000},
235// {"lsfRequireDestTag", 0x00020000},
236// ...};
237// return flags;
238// }
240#define VALUE_TO_MAP(name, value) {#name, value},
241#define TO_MAP(name, values) \
242 inline LedgerFlagMap const& get##name##Flags() \
243 { \
244 static LedgerFlagMap const flags = {values}; \
245 return flags; \
246 }
247XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP)
248
249// Create a getter function for all ledger flag maps using Meyer's singleton pattern.
250// This is used to generate the server_definitions RPC output.
251//
252// example:
253// inline std::vector<std::pair<std::string, LedgerFlagMap>> const& getAllLedgerFlags() {
254// static std::vector<std::pair<std::string, LedgerFlagMap>> const flags = {
255// {"AccountRoot", getAccountRootFlags()},
256// ...};
257// return flags;
258// }
259#define ALL_LEDGER_FLAGS(name, values) {#name, get##name##Flags()},
262{
264 XMACRO(ALL_LEDGER_FLAGS, NULL_OUTPUT, NULL_OUTPUT)};
265 return flags;
266}
267
268#undef XMACRO
269#undef TO_VALUE
270#undef VALUE_TO_MAP
271#undef NULL_NAME
272#undef NULL_OUTPUT
273#undef TO_MAP
274#undef ALL_LEDGER_FLAGS
275
276#pragma pop_macro("XMACRO")
277#pragma pop_macro("TO_VALUE")
278#pragma pop_macro("VALUE_TO_MAP")
279#pragma pop_macro("NULL_NAME")
280#pragma pop_macro("TO_MAP")
281#pragma pop_macro("ALL_LEDGER_FLAGS")
282
283//------------------------------------------------------------------------------
284
287class LedgerFormats : public KnownFormats<LedgerEntryType, LedgerFormats>
288{
289private:
294
295public:
296 static LedgerFormats const&
297 getInstance();
298
299 // Fields shared by all ledger entry formats:
300 static std::vector<SOElement> const&
302};
303
304} // namespace xrpl
305
306// NOLINTEND(readability-identifier-naming)
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
std::map< std::string, std::uint32_t > LedgerFlagMap
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.