xrpld
Loading...
Searching...
No Matches
Permissions.h
1#pragma once
2
3#include <xrpl/protocol/Rules.h>
4#include <xrpl/protocol/TER.h>
5#include <xrpl/protocol/TxFormats.h>
6
7#include <optional>
8#include <string>
9#include <unordered_map>
10#include <unordered_set>
11#include <vector>
12
13namespace xrpl {
14
15class STTx;
16
24// Macro-generated, complex
25// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
27#pragma push_macro("GRANULAR_PERMISSION")
28#undef GRANULAR_PERMISSION
29
30#define GRANULAR_PERMISSION(name, txType, value, ...) name = (value),
31
32#include <xrpl/protocol/detail/permissions.macro>
33
34#undef GRANULAR_PERMISSION
35#pragma pop_macro("GRANULAR_PERMISSION")
36};
37
38// Injected bare enumerators (xrpl::delegable / xrpl::notDelegable) are required by preprocessor
39// tricks in tests and macro-generated code; enum class would break that.
40// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
42
44{
45private:
46 Permission();
47
61
67
72
73public:
74 static Permission const&
76
77 Permission(Permission const&) = delete;
79 operator=(Permission const&) = delete;
80
81 [[nodiscard]] std::optional<std::string>
83
85 getGranularValue(std::string const& name) const;
86
87 [[nodiscard]] std::optional<std::string>
89
90 [[nodiscard]] std::optional<TxType>
92
93 // Returns a reference to avoid copying uint256 - 32 bytes. std::optional
94 // cannot hold references directly, so std::reference_wrapper is used.
96 getTxFeature(TxType txType) const;
97
98 [[nodiscard]] bool
99 isDelegable(std::uint32_t permissionValue, Rules const& rules) const;
100
101 [[nodiscard]] bool
102 hasGranularPermissions(TxType txType) const;
103
104 // for tx level permission, permission value is equal to tx type plus one
105 [[nodiscard]] static uint32_t
107
108 // tx type value is permission value minus one
109 [[nodiscard]] static std::optional<TxType>
111
124 [[nodiscard]] bool
126 STTx const& tx,
127 std::unordered_set<GranularPermissionType> const& heldPermissions) const;
128};
129
130} // namespace xrpl
std::unordered_map< std::string, GranularPermissionType > granularPermissionsByName_
Definition Permissions.h:70
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:69
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:71
std::unordered_set< TxType > granularTxTypes_
Definition Permissions.h:68
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:33
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:96
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:41
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition Permissions.h:26
BaseUInt< 256 > uint256
Definition base_uint.h:562
@ NotDelegable
Definition Permissions.h:41
@ Delegable
Definition Permissions.h:41
GranularPermissionEntry(std::string name, TxType txType, std::uint32_t permittedFlags, std::vector< SOElement > fields)