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};
107
119#pragma push_macro("XMACRO")
120#pragma push_macro("TO_VALUE")
121#pragma push_macro("VALUE_TO_MAP")
122#pragma push_macro("NULL_NAME")
123#pragma push_macro("TO_MAP")
124#pragma push_macro("ALL_LEDGER_FLAGS")
125
126#undef XMACRO
127#undef TO_VALUE
128#undef VALUE_TO_MAP
129#undef NULL_NAME
130#undef TO_MAP
131
132#undef ALL_LEDGER_FLAGS
133
134// clang-format off
135
136#define XMACRO(LEDGER_OBJECT, LSF_FLAG, LSF_FLAG2) \
137 LEDGER_OBJECT(AccountRoot, \
138 LSF_FLAG(lsfPasswordSpent, 0x00010000) /* True, if password set fee is spent. */ \
139 LSF_FLAG(lsfRequireDestTag, 0x00020000) /* True, to require a DestinationTag for payments. */ \
140 LSF_FLAG(lsfRequireAuth, 0x00040000) /* True, to require a authorization to hold IOUs. */ \
141 LSF_FLAG(lsfDisallowXRP, 0x00080000) /* True, to disallow sending XRP. */ \
142 LSF_FLAG(lsfDisableMaster, 0x00100000) /* True, force regular key */ \
143 LSF_FLAG(lsfNoFreeze, 0x00200000) /* True, cannot freeze ripple states */ \
144 LSF_FLAG(lsfGlobalFreeze, 0x00400000) /* True, all assets frozen */ \
145 LSF_FLAG(lsfDefaultRipple, 0x00800000) /* True, incoming trust lines allow rippling by default */ \
146 LSF_FLAG(lsfDepositAuth, 0x01000000) /* True, all deposits require authorization */ \
147 LSF_FLAG(lsfDisallowIncomingNFTokenOffer, 0x04000000) /* True, reject new incoming NFT offers */ \
148 LSF_FLAG(lsfDisallowIncomingCheck, 0x08000000) /* True, reject new checks */ \
149 LSF_FLAG(lsfDisallowIncomingPayChan, 0x10000000) /* True, reject new paychans */ \
150 LSF_FLAG(lsfDisallowIncomingTrustline, 0x20000000) /* True, reject new trustlines (only if no issued assets) */ \
151 LSF_FLAG(lsfAllowTrustLineLocking, 0x40000000) /* True, enable trustline locking */ \
152 LSF_FLAG(lsfAllowTrustLineClawback, 0x80000000)) /* True, enable clawback */ \
153 \
154 LEDGER_OBJECT(Offer, \
155 LSF_FLAG(lsfPassive, 0x00010000) \
156 LSF_FLAG(lsfSell, 0x00020000) /* True, offer was placed as a sell. */ \
157 LSF_FLAG(lsfHybrid, 0x00040000)) /* True, offer is hybrid. */ \
158 \
159 LEDGER_OBJECT(RippleState, \
160 LSF_FLAG(lsfLowReserve, 0x00010000) /* True, if entry counts toward reserve. */ \
161 LSF_FLAG(lsfHighReserve, 0x00020000) \
162 LSF_FLAG(lsfLowAuth, 0x00040000) \
163 LSF_FLAG(lsfHighAuth, 0x00080000) \
164 LSF_FLAG(lsfLowNoRipple, 0x00100000) \
165 LSF_FLAG(lsfHighNoRipple, 0x00200000) \
166 LSF_FLAG(lsfLowFreeze, 0x00400000) /* True, low side has set freeze flag */ \
167 LSF_FLAG(lsfHighFreeze, 0x00800000) /* True, high side has set freeze flag */ \
168 LSF_FLAG(lsfAMMNode, 0x01000000) /* True, trust line to AMM. */ \
169 /* Used by client apps to identify payments via AMM. */ \
170 LSF_FLAG(lsfLowDeepFreeze, 0x02000000) /* True, low side has set deep freeze flag */ \
171 LSF_FLAG(lsfHighDeepFreeze, 0x04000000)) /* True, high side has set deep freeze flag */ \
172 \
173 LEDGER_OBJECT(SignerList, \
174 LSF_FLAG(lsfOneOwnerCount, 0x00010000)) /* True, uses only one OwnerCount */ \
175 \
176 LEDGER_OBJECT(DirNode, \
177 LSF_FLAG(lsfNFTokenBuyOffers, 0x00000001) \
178 LSF_FLAG(lsfNFTokenSellOffers, 0x00000002)) \
179 \
180 LEDGER_OBJECT(NFTokenOffer, \
181 LSF_FLAG(lsfSellNFToken, 0x00000001)) \
182 \
183 LEDGER_OBJECT(MPTokenIssuance, \
184 LSF_FLAG(lsfMPTLocked, 0x00000001) /* Also used in ltMPTOKEN */ \
185 LSF_FLAG(lsfMPTCanLock, 0x00000002) \
186 LSF_FLAG(lsfMPTRequireAuth, 0x00000004) \
187 LSF_FLAG(lsfMPTCanEscrow, 0x00000008) \
188 LSF_FLAG(lsfMPTCanTrade, 0x00000010) \
189 LSF_FLAG(lsfMPTCanTransfer, 0x00000020) \
190 LSF_FLAG(lsfMPTCanClawback, 0x00000040) \
191 LSF_FLAG(lsfMPTCanHoldConfidentialBalance, 0x00000080)) \
192 \
193 LEDGER_OBJECT(MPToken, \
194 LSF_FLAG2(lsfMPTLocked, 0x00000001) \
195 LSF_FLAG(lsfMPTAuthorized, 0x00000002) \
196 LSF_FLAG(lsfMPTAMM, 0x00000004)) \
197 \
198 LEDGER_OBJECT(Credential, \
199 LSF_FLAG(lsfAccepted, 0x00010000)) \
200 \
201 LEDGER_OBJECT(Vault, \
202 LSF_FLAG(lsfVaultPrivate, 0x00010000)) \
203 \
204 LEDGER_OBJECT(Loan, \
205 LSF_FLAG(lsfLoanDefault, 0x00010000) \
206 LSF_FLAG(lsfLoanImpaired, 0x00020000) \
207 LSF_FLAG(lsfLoanOverpayment, 0x00040000)) /* True, loan allows overpayments */ \
208 \
209 LEDGER_OBJECT(Sponsorship, \
210 LSF_FLAG(lsfSponsorshipRequireSignForFee, 0x00010000) \
211 LSF_FLAG(lsfSponsorshipRequireSignForReserve, 0x00020000))
212
213// clang-format on
214
215// Create all the flag values as an enum.
216//
217// example:
218// enum LedgerSpecificFlags {
219// lsfPasswordSpent = 0x00010000,
220// lsfRequireDestTag = 0x00020000,
221// ...
222// };
223#define TO_VALUE(name, value) name = (value),
224#define NULL_NAME(name, values) values
225#define NULL_OUTPUT(name, value)
226// Bitwise flag enum
227// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
228enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
229
230// Create getter functions for each set of flags using Meyer's singleton pattern.
231// This avoids static initialization order fiasco while still providing efficient access.
232// This is used below in `getAllLedgerFlags()` to generate the server_definitions RPC output.
233//
234// example:
235// inline LedgerFlagMap const& getAccountRootFlags() {
236// static LedgerFlagMap const flags = {
237// {"lsfPasswordSpent", 0x00010000},
238// {"lsfRequireDestTag", 0x00020000},
239// ...};
240// return flags;
241// }
243#define VALUE_TO_MAP(name, value) {#name, value},
244#define TO_MAP(name, values) \
245 inline LedgerFlagMap const& get##name##Flags() \
246 { \
247 static LedgerFlagMap const flags = {values}; \
248 return flags; \
249 }
250XMACRO(TO_MAP, VALUE_TO_MAP, VALUE_TO_MAP)
251
252// Create a getter function for all ledger flag maps using Meyer's singleton pattern.
253// This is used to generate the server_definitions RPC output.
254//
255// example:
256// inline std::vector<std::pair<std::string, LedgerFlagMap>> const& getAllLedgerFlags() {
257// static std::vector<std::pair<std::string, LedgerFlagMap>> const flags = {
258// {"AccountRoot", getAccountRootFlags()},
259// ...};
260// return flags;
261// }
262#define ALL_LEDGER_FLAGS(name, values) {#name, get##name##Flags()},
265{
267 XMACRO(ALL_LEDGER_FLAGS, NULL_OUTPUT, NULL_OUTPUT)};
268 return flags;
269}
270
271#undef XMACRO
272#undef TO_VALUE
273#undef VALUE_TO_MAP
274#undef NULL_NAME
275#undef NULL_OUTPUT
276#undef TO_MAP
277#undef ALL_LEDGER_FLAGS
278
279#pragma pop_macro("XMACRO")
280#pragma pop_macro("TO_VALUE")
281#pragma pop_macro("VALUE_TO_MAP")
282#pragma pop_macro("NULL_NAME")
283#pragma pop_macro("TO_MAP")
284#pragma pop_macro("ALL_LEDGER_FLAGS")
285
286// MPTokenIssuance ImmutableFlags (sfImmutableFlags)
287inline constexpr std::uint32_t lsifMPTCanLock = 0x00000002;
288inline constexpr std::uint32_t lsifMPTRequireAuth = 0x00000004;
289inline constexpr std::uint32_t lsifMPTCanEscrow = 0x00000008;
290inline constexpr std::uint32_t lsifMPTCanTrade = 0x00000010;
291inline constexpr std::uint32_t lsifMPTCanTransfer = 0x00000020;
292inline constexpr std::uint32_t lsifMPTCanClawback = 0x00000040;
294inline constexpr std::uint32_t lsifMPTMetadata = 0x00010000;
295inline constexpr std::uint32_t lsifMPTTransferFee = 0x00020000;
296
297//------------------------------------------------------------------------------
298
302class LedgerFormats : public KnownFormats<LedgerEntryType, LedgerFormats>
303{
304private:
310
311public:
312 static LedgerFormats const&
313 getInstance();
314
315 // Fields shared by all ledger entry formats:
316 static std::vector<SOElement> const&
318};
319
320} // namespace xrpl
321
322// 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.
@ ltANY
A special type, matching any ledger entry type.
@ ltCHILD
A special type, matching any ledger type except directory nodes.
constexpr std::uint32_t lsifMPTCanLock
constexpr std::uint32_t lsifMPTTransferFee
constexpr std::uint32_t lsifMPTCanTransfer