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#include <xrpl/protocol/TxSettings.h>
8
9#include <cstdint>
10#include <functional>
11#include <optional>
12#include <string>
13#include <unordered_map>
14#include <unordered_set>
15#include <vector>
16
17namespace xrpl {
18
19class STTx;
20
28// Macro-generated, complex
29// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
31#pragma push_macro("GRANULAR_PERMISSION")
32#undef GRANULAR_PERMISSION
33
34#define GRANULAR_PERMISSION(name, txType, value, ...) name = (value),
35
36#include <xrpl/protocol/detail/permissions.macro>
37
38#undef GRANULAR_PERMISSION
39#pragma pop_macro("GRANULAR_PERMISSION")
40};
41
43{
44private:
45 Permission();
46
60
66
71
72public:
73 static Permission const&
75
76 Permission(Permission const&) = delete;
78 operator=(Permission const&) = delete;
79
80 [[nodiscard]] std::optional<std::string>
82
84 getGranularValue(std::string const& name) const;
85
86 [[nodiscard]] std::optional<std::string>
88
89 [[nodiscard]] std::optional<TxType>
91
92 // Returns a reference to avoid copying UInt256 - 32 bytes. std::optional
93 // cannot hold references directly, so std::reference_wrapper is used.
95 getTxFeature(TxType txType) const;
96
97 [[nodiscard]] bool
98 isDelegable(std::uint32_t permissionValue, Rules const& rules) const;
99
100 [[nodiscard]] bool
101 hasGranularPermissions(TxType txType) const;
102
103 // for tx level permission, permission value is equal to tx type plus one
104 [[nodiscard]] static uint32_t
106
107 // tx type value is permission value minus one
108 [[nodiscard]] static std::optional<TxType>
110
123 [[nodiscard]] bool
125 STTx const& tx,
126 std::unordered_set<GranularPermissionType> const& heldPermissions) const;
127};
128
129} // namespace xrpl
std::unordered_map< std::string, GranularPermissionType > granularPermissionsByName_
Definition Permissions.h:69
static uint32_t txToPermissionType(TxType type)
std::optional< std::uint32_t > getGranularValue(std::string const &name) const
std::optional< std::reference_wrapper< UInt256 const > > getTxFeature(TxType txType) const
std::unordered_map< TxType, TxDelegationEntry > txDelegationMap_
Definition Permissions.h:68
std::optional< TxType > getGranularTxType(GranularPermissionType gpType) const
bool hasGranularPermissions(TxType txType) const
std::optional< std::string > getGranularName(GranularPermissionType value) const
Permission(Permission const &)=delete
std::unordered_map< GranularPermissionType, GranularPermissionEntry > granularPermissions_
Definition Permissions.h:70
std::unordered_set< TxType > granularTxTypes_
Definition Permissions.h:67
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:30
BaseUInt< 256 > UInt256
Definition base_uint.h:580
Delegation
Definition TxSettings.h:11
GranularPermissionEntry(std::string name, TxType txType, std::uint32_t permittedFlags, std::vector< SOElement > fields)