rippled
Loading...
Searching...
No Matches
DelegateUtils.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2025 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/misc/DelegateUtils.h>
21
22#include <xrpl/protocol/STArray.h>
23
24namespace ripple {
27{
28 if (!delegate)
29 return terNO_DELEGATE_PERMISSION; // LCOV_EXCL_LINE
30
31 auto const permissionArray = delegate->getFieldArray(sfPermissions);
32 auto const txPermission = tx.getTxnType() + 1;
33
34 for (auto const& permission : permissionArray)
35 {
36 auto const permissionValue = permission[sfPermissionValue];
37 if (permissionValue == txPermission)
38 return tesSUCCESS;
39 }
40
42}
43
44void
46 std::shared_ptr<SLE const> const& delegate,
47 TxType const& txType,
49{
50 if (!delegate)
51 return; // LCOV_EXCL_LINE
52
53 auto const permissionArray = delegate->getFieldArray(sfPermissions);
54 for (auto const& permission : permissionArray)
55 {
56 auto const permissionValue = permission[sfPermissionValue];
57 auto const granularValue =
58 static_cast<GranularPermissionType>(permissionValue);
59 auto const& type =
61 if (type && *type == txType)
62 granularPermissions.insert(granularValue);
63 }
64}
65
66} // namespace ripple
std::optional< TxType > getGranularTxType(GranularPermissionType const &gpType) const
static Permission const & getInstance()
TxType getTxnType() const
Definition STTx.h:237
T insert(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
NotTEC checkTxPermission(std::shared_ptr< SLE const > const &delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
TxType
Transaction type identifiers.
Definition TxFormats.h:57
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.
@ tesSUCCESS
Definition TER.h:245
GranularPermissionType
We have both transaction type permissions and granular type permissions.
Definition Permissions.h:39
@ terNO_DELEGATE_PERMISSION
Definition TER.h:230
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:609