1#include <xrpl/protocol/Permissions.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/protocol/Rules.h>
7#include <xrpl/protocol/SField.h>
8#include <xrpl/protocol/SOTemplate.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TxFlags.h>
11#include <xrpl/protocol/TxFormats.h>
42#pragma push_macro("TRANSACTION")
45#define TRANSACTION(tag, value, name, delegable, amendment, ...) \
46 txDelegationMap_[static_cast<TxType>(value)] = {amendment, delegable};
48#include <xrpl/protocol/detail/transactions.macro>
51#pragma pop_macro("TRANSACTION")
55#pragma push_macro("GRANULAR_PERMISSION")
56#undef GRANULAR_PERMISSION
58#define GRANULAR_PERMISSION(type, ...) {#type, type},
60#include <xrpl/protocol/detail/permissions.macro>
62#undef GRANULAR_PERMISSION
63#pragma pop_macro("GRANULAR_PERMISSION")
67#pragma push_macro("GRANULAR_PERMISSION")
68#undef GRANULAR_PERMISSION
71#define GRANULAR_PERMISSION(type, txType, value, flags, fields) \
72 granularPermissions_.emplace( \
73 std::piecewise_construct, \
74 std::forward_as_tuple(GranularPermissionType::type), \
75 std::forward_as_tuple( \
76 #type, txType, static_cast<std::uint32_t>(flags), std::vector<SOElement> fields));
79#include <xrpl/protocol/detail/permissions.macro>
81#undef GRANULAR_PERMISSION
82#pragma pop_macro("GRANULAR_PERMISSION")
89 "granularPermissionsByName_ and granularPermissions_ must have same size");
95 if (type <= UINT16_MAX)
99 "Granular permission value must exceed the maximum uint16_t value: " + name);
126 for (
auto const& field : entry.permittedFields)
128 if (fmt->getSOTemplate().getIndex(field.sField()) == -1)
159 return item->getName();
170 return static_cast<uint32_t
>(it->second);
180 return it->second.name;
190 return it->second.txType;
207 "xrpl::Permission::getTxFeature : tx exists in txDelegationMap_");
209 if (it->second.amendment ==
uint256{})
218 if (permissionValue == 0)
222 return entry.amendment ==
uint256{} || rules.
enabled(entry.amendment);
228 if (
auto const granularIt =
245 amendmentEnabled(txIt->second);
251 return static_cast<uint32_t
>(type) + 1;
262 return static_cast<TxType>(value - 1);
273 for (
auto const& gp : heldPermissions)
277 unionFlags |= it->second.permittedFlags;
281 if ((tx.
getFlags() & ~unionFlags) != 0)
286 for (
auto const& field : tx)
288 if (field.getSType() == STI_NOTPRESENT)
294 it->second.permittedFields.getIndex(field.getFName()) != -1;
std::unordered_map< std::string, GranularPermissionType > granularPermissionsByName_
static uint32_t txToPermissionType(TxType type)
std::optional< std::uint32_t > getGranularValue(std::string const &name) const
std::unordered_map< TxType, TxDelegationEntry > txDelegationMap_
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
std::unordered_map< GranularPermissionType, GranularPermissionEntry > granularPermissions_
std::unordered_set< TxType > granularTxTypes_
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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::uint32_t getFlags() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TxType
Transaction type identifiers.
GranularPermissionType
We have both transaction type permissions and granular type permissions.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
SOTemplate permittedFields
std::uint32_t permittedFlags
GranularPermissionEntry(std::string name, TxType txType, std::uint32_t permittedFlags, std::vector< SOElement > fields)