cardano::util namespace

Utility namespace.

Classes

template <typename IntType>
struct BytePacker
Object for packing and unpacking bytes as integers.

Enums

enum class Endianness { BigEndian, LittleEndian }
Enum class to represent byte order.

Functions

auto ada2love(double ada) →  int64_t constexpr
Convert ADA Lovelaces.
template <class SizedRange1, class SizedRange2>
auto concatBytes(SizedRange1 const& r1, SizedRange2 const& r2) →  auto
Concatenate two byte ranges.
auto love2ada(int64_t lovelaces) →  double constexpr
Convert Lovelaces to ADA.
template <std::size_t N>
auto makeByteArray(std::span<const uint8_t> vec) →  std::array<uint8_t, N> constexpr
Convert a span of bytes into a fixed size array.
template <std::size_t N>
auto makeRandomByteArray() →  std::array<uint8_t, N>
Generate a fixed size array filled with random bytes.
auto rationalApprox(double f, int64_t md) →  std::pair<int64_t, int64_t>
Approximate a floating point number as a rational number.
void writeEnvelopeTextFile(const std::string_view file_path, const std::string_view type, const std::string_view description, const std::string_view cbor_hex)
Write CBOR date to file in the envelope format used by cardano node.

Function documentation

int64_t cardano::util::ada2love(double ada) constexpr

Convert ADA Lovelaces.

Parameters
ada The value in ADA (double).
Returns The value in lovelaces (integer).

template <class SizedRange1, class SizedRange2>
auto cardano::util::concatBytes(SizedRange1 const& r1, SizedRange2 const& r2)

Concatenate two byte ranges.

Returns A vector containing the elements of both ranges.

double cardano::util::love2ada(int64_t lovelaces) constexpr

Convert Lovelaces to ADA.

Parameters
lovelaces The value in lovelaces (integer).
Returns The equivalent value in ADA (double).

template <std::size_t N>
std::array<uint8_t, N> cardano::util::makeByteArray(std::span<const uint8_t> vec) constexpr

Convert a span of bytes into a fixed size array.

Returns An array containing the elements from the input.

template <std::size_t N>
std::array<uint8_t, N> cardano::util::makeRandomByteArray()

Generate a fixed size array filled with random bytes.

Returns An array of uint8_t containing random values.

std::pair<int64_t, int64_t> cardano::util::rationalApprox(double f, int64_t md)

Approximate a floating point number as a rational number.

Parameters
f The floating point number to convert.
md The maximum denominator.
Returns The numerator and denominator as a pair of integers.

void cardano::util::writeEnvelopeTextFile(const std::string_view file_path, const std::string_view type, const std::string_view description, const std::string_view cbor_hex)

Write CBOR date to file in the envelope format used by cardano node.

Parameters
file_path Path to the generated key file.
type A string key type specifier.
description Description of the key (maybe empty).
cbor_hex The CBOR key data in hex string format.