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>
43#pragma push_macro("TRANSACTION")
46#define TRANSACTION(tag, value, name, delegable, amendment, ...) \
47 txDelegationMap_[static_cast<TxType>(value)] = {amendment, delegable};
49#include <xrpl/protocol/detail/transactions.macro>
52#pragma pop_macro("TRANSACTION")
56#pragma push_macro("GRANULAR_PERMISSION")
57#undef GRANULAR_PERMISSION
59#define GRANULAR_PERMISSION(type, ...) {#type, type},
61#include <xrpl/protocol/detail/permissions.macro>
63#undef GRANULAR_PERMISSION
64#pragma pop_macro("GRANULAR_PERMISSION")
68#pragma push_macro("GRANULAR_PERMISSION")
69#undef GRANULAR_PERMISSION
72#define GRANULAR_PERMISSION(type, txType, value, flags, fields) \
73 granularPermissions_.emplace( \
74 std::piecewise_construct, \
75 std::forward_as_tuple(GranularPermissionType::type), \
76 std::forward_as_tuple( \
77 #type, txType, static_cast<std::uint32_t>(flags), std::vector<SOElement> fields));
80#include <xrpl/protocol/detail/permissions.macro>
82#undef GRANULAR_PERMISSION
83#pragma pop_macro("GRANULAR_PERMISSION")
90 "granularPermissionsByName_ and granularPermissions_ must have same size");
96 if (type <= UINT16_MAX)
100 "Granular permission value must exceed the maximum uint16_t value: " + name);
127 for (
auto const& field : entry.permittedFields)
129 if (
fmt->getSOTemplate().getIndex(field.sField()) == -1)
160 return item->getName();
171 return static_cast<uint32_t
>(it->second);
181 return it->second.name;
191 return it->second.txType;
208 "xrpl::Permission::getTxFeature : tx exists in txDelegationMap_");
210 if (it->second.amendment ==
uint256{})
219 if (permissionValue == 0)
223 return entry.amendment ==
uint256{} || rules.
enabled(entry.amendment);
229 if (
auto const granularIt =
246 amendmentEnabled(txIt->second);
252 return static_cast<uint32_t
>(type) + 1;
263 return static_cast<TxType>(value - 1);
274 for (
auto const& gp : heldPermissions)
278 unionFlags |= it->second.permittedFlags;
282 if ((tx.
getFlags() & ~unionFlags) != 0)
287 for (
auto const& field : tx)
289 if (field.getSType() == STI_NOTPRESENT)
295 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.
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)