rippled
Loading...
Searching...
No Matches
DelegateUtils.cpp
1#include <xrpl/protocol/STArray.h>
2#include <xrpl/tx/transactors/Delegate/DelegateUtils.h>
3
4namespace xrpl {
7{
8 if (!delegate)
9 return terNO_DELEGATE_PERMISSION; // LCOV_EXCL_LINE
10
11 auto const permissionArray = delegate->getFieldArray(sfPermissions);
12 auto const txPermission = tx.getTxnType() + 1;
13
14 for (auto const& permission : permissionArray)
15 {
16 auto const permissionValue = permission[sfPermissionValue];
17 if (permissionValue == txPermission)
18 return tesSUCCESS;
19 }
20
22}
23
24void
26 std::shared_ptr<SLE const> const& delegate,
27 TxType const& txType,
29{
30 if (!delegate)
31 return; // LCOV_EXCL_LINE
32
33 auto const permissionArray = delegate->getFieldArray(sfPermissions);
34 for (auto const& permission : permissionArray)
35 {
36 auto const permissionValue = permission[sfPermissionValue];
37 auto const granularValue = static_cast<GranularPermissionType>(permissionValue);
38 auto const& type = Permission::getInstance().getGranularTxType(granularValue);
39 if (type && *type == txType)
40 granularPermissions.insert(granularValue);
41 }
42}
43
44} // namespace xrpl
std::optional< TxType > getGranularTxType(GranularPermissionType const &gpType) const
static Permission const & getInstance()
TxType getTxnType() const
Definition STTx.h:184
T insert(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_DELEGATE_PERMISSION
Definition TER.h:210
TxType
Transaction type identifiers.
Definition TxFormats.h:37
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition Permissions.h:19
void loadGranularPermission(std::shared_ptr< SLE const > const &delegate, TxType const &type, std::unordered_set< GranularPermissionType > &granularPermissions)
Load the granular permissions granted to the delegate account for the specified transaction type.
NotTEC checkTxPermission(std::shared_ptr< SLE const > const &delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:582
@ tesSUCCESS
Definition TER.h:225