mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: chuanshanjida <chuanshanjida@outlook.com> Co-authored-by: Ed Hennis <ed@ripple.com> Co-authored-by: Bart <bthomee@users.noreply.github.com> Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com> Co-authored-by: Zhiyuan Wang <96991820+Kassaking7@users.noreply.github.com> Co-authored-by: Alex Kremer <akremer@ripple.com> Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com> Co-authored-by: Sergey Kuznetsov <skuznetsov@ripple.com> Co-authored-by: JCW <a1q123456@users.noreply.github.com> Co-authored-by: xrplf-ai-reviewer[bot] <266832837+xrplf-ai-reviewer[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gregory Tsipenyuk <gregtatcam@users.noreply.github.com> Co-authored-by: chuanshanjida <chuanshanjida@outlook.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <xrpl/protocol/Rules.h>
|
|
#include <xrpl/protocol/TER.h>
|
|
#include <xrpl/protocol/TxFormats.h>
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace xrpl {
|
|
/**
|
|
* We have both transaction type permissions and granular type permissions.
|
|
* Since we will reuse the TransactionFormats to parse the Transaction
|
|
* Permissions, only the GranularPermissionType is defined here. To prevent
|
|
* conflicts with TxType, the GranularPermissionType is always set to a value
|
|
* greater than the maximum value of uint16.
|
|
*/
|
|
enum GranularPermissionType : std::uint32_t {
|
|
#pragma push_macro("PERMISSION")
|
|
#undef PERMISSION
|
|
|
|
#define PERMISSION(type, txType, value) type = (value),
|
|
|
|
#include <xrpl/protocol/detail/permissions.macro>
|
|
|
|
#undef PERMISSION
|
|
#pragma pop_macro("PERMISSION")
|
|
};
|
|
|
|
enum Delegation { delegable, notDelegable };
|
|
|
|
class Permission
|
|
{
|
|
private:
|
|
Permission();
|
|
|
|
std::unordered_map<std::uint16_t, uint256> txFeatureMap_;
|
|
|
|
std::unordered_map<std::uint16_t, Delegation> delegableTx_;
|
|
|
|
std::unordered_map<std::string, GranularPermissionType> granularPermissionMap_;
|
|
|
|
std::unordered_map<GranularPermissionType, std::string> granularNameMap_;
|
|
|
|
std::unordered_map<GranularPermissionType, TxType> granularTxTypeMap_;
|
|
|
|
public:
|
|
static Permission const&
|
|
getInstance();
|
|
|
|
Permission(Permission const&) = delete;
|
|
Permission&
|
|
operator=(Permission const&) = delete;
|
|
|
|
std::optional<std::string>
|
|
getPermissionName(std::uint32_t const value) const;
|
|
|
|
std::optional<std::uint32_t>
|
|
getGranularValue(std::string const& name) const;
|
|
|
|
std::optional<std::string>
|
|
getGranularName(GranularPermissionType const& value) const;
|
|
|
|
std::optional<TxType>
|
|
getGranularTxType(GranularPermissionType const& gpType) const;
|
|
|
|
std::optional<std::reference_wrapper<uint256 const>>
|
|
getTxFeature(TxType txType) const;
|
|
|
|
bool
|
|
isDelegable(std::uint32_t const& permissionValue, Rules const& rules) const;
|
|
|
|
// for tx level permission, permission value is equal to tx type plus one
|
|
static uint32_t
|
|
txToPermissionType(TxType const& type);
|
|
|
|
// tx type value is permission value minus one
|
|
static TxType
|
|
permissionToTxType(uint32_t const& value);
|
|
};
|
|
|
|
} // namespace xrpl
|