From f9e28fcdf0c49edf3b7ab9f70e63572f644e9b54 Mon Sep 17 00:00:00 2001 From: "roman.khlopkov" <roman.khlopkov@demlabs.net> Date: Mon, 26 Feb 2024 16:48:08 +0300 Subject: [PATCH] [*] GUUID capitalization --- modules/common/dap_chain_common.c | 436 ------------------ modules/common/dap_chain_datum.c | 60 ++- modules/common/include/dap_chain_common.h | 31 +- .../consensus/esbocs/dap_chain_cs_esbocs.c | 8 +- .../esbocs/include/dap_chain_cs_esbocs.h | 1 + modules/net/dap_chain_net.c | 9 +- modules/net/dap_chain_node_cli_cmd.c | 2 +- modules/type/dag/dap_chain_cs_dag.c | 7 +- modules/type/dag/include/dap_chain_cs_dag.h | 1 + modules/type/none/dap_chain_cs_none.c | 4 +- 10 files changed, 50 insertions(+), 509 deletions(-) diff --git a/modules/common/dap_chain_common.c b/modules/common/dap_chain_common.c index dc36c4f7ca..11e1c4ed1f 100644 --- a/modules/common/dap_chain_common.c +++ b/modules/common/dap_chain_common.c @@ -41,17 +41,6 @@ const dap_chain_net_srv_uid_t c_dap_chain_net_srv_uid_null = {0}; const dap_chain_cell_id_t c_dap_chain_cell_id_null = {0}; const dap_chain_addr_t c_dap_chain_addr_blank = {0}; -int dap_id_uint64_parse(const char *a_id_str, uint64_t *a_id) -{ - if (!a_id_str || !a_id || (sscanf(a_id_str, "0x%16"DAP_UINT64_FORMAT_X, a_id) != 1 && - sscanf(a_id_str, "0x%16"DAP_UINT64_FORMAT_x, a_id) != 1 && - sscanf(a_id_str, "%"DAP_UINT64_FORMAT_U, a_id) != 1)) { - log_it (L_ERROR, "Can't recognize '%s' string as 64-bit id, hex or dec", a_id_str); - return -1; - } - return 0; -} - /** * @brief dap_chain_hash_to_str * @param a_hash @@ -226,428 +215,3 @@ int dap_chain_addr_check_sum(const dap_chain_addr_t *a_addr) dap_hash_fast(a_addr, sizeof(dap_chain_addr_t) - sizeof(dap_chain_hash_fast_t), &l_checksum); return memcmp(a_addr->checksum.raw, l_checksum.raw, sizeof(l_checksum.raw)); } - - - -uint64_t dap_chain_uint128_to(uint128_t a_from) -{ -#ifdef DAP_GLOBAL_IS_INT128 - if (a_from > UINT64_MAX) { - log_it(L_ERROR, "Can't convert balance to uint64_t. It's too big."); - } - return (uint64_t)a_from; -#else - if (a_from.hi) { - log_it(L_ERROR, "Can't convert balance to uint64_t. It's too big."); - } - return a_from.lo; -#endif -} - -uint64_t dap_chain_uint256_to(uint256_t a_from) -{ -#ifdef DAP_GLOBAL_IS_INT128 - if (a_from.hi || a_from.lo > UINT64_MAX) { - log_it(L_ERROR, "Can't convert balance to uint64_t. It's too big."); - } - return (uint64_t)a_from.lo; -#else - if (!IS_ZERO_128(a_from.hi) || a_from.lo.hi) { - log_it(L_ERROR, "Can't convert balance to uint64_t. It's too big."); - } - return a_from.lo.lo; -#endif -} - -// 256 -uint128_t dap_chain_uint128_from_uint256(uint256_t a_from) -{ - if ( !( EQUAL_128(a_from.hi, uint128_0) ) ) { - log_it(L_ERROR, "Can't convert to uint128_t. It's too big."); - } - return a_from.lo; -} - - -char *dap_chain_balance_print128(uint128_t a_balance) -{ - char *l_buf = DAP_NEW_Z_SIZE(char, DATOSHI_POW + 2); - if (!l_buf) { - log_it(L_CRITICAL, "Memory allocation error"); - return NULL; - } - int l_pos = 0; - uint128_t l_value = a_balance; -#ifdef DAP_GLOBAL_IS_INT128 - do { - l_buf[l_pos++] = (l_value % 10) + '0'; - l_value /= 10; - } while (l_value); -#else - uint32_t l_tmp[4] = {l_value.u32.a, l_value.u32.b, l_value.u32.c, l_value.u32.d}; - uint64_t t, q; - do { - q = 0; - // Byte order is 1, 0, 3, 2 for little endian - for (int i = 1; i <= 3; ) { - t = q << 32 | l_tmp[i]; - q = t % 10; - l_tmp[i] = t / 10; - if (i == 2) i = 4; // end of cycle - if (i == 3) i = 2; - if (i == 0) i = 3; - if (i == 1) i = 0; - } - l_buf[l_pos++] = q + '0'; - } while (l_tmp[2]); -#endif - int l_strlen = strlen(l_buf) - 1; - for (int i = 0; i < (l_strlen + 1) / 2; i++) { - char c = l_buf[i]; - l_buf[i] = l_buf[l_strlen - i]; - l_buf[l_strlen - i] = c; - } - return l_buf; -} - -char *dap_chain_balance_to_coins128(uint128_t a_balance) -{ - char *l_buf = dap_chain_balance_print128(a_balance); - int l_strlen = strlen(l_buf); - int l_pos; - if (l_strlen > DATOSHI_DEGREE) { - for (l_pos = l_strlen; l_pos > l_strlen - DATOSHI_DEGREE; l_pos--) { - l_buf[l_pos] = l_buf[l_pos - 1]; - } - l_buf[l_pos] = '.'; - } else { - int l_sub = DATOSHI_DEGREE - l_strlen + 2; - for (l_pos = DATOSHI_DEGREE + 1; l_pos >= 0; l_pos--) { - l_buf[l_pos] = (l_pos >= l_sub) ? l_buf[l_pos - l_sub] : '0'; - } - l_buf[1] = '.'; - } - return l_buf; -} - -const union __c_pow10__ { - uint64_t u64[2]; - uint32_t u32[4]; -} DAP_ALIGN_PACKED c_pow10[DATOSHI_POW] = { - { .u64 = {0, 1ULL} }, // 0 - { .u64 = {0, 10ULL} }, // 1 - { .u64 = {0, 100ULL} }, // 2 - { .u64 = {0, 1000ULL} }, // 3 - { .u64 = {0, 10000ULL} }, // 4 - { .u64 = {0, 100000ULL} }, // 5 - { .u64 = {0, 1000000ULL} }, // 6 - { .u64 = {0, 10000000ULL} }, // 7 - { .u64 = {0, 100000000ULL} }, // 8 - { .u64 = {0, 1000000000ULL} }, // 9 - { .u64 = {0, 10000000000ULL} }, // 10 - { .u64 = {0, 100000000000ULL} }, // 11 - { .u64 = {0, 1000000000000ULL} }, // 12 - { .u64 = {0, 10000000000000ULL} }, // 13 - { .u64 = {0, 100000000000000ULL} }, // 14 - { .u64 = {0, 1000000000000000ULL} }, // 15 - { .u64 = {0, 10000000000000000ULL} }, // 16 - { .u64 = {0, 100000000000000000ULL} }, // 17 - { .u64 = {0, 1000000000000000000ULL} }, // 18 - { .u64 = {0, 10000000000000000000ULL} }, // 19 - { .u64 = {5ULL, 7766279631452241920ULL} }, // 20 - { .u64 = {54ULL, 3875820019684212736ULL} }, // 21 - { .u64 = {542ULL, 1864712049423024128ULL} }, // 22 - { .u64 = {5421ULL, 200376420520689664ULL} }, // 23 - { .u64 = {54210ULL, 2003764205206896640ULL} }, // 24 - { .u64 = {542101ULL, 1590897978359414784ULL} }, // 25 - { .u64 = {5421010ULL, 15908979783594147840ULL} }, // 26 - { .u64 = {54210108ULL, 11515845246265065472ULL} }, // 27 - { .u64 = {542101086ULL, 4477988020393345024ULL} }, // 28 - { .u64 = {5421010862ULL, 7886392056514347008ULL} }, // 29 - { .u64 = {54210108624ULL, 5076944270305263616ULL} }, // 30 - { .u64 = {542101086242ULL, 13875954555633532928ULL} }, // 31 - { .u64 = {5421010862427ULL, 9632337040368467968ULL} }, // 32 - { .u64 = {54210108624275ULL, 4089650035136921600ULL} }, // 33 - { .u64 = {542101086242752ULL, 4003012203950112768ULL} }, // 34 - { .u64 = {5421010862427522ULL, 3136633892082024448ULL} }, // 35 - { .u64 = {54210108624275221ULL, 12919594847110692864ULL} }, // 36 - { .u64 = {542101086242752217ULL, 68739955140067328ULL} }, // 37 - { .u64 = {5421010862427522170ULL, 687399551400673280ULL} } // 38 -}; - -uint128_t dap_chain_balance_scan128(const char *a_balance) -{ - int l_strlen = strlen(a_balance); - uint128_t l_ret = uint128_0, l_nul = uint128_0; - if (l_strlen > DATOSHI_POW) - return l_nul; - for (int i = 0; i < l_strlen ; i++) { - char c = a_balance[l_strlen - i - 1]; - if (!isdigit(c)) { - log_it(L_WARNING, "Incorrect input number"); - return l_nul; - } - uint8_t l_digit = c - '0'; - if (!l_digit) - continue; -#ifdef DAP_GLOBAL_IS_INT128 - uint128_t l_tmp = (uint128_t)c_pow10[i].u64[0] * l_digit; - if (l_tmp >> 64) { - log_it(L_WARNING, "Input number is too big"); - return l_nul; - } - l_tmp = (l_tmp << 64) + (uint128_t)c_pow10[i].u64[1] * l_digit; - SUM_128_128(l_ret, l_tmp, &l_ret); - if (l_ret == l_nul) - return l_nul; -#else - uint128_t l_tmp; - l_tmp.hi = 0; - l_tmp.lo = (uint64_t)c_pow10[i].u32[2] * (uint64_t)l_digit; - SUM_128_128(l_ret, l_tmp, &l_ret); - if (l_ret.hi == 0 && l_ret.lo == 0) - return l_nul; - uint64_t l_mul = (uint64_t)c_pow10[i].u32[3] * (uint64_t)l_digit; - l_tmp.lo = l_mul << 32; - l_tmp.hi = l_mul >> 32; - SUM_128_128(l_ret, l_tmp, &l_ret); - if (l_ret.hi == 0 && l_ret.lo == 0) - return l_nul; - l_tmp.lo = 0; - l_tmp.hi = (uint64_t)c_pow10[i].u32[0] * (uint64_t)l_digit; - SUM_128_128(l_ret, l_tmp, &l_ret); - if (l_ret.hi == 0 && l_ret.lo == 0) - return l_nul; - l_mul = (uint64_t)c_pow10[i].u32[1] * (uint64_t)l_digit; - if (l_mul >> 32) { - log_it(L_WARNING, "Input number is too big"); - return l_nul; - } - l_tmp.hi = l_mul << 32; - SUM_128_128(l_ret, l_tmp, &l_ret); - if (l_ret.hi == 0 && l_ret.lo == 0) - return l_nul; -#endif - } - return l_ret; -} - -uint128_t dap_chain_coins_to_balance128(const char *a_coins) -{ - char l_buf [DATOSHI_POW + 2] = {0}; - uint128_t l_ret = uint128_0, l_nul = uint128_0; - - if (strlen(a_coins) > DATOSHI_POW + 1) { - log_it(L_WARNING, "Incorrect balance format - too long"); - return l_nul; - } - - strcpy(l_buf, a_coins); - char *l_point = strchr(l_buf, '.'); - int l_tail = 0; - int l_pos = strlen(l_buf); - if (l_point) { - l_tail = l_pos - 1 - (l_point - l_buf); - l_pos = l_point - l_buf; - if (l_tail > DATOSHI_DEGREE) { - log_it(L_WARNING, "Incorrect balance format - too much precision"); - return l_nul; - } - while (l_buf[l_pos]) { - l_buf[l_pos] = l_buf[l_pos + 1]; - l_pos++; - } - l_pos--; - } - if (l_pos + DATOSHI_DEGREE - l_tail > DATOSHI_POW) { - log_it(L_WARNING, "Incorrect balance format - too long with point"); - return l_nul; - } - int i; - for (i = 0; i < DATOSHI_DEGREE - l_tail; i++) { - l_buf[l_pos + i] = '0'; - } - l_buf[l_pos + i] = '\0'; - l_ret = dap_chain_balance_scan128(l_buf); - - return l_ret; -} - -//#define __NEW_STARLET__ "BMF" -#ifdef __NEW_STARLET__ - - -char *dap_chain_balance_print333(uint256_t a_balance) -{ - int l_pos, l_len, l_len_hi, l_len_lo; - char *l_buf, *l_cp, *l_cp2, *l_cps, *l_cpe, l_chr; - static const char l_zero[sizeof(uint256_t)] = {0}; - uint64_t t, q; - uint32_t l_tmp[4]; - - l_len = (DAP_CHAIN$SZ_MAX256DEC + 8) & (~7); /* Align size of the buffer to 8 bytes */ - - if ( !(l_buf = DAP_NEW_Z_SIZE(char, l_len)) ) - return log_it(L_ERROR, "Cannot allocate %d octets, errno=%d", l_len, errno), NULL; - - l_cp = l_buf; - - if ( memcmp(&a_balance.hi, &l_zero, sizeof(uint128_t)) ) - { - l_tmp [0] = a_balance.__hi.a; - l_tmp [1] = a_balance.__hi.b; - l_tmp [2] = a_balance.__hi.c; - l_tmp [3] = a_balance.__hi.d; - - l_len_hi = 0; - l_cps = l_cp; - - do { - q = 0; - // Byte order is 1, 0, 3, 2 for little endian - for (int i = 1; i <= 3; ) - { - t = q << 32 | l_tmp[i]; - q = t % 10; - l_tmp[i] = t / 10; - - if (i == 2) i = 4; // end of cycle - if (i == 3) i = 2; - if (i == 0) i = 3; - if (i == 1) i = 0; - } - - *(l_cp++) = q + '0'; - l_len_hi++; - - } while (l_tmp[2]); - - l_pos = l_len_hi / 2; /* A number of swaps */ - l_cpe = l_cp - 1; /* -- // -- to tail of the string */ - - for (int i = l_pos; i--; l_cps++, l_cpe--) /* Do swaps ... */ - { - l_chr = *l_cps; - *l_cps = *l_cpe; - *l_cpe = l_chr; - } - } - - l_tmp [0] = a_balance.__lo.a; - l_tmp [1] = a_balance.__lo.b; - l_tmp [2] = a_balance.__lo.c; - l_tmp [3] = a_balance.__lo.d; - - l_len_lo = 0; - l_cps = l_cp2 = l_cp; - - do { - q = 0; - // Byte order is 1, 0, 3, 2 for little endian - for (int i = 1; i <= 3; ) - { - t = q << 32 | l_tmp[i]; - q = t % 10; - l_tmp[i] = t / 10; - - if (i == 2) i = 4; // end of cycle - if (i == 3) i = 2; - if (i == 0) i = 3; - if (i == 1) i = 0; - } - - *(l_cp2++) = q + '0'; - l_len_lo++; - - } while (l_tmp[2]); - - - l_pos = l_len_lo / 2; /* A number of swaps */ - l_cpe = l_cp2 - 1; /* -- // -- to tail of the string */ - - for (int i = l_pos; i--; l_cps++, l_cpe--) /* Do swaps ... */ - { - l_chr = *l_cps; - *l_cps = *l_cpe; - *l_cpe = l_chr; - } - - if ( l_len_hi && (DAP_CHAIN$SZ_MAX128DEC > l_len_lo) ) /* Do we need to add leading zeroes ? */ - { - /* "123456" -> 123000...000456" */ - memmove(l_cp2 + ( DAP_CHAIN$SZ_MAX128DEC - l_len), l_cp2, l_len_lo); - memset(l_cp2, '0', ( DAP_CHAIN$SZ_MAX128DEC - l_len_lo)); - } - - return l_buf; -} - - - - - -void uint256_cvt_test (void) -{ - extern char *dap_cvt_uint256_to_str(uint256_t a_uint256); - extern uint256_t dap_cvt_str_to_uint256(const char *a_256bit_num); - extern char *dap_chain_balance_to_coins256(uint256_t a_balance); - extern char *dap_chain_balance_print333(uint256_t a_balance); - - char *cp; - uint128_t uint128 = dap_chain_uint128_from(-1); - uint256_t uint256; - uint256.hi = dap_chain_uint128_from(123); - uint256.lo = dap_chain_uint128_from(374607431768211455); - const uint256_t uint256_zero = {0}; - - uint256 = uint256_zero; - uint256.__lo.c = 1; - - cp = dap_chain_balance_print(uint256); - DAP_DELETE(cp); - - uint256 = uint256_zero; - uint256.__lo.c = 1; - cp = dap_chain_balance_to_coins(uint256); - uint256 = dap_chain_coins_to_balance(cp); - DAP_DELETE(cp); - - uint256 = uint256_zero; - uint256.__lo.c = 100000000; - cp = dap_chain_balance_to_coins(uint256); - uint256 = dap_chain_coins_to_balance(cp); - DAP_DELETE(cp); - - - - - cp = dap_chain_balance_print333(uint256); - DAP_DELETE(cp); - - - - uint256.hi = dap_chain_uint128_from(-1); - uint256.lo = dap_chain_uint128_from(-1); - cp = dap_chain_balance_print333(uint256); - DAP_DELETE(cp); - - cp = dap_chain_balance_print(uint256); - DAP_DELETE(cp); - - cp = dap_cvt_uint256_to_str(uint256 ); - uint256 = dap_cvt_str_to_uint256(cp); - DAP_DELETE(cp); - - uint256.hi = dap_chain_uint128_from(-1); - uint256.lo = dap_chain_uint128_from(-1); - cp = dap_cvt_uint256_to_str(uint256 ); - DAP_DELETE(cp); - - uint256.hi = dap_chain_uint128_from(123); - uint256.lo = dap_chain_uint128_from(374607431768211455); - - cp = dap_chain_balance_to_coins256(uint256); - uint256 = dap_chain_coins_to_balance(cp); - DAP_DELETE(cp); -} -#endif diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index 8558939cbb..564d674686 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -829,43 +829,37 @@ void dap_chain_datum_dump(dap_string_t *a_str_out, dap_chain_datum_t *a_datum, c l_emission->hdr.version); dap_string_append_printf(a_str_out, " to addr: %s\n", dap_chain_addr_to_str(&(l_emission->hdr.address))); switch (l_emission->hdr.type) { - case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_UNDEFINED: - break; - case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH: - dap_string_append_printf(a_str_out, " signs_count: %d\n", l_emission->data.type_auth.signs_count); - dap_string_append_printf(a_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U"\n", - l_emission->data.type_auth.tsd_total_size); + case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH: + dap_string_append_printf(a_str_out, " signs_count: %d\n", l_emission->data.type_auth.signs_count); + dap_string_append_printf(a_str_out, " tsd_total_size: %"DAP_UINT64_FORMAT_U"\n", + l_emission->data.type_auth.tsd_total_size); - if ( ( (void *) l_emission->tsd_n_signs + l_emission->data.type_auth.tsd_total_size) > - ((void *) l_emission + l_emission_size) ) - { - log_it(L_ERROR, "Illformed DATUM type %d, TSD section is out-of-buffer (%" DAP_UINT64_FORMAT_U " vs %zu)", - l_emission->hdr.type, l_emission->data.type_auth.tsd_total_size, l_emission_size); + if ( ( (void *) l_emission->tsd_n_signs + l_emission->data.type_auth.tsd_total_size) > + ((void *) l_emission + l_emission_size) ) + { + log_it(L_ERROR, "Illformed DATUM type %d, TSD section is out-of-buffer (%" DAP_UINT64_FORMAT_U " vs %zu)", + l_emission->hdr.type, l_emission->data.type_auth.tsd_total_size, l_emission_size); - dap_string_append_printf(a_str_out, " Skip incorrect or illformed DATUM"); - break; - } - dap_chain_datum_token_certs_dump(a_str_out, l_emission->tsd_n_signs + l_emission->data.type_auth.tsd_total_size, - l_emission->data.type_auth.size - l_emission->data.type_auth.tsd_total_size, a_hash_out_type); + dap_string_append_printf(a_str_out, " Skip incorrect or illformed DATUM"); break; - case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ALGO: - dap_string_append_printf(a_str_out, " codename: %s\n", l_emission->data.type_algo.codename); - break; - case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER: - dap_string_append_printf(a_str_out, " value_start: %.0Lf(%"DAP_UINT64_FORMAT_U"), codename: %s\n", - dap_chain_datoshi_to_coins(l_emission->data.type_atom_owner.value_start), - l_emission->data.type_atom_owner.value_start, - l_emission->data.type_atom_owner.value_change_algo_codename - ); - break; - case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT: { - char l_time_str[32]; - // get time of create datum - if(dap_time_to_str_rfc822(l_time_str, sizeof(l_time_str), l_emission->data.type_presale.lock_time) < 1) - l_time_str[0] = '\0'; - dap_string_append_printf(a_str_out, " flags: 0x%x, lock_time: %s\n", l_emission->data.type_presale.flags, l_time_str); - dap_string_append_printf(a_str_out, " addr: %s\n", dap_chain_addr_to_str(&l_emission->data.type_presale.addr)); } + dap_chain_datum_token_certs_dump(a_str_out, l_emission->tsd_n_signs + l_emission->data.type_auth.tsd_total_size, + l_emission->data.type_auth.size - l_emission->data.type_auth.tsd_total_size, a_hash_out_type); + break; + case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ALGO: + dap_string_append_printf(a_str_out, " codename: %s\n", l_emission->data.type_algo.codename); + break; + case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT: { + char l_time_str[32]; + // get time of create datum + if(dap_time_to_str_rfc822(l_time_str, sizeof(l_time_str), l_emission->data.type_presale.lock_time) < 1) + l_time_str[0] = '\0'; + dap_string_append_printf(a_str_out, " flags: 0x%x, lock_time: %s\n", l_emission->data.type_presale.flags, l_time_str); + dap_string_append_printf(a_str_out, " addr: %s\n", dap_chain_addr_to_str(&l_emission->data.type_presale.addr)); + } + case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER: + case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_UNDEFINED: + default: break; } DAP_DELETE(l_emission); diff --git a/modules/common/include/dap_chain_common.h b/modules/common/include/dap_chain_common.h index 6939ab164d..9c396a406a 100644 --- a/modules/common/include/dap_chain_common.h +++ b/modules/common/include/dap_chain_common.h @@ -63,8 +63,6 @@ typedef union dap_chain_cell_id { uint64_t uint64; } DAP_ALIGN_PACKED dap_chain_cell_id_t; -int dap_id_uint64_parse(const char *a_id_str, uint64_t *a_id); - enum { NODE_ROLE_ROOT_MASTER=0x00, NODE_ROLE_ROOT=0x01, @@ -118,13 +116,8 @@ typedef struct dap_chain_addr{ typedef union { uint8_t raw[DAP_CHAIN_NET_SRV_UID_SIZE]; -#if DAP_CHAIN_NET_SRV_UID_SIZE == 8 uint64_t raw_ui64; uint64_t uint64; -#elif DAP_CHAIN_NET_SRV_UID_SIZE == 16 - uint64_t raw_ui64[2]; - uint128_t uint128; -#endif } dap_chain_net_srv_uid_t; extern const dap_chain_net_srv_uid_t c_dap_chain_net_srv_uid_null; @@ -236,17 +229,6 @@ DAP_STATIC_INLINE bool dap_chain_addr_compare(const dap_chain_addr_t *a_addr1, c return !memcmp(a_addr1, a_addr2, sizeof(dap_chain_addr_t)); } -// Deprecated -DAP_STATIC_INLINE long double dap_chain_datoshi_to_coins(uint64_t a_count) -{ - return (double)a_count / DATOSHI_LD; -} -// Deprecated -DAP_STATIC_INLINE uint64_t dap_chain_coins_to_datoshi(long double a_count) -{ - return (uint64_t)(a_count * DATOSHI_LD); -} - DAP_STATIC_INLINE uint128_t dap_chain_uint128_from(uint64_t a_from) { return GET_128_FROM_64(a_from); @@ -266,14 +248,11 @@ DAP_STATIC_INLINE uint256_t dap_chain_uint256_from_uint128(uint128_t a_from) return GET_256_FROM_128(a_from); } -uint64_t dap_chain_uint128_to(uint128_t a_from); -// 256 -uint64_t dap_chain_uint256_to(uint256_t a_from); - -#define dap_chain_balance_print(a_balance) dap_uint256_uninteger_to_char(a_balance) -#define dap_chain_balance_scan(a_balance) dap_uint256_scan_uninteger(a_balance) -#define dap_chain_balance_to_coins(a) dap_uint256_decimal_to_char(a) -#define dap_chain_coins_to_balance(a) dap_uint256_scan_decimal(a) +#define dap_chain_balance_print dap_uint256_uninteger_to_char +#define dap_chain_balance_scan dap_uint256_scan_uninteger +#define dap_chain_balance_to_coins dap_uint256_decimal_to_char +#define dap_chain_coins_to_balance dap_uint256_scan_decimal +#define dap_chain_uint256_to dap_uint256_to_uint64 /** * @brief dap_chain_hash_to_str diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index d1b14b4cb3..d766e003f9 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -478,9 +478,9 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf l_session->my_addr.uint64 = dap_chain_net_get_cur_addr_int(l_net); l_session->my_signing_addr = l_my_signing_addr; char *l_sync_group = s_get_penalty_group(l_net->pub.id); - l_session->db_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - NULL, 0, l_sync_group, - 72 * 3600, true, + l_session->db_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), NULL, + dap_cluster_uuid_compose(l_net->pub.id.uint64, DAP_CHAIN_CLUSTER_ID_ESBOCS), + l_sync_group, 72 * 3600, true, DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); DAP_DELETE(l_sync_group); dap_global_db_cluster_add_notify_callback(l_session->db_cluster, s_db_change_notifier, l_session); @@ -834,7 +834,7 @@ static void s_session_send_startsync(dap_chain_esbocs_session_t *a_session) dap_string_append_printf(l_addr_list, NODE_ADDR_FP_STR"; ", NODE_ADDR_FP_ARGS_S(((dap_chain_esbocs_validator_t *)it->data)->node_addr)); } - char *l_sync_hash = dap_global_db_driver_hash_print(a_session->db_hash); + const char *l_sync_hash = dap_global_db_driver_hash_print(a_session->db_hash); log_it(L_MSG, "net:%s, chain:%s, round:%"DAP_UINT64_FORMAT_U"." " Sent START_SYNC pkt, sync attempt %"DAP_UINT64_FORMAT_U" current validators list: %s DB sync hash %s", a_session->chain->net_name, a_session->chain->name, a_session->cur_round.id, diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h index 210a79a3a5..53b9533a3a 100644 --- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h +++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h @@ -32,6 +32,7 @@ along with any CellFrame SDK based project. If not, see <http://www.gnu.org/lic #define DAP_CHAIN_ESBOCS_PROTOCOL_VERSION 8 #define DAP_CHAIN_ESBOCS_GDB_GROUPS_PREFIX "esbocs" +#define DAP_CHAIN_CLUSTER_ID_ESBOCS 0x8000 #define DAP_CHAIN_ESBOCS_MSG_TYPE_SUBMIT 0x04 #define DAP_CHAIN_ESBOCS_MSG_TYPE_APPROVE 0x08 diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 8bea38c39a..6e284dd6be 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -2167,13 +2167,14 @@ static int s_cli_net(int argc, char **argv, void **reply) if( l_hash_hex_str ){ l_ret = dap_global_db_set_sync(l_gdb_group_str, l_hash_hex_str, &c, sizeof(c), false ); DAP_DELETE(l_gdb_group_str); - DAP_DELETE(l_hash_hex_str); if (l_ret) { json_object_put(l_jobj_return); dap_json_rpc_error_add(DAP_CHAIN_NET_JSON_RPC_CAN_NOT_SAVE_PUBLIC_KEY_IN_DATABASE, "Can't save public key hash %s in database", l_hash_hex_str); + DAP_DELETE(l_hash_hex_str); return DAP_CHAIN_NET_JSON_RPC_CAN_NOT_SAVE_PUBLIC_KEY_IN_DATABASE; } + DAP_DELETE(l_hash_hex_str); } else{ json_object_put(l_jobj_return); dap_json_rpc_error_add(DAP_CHAIN_NET_JSON_RPC_CAN_NOT_SAVE_PUBLIC_KEY_IN_DATABASE, "%s", @@ -2877,7 +2878,7 @@ int s_net_load(dap_chain_net_t *a_net) l_gdb_groups_mask = dap_strdup_printf("%s.chain-%s.mempool", l_net->pub.gdb_groups_prefix, l_chain->name); dap_global_db_cluster_t *l_cluster = dap_global_db_cluster_add( dap_global_db_instance_get_default(), - l_net->pub.name, l_net->pub.id.uint64, + l_net->pub.name, dap_cluster_uuid_compose(l_net->pub.id.uint64, 0), l_gdb_groups_mask, DAP_CHAIN_NET_MEMPOOL_TTL, true, DAP_GDB_MEMBER_ROLE_USER, DAP_CLUSTER_ROLE_EMBEDDED); @@ -2893,7 +2894,7 @@ int s_net_load(dap_chain_net_t *a_net) // Service orders cluster l_gdb_groups_mask = dap_strdup_printf("%s.service.orders", l_net->pub.gdb_groups_prefix); l_net_pvt->orders_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_net->pub.id.uint64, + l_net->pub.name, dap_cluster_uuid_compose(l_net->pub.id.uint64, 0), l_gdb_groups_mask, 0, true, DAP_GDB_MEMBER_ROLE_GUEST, DAP_CLUSTER_ROLE_EMBEDDED); @@ -2908,7 +2909,7 @@ int s_net_load(dap_chain_net_t *a_net) l_net->pub.gdb_nodes_aliases = dap_strdup_printf("%s.nodes.aliases",l_net->pub.gdb_groups_prefix); l_gdb_groups_mask = dap_strdup_printf("%s.nodes*", l_net->pub.gdb_groups_prefix); l_net_pvt->nodes_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_net->pub.id.uint64, + l_net->pub.name, dap_cluster_uuid_compose(l_net->pub.id.uint64, 0), l_gdb_groups_mask, 0, true, DAP_GDB_MEMBER_ROLE_GUEST, DAP_CLUSTER_ROLE_EMBEDDED); diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index be2c6285b4..2e24fe3885 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -3782,7 +3782,7 @@ int _cmd_mempool_proc(dap_chain_net_t *a_net, dap_chain_t *a_chain, const char * return DAP_JSON_RPC_ERR_CODE_MEMORY_ALLOCATED; } json_object_object_add(l_jobj_verify, "isProcessed", l_jobj_verify_status); - if (dap_global_db_del_sync(l_gdb_group_mempool, a_datum_hash)){ + if (false) { //dap_global_db_del_sync(l_gdb_group_mempool, a_datum_hash)){ json_object *l_jobj_wrn_text = json_object_new_string("Can't delete datum from mempool!"); if (!l_jobj_wrn_text) { json_object_put(l_jobj_verify); diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index e670ddea7d..86b67da9a1 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -322,9 +322,10 @@ static int s_chain_cs_dag_new(dap_chain_t * a_chain, dap_config_t * a_chain_cfg) dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id); l_dag->gdb_group_events_round_new = dap_strdup_printf(l_dag->is_celled ? "dag-%s-%s-%016llx-round.new" : "dag-%s-%s-round.new", l_net->pub.gdb_groups_prefix, a_chain->name, 0LLU); - dap_global_db_cluster_t *l_dag_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - NULL, 0, l_dag->gdb_group_events_round_new, - 900, true, DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); + dap_global_db_cluster_t *l_dag_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), NULL, + dap_cluster_uuid_compose(l_net->pub.id.uint64, DAP_CHAIN_CLUSTER_ID_DAG), + l_dag->gdb_group_events_round_new, 900, true, + DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); dap_global_db_cluster_add_notify_callback(l_dag_cluster, s_round_changes_notify, l_dag); dap_chain_net_add_poa_certs_to_cluster(l_net, l_dag_cluster); byte_t *l_current_round = dap_global_db_get_sync(l_dag->gdb_group_events_round_new, DAG_ROUND_CURRENT_KEY, NULL, NULL, NULL); diff --git a/modules/type/dag/include/dap_chain_cs_dag.h b/modules/type/dag/include/dap_chain_cs_dag.h index 8e07f06824..7ce4445e95 100644 --- a/modules/type/dag/include/dap_chain_cs_dag.h +++ b/modules/type/dag/include/dap_chain_cs_dag.h @@ -27,6 +27,7 @@ #include "dap_chain_cs_dag_event.h" #define DAG_ROUND_CURRENT_KEY "round_current" +#define DAP_CHAIN_CLUSTER_ID_DAG 0x10000 typedef struct dap_chain_cs_dag dap_chain_cs_dag_t; diff --git a/modules/type/none/dap_chain_cs_none.c b/modules/type/none/dap_chain_cs_none.c index 87669c1d41..d53fbe4351 100644 --- a/modules/type/none/dap_chain_cs_none.c +++ b/modules/type/none/dap_chain_cs_none.c @@ -170,8 +170,8 @@ static int s_cs_callback_new(dap_chain_t *a_chain, dap_config_t UNUSED_ARG *a_ch dap_global_db_cluster_t *l_nonconsensus_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_net->pub.name, l_net->pub.id.uint64, - l_nochain_priv->group_datums, 0, true, - DAP_GDB_MEMBER_ROLE_USER, DAP_CLUSTER_ROLE_EMBEDDED); + l_nochain_priv->group_datums, dap_cluster_uuid_compose(l_net->pub.id.uint64, 0), + true, DAP_GDB_MEMBER_ROLE_USER, DAP_CLUSTER_ROLE_EMBEDDED); if (!l_nonconsensus_cluster) { log_it(L_ERROR, "Can't create global DB cluster for synchronization"); return -3; -- GitLab