xrpld
Loading...
Searching...
No Matches
DelegateUtils.cpp
1#include <xrpl/ledger/helpers/DelegateHelpers.h>
2#include <xrpl/protocol/Permissions.h>
3#include <xrpl/protocol/SField.h>
4#include <xrpl/protocol/STArray.h>
5#include <xrpl/protocol/STLedgerEntry.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/protocol/TxFormats.h>
9
10#include <unordered_set>
11
12namespace xrpl {
15{
16 if (!delegate)
18
19 auto const permissionArray = delegate->getFieldArray(sfPermissions);
20 auto const txPermission = tx.getTxnType() + 1;
21
22 for (auto const& permission : permissionArray)
23 {
24 auto const permissionValue = permission[sfPermissionValue];
25 if (permissionValue == txPermission)
26 return tesSUCCESS;
27 }
28
30}
31
34{
36 if (!delegate)
37 return granularPermissions;
38
39 auto const permissionArray = delegate->getFieldArray(sfPermissions);
40 for (auto const& permission : permissionArray)
41 {
42 auto const permissionValue = permission[sfPermissionValue];
43 auto const granularValue = static_cast<GranularPermissionType>(permissionValue);
44 auto const& type = Permission::getInstance().getGranularTxType(granularValue);
45 if (type && *type == txType)
46 granularPermissions.insert(granularValue);
47 }
48
49 return granularPermissions;
50}
51
52} // namespace xrpl
std::optional< TxType > getGranularTxType(GranularPermissionType gpType) const
static Permission const & getInstance()
std::shared_ptr< STLedgerEntry const > const & const_ref
TxType getTxnType() const
Definition STTx.h:188
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:222
TxType
Transaction type identifiers.
Definition TxFormats.h:41
std::unordered_set< GranularPermissionType > getGranularPermission(SLE::const_ref delegate, TxType const &type)
Load the granular permissions granted to the delegate account for the specified transaction type.
NotTEC checkTxPermission(SLE::const_ref delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition Permissions.h:26
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
@ tesSUCCESS
Definition TER.h:240