3#include <eosio/eosio.hpp>
4#include <eosio/transaction.hpp>
5#include <eosio/crypto.hpp>
7static uint128_t
combine_ids(
const uint64_t &x,
const uint64_t &y) {
8 return (uint128_t{x} << 64) | y;
12 auto hash_bytes = hash.extract_as_byte_array();
13 uint64_t truncated_hash = *
reinterpret_cast<const uint64_t*
>(hash_bytes.data());
19 const char ALPHABET[] =
"abcdefghijklmnopqrstuvwxyz";
20 const int ALPHABET_SIZE =
sizeof(ALPHABET) - 1;
21 const int NAME_LENGTH = 12;
23 uint64_t current_time =
24 eosio::current_time_point().sec_since_epoch();
25 std::string random_name;
27 for (
int i = 0; i < NAME_LENGTH; ++i) {
28 current_time = (current_time * 1103515245 + 12345) %
30 int random_index = (current_time % ALPHABET_SIZE);
31 random_name += ALPHABET[random_index];
37eosio::checksum256
hashit(std::string str) {
38 return eosio::sha256(
const_cast<char *
>(str.c_str()), str.size());
41uint64_t
hash64(
const char *buf,
size_t len) {
42 eosio::checksum256 hash = eosio::sha256(buf, len);
43 return *(
reinterpret_cast<const uint64_t *
>(&hash));
46uint64_t
hash64(
const std::string &arg) {
47 return hash64(arg.c_str(), arg.size());
51 auto size = eosio::transaction_size();
53 uint32_t read = eosio::read_transaction(buf, size);
54 eosio::check(size == read,
"read_transaction failed");
56 uint64_t seed = eosio::current_time_point().sec_since_epoch();
57 for (
int i = 0; i < size; i++) {
58 seed ^= ((uint64_t)buf[i] << (i % 8));
65 auto hash_bytes = hash.extract_as_byte_array();
67 for (
const auto&
byte : hash_bytes) {
69 sprintf(hex_char,
"%02x",
byte);
77 std::string search_key =
"\"registry_id\":";
78 size_t pos = meta_json.find(search_key);
80 eosio::check(pos != std::string::npos,
"registry_id not found in meta");
83 pos += search_key.length();
86 while (pos < meta_json.length() && (meta_json[pos] <
'0' || meta_json[pos] >
'9')) {
90 eosio::check(pos < meta_json.length(),
"registry_id value not found");
94 while (pos < meta_json.length() && meta_json[pos] >=
'0' && meta_json[pos] <=
'9') {
95 result = result * 10 + (meta_json[pos] -
'0');
99 eosio::check(result > 0,
"invalid registry_id value");
eosio::checksum256 hashit(std::string str)
Definition: utils.hpp:37
uint64_t generate()
Definition: utils.hpp:50
uint64_t extract_registry_id_from_meta(const std::string &meta_json)
Definition: utils.hpp:75
std::string checksum256_to_hex(const eosio::checksum256 &hash)
Definition: utils.hpp:64
static uint128_t combine_checksum_ids(const checksum256 &hash, eosio::name username)
Definition: utils.hpp:11
std::string generate_random_name()
Definition: utils.hpp:18
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y)
Definition: utils.hpp:7
uint64_t hash64(const char *buf, size_t len)
Definition: utils.hpp:41