rippled
Loading...
Searching...
No Matches
Permissions.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2025 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_PERMISSION_H_INCLUDED
21#define RIPPLE_PROTOCOL_PERMISSION_H_INCLUDED
22
23#include <xrpl/protocol/TxFormats.h>
24
25#include <optional>
26#include <string>
27#include <unordered_map>
28#include <unordered_set>
29
30namespace ripple {
39#pragma push_macro("PERMISSION")
40#undef PERMISSION
41
42#define PERMISSION(type, txType, value) type = value,
43
44#include <xrpl/protocol/detail/permissions.macro>
45
46#undef PERMISSION
47#pragma pop_macro("PERMISSION")
48};
49
51
53{
54private:
55 Permission();
56
58
61
63
65
66public:
67 static Permission const&
69
70 Permission(Permission const&) = delete;
72 operator=(Permission const&) = delete;
73
75 getGranularValue(std::string const& name) const;
76
78 getGranularName(GranularPermissionType const& value) const;
79
81 getGranularTxType(GranularPermissionType const& gpType) const;
82
83 bool
84 isDelegatable(std::uint32_t const& permissionValue) const;
85
86 // for tx level permission, permission value is equal to tx type plus one
87 uint32_t
88 txToPermissionType(TxType const& type) const;
89
90 // tx type value is permission value minus one
91 TxType
92 permissionToTxType(uint32_t const& value) const;
93};
94
95} // namespace ripple
96
97#endif
std::unordered_map< std::uint16_t, Delegation > delegatableTx_
Definition: Permissions.h:57
TxType permissionToTxType(uint32_t const &value) const
bool isDelegatable(std::uint32_t const &permissionValue) const
std::optional< std::string > getGranularName(GranularPermissionType const &value) const
Permission(Permission const &)=delete
std::unordered_map< GranularPermissionType, std::string > granularNameMap_
Definition: Permissions.h:62
std::unordered_map< std::string, GranularPermissionType > granularPermissionMap_
Definition: Permissions.h:60
std::optional< std::uint32_t > getGranularValue(std::string const &name) const
Definition: Permissions.cpp:91
std::optional< TxType > getGranularTxType(GranularPermissionType const &gpType) const
uint32_t txToPermissionType(TxType const &type) const
Permission & operator=(Permission const &)=delete
static Permission const & getInstance()
Definition: Permissions.cpp:84
std::unordered_map< GranularPermissionType, TxType > granularTxTypeMap_
Definition: Permissions.h:64
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
TxType
Transaction type identifiers.
Definition: TxFormats.h:57
@ delegatable
Definition: Permissions.h:50
@ notDelegatable
Definition: Permissions.h:50
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition: Permissions.h:38