xrpld
Loading...
Searching...
No Matches
tokens.h
1#pragma once
2
3#include <xrpl/basics/contract.h>
4#include <xrpl/protocol/detail/token_errors.h>
5
6#include <cstdint>
7#include <expected>
8#include <optional>
9#include <span>
10#include <string>
11#include <string_view>
12
13namespace xrpl {
14
15template <class T>
16using B58Result = std::expected<T, std::error_code>;
17
18enum class TokenType : std::uint8_t {
19 None = 1, // unused
25 FamilyGenerator = 41, // unused
27};
28
29template <class T>
30[[nodiscard]] std::optional<T>
32
33template <class T>
34[[nodiscard]] std::optional<T>
36
48[[nodiscard]] std::string
49encodeBase58Token(TokenType type, void const* token, std::size_t size);
50
51[[nodiscard]] std::string
53
54namespace b58_ref {
55// The reference version does not use gcc extensions (int128 in particular)
56[[nodiscard]] std::string
57encodeBase58Token(TokenType type, void const* token, std::size_t size);
58
59[[nodiscard]] std::string
61
62namespace detail {
63// Expose detail functions for unit tests only
65encodeBase58(void const* message, std::size_t size, void* temp, std::size_t tempSize);
66
69} // namespace detail
70} // namespace b58_ref
71
72#ifndef _MSC_VER
73namespace b58_fast {
74// Use the fast version (10-15x faster) is using gcc extensions (int128 in
75// particular)
78 TokenType tokenType,
81
84
85// This interface matches the old interface, but requires additional allocation
86[[nodiscard]] std::string
87encodeBase58Token(TokenType type, void const* token, std::size_t size);
88
89// This interface matches the old interface, but requires additional allocation
90[[nodiscard]] std::string
92
93namespace detail {
94// Expose detail functions for unit tests only
97
99b58ToB256Be(std::string_view input, std::span<std::uint8_t> out);
100} // namespace detail
101
102} // namespace b58_fast
103#endif // _MSC_VER
104} // namespace xrpl
std::string decodeBase58(std::string const &s)
Definition tokens.cpp:249
std::string encodeBase58(void const *message, std::size_t size, void *temp, std::size_t tempSize)
Definition tokens.cpp:202
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Definition tokens.cpp:297
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:320
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::expected< T, std::error_code > B58Result
Definition tokens.h:16
TokenType
Definition tokens.h:18
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Encode data in Base58Check format using XRPL alphabet.
Definition tokens.cpp:178
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition tokens.cpp:188