diff --git a/modules/net/dap_chain_ledger.c b/modules/net/dap_chain_ledger.c index 172b01803977ce04504682e1614bd5028cf6f5a3..e5b41bacbfcbf3efb30caacb267eaa40239095c4 100644 --- a/modules/net/dap_chain_ledger.c +++ b/modules/net/dap_chain_ledger.c @@ -3657,7 +3657,7 @@ static int s_tx_cache_check(dap_ledger_t *a_ledger, bool a_from_threshold, dap_list_t **a_list_bound_items, dap_list_t **a_list_tx_out, - char **a_main_ticker, + char *a_main_ticker, dap_chain_net_srv_uid_t *a_tag, dap_chain_tx_tag_action_type_t *a_action, bool a_check_for_removing) @@ -4109,7 +4109,7 @@ static int s_tx_cache_check(dap_ledger_t *a_ledger, if (l_err_num) break; l_bound_item->in.addr_from = *l_addr_from; - dap_strncpy(l_bound_item->in.token_ticker, l_token, DAP_CHAIN_TICKER_SIZE_MAX - 1); + dap_strncpy(l_bound_item->in.token_ticker, l_token, DAP_CHAIN_TICKER_SIZE_MAX); // 4. compare public key hashes in the signature of the current transaction and in the 'out' item of the previous transaction if (l_addr_from->net_id.uint64 != a_ledger->net->pub.id.uint64 || !dap_hash_fast_compare(&l_tx_first_sign_pkey_hash, &l_addr_from->data.hash_fast)) { @@ -4465,7 +4465,7 @@ static int s_tx_cache_check(dap_ledger_t *a_ledger, } if (a_main_ticker && !l_err_num) - *a_main_ticker = dap_strdup(l_main_ticker); + dap_strncpy(a_main_ticker, l_main_ticker, DAP_CHAIN_TICKER_SIZE_MAX); HASH_ITER(hh, l_values_from_prev_tx, l_value_cur, l_tmp) { HASH_DEL(l_values_from_prev_tx, l_value_cur); @@ -4567,7 +4567,7 @@ int dap_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, dap_ha dap_list_t *l_list_bound_items = NULL; dap_list_t *l_list_tx_out = NULL; dap_ledger_tx_item_t *l_item_tmp = NULL; - char *l_main_token_ticker = NULL; + char l_main_token_ticker[DAP_CHAIN_TICKER_SIZE_MAX] = { '\0' }; bool l_from_threshold = a_from_threshold; char l_tx_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; @@ -4580,7 +4580,7 @@ int dap_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, dap_ha if( (l_ret_check = s_tx_cache_check(a_ledger, a_tx, a_tx_hash, a_from_threshold, &l_list_bound_items, &l_list_tx_out, - &l_main_token_ticker, &l_tag, &l_action, false))) { + l_main_token_ticker, &l_tag, &l_action, false))) { if (l_ret_check == DAP_CHAIN_CS_VERIFY_CODE_TX_NO_PREVIOUS || l_ret_check == DAP_CHAIN_CS_VERIFY_CODE_TX_NO_EMISSION) { if (!l_from_threshold) { @@ -4923,7 +4923,6 @@ FIN: dap_list_free_full(l_list_bound_items, NULL); if (l_list_tx_out) dap_list_free(l_list_tx_out); - DAP_DEL_Z(l_main_token_ticker); if (PVT(a_ledger)->cached) { if (l_cache_used_outs) { for (size_t i = 1; i <= l_outs_used; i++) { @@ -4951,7 +4950,7 @@ int dap_ledger_tx_remove(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, dap dap_ledger_private_t *l_ledger_pvt = PVT(a_ledger); dap_list_t *l_list_bound_items = NULL; dap_list_t *l_list_tx_out = NULL; - char *l_main_token_ticker = NULL; + char l_main_token_ticker[DAP_CHAIN_TICKER_SIZE_MAX] = { '\0' }; char l_tx_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; dap_chain_hash_fast_to_str(a_tx_hash, l_tx_hash_str, sizeof(l_tx_hash_str)); @@ -4961,7 +4960,7 @@ int dap_ledger_tx_remove(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, dap int l_ret_check; if( (l_ret_check = s_tx_cache_check(a_ledger, a_tx, a_tx_hash, false, &l_list_bound_items, &l_list_tx_out, - &l_main_token_ticker, NULL, NULL, true))) { + l_main_token_ticker, NULL, NULL, true))) { debug_if(s_debug_more, L_WARNING, "dap_ledger_tx_remove() tx %s not passed the check: %s ", l_tx_hash_str, dap_ledger_check_error_str(l_ret_check)); return l_ret_check; @@ -5213,7 +5212,6 @@ FIN: dap_list_free_full(l_list_bound_items, NULL); if (l_list_tx_out) dap_list_free(l_list_tx_out); - DAP_DEL_Z(l_main_token_ticker); if (PVT(a_ledger)->cached) { if (l_cache_used_outs) { for (size_t i = 1; i < l_outs_used; i++) { @@ -6316,15 +6314,13 @@ void dap_ledger_set_cache_tx_check_callback(dap_ledger_t *a_ledger, dap_ledger_c const char *dap_ledger_tx_calculate_main_ticker(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, int *a_ledger_rc) { - char *l_main_ticker = NULL; + static _Thread_local char s_main_ticker[DAP_CHAIN_TICKER_SIZE_MAX] = { '\0' }; dap_chain_hash_fast_t *l_tx_hash = dap_chain_node_datum_tx_calc_hash(a_tx); - int l_rc = s_tx_cache_check(a_ledger, a_tx, l_tx_hash, false, NULL, NULL, &l_main_ticker, NULL, NULL, false); + int l_rc = s_tx_cache_check(a_ledger, a_tx, l_tx_hash, false, NULL, NULL, s_main_ticker, NULL, NULL, false); if (l_rc == DAP_LEDGER_CHECK_ALREADY_CACHED) - l_main_ticker = (char *)dap_ledger_tx_get_token_ticker_by_hash(a_ledger, l_tx_hash); + dap_strncpy( s_main_ticker, dap_ledger_tx_get_token_ticker_by_hash(a_ledger, l_tx_hash), DAP_CHAIN_TICKER_SIZE_MAX ); DAP_DEL_Z(l_tx_hash); - if (a_ledger_rc) *a_ledger_rc = l_rc; - - return l_main_ticker; + return s_main_ticker; } diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 2f80da55f3bd3943a1a03295dc3dd14fc76b3d49..bf96259b4476f1ddb9094fe43de336ba73082e2b 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -2817,7 +2817,7 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a dap_list_free(l_list_sig_item); dap_list_t *l_list_in_reward = dap_chain_datum_tx_items_get(l_tx, TX_ITEM_TYPE_IN_REWARD, NULL); if (l_list_in_reward) { - json_object *l_obj_in_reward_arary = json_object_new_array(); + /*json_object *l_obj_in_reward_arary = json_object_new_array(); if (!l_obj_in_reward_arary) { dap_list_free(l_list_in_reward); json_object_put(l_jobj_datum); @@ -2844,7 +2844,8 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a } json_object_array_add(l_obj_in_reward_arary, l_jobj_block_hash); DAP_DELETE(l_block_hash); - } + }*/ + dap_list_free(l_list_in_reward); } else { json_object *l_jobj_addr_from = json_object_new_string(dap_chain_addr_to_str(&l_addr_from)); if (!l_jobj_addr_from) { @@ -2987,20 +2988,6 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a } if (l_dist_addr) { - json_object *l_jobj_addr = json_object_new_string(dap_chain_addr_to_str(l_dist_addr)); - if (!l_jobj_addr) { - json_object_put(l_jobj_to_list); - json_object_put(l_jobj_change_list); - json_object_put(l_jobj_to_from_emi); - json_object_put(l_jobj_fee_list); - json_object_put(l_jobj_money); - json_object_put(l_jobj_datum); - json_object_put(l_jobj_datums); - json_object_put(l_obj_chain); - dap_global_db_objs_delete(l_objs, l_objs_count); - dap_json_rpc_allocation_error; - return; - } if (!datum_is_accepted_addr && l_wallet_addr) { datum_is_accepted_addr = dap_chain_addr_compare(l_wallet_addr, l_dist_addr); } @@ -3010,7 +2997,6 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a json_object_put(l_jobj_change_list); json_object_put(l_jobj_to_from_emi); json_object_put(l_jobj_fee_list); - json_object_put(l_jobj_addr); json_object_put(l_jobj_money); json_object_put(l_jobj_datum); json_object_put(l_jobj_datums); @@ -3036,7 +3022,6 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a json_object_put(l_jobj_change_list); json_object_put(l_jobj_to_from_emi); json_object_put(l_jobj_fee_list); - json_object_put(l_jobj_addr); json_object_put(l_jobj_money); json_object_put(l_jobj_datum); json_object_put(l_jobj_datums); @@ -3055,7 +3040,7 @@ void s_com_mempool_list_print_for_chain(dap_chain_net_t * a_net, dap_chain_t * a else json_object_array_add(l_jobj_change_list, l_jobj_f); } else { - json_object_object_add(l_jobj_f, "addr", l_jobj_addr); + json_object_object_add(l_jobj_f, "addr", json_object_new_string(dap_chain_addr_to_str(l_dist_addr))); json_object_array_add(l_jobj_to_list, l_jobj_f); } } else {