xrpld
Loading...
Searching...
No Matches
libxrpl
tx
transactors
delegate
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
12
namespace
xrpl
{
13
NotTEC
14
checkTxPermission
(
SLE::const_ref
delegate,
STTx
const
& tx)
15
{
16
if
(!delegate)
17
return
terNO_DELEGATE_PERMISSION
;
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
29
return
terNO_DELEGATE_PERMISSION
;
30
}
31
32
std::unordered_set<GranularPermissionType>
33
getGranularPermission
(
SLE::const_ref
delegate,
TxType
const
& txType)
34
{
35
std::unordered_set<GranularPermissionType>
granularPermissions;
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
xrpl::Permission::getGranularTxType
std::optional< TxType > getGranularTxType(GranularPermissionType gpType) const
Definition
Permissions.cpp:186
xrpl::Permission::getInstance
static Permission const & getInstance()
Definition
Permissions.cpp:139
xrpl::STLedgerEntry::const_ref
std::shared_ptr< STLedgerEntry const > const & const_ref
Definition
STLedgerEntry.h:22
xrpl::STTx
Definition
STTx.h:28
xrpl::STTx::getTxnType
TxType getTxnType() const
Definition
STTx.h:188
std::unordered_set::insert
T insert(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::terNO_DELEGATE_PERMISSION
@ terNO_DELEGATE_PERMISSION
Definition
TER.h:222
xrpl::TxType
TxType
Transaction type identifiers.
Definition
TxFormats.h:41
xrpl::getGranularPermission
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.
Definition
DelegateUtils.cpp:33
xrpl::checkTxPermission
NotTEC checkTxPermission(SLE::const_ref delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
Definition
DelegateUtils.cpp:14
xrpl::GranularPermissionType
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition
Permissions.h:26
xrpl::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition
TER.h:594
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:240
unordered_set
Generated by
1.16.1