9namespace fc {
namespace crypto {
10 template<
typename DataType>
20 if (prefix !=
nullptr) {
23 return encoder.result()._hash[0];
29 return str.size() > prefix_len && str.substr(0, prefix_len).compare(prefix) == 0;
32 template<
typename,
const char *
const *, int,
typename ...>
35 template<
typename Result,
const char *
const * Prefixes,
int Position,
typename KeyType,
typename ...Rem>
37 static Result
apply(
const std::string& prefix_str,
const std::string& data_str)
39 using data_type =
typename KeyType::data_type;
41 constexpr auto prefix = Prefixes[Position];
43 if (prefix == prefix_str) {
48 FC_ASSERT(!unpacker.remaining(),
"decoded base58 length too long");
49 auto checksum = wrapper::calculate_checksum(wrapped.data, prefix);
51 return Result(KeyType(wrapped.data));
58 template<
typename Result, const
char * const * Prefixes,
int Position>
60 static Result
apply(
const std::string& prefix_str,
const std::string& data_str ) {
61 FC_ASSERT(
false,
"No matching suite type for ${prefix}_${data}", (
"prefix", prefix_str)(
"data",data_str));
65 template<
typename, const
char * const * Prefixes>
74 template<
const char *
const * Prefixes,
typename ...Ts>
76 static std::variant<Ts...>
apply(
const std::string& base58str) {
77 const auto pivot = base58str.find(
'_');
78 FC_ASSERT(pivot != std::string::npos,
"No delimiter in data, cannot determine suite type: ${str}", (
"str", base58str));
80 const auto prefix_str = base58str.substr(0, pivot);
81 auto data_str = base58str.substr(pivot + 1);
82 FC_ASSERT(!data_str.empty(),
"Data only has suite type prefix: ${str}", (
"str", base58str));
88 template<
typename Storage,
const char *
const * Prefixes,
int DefaultPosition = -1>
92 template<
typename KeyType >
94 using data_type =
typename KeyType::data_type;
96 constexpr bool is_default = position == DefaultPosition;
99 wrapper.
data = key.serialize();
108 data_str =
string(Prefixes[position]) +
"_" + data_str;
120 return a.serialize() == b.serialize();
124 template<
typename ... Ts>
131 template<
typename KeyType>
133 const auto &b = std::template get<KeyType>(_b);
141 return a.index() == b.index() && std::visit(
visitor(b),
a);
148 return a.serialize() < b.serialize();
152 template<
typename ... Ts>
159 template<
typename KeyType>
161 const auto &b = std::template get<KeyType>(_b);
169 return a.index() < b.index() || (
a.index() == b.index() && std::visit(
visitor(b),
a));
173 template<
typename Data>
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
bool prefix_matches(const char *prefix, const std::string &str)
void unpack(Stream &s, std::deque< T > &value)
void pack(Stream &s, const std::deque< T > &value)
std::string to_base58(const char *d, size_t s, const fc::yield_function_t &yield)
constexpr size_t const_strlen(const char *str)
std::vector< char > from_base58(const std::string &base58_str)
constexpr std::size_t get_index()
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
void apply(uint64_t, uint64_t, uint64_t)
#define T(meth, val, expected)
#define FC_REFLECT_TEMPLATE(TEMPLATE_ARGS, TYPE, MEMBERS)
static std::variant< Ts... > apply(const std::string &base58str)
static Result apply(const std::string &prefix_str, const std::string &data_str)
static Result apply(const std::string &prefix_str, const std::string &data_str)
const fc::yield_function_t _yield
base58str_visitor(const fc::yield_function_t &yield)
std::string operator()(const KeyType &key) const
static auto calculate_checksum(const DataType &data, const char *prefix=nullptr)
visitor(const variant_type &b)
bool operator()(const KeyType &a) const
static bool apply(const variant_type &a, const variant_type &b)
std::variant< Ts... > variant_type
static bool apply(const T &a, const T &b)
bool operator()(const KeyType &a) const
visitor(const variant_type &b)
std::variant< Ts... > variant_type
static bool apply(const variant_type &a, const variant_type &b)
static bool apply(const T &a, const T &b)
const data_type & serialize() const
shim(const data_type &data)