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/Feature.h>
7#include <xrpl/protocol/Rules.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/SOTemplate.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol/TxFlags.h>
12#include <xrpl/protocol/TxFormats.h>
13#include <xrpl/protocol/TxSettings.h>
45#pragma push_macro("UNWRAP")
47#pragma push_macro("TRANSACTION")
50#define UNWRAP(...) __VA_ARGS__
51#define TRANSACTION(tag, value, name, settings, ...) \
53 TxSettings const s = UNWRAP settings; \
54 txDelegationMap_[static_cast<TxType>(value)] = {s.amendment, s.delegable}; \
57#include <xrpl/protocol/detail/transactions.macro>
60#pragma pop_macro("TRANSACTION")
62#pragma pop_macro("UNWRAP")
66#pragma push_macro("GRANULAR_PERMISSION")
67#undef GRANULAR_PERMISSION
69#define GRANULAR_PERMISSION(type, ...) {#type, type},
71#include <xrpl/protocol/detail/permissions.macro>
73#undef GRANULAR_PERMISSION
74#pragma pop_macro("GRANULAR_PERMISSION")
78#pragma push_macro("GRANULAR_PERMISSION")
79#undef GRANULAR_PERMISSION
82#define GRANULAR_PERMISSION(type, txType, value, flags, fields) \
83 granularPermissions_.emplace( \
84 std::piecewise_construct, \
85 std::forward_as_tuple(GranularPermissionType::type), \
86 std::forward_as_tuple( \
87 #type, txType, static_cast<std::uint32_t>(flags), std::vector<SOElement> fields));
90#include <xrpl/protocol/detail/permissions.macro>
92#undef GRANULAR_PERMISSION
93#pragma pop_macro("GRANULAR_PERMISSION")
100 "granularPermissionsByName_ and granularPermissions_ must have same size");
106 if (type <= UINT16_MAX)
110 "Granular permission value must exceed the maximum uint16_t value: {}", name));
137 for (
auto const& field : entry.permittedFields)
139 if (
fmt->getSOTemplate().getIndex(field.sField()) == -1)
170 return item->getName();
181 return static_cast<uint32_t
>(it->second);
191 return it->second.name;
201 return it->second.txType;
218 "xrpl::Permission::getTxFeature : tx exists in txDelegationMap_");
220 if (it->second.amendment ==
UInt256{})
229 if (permissionValue == 0)
233 return entry.amendment ==
UInt256{} || rules.
enabled(entry.amendment);
239 if (
auto const granularIt =
256 amendmentEnabled(txIt->second);
262 return static_cast<uint32_t
>(type) + 1;
273 return static_cast<TxType>(value - 1);
284 for (
auto const& gp : heldPermissions)
288 unionFlags |= it->second.permittedFlags;
292 if ((tx.
getFlags() & ~unionFlags) != 0)
297 for (
auto const& field : tx)
299 if (field.getSType() == STI_NOTPRESENT)
305 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::optional< std::reference_wrapper< UInt256 const > > getTxFeature(TxType txType) const
std::unordered_map< TxType, TxDelegationEntry > txDelegationMap_
std::optional< TxType > getGranularTxType(GranularPermissionType gpType) const
bool hasGranularPermissions(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.
static std::string fmt(BigInt const &value)
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)