1#include <eosio/eosio.hpp>
2#include <eosio/transaction.hpp>
3#include <eosio/crypto.hpp>
5static uint128_t
combine_ids(
const uint64_t &x,
const uint64_t &y) {
6 return (uint128_t{x} << 64) | y;
10 auto hash_bytes = hash.extract_as_byte_array();
11 uint64_t truncated_hash = *
reinterpret_cast<const uint64_t*
>(hash_bytes.data());
17 const char ALPHABET[] =
"abcdefghijklmnopqrstuvwxyz";
18 const int ALPHABET_SIZE =
sizeof(ALPHABET) - 1;
19 const int NAME_LENGTH = 12;
21 uint64_t current_time =
22 eosio::current_time_point().sec_since_epoch();
23 std::string random_name;
25 for (
int i = 0; i < NAME_LENGTH; ++i) {
26 current_time = (current_time * 1103515245 + 12345) %
28 int random_index = (current_time % ALPHABET_SIZE);
29 random_name += ALPHABET[random_index];
35eosio::checksum256
hashit(std::string str) {
36 return eosio::sha256(
const_cast<char *
>(str.c_str()), str.size());
39uint64_t
hash64(
const char *buf,
size_t len) {
40 eosio::checksum256 hash = eosio::sha256(buf, len);
41 return *(
reinterpret_cast<const uint64_t *
>(&hash));
44uint64_t
hash64(
const std::string &arg) {
45 return hash64(arg.c_str(), arg.size());
49 auto size = eosio::transaction_size();
51 uint32_t read = eosio::read_transaction(buf, size);
52 eosio::check(size == read,
"read_transaction failed");
54 uint64_t seed = eosio::current_time_point().sec_since_epoch();
55 for (
int i = 0; i < size; i++) {
56 seed ^= ((uint64_t)buf[i] << (i % 8));
63 auto hash_bytes = hash.extract_as_byte_array();
65 for (
const auto&
byte : hash_bytes) {
67 sprintf(hex_char,
"%02x",
byte);
75 std::string search_key =
"\"registry_id\":";
76 size_t pos = meta_json.find(search_key);
78 eosio::check(pos != std::string::npos,
"registry_id not found in meta");
81 pos += search_key.length();
84 while (pos < meta_json.length() && (meta_json[pos] <
'0' || meta_json[pos] >
'9')) {
88 eosio::check(pos < meta_json.length(),
"registry_id value not found");
92 while (pos < meta_json.length() && meta_json[pos] >=
'0' && meta_json[pos] <=
'9') {
93 result = result * 10 + (meta_json[pos] -
'0');
97 eosio::check(result > 0,
"invalid registry_id value");
eosio::checksum256 hashit(std::string str)
Definition: utils.hpp:35
uint64_t generate()
Definition: utils.hpp:48
uint64_t extract_registry_id_from_meta(const std::string &meta_json)
Definition: utils.hpp:73
std::string checksum256_to_hex(const eosio::checksum256 &hash)
Definition: utils.hpp:62
static uint128_t combine_checksum_ids(const checksum256 &hash, eosio::name username)
Definition: utils.hpp:9
std::string generate_random_name()
Definition: utils.hpp:16
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y)
Definition: utils.hpp:5
uint64_t hash64(const char *buf, size_t len)
Definition: utils.hpp:39