Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util Namespace Reference

This namespace contains various utilities. More...

Namespaces

namespace  async
 This namespace implements an async framework built on top of execution contexts.
 

Classes

class  Atomic
 Atomic wrapper for integral and floating point types. More...
 
class  BaseTagDecorator
 Represents any tag decorator. More...
 
class  Config
 Convenience wrapper to query a JSON configuration file. More...
 
class  ConfigReader
 Simple configuration file reader. More...
 
class  CoroutineGroup
 CoroutineGroup is a helper class to manage a group of coroutines. It allows to spawn multiple coroutines and wait for all of them to finish. More...
 
class  ExponentialBackoffStrategy
 A retry strategy that retries while exponentially increasing the delay between attempts. More...
 
class  LedgerTypes
 A helper class that provides lists of different ledger type catagory. More...
 
class  Lock
 A lock on a mutex that provides access to the protected data. More...
 
class  Logger
 A simple thread-safe logger for the channel specified in the constructor. More...
 
class  LogService
 A global logging service. More...
 
class  MoveTracker
 A base-class that can be used to check whether the current instance was moved from. More...
 
class  Mutex
 A container for data that is protected by a mutex. Inspired by Mutex in Rust. More...
 
struct  OverloadSet
 Overload set for lambdas. More...
 
class  Random
 Random number generator. More...
 
class  Repeat
 A class to repeat some action at a regular interval. More...
 
class  ResponseExpirationCache
 Cache of requests' responses with TTL support and configurable cachable commands. More...
 
class  Retry
 A retry mechanism. More...
 
class  RetryStrategy
 Interface for retry strategies. More...
 
class  SignalsHandler
 Class handling signals. More...
 
class  SourceLocation
 A class representing the source location of the current code. More...
 
class  StopHelper
 Helper class to stop a class asynchronously. More...
 
class  StrandedPriorityQueue
 A wrapper for std::priority_queue that serialises operations using a strand. More...
 
class  TagDecorator
 A decorator that decorates a string (log line) with a unique tag. More...
 
class  TagDecorator< impl::NullTagGenerator >
 Specialization for a nop/null decorator. More...
 
class  TagDecoratorFactory
 A factory for TagDecorator instantiation. More...
 
class  Taggable
 A base class that allows attaching a tag decorator to a subclass. More...
 

Concepts

concept  SomeNumberType
 Specifies a number type.
 

Typedefs

template<SomeNumberType NumberType>
using AtomicPtr = std::unique_ptr<Atomic<NumberType>>
 
using RetryStrategyPtr = std::unique_ptr<RetryStrategy>
 
using SourceLocationType = SourceLocation
 

Enumerations

enum class  Severity {
  TRC , DBG , NFO , WRN ,
  ERR , FTL
}
 Custom severity levels for util::Logger.
 

Functions

template<class T >
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 alphanumeric. If not, it returns an empty optional, instead of calling the parseBase58 function.
 
template<class T >
std::optional< T > parseBase58Wrapper (ripple::TokenType type, std::string const &str)
 A wrapper of parseBase58 function. It add the check if all characters in the input string are alphanumeric. If not, it returns an empty optional, instead of calling the parseBase58 function.
 
template<typename... Args>
constexpr void assertImpl (SourceLocationType const location, char const *expression, bool const condition, fmt::format_string< Args... > format, Args &&... args)
 Assert that a condition is true.
 
void forEachBatch (std::ranges::forward_range auto &&container, std::size_t batchSize, auto &&fn)
 Iterate over a container in batches.
 
constexpr std::uint64_t mbToBytes (std::uint32_t mb)
 Convert megabytes to bytes.
 
static consteval auto hasNoDuplicates (auto &&... values)
 Checks that the list of given values contains no duplicates.
 
template<typename... Types>
constexpr bool hasNoDuplicateNames ()
 Checks that the list of given type contains no duplicates.
 
std::string toLower (std::string str)
 Convert a string to lowercase.
 
std::string toUpper (std::string str)
 Convert a string to uppercase.
 
boost::json::object removeSecret (boost::json::object const &object)
 Removes any detected secret information from a response JSON object.
 
ripple::LedgerHeader deserializeHeader (ripple::Slice data)
 Deserializes a ripple::LedgerHeader from ripple::Slice of data.
 
std::string toString (ripple::LedgerHeader const &info)
 A helper function that converts a ripple::LedgerHeader to a string representation.
 
std::ostream & operator<< (std::ostream &stream, Severity sev)
 Custom labels for Severity in log output.
 
static Severity getSeverityLevel (std::string_view logLevel)
 converts the loglevel to string to a corresponding Severity enum value.
 
template<class... Ts>
 OverloadSet (Ts...) -> OverloadSet< Ts... >
 Deduction guide for OverloadSet.
 
template<typename U = std::chrono::milliseconds, typename FnType >
auto timed (FnType &&func)
 Profiler function to measure the time a function execution consumes.
 
Retry makeRetryExponentialBackoff (std::chrono::steady_clock::duration delay, std::chrono::steady_clock::duration maxDelay, boost::asio::strand< boost::asio::io_context::executor_type > strand)
 Create a retry mechanism with exponential backoff strategy.
 
void setTerminationHandler ()
 Set a termination handler that logs a backtrace on termination.
 
std::optional< std::chrono::system_clock::time_point > systemTpFromUtcStr (std::string const &dateStr, std::string const &format)
 Convert a UTC date string to a system_clock::time_point if possible.
 
std::chrono::system_clock::time_point systemTpFromLedgerCloseTime (ripple::NetClock::time_point closeTime)
 Convert a ledger close time which is XRPL network clock to a system_clock::time_point.
 
std::unordered_set< std::string > const & getTxTypesInLowercase ()
 Get the transaction types in lowercase.
 
template<typename Operation >
boost::system::error_code withTimeout (Operation &&operation, boost::asio::yield_context yield, std::chrono::steady_clock::duration timeout)
 Perform a coroutine operation with a timeout.
 

Variables

static constexpr std::size_t kMILLISECONDS_PER_SECOND = 1000
 
template<typename >
static constexpr bool Unsupported = false
 used for compile time checking of unsupported types
 

Detailed Description

This namespace contains various utilities.

Function Documentation

◆ assertImpl()

template<typename... Args>
void util::assertImpl ( SourceLocationType const location,
char const * expression,
bool const condition,
fmt::format_string< Args... > format,
Args &&... args )
constexpr

Assert that a condition is true.

Note
Calls std::exit if the condition is false
Template Parameters
ArgsThe format argument types
Parameters
locationThe location of the assertion
expressionThe expression to assert
conditionThe condition to assert
formatThe format string
argsThe format arguments

◆ deserializeHeader()

ripple::LedgerHeader util::deserializeHeader ( ripple::Slice data)
inline

Deserializes a ripple::LedgerHeader from ripple::Slice of data.

Parameters
dataThe slice to deserialize
Returns
The deserialized ripple::LedgerHeader

◆ forEachBatch()

void util::forEachBatch ( std::ranges::forward_range auto && container,
std::size_t batchSize,
auto && fn )

Iterate over a container in batches.

Parameters
containerThe container to iterate over
batchSizeThe size of each batch
fnThe function to call for each batch

◆ getSeverityLevel()

static Severity util::getSeverityLevel ( std::string_view logLevel)
static

converts the loglevel to string to a corresponding Severity enum value.

Parameters
logLevelA string representing the log level
Returns
Severity The corresponding Severity enum value.

◆ getTxTypesInLowercase()

std::unordered_set< std::string > const & util::getTxTypesInLowercase ( )
nodiscard

Get the transaction types in lowercase.

Returns
The transaction types in lowercase

◆ hasNoDuplicateNames()

template<typename... Types>
bool util::hasNoDuplicateNames ( )
constexpr

Checks that the list of given type contains no duplicates.

Template Parameters
TypesThe types to check
Returns
true if no duplicates exist; false otherwise

◆ hasNoDuplicates()

static consteval auto util::hasNoDuplicates ( auto &&... values)
staticconsteval

Checks that the list of given values contains no duplicates.

Parameters
valuesThe list of values to check
Returns
true if no duplicates exist; false otherwise

◆ makeRetryExponentialBackoff()

Retry util::makeRetryExponentialBackoff ( std::chrono::steady_clock::duration delay,
std::chrono::steady_clock::duration maxDelay,
boost::asio::strand< boost::asio::io_context::executor_type > strand )

Create a retry mechanism with exponential backoff strategy.

Parameters
delayThe initial delay value
maxDelayThe maximum delay value
strandThe strand to use for async operations
Returns
The retry object

◆ mbToBytes()

std::uint64_t util::mbToBytes ( std::uint32_t mb)
constexpr

Convert megabytes to bytes.

Parameters
mbNumber of megabytes to convert
Returns
The equivalent number of bytes

◆ operator<<()

std::ostream & util::operator<< ( std::ostream & stream,
Severity sev )

Custom labels for Severity in log output.

Parameters
streamstd::ostream The output stream
sevSeverity The severity to output to the ostream
Returns
The same ostream we were given

◆ OverloadSet()

template<class... Ts>
util::OverloadSet ( Ts... ) -> OverloadSet< Ts... >

Deduction guide for OverloadSet.

Template Parameters
TsTypes of lambdas

◆ parseBase58Wrapper() [1/2]

template<class T >
std::optional< T > util::parseBase58Wrapper ( ripple::TokenType type,
std::string const & str )
nodiscard

A wrapper of parseBase58 function. It add the check if all characters in the input string are alphanumeric. If not, it returns an empty optional, instead of calling the parseBase58 function.

Template Parameters
TThe type of the value to parse to.
Parameters
typeThe type of the token to parse.
strThe string to parse.
Returns
An optional with the parsed value, or an empty optional if the parse fails.

◆ parseBase58Wrapper() [2/2]

template<class T >
std::optional< T > util::parseBase58Wrapper ( std::string const & str)
nodiscard

A wrapper of parseBase58 function. It adds the check if all characters in the input string are alphanumeric. If not, it returns an empty optional, instead of calling the parseBase58 function.

Template Parameters
TThe type of the value to parse to.
Parameters
strThe string to parse.
Returns
An optional with the parsed value, or an empty optional if the parse fails.

◆ removeSecret()

boost::json::object util::removeSecret ( boost::json::object const & object)
inline

Removes any detected secret information from a response JSON object.

Parameters
objectThe JSON object to remove secrets from
Returns
A secret-free copy of the passed object

◆ systemTpFromLedgerCloseTime()

std::chrono::system_clock::time_point util::systemTpFromLedgerCloseTime ( ripple::NetClock::time_point closeTime)
nodiscard

Convert a ledger close time which is XRPL network clock to a system_clock::time_point.

Parameters
closeTimeThe ledger close time to convert.
Returns
The system_clock::time_point.

◆ systemTpFromUtcStr()

std::optional< std::chrono::system_clock::time_point > util::systemTpFromUtcStr ( std::string const & dateStr,
std::string const & format )
nodiscard

Convert a UTC date string to a system_clock::time_point if possible.

Parameters
dateStrThe UTC date string to convert.
formatThe format of the date string.
Returns
The system_clock::time_point if the conversion was successful, otherwise std::nullopt.

◆ timed()

template<typename U = std::chrono::milliseconds, typename FnType >
auto util::timed ( FnType && func)
nodiscard

Profiler function to measure the time a function execution consumes.

Template Parameters
UThe duration measurement to use; defaults to milliseconds
FnTypeThe type of the function object
Parameters
funcAny function object
Returns
If the function object has a return value, the result of the function call and the elapsed time(ms) is returned as a pair
Only return the elapsed time if passed function object does not have a return value

◆ toLower()

std::string util::toLower ( std::string str)
inline

Convert a string to lowercase.

Parameters
strThe string to convert
Returns
The string in lowercase

◆ toString()

std::string util::toString ( ripple::LedgerHeader const & info)
inline

A helper function that converts a ripple::LedgerHeader to a string representation.

Parameters
infoThe ledger header
Returns
The string representation of the supplied ledger header

◆ toUpper()

std::string util::toUpper ( std::string str)
inline

Convert a string to uppercase.

Parameters
strThe string to convert
Returns
The string in uppercase

◆ withTimeout()

template<typename Operation >
boost::system::error_code util::withTimeout ( Operation && operation,
boost::asio::yield_context yield,
std::chrono::steady_clock::duration timeout )

Perform a coroutine operation with a timeout.

Template Parameters
OperationThe operation type to perform. Must be a callable accepting yield context with bound cancellation token.
Parameters
operationThe operation to perform.
yieldThe yield context.
timeoutThe timeout duration.
Returns
The error code of the operation.