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 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 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 (ripple::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::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
auto const account = util::parseBase58Wrapper<ripple::AccountID>(boost::json::value_to<std::string>(value));
if (!account || account->isZero())
return Error{Status{ClioError::RpcMalformedAddress}};
return MaybeError{};
}}
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:55
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:75
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:42
A status returned from any RPC handler.
Definition Errors.hpp:82

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::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
if (!parseAccountCursor(boost::json::value_to<std::string>(value))) {
return Error{Status{RippledError::rpcINVALID_PARAMS, "Malformed cursor."}};
}
return MaybeError{};
}}
std::optional< AccountCursor > parseAccountCursor(std::optional< std::string > jsonCursor)
Parse the account cursor from the JSON.
Definition RPCHelpers.cpp:110

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.

◆ 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::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
if (!accountFromStringStrict(boost::json::value_to<std::string>(value)))
return Error{Status{RippledError::rpcACT_MALFORMED, std::string(key) + "Malformed"}};
return MaybeError{};
}}
std::optional< ripple::AccountID > accountFromStringStrict(std::string const &account)
Get a ripple::AccountID from its string representation.
Definition RPCHelpers.cpp:185

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 = ripple::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() > ripple::maxCredentialTypeLength) {
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::rpcINVALID_PARAMS, std::string(key) + "NotObject"}};
try {
parseIssue(value.as_object());
} catch (std::runtime_error const&) {
return Error{Status{ClioError::RpcMalformedRequest}};
}
return MaybeError{};
}}
ripple::Issue parseIssue(boost::json::object const &issue)
Parse the json object into a ripple::Issue object.
Definition RPCHelpers.cpp:1320

Validates an asset (ripple::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::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
auto const currencyStr = boost::json::value_to<std::string>(value);
if (currencyStr.empty())
return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + "IsEmpty"}};
ripple::Currency currency;
if (!ripple::to_currency(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::rpcINVALID_PARAMS, std::string(key) + "NotString"}};
ripple::AccountID issuer;
if (!ripple::to_issuer(issuer, boost::json::value_to<std::string>(value)))
return Error{Status{RippledError::rpcINVALID_PARAMS, fmt::format("Invalid field '{}', bad issuer.", key)}};
if (issuer == ripple::noAccount()) {
return Error{
Status{RippledError::rpcINVALID_PARAMS, 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::rpcINVALID_PARAMS, "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.

◆ 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::rpcINVALID_PARAMS, std::string(key) + "NotArray"}};
if (value.as_array().empty())
return Error{Status{RippledError::rpcACT_MALFORMED, 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:77
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:491

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::rpcINVALID_PARAMS, std::string(key) + "NotArray"}};
static std::unordered_set<std::string> const kVALID_STREAMS = {
"ledger", "transactions", "transactions_proposed", "book_changes", "manifests", "validations"
};
static std::unordered_set<std::string> const kNOT_SUPPORT_STREAMS = {"peer_status", "consensus", "server"};
for (auto const& v : value.as_array()) {
if (!v.is_string())
return Error{Status{RippledError::rpcINVALID_PARAMS, "streamNotString"}};
if (kNOT_SUPPORT_STREAMS.contains(boost::json::value_to<std::string>(v)))
return Error{Status{RippledError::rpcNOT_SUPPORTED}};
if (not kVALID_STREAMS.contains(boost::json::value_to<std::string>(v)))
return Error{Status{RippledError::rpcSTREAM_MALFORMED}};
}
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<ripple::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<ripple::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<ripple::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: