rippled
Loading...
Searching...
No Matches
InvariantCheckPrivilege.h
1#pragma once
2
3#include <xrpl/protocol/STTx.h>
4
5#include <type_traits>
6
7namespace xrpl {
8
9/*
10assert(enforce)
11
12There are several asserts (or XRPL_ASSERTs) in invariant check files that check
13a variable named `enforce` when an invariant fails. At first glance, those
14asserts may look incorrect, but they are not.
15
16Those asserts take advantage of two facts:
171. `asserts` are not (normally) executed in release builds.
182. Invariants should *never* fail, except in tests that specifically modify
19 the open ledger to break them.
20
21This makes `assert(enforce)` sort of a second-layer of invariant enforcement
22aimed at _developers_. It's designed to fire if a developer writes code that
23violates an invariant, and runs it in unit tests or a develop build that _does
24not have the relevant amendments enabled_. It's intentionally a pain in the neck
25so that bad code gets caught and fixed as early as possible.
26*/
27
29 noPriv = 0x0000, // The transaction can not do any of the enumerated operations
30 createAcct = 0x0001, // The transaction can create a new ACCOUNT_ROOT object.
31 createPseudoAcct = 0x0002, // The transaction can create a pseudo account,
32 // which implies createAcct
33 mustDeleteAcct = 0x0004, // The transaction must delete an ACCOUNT_ROOT object
34 mayDeleteAcct = 0x0008, // The transaction may delete an ACCOUNT_ROOT
35 // object, but does not have to
36 overrideFreeze = 0x0010, // The transaction can override some freeze rules
37 changeNFTCounts = 0x0020, // The transaction can mint or burn an NFT
38 createMPTIssuance = 0x0040, // The transaction can create a new MPT issuance
39 destroyMPTIssuance = 0x0080, // The transaction can destroy an MPT issuance
40 mustAuthorizeMPT = 0x0100, // The transaction MUST create or delete an MPT
41 // object (except by issuer)
42 mayAuthorizeMPT = 0x0200, // The transaction MAY create or delete an MPT
43 // object (except by issuer)
44 mayDeleteMPT = 0x0400, // The transaction MAY delete an MPT object. May not create.
45 mustModifyVault = 0x0800, // The transaction must modify, delete or create, a vault
46 mayModifyVault = 0x1000, // The transaction MAY modify, delete or create, a vault
47};
48
49constexpr Privilege
51{
52 return safe_cast<Privilege>(
55}
56
57bool
58hasPrivilege(STTx const& tx, Privilege priv);
59
60} // namespace xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition base_uint.h:587
bool hasPrivilege(STTx const &tx, Privilege priv)
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safe_cast(Src s) noexcept
Definition safe_cast.h:21