Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
rpc::validation::CustomValidators Struct Referencefinal

A group of custom validation functions. More...

#include <Validators.hpp>

Collaboration diagram for rpc::validation::CustomValidators:

Static Public Attributes

static CustomValidator ledgerIndexValidator
 Provides a commonly used validator for ledger index.
static CustomValidator ledgerTypeValidator
 Provides a validator for ledger type.
static CustomValidator accountValidator
 Provides a commonly used validator for accounts.
static CustomValidator accountBase58Validator
 Provides a commonly used validator for accounts.
static CustomValidator accountMarkerValidator
 Provides a commonly used validator for markers.
static CustomValidator accountTypeValidator
 Provides a validator for account type.
static CustomValidator uint160HexStringValidator
 Provides a commonly used validator for uint160(AccountID) hex string.
static CustomValidator uint192HexStringValidator
 Provides a commonly used validator for uint192 hex string.
static CustomValidator uint256HexStringValidator
 Provides a commonly used validator for uint256 hex string.
static CustomValidator currencyValidator
 Provides a commonly used validator for currency, including standard currency code and token code.
static CustomValidator issuerValidator
 Provides a commonly used validator for issuer type.
static CustomValidator subscribeStreamValidator
 Provides a validator for validating streams used in subscribe/unsubscribe.
static CustomValidator subscribeAccountsValidator
 Provides a validator for validating accounts used in subscribe/unsubscribe.
static CustomValidator currencyIssueValidator
 Validates an asset (xrpl::Issue).
static CustomValidator authorizeCredentialValidator
 Provides a validator for validating authorized_credentials json array.
static CustomValidator credentialTypeValidator
 Provides a validator for validating credential_type.

Detailed Description

A group of custom validation functions.

Member Data Documentation

◆ accountBase58Validator

CustomValidator rpc::validation::CustomValidators::accountBase58Validator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotString"}};
auto const account =
util::parseBase58Wrapper<xrpl::AccountID>(boost::json::value_to<std::string>(value));
if (!account || account->isZero())
return Error{Status{ClioError::RpcMalformedAddress}};
return MaybeError{};
}}
A meta-validator that allows to specify a custom validation function.
Definition Validators.hpp:423
std::expected< void, Status > MaybeError
Return type used for Validators that can return error but don't have specific value to return.
Definition Types.hpp:36
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:56
std::optional< T > parseBase58Wrapper(std::string const &str)
A wrapper of parseBase58 function. It adds the check if all characters in the input string are alphan...
Definition AccountUtils.hpp:24
A status returned from any RPC handler.
Definition Errors.hpp:73

Provides a commonly used validator for accounts.

Account must be a string and can convert to base58.

◆ accountMarkerValidator

CustomValidator rpc::validation::CustomValidators::accountMarkerValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotString"}};
if (!parseAccountCursor(boost::json::value_to<std::string>(value))) {
return Error{Status{RippledError::RpcInvalidParams, "Malformed cursor."}};
}
return MaybeError{};
}}
std::optional< AccountCursor > parseAccountCursor(std::optional< std::string > jsonCursor)
Parse the account cursor from the JSON.
Definition RPCHelpers.cpp:88

Provides a commonly used validator for markers.

A marker is composed of a comma-separated index and a start hint. The former will be read as hex, and the latter can be cast to uint64.

◆ accountTypeValidator

CustomValidator rpc::validation::CustomValidators::accountTypeValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string()) {
return Error{Status{
RippledError::RpcInvalidParams, fmt::format("Invalid field '{}', not string.", key)
}};
}
boost::json::value_to<std::string>(value)
);
if (type == xrpl::ltANY) {
return Error{
Status{RippledError::RpcInvalidParams, fmt::format("Invalid field '{}'.", key)}
};
}
return MaybeError{};
}}
static xrpl::LedgerEntryType getAccountOwnedLedgerTypeFromStr(std::string const &entryName)
Returns the xrpl::LedgerEntryType from the given string.
Definition LedgerUtils.cpp:25

Provides a validator for account type.

A type accepts canonical names of owned ledger entry types (case insensitive) or short names. Used by account_objects.

◆ accountValidator

CustomValidator rpc::validation::CustomValidators::accountValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotString"}};
if (!accountFromStringStrict(boost::json::value_to<std::string>(value)))
return Error{Status{RippledError::RpcActMalformed, std::string(key) + "Malformed"}};
return MaybeError{};
}}
std::optional< xrpl::AccountID > accountFromStringStrict(std::string const &account)
Get a xrpl::AccountID from its string representation.
Definition RPCHelpers.cpp:160

Provides a commonly used validator for accounts.

Account must be a string and the converted public key is valid.

◆ authorizeCredentialValidator

CustomValidator rpc::validation::CustomValidators::authorizeCredentialValidator
static

Provides a validator for validating authorized_credentials json array.

Used by deposit_preauth.

◆ credentialTypeValidator

CustomValidator rpc::validation::CustomValidators::credentialTypeValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (not value.is_string()) {
return Error{Status{
ClioError::RpcMalformedAuthorizedCredentials, std::string(key) + " NotString"
}};
}
auto const& credTypeHex = xrpl::strViewUnHex(value.as_string());
if (!credTypeHex.has_value()) {
return Error{Status{
ClioError::RpcMalformedAuthorizedCredentials, std::string(key) + " NotHexString"
}};
}
if (credTypeHex->empty()) {
return Error{
Status{ClioError::RpcMalformedAuthorizedCredentials, std::string(key) + " is empty"}
};
}
if (credTypeHex->size() > xrpl::kMaxCredentialTypeLength) {
return Error{Status{
ClioError::RpcMalformedAuthorizedCredentials,
std::string(key) + " greater than max length"
}};
}
return MaybeError{};
}}

Provides a validator for validating credential_type.

Used by AuthorizeCredentialValidator in deposit_preauth.

◆ currencyIssueValidator

CustomValidator rpc::validation::CustomValidators::currencyIssueValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (not value.is_object())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotObject"}};
try {
parseIssue(value.as_object());
} catch (std::runtime_error const&) {
return Error{Status{ClioError::RpcMalformedRequest}};
}
return MaybeError{};
}}
xrpl::Issue parseIssue(boost::json::object const &issue)
Parse the json object into a xrpl::Issue object.
Definition RPCHelpers.cpp:1572

Validates an asset (xrpl::Issue).

Used by amm_info.

◆ currencyValidator

CustomValidator rpc::validation::CustomValidators::currencyValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotString"}};
auto const currencyStr = boost::json::value_to<std::string>(value);
if (currencyStr.empty())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "IsEmpty"}};
xrpl::Currency currency;
if (!xrpl::toCurrency(currency, currencyStr))
return Error{Status{ClioError::RpcMalformedCurrency, "malformedCurrency"}};
return MaybeError{};
}}

Provides a commonly used validator for currency, including standard currency code and token code.

◆ issuerValidator

CustomValidator rpc::validation::CustomValidators::issuerValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotString"}};
xrpl::AccountID issuer;
if (!xrpl::toIssuer(issuer, boost::json::value_to<std::string>(value))) {
return Error{Status{
RippledError::RpcInvalidParams, fmt::format("Invalid field '{}', bad issuer.", key)
}};
}
if (issuer == xrpl::noAccount()) {
return Error{Status{
RippledError::RpcInvalidParams,
fmt::format("Invalid field '{}', bad issuer account one.", key)
}};
}
return MaybeError{};
}}

Provides a commonly used validator for issuer type.

It must be a hex string or base58 string.

◆ ledgerIndexValidator

CustomValidator rpc::validation::CustomValidators::ledgerIndexValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view ) -> MaybeError {
auto err = Error{Status{RippledError::RpcInvalidParams, "ledgerIndexMalformed"}};
if (!value.is_string() && !(value.is_uint64() || value.is_int64()))
return err;
if (value.is_string() && value.as_string() != "validated" &&
!checkIsU32Numeric(boost::json::value_to<std::string>(value)))
return err;
return MaybeError{};
}}

Provides a commonly used validator for ledger index.

LedgerIndex must be a string or an int. If the specified LedgerIndex is a string, its value must be either "validated" or a valid integer value represented as a string.

◆ ledgerTypeValidator

CustomValidator rpc::validation::CustomValidators::ledgerTypeValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_string()) {
return Error{Status{
RippledError::RpcInvalidParams, fmt::format("Invalid field '{}', not string.", key)
}};
}
auto const type =
util::LedgerTypes::getLedgerEntryTypeFromStr(boost::json::value_to<std::string>(value));
if (type == xrpl::ltANY) {
return Error{
Status{RippledError::RpcInvalidParams, fmt::format("Invalid field '{}'.", key)}
};
}
return MaybeError{};
}}
static xrpl::LedgerEntryType getLedgerEntryTypeFromStr(std::string const &entryName)
Returns the xrpl::LedgerEntryType from the given string.
Definition LedgerUtils.cpp:16

Provides a validator for ledger type.

A type accepts canonical names of ledger entry types (case insensitive) or short names. Used by ledger_data.

◆ subscribeAccountsValidator

CustomValidator rpc::validation::CustomValidators::subscribeAccountsValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_array())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotArray"}};
if (value.as_array().empty())
return Error{Status{RippledError::RpcActMalformed, std::string(key) + " malformed."}};
for (auto const& v : value.as_array()) {
auto obj = boost::json::object();
auto const keyItem = std::string(key) + "'sItem";
obj[keyItem] = v;
if (auto err = accountValidator.verify(obj, keyItem); !err)
return err;
}
return MaybeError{};
}}
MaybeError verify(boost::json::value const &value, std::string_view key) const
Verify that the JSON value is valid according to the custom validation function stored.
Definition Validators.cpp:63
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:504

Provides a validator for validating accounts used in subscribe/unsubscribe.

◆ subscribeStreamValidator

CustomValidator rpc::validation::CustomValidators::subscribeStreamValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
if (!value.is_array())
return Error{Status{RippledError::RpcInvalidParams, std::string(key) + "NotArray"}};
static std::unordered_set<std::string> const kValidStreams = {
"ledger",
"transactions",
"transactions_proposed",
"book_changes",
"manifests",
"validations"
};
static std::unordered_set<std::string> const kNotSupportStreams = {
"peer_status", "consensus", "server"
};
for (auto const& v : value.as_array()) {
if (!v.is_string())
return Error{Status{RippledError::RpcInvalidParams, "streamNotString"}};
if (kNotSupportStreams.contains(boost::json::value_to<std::string>(v)))
return Error{Status{RippledError::RpcNotSupported}};
if (not kValidStreams.contains(boost::json::value_to<std::string>(v)))
return Error{Status{RippledError::RpcStreamMalformed}};
}
return MaybeError{};
}}

Provides a validator for validating streams used in subscribe/unsubscribe.

◆ uint160HexStringValidator

CustomValidator rpc::validation::CustomValidators::uint160HexStringValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
return makeHexStringValidator<xrpl::uint160>(value, key);
}}

Provides a commonly used validator for uint160(AccountID) hex string.

It must be a string and also a decodable hex. AccountID uses this validator.

◆ uint192HexStringValidator

CustomValidator rpc::validation::CustomValidators::uint192HexStringValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
return makeHexStringValidator<xrpl::uint192>(value, key);
}}

Provides a commonly used validator for uint192 hex string.

It must be a string and also a decodable hex. MPTIssuanceID uses this validator.

◆ uint256HexStringValidator

CustomValidator rpc::validation::CustomValidators::uint256HexStringValidator
static
Initial value:
=
CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError {
return makeHexStringValidator<xrpl::uint256>(value, key);
}}

Provides a commonly used validator for uint256 hex string.

It must be a string and also a decodable hex. Transaction index, ledger hash all use this validator.


The documentation for this struct was generated from the following files:
  • /__w/clio/clio/src/rpc/common/Validators.hpp
  • /__w/clio/clio/src/rpc/common/Validators.cpp