xrpld
Loading...
Searching...
No Matches
LedgerFormats.h
1#pragma once
2
3// NOLINTBEGIN(readability-identifier-naming)
4
5#include <xrpl/protocol/KnownFormats.h>
6#include <xrpl/protocol/SOTemplate.h>
7
8#include <cstdint>
9#include <map>
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace xrpl {
38// Protocol-critical, hundreds of usages
39// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
41
42#pragma push_macro("LEDGER_ENTRY")
43#undef LEDGER_ENTRY
44
45#define LEDGER_ENTRY(tag, value, ...) tag = value,
46
47#include <xrpl/protocol/detail/ledger_entries.macro>
48
49#undef LEDGER_ENTRY
50#pragma pop_macro("LEDGER_ENTRY")
51
52 //---------------------------------------------------------------------------
63 ltANY = 0,
64
76 ltCHILD = 0x1CD2,
77
78 //---------------------------------------------------------------------------
86 ltNICKNAME [[deprecated("This object type is not supported and should not be used.")]] = 0x006e,
87
95 ltCONTRACT [[deprecated("This object type is not supported and should not be used.")]] = 0x0063,
96
104 ltGENERATOR_MAP [[deprecated("This object type is not supported and should not be used.")]] =
105 0x0067,
106
113 ltBRIDGE [[deprecated("This object type is not supported and should not be used.")]] = 0x0069,
114
122 [[deprecated("This object type is not supported and should not be used.")]] = 0x0071,
123
131 [[deprecated("This object type is not supported and should not be used.")]] = 0x0074,
132};
133
145#pragma push_macro("XMACRO")
146#pragma push_macro("TO_VALUE")
147#pragma push_macro("VALUE_TO_MAP")
148#pragma push_macro("NULL_NAME")
149#pragma push_macro("TO_MAP")
150#pragma push_macro("ALL_LEDGER_FLAGS")
151
152#undef XMACRO
153#undef TO_VALUE
154#undef VALUE_TO_MAP
155#undef NULL_NAME
156#undef TO_MAP
157
158#undef ALL_LEDGER_FLAGS
159
160// clang-format off
161
162#define XMACRO(LEDGER_OBJECT, LSF_FLAG, LSF_FLAG2) \
163 LEDGER_OBJECT(AccountRoot, \
164 LSF_FLAG(lsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \
165 LSF_FLAG(lsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \
166 LSF_FLAG(lsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \
167 LSF_FLAG(lsfDisallowXRP, 0x00080000) /* True, to disallow sending XRP. */ \
168 LSF_FLAG(lsfDisableMaster, 0x00100000) /* True, force regular key */ \
169 LSF_FLAG(lsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \
170 LSF_FLAG(lsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \
171 LSF_FLAG(lsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \
172 LSF_FLAG(lsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \
173 LSF_FLAG(lsfDisallowIncomingNFTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \
174 LSF_FLAG(lsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \
175 LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \
176 LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \
177 LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \
178 LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \
179 \
180 LEDGER_OBJECT(Offer, \
181 LSF_FLAG(lsfPassive, 0x00010000) \
182 LSF_FLAG(lsfSell, 0x00020000) /* True, offer was placed as a sell. */ \
183 LSF_FLAG(lsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \
184 \
185 LEDGER_OBJECT(RippleState, \
186 LSF_FLAG(lsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \
187 LSF_FLAG(lsfHighReserve, 0x00020000) \
188 LSF_FLAG(lsfLowAuth, 0x00040000) \
189 LSF_FLAG(lsfHighAuth, 0x00080000) \
190 LSF_FLAG(lsfLowNoRipple, 0x00100000) \
191 LSF_FLAG(lsfHighNoRipple, 0x00200000) \
192 LSF_FLAG(lsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \
193 LSF_FLAG(lsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \
194 LSF_FLAG(lsfAMMNode, 0x01000000) /* True, trust line to AMM. */ \
195 /* Used by client apps to identify payments via AMM. */ \
196 LSF_FLAG(lsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \
197 LSF_FLAG(lsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \
198 \
199 LEDGER_OBJECT(SignerList, \
200 LSF_FLAG(lsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \
201 \
202 LEDGER_OBJECT(DirNode, \
203 LSF_FLAG(lsfNFTokenBuyOffers, 0x00000001) \
204 LSF_FLAG(lsfNFTokenSellOffers, 0x00000002)) \
205 \
206 LEDGER_OBJECT(NFTokenOffer, \
207 LSF_FLAG(lsfSellNFToken, 0x00000001)) \
208 \
209 LEDGER_OBJECT(MPTokenIssuance, \
210 LSF_FLAG(lsfMPTLocked, 0x00000001) /* Also used in ltMPTOKEN */ \
211 LSF_FLAG(lsfMPTCanLock, 0x00000002) \
212 LSF_FLAG(lsfMPTRequireAuth, 0x00000004) \
213 LSF_FLAG(lsfMPTCanEscrow, 0x00000008) \
214 LSF_FLAG(lsfMPTCanTrade, 0x00000010) \
215 LSF_FLAG(lsfMPTCanTransfer, 0x00000020) \
216 LSF_FLAG(lsfMPTCanClawback, 0x00000040) \
217 LSF_FLAG(lsfMPTCanHoldConfidentialBalance, 0x00000080)) \
218 \
219 LEDGER_OBJECT(MPToken, \
220 LSF_FLAG2(lsfMPTLocked, 0x00000001) \
221 LSF_FLAG(lsfMPTAuthorized, 0x00000002) \
222 LSF_FLAG(lsfMPTAMM, 0x00000004)) \
223 \
224 LEDGER_OBJECT(Credential, \
225 LSF_FLAG(lsfAccepted, 0x00010000)) \
226 \
227 LEDGER_OBJECT(Vault, \
228 LSF_FLAG(lsfVaultPrivate, 0x00010000)) \
229 \
230 LEDGER_OBJECT(Loan, \
231 LSF_FLAG(lsfLoanDefault, 0x00010000) \
232 LSF_FLAG(lsfLoanImpaired, 0x00020000) \
233 LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */ \
234 \
235 LEDGER_OBJECT(Sponsorship, \
236 LSF_FLAG(lsfSponsorshipRequireSignForFee, 0x00010000) \
237 LSF_FLAG(lsfSponsorshipRequireSignForReserve, 0x00020000)) \
238 \
239 LEDGER_OBJECT(LoanBroker, \
240 LSF_FLAG(lsfLoanBrokerPrivate, 0x00010000))
241
242// clang-format on
243
244// Create all the flag values as an enum.
245//
246// example:
247// enum LedgerSpecificFlags {
248// lsfPasswordSpent = 0x00010000,
249// lsfRequireDestTag = 0x00020000,
250// ...
251// };
252#define TO_VALUE(name, value) name = (value),
253#define NULL_NAME(name, values) values
254#define NULL_OUTPUT(name, value)
255// Bitwise flag enum
256// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
257enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
258
259// Create getter functions for each set of flags using Meyer's singleton pattern.
260// This avoids static initialization order fiasco while still providing efficient access.
261// This is used below in `getAllLedgerFlags()` to generate the server_definitions RPC output.
262//
263// example:
264// inline LedgerFlagMap const& getAccountRootFlags() {
265// static LedgerFlagMap const flags = {
266// {"lsfPasswordSpent", 0x00010000},
267// {"lsfRequireDestTag", 0x00020000},
268// ...};
269// return flags;
270// }
272#define VALUE_TO_MAP(name, value) {#name, value},
273#define TO_MAP(name, values) \
274 inline LedgerFlagMap const& get##name##Flags() \
275 { \
276 static LedgerFlagMap const flags = {values}; \
277 return flags; \
278 }
279XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP)
280
281// Create a getter function for all ledger flag maps using Meyer's singleton pattern.
282// This is used to generate the server_definitions RPC output.
283//
284// example:
285// inline std::vector<std::pair<std::string, LedgerFlagMap>> const& getAllLedgerFlags() {
286// static std::vector<std::pair<std::string, LedgerFlagMap>> const flags = {
287// {"AccountRoot", getAccountRootFlags()},
288// ...};
289// return flags;
290// }
291#define ALL_LEDGER_FLAGS(name, values) {#name, get##name##Flags()},
294{
296 XMACRO(ALL_LEDGER_FLAGS, NULL_OUTPUT, NULL_OUTPUT)};
297 return flags;
298}
299
300#undef XMACRO
301#undef TO_VALUE
302#undef VALUE_TO_MAP
303#undef NULL_NAME
304#undef NULL_OUTPUT
305#undef TO_MAP
306#undef ALL_LEDGER_FLAGS
307
308#pragma pop_macro("XMACRO")
309#pragma pop_macro("TO_VALUE")
310#pragma pop_macro("VALUE_TO_MAP")
311#pragma pop_macro("NULL_NAME")
312#pragma pop_macro("TO_MAP")
313#pragma pop_macro("ALL_LEDGER_FLAGS")
314
315// MPTokenIssuance ImmutableFlags (sfImmutableFlags)
316inline constexpr std::uint32_t lsifMPTCanLock = 0x00000002;
317inline constexpr std::uint32_t lsifMPTRequireAuth = 0x00000004;
318inline constexpr std::uint32_t lsifMPTCanEscrow = 0x00000008;
319inline constexpr std::uint32_t lsifMPTCanTrade = 0x00000010;
320inline constexpr std::uint32_t lsifMPTCanTransfer = 0x00000020;
321inline constexpr std::uint32_t lsifMPTCanClawback = 0x00000040;
323inline constexpr std::uint32_t lsifMPTMetadata = 0x00010000;
324inline constexpr std::uint32_t lsifMPTTransferFee = 0x00020000;
325
326//------------------------------------------------------------------------------
327
331class LedgerFormats : public KnownFormats<LedgerEntryType, LedgerFormats>
332{
333private:
339
340public:
341 static LedgerFormats const&
342 getInstance();
343
344 // Fields shared by all ledger entry formats:
345 static std::vector<SOElement> const&
347};
348
349} // namespace xrpl
350
351// 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
constexpr std::uint32_t lsifMPTCanClawback
constexpr std::uint32_t lsifMPTCanHoldConfidentialBalance
constexpr std::uint32_t lsifMPTRequireAuth
constexpr std::uint32_t lsifMPTCanEscrow
LedgerSpecificFlags
constexpr std::uint32_t lsifMPTCanTrade
constexpr std::uint32_t lsifMPTMetadata
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.
@ ltBRIDGE
A deprecated type, removed with the XChainBridge amendment.
@ ltANY
A special type, matching any ledger entry type.
@ ltXCHAIN_OWNED_CLAIM_ID
A deprecated type, removed with the XChainBridge amendment.
@ ltCHILD
A special type, matching any ledger type except directory nodes.
@ ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID
A deprecated type, removed with the XChainBridge amendment.
constexpr std::uint32_t lsifMPTCanLock
constexpr std::uint32_t lsifMPTTransferFee
constexpr std::uint32_t lsifMPTCanTransfer