xrpld
Loading...
Searching...
No Matches
Permissions.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/protocol/Rules.h>
5#include <xrpl/protocol/SOTemplate.h>
6#include <xrpl/protocol/TxFormats.h>
7
8#include <cstdint>
9#include <functional>
10#include <optional>
11#include <string>
12#include <unordered_map>
13#include <unordered_set>
14#include <vector>
15
16namespace xrpl {
17
18class STTx;
19
27// Macro-generated, complex
28// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
30#pragma push_macro("GRANULAR_PERMISSION")
31#undef GRANULAR_PERMISSION
32
33#define GRANULAR_PERMISSION(name, txType, value, ...) name = (value),
34
35#include <xrpl/protocol/detail/permissions.macro>
36
37#undef GRANULAR_PERMISSION
38#pragma pop_macro("GRANULAR_PERMISSION")
39};
40
41// Injected bare enumerators (xrpl::delegable / xrpl::notDelegable) are required by preprocessor
42// tricks in tests and macro-generated code; enum class would break that.
43// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
45
47{
48private:
49 Permission();
50
64
70
75
76public:
77 static Permission const&
79
80 Permission(Permission const&) = delete;
82 operator=(Permission const&) = delete;
83
84 [[nodiscard]] std::optional<std::string>
86
88 getGranularValue(std::string const& name) const;
89
90 [[nodiscard]] std::optional<std::string>
92
93 [[nodiscard]] std::optional<TxType>
95
96 // Returns a reference to avoid copying uint256 - 32 bytes. std::optional
97 // cannot hold references directly, so std::reference_wrapper is used.
99 getTxFeature(TxType txType) const;
100
101 [[nodiscard]] bool
102 isDelegable(std::uint32_t permissionValue, Rules const& rules) const;
103
104 [[nodiscard]] bool
105 hasGranularPermissions(TxType txType) const;
106
107 // for tx level permission, permission value is equal to tx type plus one
108 [[nodiscard]] static uint32_t
110
111 // tx type value is permission value minus one
112 [[nodiscard]] static std::optional<TxType>
114
127 [[nodiscard]] bool
129 STTx const& tx,
130 std::unordered_set<GranularPermissionType> const& heldPermissions) const;
131};
132
133} // namespace xrpl
std::unordered_map< std::string, GranularPermissionType > granularPermissionsByName_
Definition Permissions.h:73
static uint32_t txToPermissionType(TxType type)
std::optional< std::uint32_t > getGranularValue(std::string const &name) const
std::unordered_map< TxType, TxDelegationEntry > txDelegationMap_
Definition Permissions.h:72
std::optional< TxType > getGranularTxType(GranularPermissionType gpType) const
bool hasGranularPermissions(TxType txType) const
std::optional< std::reference_wrapper< uint256 const > > getTxFeature(TxType txType) const
std::optional< std::string > getGranularName(GranularPermissionType value) const
Permission(Permission const &)=delete
std::unordered_map< GranularPermissionType, GranularPermissionEntry > granularPermissions_
Definition Permissions.h:74
std::unordered_set< TxType > granularTxTypes_
Definition Permissions.h:71
Permission & operator=(Permission const &)=delete
bool checkGranularSandbox(STTx const &tx, std::unordered_set< GranularPermissionType > const &heldPermissions) const
Verifies a delegated transaction against its granular permission template.
static std::optional< TxType > permissionToTxType(std::uint32_t value)
bool isDelegable(std::uint32_t permissionValue, Rules const &rules) const
std::optional< std::string > getPermissionName(std::uint32_t value) const
static Permission const & getInstance()
Rules controlling protocol behavior.
Definition Rules.h:40
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:105
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TxType
Transaction type identifiers.
Definition TxFormats.h:45
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition Permissions.h:29
BaseUInt< 256 > uint256
Definition base_uint.h:580
@ NotDelegable
Definition Permissions.h:44
@ Delegable
Definition Permissions.h:44
GranularPermissionEntry(std::string name, TxType txType, std::uint32_t permittedFlags, std::vector< SOElement > fields)