From 7ad929293a4a2af217670a0258ff3953b64f10ce Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Wed, 4 Dec 2024 09:28:49 +0000 Subject: [PATCH 01/18] 13961 --- dap-sdk | 2 +- modules/service/voting/dap_chain_net_srv_voting.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dap-sdk b/dap-sdk index 5a92226d09..d6b6934683 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 5a92226d095b1df1996c1122de2dbe636b139ffc +Subproject commit d6b6934683168160e7d25647ceef59d9439de2c3 diff --git a/modules/service/voting/dap_chain_net_srv_voting.c b/modules/service/voting/dap_chain_net_srv_voting.c index 96b7ddc57c..cfce14f4ac 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -921,7 +921,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) json_object_new_string("expired")); } if (l_voting->params->votes_max_count){ - char *l_val = dap_strdup_printf(" %"DAP_UINT64_FORMAT_U" (%s)\n", l_voting->params->votes_max_count, + char *l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U" (%s)", l_voting->params->votes_max_count, l_voting->params->votes_max_count <= l_votes_count ? "closed" : "active"); json_object_object_add(json_vote_out, "Votes max count", json_object_new_string(l_val)); DAP_DELETE(l_val); @@ -937,7 +937,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) for (uint64_t i = 0; i < dap_list_length(l_voting->params->options); i++){ json_object* json_vote_obj = json_object_new_object(); char *l_val = NULL; - l_val = dap_strdup_printf(" %"DAP_UINT64_FORMAT_U") ", i); + l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U")", i); json_object_object_add(json_vote_obj, "#", json_object_new_string(l_val)); DAP_DELETE(l_val); dap_list_t* l_option = dap_list_nth(l_voting->params->options, (uint64_t)i); @@ -949,7 +949,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) MULT_256_COIN(l_weight_percentage, dap_chain_balance_coins_scan("100.0"), &l_weight_percentage); const char *l_weight_percentage_str = dap_uint256_decimal_to_round_char(l_weight_percentage, 2, true); const char *l_w_coins, *l_w_datoshi = dap_uint256_to_char(l_results[i].weights, &l_w_coins); - l_val = dap_strdup_printf("Votes: %"DAP_UINT64_FORMAT_U" (%.2f%%)\nWeight: %s (%s) %s (%s%%)", + l_val = dap_strdup_printf("Votes: %"DAP_UINT64_FORMAT_U" (%.2f%%) Weight: %s (%s) %s (%s%%)", l_results[i].num_of_votes, l_percentage, l_w_coins, l_w_datoshi, l_net->pub.native_ticker, l_weight_percentage_str); json_object_object_add(json_vote_obj, "price", json_object_new_string(l_val)); DAP_DELETE(l_val); @@ -958,11 +958,11 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) json_object_object_add(json_vote_out, "Results", json_arr_vote_out); DAP_DELETE(l_results); char *l_val = NULL; - l_val = dap_strdup_printf(" %"DAP_UINT64_FORMAT_U, l_votes_count); + l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U, l_votes_count); json_object_object_add(json_vote_out, "Total number of votes", json_object_new_string(l_val)); DAP_DELETE(l_val); const char *l_tw_coins, *l_tw_datoshi = dap_uint256_to_char(l_total_weight, &l_tw_coins); - l_val = dap_strdup_printf("%s (%s) %s\n\n", l_tw_coins, l_tw_datoshi, l_net->pub.native_ticker); + l_val = dap_strdup_printf("%s (%s) %s", l_tw_coins, l_tw_datoshi, l_net->pub.native_ticker); json_object_object_add(json_vote_out, "Total weight", json_object_new_string(l_val)); DAP_DELETE(l_val); json_object_array_add(*json_arr_reply, json_vote_out); -- GitLab From e3b87386e6e8327a87559f8aade9112a3435c387 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 12:58:18 +0700 Subject: [PATCH 02/18] 13616 port --- modules/node-cli/dap_chain_node_cli.c | 2 +- modules/node-cli/dap_chain_node_cli_cmd.c | 24 +++++++++++++++---- .../node-cli/include/dap_chain_node_cli_cmd.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/node-cli/dap_chain_node_cli.c b/modules/node-cli/dap_chain_node_cli.c index 9dde939f63..d29e4f1b4b 100644 --- a/modules/node-cli/dap_chain_node_cli.c +++ b/modules/node-cli/dap_chain_node_cli.c @@ -159,7 +159,7 @@ int dap_chain_node_cli_init(dap_config_t * g_config) "wallet info {-addr <addr> | -w <wallet_name>} -net <net_name>\n" "wallet activate -w <wallet_name> -password <password> [-ttl <password_ttl_in_minutes>]\n" "wallet deactivate -w <wallet_name>>\n" - "wallet convert -w <wallet_name> -password <password>\n"); + "wallet convert -w <wallet_name> -password <password> | -remove_password }\n"); // Token commands dap_cli_server_cmd_add ("token_update", com_token_update, "Token update", "\nPrivate or CF20 token update\n" diff --git a/modules/node-cli/dap_chain_node_cli_cmd.c b/modules/node-cli/dap_chain_node_cli_cmd.c index aba036a214..8fce987ee5 100644 --- a/modules/node-cli/dap_chain_node_cli_cmd.c +++ b/modules/node-cli/dap_chain_node_cli_cmd.c @@ -1790,7 +1790,7 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; json_object_put(json_arr_out); return DAP_CHAIN_NODE_CLI_COM_TX_WALLET_NAME_ERR; } - if( cmd_num != CMD_WALLET_DEACTIVATE && !l_pass_str && cmd_num != CMD_WALLET_NEW) { + if( cmd_num != CMD_WALLET_DEACTIVATE && !l_pass_str && cmd_num != CMD_WALLET_NEW && cmd_num != CMD_WALLET_CONVERT ) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PASS_ERR, "Wallet password option <-password> not defined"); json_object_put(json_arr_out); @@ -1850,13 +1850,16 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; } break; // convert wallet case CMD_WALLET_CONVERT: { + bool l_remove_password = false; + if(dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-remove_password", NULL)) + l_remove_password = true; l_wallet = dap_chain_wallet_open(l_wallet_name, c_wallets_path, NULL); if (!l_wallet) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PASS_ERR, - "wrong password"); + "Can't open wallet"); json_object_put(json_arr_out); return DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PASS_ERR; - } else if (l_wallet->flags & DAP_WALLET$M_FL_ACTIVE) { + } else if (l_wallet->flags & DAP_WALLET$M_FL_ACTIVE && !l_remove_password) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_CONVERT_ERR, "Wallet can't be converted twice"); json_object_put(json_arr_out); @@ -1877,9 +1880,22 @@ int l_arg_index = 1, l_rc, cmd_num = CMD_NONE; json_object_put(json_arr_out); return DAP_CHAIN_NODE_CLI_COM_TX_WALLET_BACKUP_ERR; } + if (l_remove_password) { + if (dap_chain_wallet_deactivate(l_wallet_name, strlen(l_wallet_name))){ + dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_BACKUP_ERR, + "Can't deactivate wallet"); + json_object_put(json_arr_out); + return DAP_CHAIN_NODE_CLI_COM_TX_WALLET_DEACT_ERR; + } + } else if (!l_pass_str) { + dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PASS_ERR, + "Wallet password option <-password> not defined"); + json_object_put(json_arr_out); + return DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PASS_ERR; + } // change to old filename snprintf(l_file_name->file_name, sizeof(l_file_name->file_name), "%s/%s%s", c_wallets_path, l_wallet_name, ".dwallet"); - if ( dap_chain_wallet_save(l_wallet, l_pass_str) ) { + if ( dap_chain_wallet_save(l_wallet, l_remove_password ? NULL : l_pass_str) ) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_CONVERT_ERR, "Wallet is not converted because of internal error"); json_object_put(json_arr_out); diff --git a/modules/node-cli/include/dap_chain_node_cli_cmd.h b/modules/node-cli/include/dap_chain_node_cli_cmd.h index 35f2908dfc..ac4ae9bd4f 100644 --- a/modules/node-cli/include/dap_chain_node_cli_cmd.h +++ b/modules/node-cli/include/dap_chain_node_cli_cmd.h @@ -152,6 +152,7 @@ typedef enum s_com_tx_wallet_err{ DAP_CHAIN_NODE_CLI_COM_TX_WALLET_ACTIVE_ERR, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_CONVERT_ERR, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_BACKUP_ERR, + DAP_CHAIN_NODE_CLI_COM_TX_WALLET_DEACT_ERR, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_UNKNOWN_SIGN_ERR, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_PROTECTION_ERR, DAP_CHAIN_NODE_CLI_COM_TX_WALLET_HASH_ERR, -- GitLab From e0bdbb23572e5a330bf511d3ab2c4aaaf0aaee72 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Wed, 4 Dec 2024 20:12:31 +0700 Subject: [PATCH 03/18] ... --- modules/chain/dap_chain.c | 4 +- modules/datum/dap_chain_datum_tx.c | 6 +- modules/node-cli/dap_chain_node_cli_cmd_tx.c | 72 +++++++++++++------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/modules/chain/dap_chain.c b/modules/chain/dap_chain.c index a4d6e53543..83c94b8113 100644 --- a/modules/chain/dap_chain.c +++ b/modules/chain/dap_chain.c @@ -912,9 +912,7 @@ void dap_chain_datum_notify(dap_chain_cell_t *a_chain_cell, dap_hash_fast_t *a_ .callback = l_notifier->callback, .callback_arg = l_notifier->arg, .chain = a_chain_cell->chain, .cell_id = a_chain_cell->id, .hash = *a_hash, - .atom_hash = *a_atom_hash, - .datum = a_chain_cell->chain->is_mapped ? (byte_t *)a_datum - : DAP_DUP_SIZE((byte_t *)a_datum, a_datum_size), + .datum = a_chain_cell->chain->is_mapped ? (byte_t*)a_datum : DAP_DUP_SIZE((byte_t*)a_datum, a_datum_size), .datum_size = a_datum_size, .ret_code = a_ret_code, .action = a_action, diff --git a/modules/datum/dap_chain_datum_tx.c b/modules/datum/dap_chain_datum_tx.c index ea2410e571..be2e159c1d 100644 --- a/modules/datum/dap_chain_datum_tx.c +++ b/modules/datum/dap_chain_datum_tx.c @@ -363,8 +363,10 @@ dap_chain_tx_out_cond_t *dap_chain_datum_tx_out_cond_get(dap_chain_datum_tx_t *a TX_ITEM_ITER_TX(l_item, l_tx_item_size, a_tx) { switch (*l_item) { case TX_ITEM_TYPE_OUT_COND: - if ( l_idx >= 0 && ((dap_chain_tx_out_cond_t*)l_item)->header.subtype == a_cond_subtype ) - return (a_out_num ? (*a_out_num = l_idx) : 0), (dap_chain_tx_out_cond_t*)l_item; + if ( l_idx >= 0 && ((dap_chain_tx_out_cond_t*)l_item)->header.subtype == a_cond_subtype ) { + if (a_out_num) *a_out_num += l_idx; + return (dap_chain_tx_out_cond_t*)l_item; + } case TX_ITEM_TYPE_OUT: case TX_ITEM_TYPE_OUT_OLD: case TX_ITEM_TYPE_OUT_EXT: ++l_idx; default: diff --git a/modules/node-cli/dap_chain_node_cli_cmd_tx.c b/modules/node-cli/dap_chain_node_cli_cmd_tx.c index 32abe86479..a9e5be8950 100644 --- a/modules/node-cli/dap_chain_node_cli_cmd_tx.c +++ b/modules/node-cli/dap_chain_node_cli_cmd_tx.c @@ -118,7 +118,6 @@ bool s_dap_chain_datum_tx_out_data(json_object* a_json_arr_reply, json_object_array_add(json_arr_items, l_json_obj_datum); l_spent = true; } - break; } json_object_object_add(json_obj_out, "Spent OUTs", json_arr_items); json_object_object_add(json_obj_out, "all OUTs yet unspent", l_spent ? json_object_new_string("no") : json_object_new_string("yes")); @@ -2108,14 +2107,39 @@ int s_json_rpc_tx_parse_json(dap_chain_net_t *a_net, dap_chain_t *a_chain, json_ dap_chain_wallet_t *l_wallet = s_json_get_wallet(l_json_item_obj, "wallet"); const dap_cert_t *l_cert = s_json_get_cert(l_json_item_obj, "cert"); + const char *l_sign_type_str = s_json_get_text(l_json_item_obj, "sig_type"); + int64_t l_pkey_size, l_sig_size; + uint8_t *l_pkey = NULL; + dap_sign_t *l_sign = NULL; + dap_enc_key_type_t l_type = dap_enc_key_type_find_by_name(l_sign_type_str); + dap_enc_key_t * l_ret = dap_enc_key_new(l_type); + //wallet goes first - if (l_wallet) { + if (l_wallet) l_enc_key = dap_chain_wallet_get_key(l_wallet, 0); - - } else if (l_cert && l_cert->enc_key) { + else if (l_cert && l_cert->enc_key) l_enc_key = l_cert->enc_key; - } - else{ + else if (l_sign_type_str) { + + s_json_get_int64(l_json_item_obj, "pub_key_size", &l_pkey_size); + s_json_get_int64(l_json_item_obj, "sig_size", &l_sig_size); + + json_object *l_jobj_sign = json_object_object_get(l_json_item_obj, "sig_b64"); + const char *l_sign_str = json_object_get_string(l_jobj_sign); + dap_sign_t *l_sign = DAP_NEW_Z_SIZE(dap_sign_t, DAP_ENC_BASE64_DECODE_SIZE(dap_strlen(l_sign_str))); + size_t l_sign_decree_size = dap_enc_base64_decode(l_sign_str, dap_strlen(l_sign_str), l_sign, DAP_ENC_DATA_TYPE_B64); + + json_object *l_jobj_pub_key = json_object_object_get(l_json_item_obj, "pub_key_b64"); + const char *l_pub_key_str = json_object_get_string(l_jobj_pub_key); + + size_t l_proc_buf_size = 0; + char *l_proc_buf = DAP_NEW_SIZE(char, DAP_ENC_BASE64_DECODE_SIZE(l_pkey_size)); + l_proc_buf_size = dap_enc_base64_decode(l_pub_key_str, l_pkey_size, l_proc_buf, DAP_ENC_DATA_TYPE_B64); + if (dap_enc_key_deserialize_pub_key(l_ret, l_proc_buf, l_pkey_size)) { + log_it(L_ERROR, "Error in enc pub key deserialize"); + DAP_DEL_Z(l_ret); + } + } else{ json_object *l_jobj_err = json_object_new_string("Can't create sign for transactions."); json_object_array_add(l_jobj_errors, l_jobj_err); log_it(L_ERROR, "Json TX: Item sign has no wallet or cert of they are invalid "); @@ -2130,6 +2154,17 @@ int s_json_rpc_tx_parse_json(dap_chain_net_t *a_net, dap_chain_t *a_chain, json_ l_list = dap_list_next(l_list); continue; } + if (l_sign) { + size_t l_chain_sign_size = dap_sign_get_size(l_sign); // sign data + + dap_chain_tx_sig_t *l_tx_sig = DAP_NEW_Z_SIZE(dap_chain_tx_sig_t, + sizeof(dap_chain_tx_sig_t) + l_chain_sign_size); + l_tx_sig->header.type = TX_ITEM_TYPE_SIG; + l_tx_sig->header.sig_size =(uint32_t) l_chain_sign_size; + memcpy(l_tx_sig->sig, l_sign, l_chain_sign_size); + dap_chain_datum_tx_add_item(&l_tx, l_tx_sig); + DAP_DELETE(l_sign); + } if (l_wallet) { dap_chain_wallet_close(l_wallet); @@ -2620,9 +2655,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) for (size_t i = 0; i < l_addr_el_count; ++i) { l_addr_to[i] = dap_chain_addr_from_str(l_addr_base58_to_array[i]); if(!l_addr_to[i]) { - for (size_t j = 0; j < i; ++j) { - DAP_DELETE(l_addr_to[j]); - } + DAP_DEL_ARRAY(l_addr_to, i); DAP_DEL_MULTY(l_addr_to, l_addr_base58_to_array, l_value); dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_DESTINATION_ADDRESS_INVALID, "destination address is invalid"); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_DESTINATION_ADDRESS_INVALID; @@ -2659,9 +2692,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) l_ret = DAP_CHAIN_NODE_CLI_COM_TX_CREATE_CAN_NOT_ADD_DATUM_IN_MEMPOOL; } json_object_array_add(*a_json_arr_reply, l_jobj_emission); - for (size_t i = 0; i < l_addr_el_count; ++i) { - DAP_DELETE(l_addr_to[i]); - } + DAP_DEL_ARRAY(l_addr_to, l_addr_el_count); DAP_DEL_MULTY(l_addr_to, l_value); if (l_wallet_fee) { dap_chain_wallet_close(l_wallet_fee); @@ -2676,9 +2707,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) if(!l_wallet) { dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_WALLET_DOES_NOT_EXIST, "wallet %s does not exist", l_from_wallet_name); - for (size_t i = 0; i < l_addr_el_count; ++i) { - DAP_DELETE(l_addr_to[i]); - } + DAP_DEL_ARRAY(l_addr_to, l_addr_el_count); DAP_DEL_MULTY(l_addr_to, l_value); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_WALLET_DOES_NOT_EXIST; } else { @@ -2695,9 +2724,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) dap_enc_key_delete(l_priv_key); dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_TX_CREATE_SOURCE_ADDRESS_INVALID, "source address is invalid"); json_object_put(l_jobj_result); - for (size_t i = 0; i < l_addr_el_count; ++i) { - DAP_DELETE(l_addr_to[i]); - } + DAP_DEL_ARRAY(l_addr_to, l_addr_el_count); DAP_DEL_MULTY(l_addr_to, l_value); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_SOURCE_ADDRESS_INVALID; } @@ -2738,9 +2765,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) dap_string_free(l_allowed_list, true); json_object_put(l_jobj_result); - for (size_t j = 0; j < l_addr_el_count; ++j) { - DAP_DELETE(l_addr_to[j]); - } + DAP_DEL_ARRAY(l_addr_to, l_addr_el_count); DAP_DEL_MULTY(l_addr_to, l_value); return DAP_CHAIN_NODE_CLI_COM_TX_CREATE_DESTINATION_NETWORK_IS_UNREACHEBLE; } @@ -2773,10 +2798,7 @@ int com_tx_create(int a_argc, char **a_argv, void **a_json_arr_reply) } json_object_array_add(*a_json_arr_reply, l_jobj_result); - - for (size_t i = 0; i < l_addr_el_count; ++i) { - DAP_DELETE(l_addr_to[i]); - } + DAP_DEL_ARRAY(l_addr_to, l_addr_el_count); DAP_DEL_MULTY(l_addr_from, l_addr_to, l_value); dap_chain_wallet_close(l_wallet); dap_enc_key_delete(l_priv_key); -- GitLab From 24e1e7987c88e83829e1b7efd8bff76597b39271 Mon Sep 17 00:00:00 2001 From: Constantin P <papizh.konstantin@demlabs.net> Date: Mon, 9 Dec 2024 18:33:51 +0700 Subject: [PATCH 04/18] Voting dumps port --- .../service/voting/dap_chain_net_srv_voting.c | 114 ++++++++---------- 1 file changed, 47 insertions(+), 67 deletions(-) diff --git a/modules/service/voting/dap_chain_net_srv_voting.c b/modules/service/voting/dap_chain_net_srv_voting.c index cfce14f4ac..2e2e770539 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -849,9 +849,10 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) struct voting *votings_ht = s_votings_ht_get(l_net->pub.id); for (struct voting *it = votings_ht; it; it = it->hh.next) { json_object* json_obj_vote = json_object_new_object(); - json_object_object_add(json_obj_vote, "Voting hash", - json_object_new_string(dap_chain_hash_fast_to_str_static(&it->hash))); - json_object_object_add(json_obj_vote, "Voting question", json_object_new_string((char *)it->params->question)); + json_object_object_add( json_obj_vote, "voting_tx", + json_object_new_string_len(dap_chain_hash_fast_to_str_static(&it->hash), sizeof(dap_hash_str_t)) ); + json_object_object_add( json_obj_vote, "question", + json_object_new_string(it->params->question) ); json_object_array_add(json_arr_voting_out, json_obj_vote); } json_object_array_add(*json_arr_reply, json_arr_voting_out); @@ -859,7 +860,6 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) case CMD_DUMP: { const char* l_hash_str = NULL; - dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-hash", &l_hash_str); if(!l_hash_str){ dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_VOTE_DUMP_HASH_PARAM_NOT_FOUND, "Command 'results' require the parameter -hash"); @@ -885,93 +885,73 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) return -DAP_CHAIN_NET_VOTE_DUMP_NO_OPTIONS; } - struct voting_results {uint64_t num_of_votes; uint256_t weights;}; + struct voting_results { + uint256_t weights; uint64_t num_of_votes; + } l_results[l_options_count]; + memset(l_results, 0, sizeof(l_results)); - struct voting_results* l_results = DAP_NEW_Z_SIZE(struct voting_results, sizeof(struct voting_results)*l_options_count); - if(!l_results){ - dap_json_rpc_error_add(*json_arr_reply, DAP_CHAIN_NET_VOTE_DUMP_MEMORY_ERR, "Memory allocation error!"); - return -DAP_CHAIN_NET_VOTE_DUMP_MEMORY_ERR; - } - dap_list_t* l_list_tmp = l_voting->votes; - uint256_t l_total_weight = {}; - while(l_list_tmp){ - struct vote *l_vote = l_list_tmp->data; - l_results[l_vote->answer_idx].num_of_votes++; + uint256_t l_total_weight = { }; + int l_votes_count = 0, i = 0; + for (dap_list_t *l_vote_item = l_voting->votes; l_vote_item; l_vote_item = l_vote_item->next, ++l_votes_count) { + struct vote *l_vote = l_vote_item->data; + ++l_results[l_vote->answer_idx].num_of_votes; SUM_256_256(l_results[l_vote->answer_idx].weights, l_vote->weight, &l_results[l_vote->answer_idx].weights); - l_list_tmp = l_list_tmp->next; SUM_256_256(l_total_weight, l_vote->weight, &l_total_weight); } - uint64_t l_votes_count = 0; - l_votes_count = dap_list_length(l_voting->votes); json_object* json_vote_out = json_object_new_object(); - json_object_object_add(json_vote_out, "hash of voting", - json_object_new_string(l_hash_str)); - json_object_object_add(json_vote_out, "Voting dump", json_object_new_string((char *)l_voting->params->question)); - + json_object_object_add(json_vote_out, "voting_tx", json_object_new_string_len(l_hash_str, sizeof(dap_hash_str_t))); + json_object_object_add(json_vote_out, "question", json_object_new_string(l_voting->params->question)); if (l_voting->params->voting_expire) { char l_tmp_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_voting->params->voting_expire); - json_object_object_add(json_vote_out, "Voting expire", + json_object_object_add(json_vote_out, "expiration", json_object_new_string(l_tmp_buf)); - //dap_string_truncate(l_str_out, l_str_out->len - 1); - json_object_object_add(json_vote_out, "status", - l_voting->params->voting_expire > dap_time_now() ? - json_object_new_string("active") : - json_object_new_string("expired")); + json_object_object_add(json_vote_out, "status", + json_object_new_string( l_voting->params->voting_expire >= dap_time_now() ? "active" : "expired" )); } if (l_voting->params->votes_max_count){ - char *l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U" (%s)", l_voting->params->votes_max_count, - l_voting->params->votes_max_count <= l_votes_count ? "closed" : "active"); - json_object_object_add(json_vote_out, "Votes max count", json_object_new_string(l_val)); - DAP_DELETE(l_val); + json_object_object_add(json_vote_out, "votes_max", + json_object_new_uint64( l_voting->params->votes_max_count )); + json_object_object_add( json_vote_out, "votes_available", + json_object_new_uint64( l_voting->params->votes_max_count - l_votes_count )); } - json_object_object_add(json_vote_out, "changing vote status", l_voting->params->vote_changing_allowed ? - json_object_new_string("available") : - json_object_new_string("not available")); - json_object_object_add(json_vote_out, "delegated voting key status", l_voting->params->delegate_key_required ? - json_object_new_string("is required") : - json_object_new_string("not required")); + json_object_object_add(json_vote_out, "can_change_status", + json_object_new_boolean(l_voting->params->vote_changing_allowed)); + json_object_object_add(json_vote_out, "delegated_key_required", + json_object_new_boolean(l_voting->params->delegate_key_required)); json_object* json_arr_vote_out = json_object_new_array(); - for (uint64_t i = 0; i < dap_list_length(l_voting->params->options); i++){ + + for (dap_list_t *l_option = l_voting->params->options; l_option; l_option = l_option->next, ++i) { json_object* json_vote_obj = json_object_new_object(); - char *l_val = NULL; - l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U")", i); - json_object_object_add(json_vote_obj, "#", json_object_new_string(l_val)); - DAP_DELETE(l_val); - dap_list_t* l_option = dap_list_nth(l_voting->params->options, (uint64_t)i); - json_object_object_add(json_vote_obj, "voting tx", json_object_new_string(l_option->data)); - float l_percentage = l_votes_count ? ((float)l_results[i].num_of_votes/l_votes_count)*100 : 0; - uint256_t l_weight_percentage = {}; + json_object_object_add(json_vote_obj, "option_id", json_object_new_int(i)); + json_object_object_add( json_vote_obj, "vote_tx", json_object_new_string(l_option->data) ); + json_object_object_add(json_vote_obj, "voting_power", json_object_new_uint64( l_results[i].num_of_votes) ); + int l_percentage = l_votes_count ? (int)((float)l_results[i].num_of_votes/l_votes_count * 100 + 0.5) : 0; + json_object_object_add(json_vote_obj, "vote_share", json_object_new_int(l_percentage) ); + uint256_t l_weight_percentage = { }; DIV_256_COIN(l_results[i].weights, l_total_weight, &l_weight_percentage); MULT_256_COIN(l_weight_percentage, dap_chain_balance_coins_scan("100.0"), &l_weight_percentage); - const char *l_weight_percentage_str = dap_uint256_decimal_to_round_char(l_weight_percentage, 2, true); - const char *l_w_coins, *l_w_datoshi = dap_uint256_to_char(l_results[i].weights, &l_w_coins); - l_val = dap_strdup_printf("Votes: %"DAP_UINT64_FORMAT_U" (%.2f%%) Weight: %s (%s) %s (%s%%)", - l_results[i].num_of_votes, l_percentage, l_w_coins, l_w_datoshi, l_net->pub.native_ticker, l_weight_percentage_str); - json_object_object_add(json_vote_obj, "price", json_object_new_string(l_val)); - DAP_DELETE(l_val); + const char *l_weight_percentage_str = dap_uint256_decimal_to_round_char(l_weight_percentage, 2, true), + *l_w_coins, *l_w_datoshi = dap_uint256_to_char(l_results[i].weights, &l_w_coins); + json_object_object_add(json_vote_obj, "vote_sum", json_object_new_string(l_w_coins)); + json_object_object_add(json_vote_obj, "vote_sum_datoshi", json_object_new_string(l_w_datoshi)); + json_object_object_add(json_vote_obj, "vote_sum_weight", json_object_new_string(l_weight_percentage_str)); json_object_array_add(json_arr_vote_out, json_vote_obj); } - json_object_object_add(json_vote_out, "Results", json_arr_vote_out); - DAP_DELETE(l_results); - char *l_val = NULL; - l_val = dap_strdup_printf("%"DAP_UINT64_FORMAT_U, l_votes_count); - json_object_object_add(json_vote_out, "Total number of votes", json_object_new_string(l_val)); - DAP_DELETE(l_val); + json_object_object_add(json_vote_out, "results", json_arr_vote_out); + json_object_object_add(json_vote_out, "votes_count", json_object_new_uint64(l_votes_count)); const char *l_tw_coins, *l_tw_datoshi = dap_uint256_to_char(l_total_weight, &l_tw_coins); - l_val = dap_strdup_printf("%s (%s) %s", l_tw_coins, l_tw_datoshi, l_net->pub.native_ticker); - json_object_object_add(json_vote_out, "Total weight", json_object_new_string(l_val)); - DAP_DELETE(l_val); + json_object_object_add(json_vote_out, "total_sum", json_object_new_string(l_tw_coins)); + json_object_object_add(json_vote_out, "total_sum_datoshi", json_object_new_string(l_tw_datoshi)); + json_object_object_add(json_vote_out, "ticker", json_object_new_string(l_net->pub.native_ticker)); json_object_array_add(*json_arr_reply, json_vote_out); - }break; - default:{ - - }break; + } break; + default: + break; } - return 0; } -- GitLab From c991c7df678061c5aaeb21bb806d8b990cf1cd01 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 18:38:01 +0700 Subject: [PATCH 05/18] 14511 port --- modules/type/blocks/dap_chain_cs_blocks.c | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index b98acbf16d..0e6d92bd0f 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -561,20 +561,23 @@ static void s_print_autocollect_table(dap_chain_net_t *a_net, json_object *a_jso DAP_DEL_MULTY(l_key, l_val); } - - -static int block_list_sort_by_date(const void *a, const void *b) +static int block_list_sort_by_date(const void *a, const void *b, bool a_forward) { - struct json_object *obj_a = *(struct json_object **)a; - struct json_object *obj_b = *(struct json_object **)b; + struct json_object *obj_a = (struct json_object*)a, + *obj_b = (struct json_object*)b; - struct json_object *timestamp_a = json_object_object_get(obj_a, "timestamp"); - struct json_object *timestamp_b = json_object_object_get(obj_b, "timestamp"); + struct json_object *timestamp_a = json_object_object_get(obj_a, "timestamp"), + *timestamp_b = json_object_object_get(obj_b, "timestamp"); + int l_fwd = a_forward ? 1 : -1; + return timestamp_a > timestamp_b ? a_forward : timestamp_a < timestamp_b ? -a_forward : 0; +} - int64_t time_a = json_object_get_int64(timestamp_a); - int64_t time_b = json_object_get_int64(timestamp_b); +static int blocks_sort_fwd(const void *a, const void *b) { + return block_list_sort_by_date(a, b, true); +} - return time_a - time_b; +static int blocks_sort_rev(const void *a, const void *b) { + return block_list_sort_by_date(a, b, false); } /** @@ -1019,9 +1022,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) } i_tmp++; char l_buf[DAP_TIME_STR_SIZE]; - json_object* json_obj_bl_cache = json_object_new_object(); dap_time_to_str_rfc822(l_buf, DAP_TIME_STR_SIZE, l_ts); - json_object_object_add(json_obj_bl_cache, "#",json_object_new_uint64(i_tmp)); + json_object* json_obj_bl_cache = json_object_new_object(); json_object_object_add(json_obj_bl_cache, "block number",json_object_new_uint64(l_block_cache->block_number)); json_object_object_add(json_obj_bl_cache, "hash",json_object_new_string(l_block_cache->block_hash_str)); json_object_object_add(json_obj_bl_cache, "timestamp", json_object_new_uint64(l_ts)); @@ -1032,7 +1034,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **a_str_reply) } pthread_rwlock_unlock(&PVT(l_blocks)->rwlock); //sort by time - json_object_array_sort(json_arr_bl_cache_out, block_list_sort_by_date); + json_object_array_sort(json_arr_bl_cache_out, l_head ? blocks_sort_fwd : blocks_sort_rev); // Remove the timestamp and change block num size_t l_length = json_object_array_length(json_arr_bl_cache_out); for (size_t i = 0; i < l_length; i++) { -- GitLab From c72ba5c1551be95843995a428b89ab9f33e7b04b Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 18:44:26 +0700 Subject: [PATCH 06/18] 14607 port --- modules/chain/dap_chain_cell.c | 12 +++++++++++- modules/wallet/dap_chain_wallet.c | 5 ++--- modules/wallet/include/dap_chain_wallet_internal.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/chain/dap_chain_cell.c b/modules/chain/dap_chain_cell.c index 86f8a43330..40d8deefa3 100644 --- a/modules/chain/dap_chain_cell.c +++ b/modules/chain/dap_chain_cell.c @@ -510,7 +510,17 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) if ( l_pos < l_full_size ) { log_it(L_ERROR, "Chain \"%s\" has incomplete tail, truncating %zu bytes", a_cell->file_storage_path, l_full_size - l_pos ); - ftruncate(fileno(a_cell->file_storage), l_pos); +#ifdef DAP_OS_WINDOWS + if (a_cell->chain->is_mapped) { + LARGE_INTEGER SectionSize = (LARGE_INTEGER) { .QuadPart = l_pos }; + HANDLE hSection = (HANDLE)a_cell->map_range_bounds->data; + NTSTATUS err = pfnNtExtendSection(hSection, &SectionSize); + if ( !NT_SUCCESS(err) ) { + log_it(L_ERROR, "NtExtendSection() failed, status %lx", err); + } + } else +#endif + ftruncate(fileno(a_cell->file_storage), l_pos); } fseeko(a_cell->file_storage, l_pos, SEEK_SET); log_it(L_INFO, "Loaded %lu atoms in cell %s", q, a_cell->file_storage_path); diff --git a/modules/wallet/dap_chain_wallet.c b/modules/wallet/dap_chain_wallet.c index 38edb47b0d..76b4c24f88 100644 --- a/modules/wallet/dap_chain_wallet.c +++ b/modules/wallet/dap_chain_wallet.c @@ -57,7 +57,6 @@ #include "dap_chain_wallet.h" #include "dap_chain_wallet_internal.h" #include "dap_chain_wallet_cache.h" -#include "dap_enc_key.h" #include "crc32c_adler.h" #include "dap_chain_ledger.h" #include "dap_strfuncs.h" @@ -642,7 +641,7 @@ if ( a_pass ) return log_it(L_ERROR, "Error create key context"), -EINVAL; #ifdef DAP_OS_WINDOWS - l_fh = CreateFile(l_wallet_internal->file_name, GENERIC_WRITE, /*FILE_SHARE_READ | FILE_SHARE_WRITE */ 0, NULL, CREATE_ALWAYS, + l_fh = CreateFile(l_wallet_internal->file_name, GENERIC_WRITE, FILE_SHARE_READ /* | FILE_SHARE_WRITE */, NULL, CREATE_ALWAYS, /*FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING*/ 0, NULL); if (l_fh != INVALID_HANDLE_VALUE) { SetEndOfFile(l_fh); @@ -785,7 +784,7 @@ uint32_t l_csum = CRC32C_INIT, l_csum2 = CRC32C_INIT; #ifdef DAP_OS_WINDOWS DWORD l_rc = 0; - if ((l_fh = CreateFile(a_file_name, GENERIC_READ, 0, 0, + if ((l_fh = CreateFile(a_file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 0)) == INVALID_HANDLE_VALUE) { l_err = GetLastError(); diff --git a/modules/wallet/include/dap_chain_wallet_internal.h b/modules/wallet/include/dap_chain_wallet_internal.h index 66d9782a55..f11d1bc16c 100644 --- a/modules/wallet/include/dap_chain_wallet_internal.h +++ b/modules/wallet/include/dap_chain_wallet_internal.h @@ -29,7 +29,7 @@ #include "dap_chain_common.h" #include "dap_chain_wallet.h" -#define DAP_CHAIN_WALLETS_FILE_SIGNATURE 0x1a167bef15feea18 +#define DAP_CHAIN_WALLETS_FILE_SIGNATURE (uint64_t)0x1a167bef15feea18 enum { -- GitLab From 40475caae04542eed50f978f7ac510edbc60102c Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 19:33:42 +0700 Subject: [PATCH 07/18] 14555 port --- modules/wallet/dap_chain_wallet_cache.c | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/modules/wallet/dap_chain_wallet_cache.c b/modules/wallet/dap_chain_wallet_cache.c index 6f69cba636..2ca1d07c95 100644 --- a/modules/wallet/dap_chain_wallet_cache.c +++ b/modules/wallet/dap_chain_wallet_cache.c @@ -95,7 +95,7 @@ typedef struct dap_atom_notify_arg { static dap_s_wallets_cache_type_t s_wallets_cache_type = DAP_WALLET_CACHE_TYPE_LOCAL; static dap_wallet_cache_t *s_wallets_cache = NULL; -static pthread_rwlock_t s_wallet_cache_rwlock; +static pthread_rwlock_t s_wallet_cache_rwlock = PTHREAD_RWLOCK_INITIALIZER; static int s_save_tx_into_wallet_cache(dap_chain_t *a_chain, dap_chain_datum_tx_t *a_tx, dap_hash_fast_t *a_tx_hash, dap_hash_fast_t *a_atom_hash, int a_ret_code, char* a_main_token_ticker, dap_chain_srv_uid_t a_srv_uid, dap_chain_tx_tag_action_type_t a_action); @@ -126,26 +126,20 @@ int dap_chain_wallet_cache_init() { const char *l_walet_cache_type_str = dap_config_get_item_str(g_config, "wallets", "wallets_cache"); if (l_walet_cache_type_str){ - if (!dap_strcmp(l_walet_cache_type_str, "disable")){ + if (!dap_strcmp(l_walet_cache_type_str, "disable")) { s_wallets_cache_type = DAP_WALLET_CACHE_TYPE_DISABLED; + return log_it(L_WARNING, "Wallet cache is disabled"), 0; } else if (!dap_strcmp(l_walet_cache_type_str, "local")){ s_wallets_cache_type = DAP_WALLET_CACHE_TYPE_LOCAL; } else if (!dap_strcmp(l_walet_cache_type_str, "all")){ s_wallets_cache_type = DAP_WALLET_CACHE_TYPE_ALL; } else { - log_it( L_WARNING, "Unknown cache type in config. Remain default: %s", s_wallet_cache_type_to_str(s_wallets_cache_type)); + log_it( L_WARNING, "Unknown cache type in config. Remains default: %s", s_wallet_cache_type_to_str(s_wallets_cache_type)); } } - if (s_wallets_cache_type == DAP_WALLET_CACHE_TYPE_DISABLED){ - log_it( L_WARNING, "Wallet cache is disabled."); - return 0; - } - log_it(L_INFO, "Wallet cache type: %s", s_wallet_cache_type_to_str(s_wallets_cache_type)); - pthread_rwlock_init(&s_wallet_cache_rwlock, NULL); - // Add notify callback for all chain with transactions in all nets for(dap_chain_net_t *l_net = dap_chain_net_iter_start(); l_net; l_net=dap_chain_net_iter_next(l_net)){ // Find chain with transactions @@ -156,14 +150,14 @@ int dap_chain_wallet_cache_init() dap_atom_notify_arg_t *l_arg = DAP_NEW_Z(dap_atom_notify_arg_t); l_arg->chain = l_chain; l_arg->net = l_net; - dap_chain_datum_iter_t *l_iter = l_chain->callback_datum_iter_create(l_chain); + /* dap_chain_datum_iter_t *l_iter = l_chain->callback_datum_iter_create(l_chain); for (dap_chain_datum_t *l_datum = l_chain->callback_datum_iter_get_first(l_iter); l_datum; l_datum = l_chain->callback_datum_iter_get_next(l_iter)){ s_callback_datum_notify(l_arg, l_iter->cur_hash, l_iter->cur_atom_hash, l_datum, l_iter->cur_size, l_iter->ret_code, l_iter->action, l_iter->uid); } - l_chain->callback_datum_iter_delete(l_iter); + l_chain->callback_datum_iter_delete(l_iter); */ dap_chain_add_callback_datum_index_notify(l_chain, s_callback_datum_notify, NULL, l_arg); dap_chain_add_callback_datum_removed_from_index_notify(l_chain, s_callback_datum_removed_notify, NULL, l_arg); } @@ -183,9 +177,9 @@ int dap_chain_wallet_cache_init() HASH_FIND(hh, s_wallets_cache, l_addr, sizeof(dap_chain_addr_t), l_wallet_item); if (!l_wallet_item){ l_wallet_item = DAP_NEW_Z(dap_wallet_cache_t); - memcpy (&l_wallet_item->wallet_addr, l_addr, sizeof(dap_chain_addr_t)); + l_wallet_item->wallet_addr = *l_addr; HASH_ADD(hh, s_wallets_cache, wallet_addr, sizeof(dap_chain_addr_t), l_wallet_item); - log_it(L_ERROR, "Wallet %s saved.", dap_chain_addr_to_str_static(l_addr)); + log_it(L_DEBUG, "Wallet %s cached", dap_chain_addr_to_str_static(l_addr)); } } pthread_rwlock_unlock(&s_wallet_cache_rwlock); @@ -205,6 +199,8 @@ int dap_chain_wallet_cache_deinit() int dap_chain_wallet_cache_tx_find(dap_chain_addr_t *a_addr, char *a_token, dap_chain_datum_tx_t **a_datum, dap_hash_fast_t *a_tx_hash_curr, int* a_ret_code) { + if ( s_wallets_cache_type == DAP_WALLET_CACHE_TYPE_DISABLED ) + return -101; dap_wallet_cache_t *l_wallet_item = NULL; pthread_rwlock_rdlock(&s_wallet_cache_rwlock); HASH_FIND(hh, s_wallets_cache, a_addr, sizeof(dap_chain_addr_t), l_wallet_item); @@ -285,6 +281,8 @@ int dap_chain_wallet_cache_tx_find(dap_chain_addr_t *a_addr, char *a_token, dap_ int dap_chain_wallet_cache_tx_find_in_history(dap_chain_addr_t *a_addr, char **a_token, int* a_ret_code, dap_chain_tx_tag_action_type_t *a_action, dap_chain_srv_uid_t *a_uid, dap_chain_datum_tx_t **a_datum, dap_hash_fast_t *a_tx_hash_curr) { + if ( s_wallets_cache_type == DAP_WALLET_CACHE_TYPE_DISABLED ) + return -101; dap_wallet_cache_t *l_wallet_item = NULL; if (!a_tx_hash_curr) @@ -349,7 +347,8 @@ int dap_chain_wallet_cache_tx_find_in_history(dap_chain_addr_t *a_addr, char **a int dap_chain_wallet_cache_tx_find_outs_with_val(dap_chain_net_t *a_net, const char *a_token_ticker, const dap_chain_addr_t *a_addr, dap_list_t **a_outs_list, uint256_t a_value_need, uint256_t *a_value_transfer) { - + if ( s_wallets_cache_type == DAP_WALLET_CACHE_TYPE_DISABLED ) + return -101; dap_list_t *l_list_used_out = NULL; // list of transaction with 'out' items uint256_t l_value_transfer = { }; dap_chain_datum_tx_t *l_tx; -- GitLab From a319d059e2d2b3c5189925ea3568dcc389ffa21e Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Sat, 28 Dec 2024 22:12:06 +0700 Subject: [PATCH 08/18] Various fixes port --- modules/chain/dap_chain_cell.c | 8 ++-- .../consensus/dag-poa/dap_chain_cs_dag_poa.c | 14 ++++-- .../consensus/esbocs/dap_chain_cs_esbocs.c | 19 +++++--- modules/datum/dap_chain_datum_tx.c | 48 ++++++++++++------- modules/ledger/dap_chain_ledger_anchor.c | 17 ++++--- modules/ledger/dap_chain_ledger_decree.c | 23 ++++----- modules/type/blocks/dap_chain_cs_blocks.c | 6 +-- 7 files changed, 80 insertions(+), 55 deletions(-) diff --git a/modules/chain/dap_chain_cell.c b/modules/chain/dap_chain_cell.c index 40d8deefa3..1e9eb3e6ef 100644 --- a/modules/chain/dap_chain_cell.c +++ b/modules/chain/dap_chain_cell.c @@ -144,7 +144,7 @@ DAP_STATIC_INLINE int s_cell_map_new_volume(dap_chain_cell_t *a_cell, size_t a_f .QuadPart = l_ssize }; - NTSTATUS err = pfnNtCreateSection(&hSection, SECTION_MAP_READ|SECTION_EXTEND_SIZE|SECTION_MAP_WRITE, + NTSTATUS err = pfnNtCreateSection(&hSection, SECTION_MAP_READ | SECTION_EXTEND_SIZE, NULL, &SectionSize, PAGE_READWRITE, SEC_RESERVE, (HANDLE)_get_osfhandle(fileno(a_cell->file_storage))); if ( !NT_SUCCESS(err) ) return log_it(L_ERROR, "NtCreateSection() failed, status %lx", err), -1; @@ -166,13 +166,13 @@ DAP_STATIC_INLINE int s_cell_map_new_volume(dap_chain_cell_t *a_cell, size_t a_f .QuadPart = l_volume_start }; err = pfnNtMapViewOfSection(hSection, GetCurrentProcess(), (HANDLE)&a_cell->map, 0, 0, - &Offset, &l_map_size, ViewUnmap, MEM_RESERVE, PAGE_WRITECOPY); + &Offset, &l_map_size, ViewUnmap, MEM_RESERVE, PAGE_READONLY); if ( !NT_SUCCESS(err) ) return NtClose(hSection), log_it(L_ERROR, "NtMapViewOfSection() failed, status %lx", err), -1; #else if (a_load) s_cell_reclaim_cur_volume(a_cell); - if (( a_cell->map = mmap(NULL, l_map_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, + if (( a_cell->map = mmap(NULL, l_map_size, PROT_READ, MAP_PRIVATE, fileno(a_cell->file_storage), l_volume_start) ) == MAP_FAILED ) return log_it(L_ERROR, "Chain cell \"%s\" 0x%016"DAP_UINT64_FORMAT_X" cannot be mapped, errno %d", a_cell->file_storage_path, a_cell->id.uint64, errno), -1; @@ -565,7 +565,7 @@ static int s_cell_file_atom_add(dap_chain_cell_t *a_cell, dap_chain_atom_ptr_t a #ifdef DAP_OS_DARWIN fflush(a_cell->file_storage); if (a_cell->chain->is_mapped) { - if ( MAP_FAILED == (a_cell->map = mmap(a_cell->map, dap_page_roundup(DAP_MAPPED_VOLUME_LIMIT), PROT_READ|PROT_WRITE, + if ( MAP_FAILED == (a_cell->map = mmap(a_cell->map, dap_page_roundup(DAP_MAPPED_VOLUME_LIMIT), PROT_READ, MAP_PRIVATE|MAP_FIXED, fileno(a_cell->file_storage), a_cell->cur_vol_start)) ) { log_it(L_ERROR, "Chain cell \"%s\" 0x%016"DAP_UINT64_FORMAT_X" cannot be remapped, errno %d", a_cell->file_storage_path, a_cell->id.uint64, errno); diff --git a/modules/consensus/dag-poa/dap_chain_cs_dag_poa.c b/modules/consensus/dag-poa/dap_chain_cs_dag_poa.c index 409a5ccf59..b17c6b480d 100644 --- a/modules/consensus/dag-poa/dap_chain_cs_dag_poa.c +++ b/modules/consensus/dag-poa/dap_chain_cs_dag_poa.c @@ -871,21 +871,27 @@ static int s_callback_event_verify(dap_chain_cs_dag_t *a_dag, dap_chain_cs_dag_e } uint16_t l_signs_verified_count = 0; if (l_signs_count >= l_certs_count_verify) { - uint16_t l_event_signs_count = a_event->header.signs_count; + dap_chain_cs_dag_event_t * l_event = a_dag->chain->is_mapped + ? DAP_DUP_SIZE(a_event, l_event_size) + : a_event; + uint16_t l_event_signs_count = l_event->header.signs_count; for (size_t i = 0; i < l_signs_count; i++) { dap_sign_t *l_sign = (dap_sign_t *)l_signs[i]; // Compare signature with auth_certs - a_event->header.signs_count = i; + l_event->header.signs_count = i; for (uint16_t j = 0; j < l_poa_pvt->auth_certs_count; j++) { if (!dap_cert_compare_with_sign( l_poa_pvt->auth_certs[j], l_sign) - && !dap_sign_verify(l_sign, a_event, l_offset_from_beginning)){ + && !dap_sign_verify(l_sign, l_event, l_offset_from_beginning)){ l_signs_verified_count++; break; } } } - a_event->header.signs_count = l_event_signs_count; DAP_DELETE(l_signs); + if (a_dag->chain->is_mapped) + DAP_DELETE(l_event); + else + a_event->header.signs_count = l_event_signs_count; if (l_signs_verified_count >= l_certs_count_verify) return 0; } diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index ed9be96ca9..15c98911d7 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -2866,7 +2866,10 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl bool l_block_is_emergency = s_block_is_emergency(a_block, l_block_size); // Get the header on signing operation time size_t l_block_original = a_block->hdr.meta_n_datum_n_signs_size; - a_block->hdr.meta_n_datum_n_signs_size = l_block_excl_sign_size - sizeof(a_block->hdr); + dap_chain_block_t *l_block = a_blocks->chain->is_mapped + ? DAP_DUP_SIZE(a_block, l_block_size) + : a_block; + l_block->hdr.meta_n_datum_n_signs_size = l_block_excl_sign_size - sizeof(l_block->hdr); for (size_t i = 0; i < l_signs_count; i++) { dap_sign_t *l_sign = l_signs[i]; dap_chain_addr_t l_signing_addr = { .net_id = a_blocks->chain->net_id }; @@ -2902,7 +2905,7 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl l_ret = -5; break; } else if (l_esbocs_pvt->check_signs_structure && - !s_check_signing_rights(l_esbocs, a_block, l_block_size, &l_signing_addr, true)) { + !s_check_signing_rights(l_esbocs, l_block, l_block_size, &l_signing_addr, true)) { if (l_esbocs_pvt->debug) { char l_block_hash_str[DAP_HASH_FAST_STR_SIZE]; dap_hash_fast_to_str(a_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE); @@ -2914,7 +2917,7 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl } else { if (l_block_is_emergency && !s_check_emergency_rights(l_esbocs, &l_signing_addr) && l_esbocs_pvt->check_signs_structure && - !s_check_signing_rights(l_esbocs, a_block, l_block_size, &l_signing_addr, false)) { + !s_check_signing_rights(l_esbocs, l_block, l_block_size, &l_signing_addr, false)) { if (l_esbocs_pvt->debug) { char l_block_hash_str[DAP_HASH_FAST_STR_SIZE]; dap_hash_fast_to_str(a_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE); @@ -2923,7 +2926,7 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl l_ret = -5; break; } else if (l_esbocs_pvt->check_signs_structure && - !s_check_signing_rights(l_esbocs, a_block, l_block_size, &l_signing_addr, false)) { + !s_check_signing_rights(l_esbocs, l_block, l_block_size, &l_signing_addr, false)) { if (l_esbocs_pvt->debug) { char l_block_hash_str[DAP_HASH_FAST_STR_SIZE]; dap_hash_fast_to_str(a_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE); @@ -2933,13 +2936,15 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl break; } } - if (!dap_sign_verify(l_sign, a_block, l_block_excl_sign_size)) + if (!dap_sign_verify(l_sign, l_block, l_block_excl_sign_size)) l_signs_verified_count++; } DAP_DELETE(l_signs); // Restore the original header - a_block->hdr.meta_n_datum_n_signs_size = l_block_original; - + if ( a_blocks->chain->is_mapped ) + DAP_DELETE(l_block); + else + l_block->hdr.meta_n_datum_n_signs_size = l_block_original; if (l_signs_verified_count < l_esbocs_pvt->min_validators_count) { debug_if(l_esbocs_pvt->debug, L_ERROR, "Corrupted block %s: not enough authorized signs: %u of %u", dap_hash_fast_to_str_static(a_block_hash), l_signs_verified_count, l_esbocs_pvt->min_validators_count); diff --git a/modules/datum/dap_chain_datum_tx.c b/modules/datum/dap_chain_datum_tx.c index be2e159c1d..96e28d1c25 100644 --- a/modules/datum/dap_chain_datum_tx.c +++ b/modules/datum/dap_chain_datum_tx.c @@ -239,26 +239,38 @@ int dap_chain_datum_tx_verify_sign(dap_chain_datum_tx_t *a_tx, int a_sign_num) { dap_return_val_if_pass(!a_tx, -1); int l_ret = -4, l_sign_num = 0; - byte_t *l_item; size_t l_item_size; + byte_t *l_item = NULL; size_t l_item_size; TX_ITEM_ITER_TX(l_item, l_item_size, a_tx) { - if (*l_item != TX_ITEM_TYPE_SIG) - continue; - if (l_sign_num++ != a_sign_num) - continue; - dap_chain_tx_sig_t *l_sign_item = (dap_chain_tx_sig_t *)l_item; - dap_sign_t *l_sign = dap_chain_datum_tx_item_sign_get_sig(l_sign_item); - byte_t *l_data_ptr = l_sign_item->header.version ? (byte_t *)a_tx : a_tx->tx_items; - const size_t l_data_size = (size_t)(l_item - l_data_ptr); - size_t l_tx_items_size = a_tx->header.tx_items_size; - if (l_sign_item->header.version) - a_tx->header.tx_items_size = 0; - l_ret = dap_sign_verify_all(l_sign, l_item_size, l_data_ptr, l_data_size); - a_tx->header.tx_items_size = l_tx_items_size; - if (l_ret < -1) - log_it(L_WARNING, "Incorrect signature header, possible corrupted data"); - break; + if ( *l_item == TX_ITEM_TYPE_SIG && l_sign_num++ == a_sign_num ) + break; + } + if (!l_item || !l_item_size) + return log_it(L_ERROR, "Sign not found in TX"), l_ret; + + dap_chain_tx_sig_t *l_sign_item = (dap_chain_tx_sig_t*)l_item; + dap_sign_t *l_sign = dap_chain_datum_tx_item_sign_get_sig(l_sign_item); + size_t l_tx_items_size = a_tx->header.tx_items_size, l_data_size; + dap_chain_datum_tx_t *l_tx; + byte_t *l_tx_data; + if ( l_sign_item->header.version ) { + l_data_size = (size_t)( l_item - (byte_t*)a_tx ); + l_tx = dap_config_get_item_bool_default(g_config, "ledger", "mapped", true) + ? DAP_DUP_SIZE(a_tx, dap_chain_datum_tx_get_size(a_tx)) : a_tx; + l_tx_data = (byte_t*)l_tx; + l_tx->header.tx_items_size = 0; + } else { + l_tx = a_tx; + l_tx_data = a_tx->tx_items; + l_data_size = (size_t)( l_item - l_tx_data ); + } + l_ret = dap_sign_verify_all(l_sign, l_item_size, l_tx_data, l_data_size); + if (l_sign_item->header.version) { + if ( dap_config_get_item_bool_default(g_config, "ledger", "mapped", true) ) + DAP_DELETE(l_tx); + else + a_tx->header.tx_items_size = l_tx_items_size; } - return l_ret; + return debug_if(l_ret, L_ERROR, "Sign verification error %d", l_ret), l_ret; } /** diff --git a/modules/ledger/dap_chain_ledger_anchor.c b/modules/ledger/dap_chain_ledger_anchor.c index 7887633a6e..e7fb5078f3 100644 --- a/modules/ledger/dap_chain_ledger_anchor.c +++ b/modules/ledger/dap_chain_ledger_anchor.c @@ -67,26 +67,31 @@ static int s_anchor_verify(dap_chain_net_t *a_net, dap_chain_datum_anchor_t *a_a return log_it(L_WARNING, "No unique signatures!"), -106; bool l_sign_authorized = false; size_t l_signs_size_original = a_anchor->header.signs_size; - a_anchor->header.signs_size = 0; + dap_chain_datum_anchor_t *l_anchor = a_net->pub.chains->is_mapped + ? DAP_DUP_SIZE(a_anchor, a_data_size) + : a_anchor; + l_anchor->header.signs_size = 0; dap_ledger_private_t *l_ledger_pvt = PVT(a_net->pub.ledger); for (size_t i = 0; i < l_num_of_unique_signs; i++) { for (dap_list_t *it = l_ledger_pvt->decree_owners_pkeys; it; it = it->next) { if (dap_pkey_compare_with_sign(it->data, l_unique_signs[i])) { // TODO make signs verification in s_concate_all_signs_in_array to correctly header.signs_size calculation - size_t l_verify_data_size = a_anchor->header.data_size + sizeof(dap_chain_datum_anchor_t); - if (dap_sign_verify_all(l_unique_signs[i], l_signs_size_original, a_anchor, l_verify_data_size)) + size_t l_verify_data_size = l_anchor->header.data_size + sizeof(dap_chain_datum_anchor_t); + if (dap_sign_verify_all(l_unique_signs[i], l_signs_size_original, l_anchor, l_verify_data_size)) continue; l_sign_authorized = true; break; } } - a_anchor->header.signs_size += dap_sign_get_size(l_unique_signs[i]); + l_anchor->header.signs_size += dap_sign_get_size(l_unique_signs[i]); if (l_sign_authorized) break; } DAP_DELETE(l_unique_signs); - a_anchor->header.signs_size = l_signs_size_original; - + if ( a_net->pub.chains->is_mapped ) + DAP_DELETE(l_anchor); + else + l_anchor->header.signs_size = l_signs_size_original; if (!l_sign_authorized) { log_it(L_WARNING, "Anchor signs verify failed"); return -108; diff --git a/modules/ledger/dap_chain_ledger_decree.c b/modules/ledger/dap_chain_ledger_decree.c index 1756af8d5e..9c496ad3d6 100644 --- a/modules/ledger/dap_chain_ledger_decree.c +++ b/modules/ledger/dap_chain_ledger_decree.c @@ -137,32 +137,33 @@ static int s_decree_verify(dap_chain_net_t *a_net, dap_chain_datum_decree_t *a_d // Verify all keys and its signatures uint16_t l_signs_size_for_current_sign = 0, l_signs_verify_counter = 0; - a_decree->header.signs_size = 0; - size_t l_verify_data_size = a_decree->header.data_size + sizeof(dap_chain_datum_decree_t); + dap_chain_datum_decree_t *l_decree = a_net->pub.chains->is_mapped + ? DAP_DUP_SIZE(a_decree, a_data_size) + : a_decree; + l_decree->header.signs_size = 0; + size_t l_verify_data_size = l_decree->header.data_size + sizeof(dap_chain_datum_decree_t); for (size_t i = 0; i < l_num_of_unique_signs; i++) { size_t l_sign_max_size = dap_sign_get_size(l_unique_signs[i]); if (s_verify_pkey(l_unique_signs[i], a_net)) { // 3. verify sign - if(!dap_sign_verify_all(l_unique_signs[i], l_sign_max_size, a_decree, l_verify_data_size)) + if(!dap_sign_verify_all(l_unique_signs[i], l_sign_max_size, l_decree, l_verify_data_size)) l_signs_verify_counter++; } else { dap_hash_fast_t l_sign_pkey_hash = {0}; size_t l_pkey_size = 0; uint8_t *l_pkey = dap_sign_get_pkey(l_unique_signs[i], &l_pkey_size); - dap_hash_fast(l_pkey, l_pkey_size, &l_sign_pkey_hash); - char *l_sign_hash_str = dap_hash_fast_to_str_new(&l_sign_pkey_hash); - log_it(L_WARNING, "Signature [%zu] %s failed public key verification.", i, l_sign_hash_str); - DAP_DELETE(l_sign_hash_str); + log_it(L_WARNING, "Signature [%zu] %s failed public key verification.", i, dap_get_data_hash_str(l_pkey, l_pkey_size).s); } // Each sign change the sign_size field by adding its size after signing. So we need to change this field in header for each sign. l_signs_size_for_current_sign += l_sign_max_size; - a_decree->header.signs_size = l_signs_size_for_current_sign; + l_decree->header.signs_size = l_signs_size_for_current_sign; } - a_decree->header.signs_size = l_signs_size; - -// DAP_DELETE(l_signs_arr); + if ( a_net->pub.chains->is_mapped ) + DAP_DELETE(l_decree); + else + l_decree->header.signs_size = l_signs_size; DAP_DELETE(l_unique_signs); if (l_signs_verify_counter < l_min_signs) { diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 0e6d92bd0f..5e29009c72 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -406,11 +406,7 @@ static char *s_blocks_decree_set_reward(dap_chain_net_t *a_net, dap_chain_t *a_c // Create decree size_t l_tsd_total_size = sizeof(dap_tsd_t) + sizeof(uint256_t); size_t l_decree_size = sizeof(dap_chain_datum_decree_t) + l_tsd_total_size; - dap_chain_datum_decree_t *l_decree = DAP_NEW_Z_SIZE(dap_chain_datum_decree_t, l_decree_size); - if (!l_decree) { - log_it(L_CRITICAL, "%s", c_error_memory_alloc); - return NULL; - } + dap_chain_datum_decree_t *l_decree = DAP_NEW_Z_SIZE_RET_VAL_IF_FAIL(dap_chain_datum_decree_t, l_decree_size, NULL); // Fill the header l_decree->decree_version = DAP_CHAIN_DATUM_DECREE_VERSION; l_decree->header.ts_created = dap_time_now(); -- GitLab From ae76c847062ee642802a0918a00291dafaf76b02 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 20:22:39 +0700 Subject: [PATCH 09/18] 14796 port --- modules/ledger/dap_chain_ledger_decree.c | 36 ++++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/ledger/dap_chain_ledger_decree.c b/modules/ledger/dap_chain_ledger_decree.c index 9c496ad3d6..5bcfdee15c 100644 --- a/modules/ledger/dap_chain_ledger_decree.c +++ b/modules/ledger/dap_chain_ledger_decree.c @@ -344,21 +344,27 @@ static int s_common_decree_handler(dap_chain_datum_decree_t *a_decree, dap_chain switch (a_decree->header.sub_type) { case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_FEE: - if (dap_chain_datum_decree_get_fee_addr(a_decree, &l_addr)) { - if (dap_chain_addr_is_blank(&a_net->pub.fee_addr)) { - log_it(L_WARNING, "Fee wallet address not set."); - return -111; - } else - l_addr = a_net->pub.fee_addr; - } - if (dap_chain_datum_decree_get_fee(a_decree, &l_value)) { - log_it(L_WARNING,"Can't get fee value from decree."); - return -103; - } - if (!a_apply) - break; - if (!dap_chain_net_tx_set_fee(a_net->pub.id, l_value, l_addr)) - log_it(L_ERROR, "Can't set fee value for network %s", a_net->pub.name); + /* if (dap_chain_datum_decree_get_fee_addr(a_decree, &l_addr)) { + if (dap_chain_addr_is_blank(&a_net->pub.fee_addr)) { + log_it(L_WARNING, "Fee wallet address not set."); + return -111; + } else + l_addr = a_net->pub.fee_addr; + } */ + if (!a_anchored) + break; + if (dap_chain_datum_decree_get_fee(a_decree, &l_value)) + return log_it(L_WARNING,"Can't get fee value from decree"), -103; + if (dap_chain_datum_decree_get_fee_addr(a_decree, &l_addr)) { + if (dap_chain_addr_is_blank(&a_net->pub.fee_addr)) + return log_it(L_WARNING, "Fee wallet address not set"), -111; + else + l_addr = a_net->pub.fee_addr; + } + if (!a_apply) + break; + if (!dap_chain_net_tx_set_fee(a_net->pub.id, l_value, l_addr)) + log_it(L_ERROR, "Can't set fee value for network %s", a_net->pub.name); break; case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_OWNERS: l_owners_list = dap_chain_datum_decree_get_owners(a_decree, &l_owners_num); -- GitLab From 8a23f8cde60b6ada4dfbcd72b3d6b17739199bc8 Mon Sep 17 00:00:00 2001 From: "daniil.frolov" <daniil.frolov@demlabs.net> Date: Sun, 29 Dec 2024 09:54:31 +0000 Subject: [PATCH 10/18] hotfix-14909 --- modules/wallet/dap_chain_wallet_cache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/wallet/dap_chain_wallet_cache.c b/modules/wallet/dap_chain_wallet_cache.c index 2ca1d07c95..f070ce9685 100644 --- a/modules/wallet/dap_chain_wallet_cache.c +++ b/modules/wallet/dap_chain_wallet_cache.c @@ -685,7 +685,8 @@ static int s_save_tx_into_wallet_cache(dap_chain_t *a_chain, dap_chain_datum_tx_ int l_prev_idx = ((dap_chain_tx_in_t*)it->data)->header.tx_out_prev_idx; if (dap_hash_fast_is_blank(&l_prev_tx_hash)) continue; - dap_chain_datum_tx_t *l_tx_prev = (dap_chain_datum_tx_t *)(a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL)->data); + dap_chain_datum_t *l_prev_datum = a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL); + dap_chain_datum_tx_t *l_tx_prev = l_prev_datum ? (dap_chain_datum_tx_t *)(l_prev_datum->data) : NULL; if (!l_tx_prev) continue; uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); @@ -924,7 +925,8 @@ static int s_save_tx_cache_for_addr(dap_chain_t *a_chain, dap_chain_addr_t *a_ad int l_prev_idx = ((dap_chain_tx_in_t*)l_tx_item)->header.tx_out_prev_idx; if (dap_hash_fast_is_blank(&l_prev_tx_hash)) continue; - dap_chain_datum_tx_t *l_tx_prev = (dap_chain_datum_tx_t *)(a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL)->data); + dap_chain_datum_t *l_prev_datum = a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL); + dap_chain_datum_tx_t *l_tx_prev = l_prev_datum ? (dap_chain_datum_tx_t *)(l_prev_datum->data) : NULL; if (!l_tx_prev) continue; uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); -- GitLab From f35af686494e322c024456e84f3c82b59d357585 Mon Sep 17 00:00:00 2001 From: "daniil.frolov" <daniil.frolov@demlabs.net> Date: Sun, 29 Dec 2024 13:29:13 +0300 Subject: [PATCH 11/18] [+] Add log if previous tx not found --- modules/wallet/dap_chain_wallet_cache.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/wallet/dap_chain_wallet_cache.c b/modules/wallet/dap_chain_wallet_cache.c index f070ce9685..cc81527a5b 100644 --- a/modules/wallet/dap_chain_wallet_cache.c +++ b/modules/wallet/dap_chain_wallet_cache.c @@ -687,11 +687,15 @@ static int s_save_tx_into_wallet_cache(dap_chain_t *a_chain, dap_chain_datum_tx_ continue; dap_chain_datum_t *l_prev_datum = a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL); dap_chain_datum_tx_t *l_tx_prev = l_prev_datum ? (dap_chain_datum_tx_t *)(l_prev_datum->data) : NULL; - if (!l_tx_prev) + if (!l_tx_prev){ + log_it(L_ERROR, "Can't find previous transactions (hash=%s)", dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; + } uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); - if (!l_prev_item) + if (!l_prev_item){ + log_it(L_ERROR, "Can't find out with index %d transactions (hash=%s)", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; + } uint8_t l_out_type = *(uint8_t *)l_prev_item; switch(l_out_type){ case TX_ITEM_TYPE_OUT_OLD: { @@ -927,11 +931,15 @@ static int s_save_tx_cache_for_addr(dap_chain_t *a_chain, dap_chain_addr_t *a_ad continue; dap_chain_datum_t *l_prev_datum = a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL); dap_chain_datum_tx_t *l_tx_prev = l_prev_datum ? (dap_chain_datum_tx_t *)(l_prev_datum->data) : NULL; - if (!l_tx_prev) + if (!l_tx_prev){ + log_it(L_ERROR, "Can't find previous transactions (hash=%s)", dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; + } uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); - if (!l_prev_item) + if (!l_prev_item){ + log_it(L_ERROR, "Can't find out with index %d transactions (hash=%s)", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; + } uint8_t l_out_type = *(uint8_t *)l_prev_item; switch(l_out_type){ case TX_ITEM_TYPE_OUT_OLD: { -- GitLab From 3796f3fc0609f833504e18dce7b68db98386ce55 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 20:31:27 +0700 Subject: [PATCH 12/18] 14915 port --- modules/ledger/dap_chain_ledger_token.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/ledger/dap_chain_ledger_token.c b/modules/ledger/dap_chain_ledger_token.c index a624cd3c90..3c91f2a6c8 100644 --- a/modules/ledger/dap_chain_ledger_token.c +++ b/modules/ledger/dap_chain_ledger_token.c @@ -240,7 +240,10 @@ static int s_token_tsd_parse(dap_ledger_token_item_t *a_item_apply_to, dap_chain } if (!a_apply) break; + uint256_t l_supply_delta = {}; + SUBTRACT_256_256(l_new_supply, a_item_apply_to->total_supply, &l_supply_delta); // TODO: deal with INF! a_item_apply_to->total_supply = l_new_supply; + SUM_256_256(a_item_apply_to->current_supply, l_supply_delta, &a_item_apply_to->current_supply); } break; // Allowed tx receiver addres list add, remove or clear -- GitLab From 08e854c41f29a6cc239a9f0872083e15c538674f Mon Sep 17 00:00:00 2001 From: "daniil.frolov" <daniil.frolov@demlabs.net> Date: Tue, 31 Dec 2024 03:59:34 +0000 Subject: [PATCH 13/18] hotfix-14918 --- modules/wallet/dap_chain_wallet_cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/wallet/dap_chain_wallet_cache.c b/modules/wallet/dap_chain_wallet_cache.c index cc81527a5b..8adf31ce31 100644 --- a/modules/wallet/dap_chain_wallet_cache.c +++ b/modules/wallet/dap_chain_wallet_cache.c @@ -684,16 +684,16 @@ static int s_save_tx_into_wallet_cache(dap_chain_t *a_chain, dap_chain_datum_tx_ dap_hash_fast_t l_prev_tx_hash = ((dap_chain_tx_in_t*)it->data)->header.tx_prev_hash; int l_prev_idx = ((dap_chain_tx_in_t*)it->data)->header.tx_out_prev_idx; if (dap_hash_fast_is_blank(&l_prev_tx_hash)) - continue; + continue; dap_chain_datum_t *l_prev_datum = a_chain->callback_datum_find_by_hash(a_chain, &l_prev_tx_hash, NULL, NULL); dap_chain_datum_tx_t *l_tx_prev = l_prev_datum ? (dap_chain_datum_tx_t *)(l_prev_datum->data) : NULL; if (!l_tx_prev){ log_it(L_ERROR, "Can't find previous transactions (hash=%s)", dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; } - uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); + uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT_ALL, l_prev_idx); if (!l_prev_item){ - log_it(L_ERROR, "Can't find out with index %d transactions (hash=%s)", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); + log_it(L_ERROR, "Can't find out with index %d in transaction %s", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; } uint8_t l_out_type = *(uint8_t *)l_prev_item; @@ -937,7 +937,7 @@ static int s_save_tx_cache_for_addr(dap_chain_t *a_chain, dap_chain_addr_t *a_ad } uint8_t* l_prev_item = dap_chain_datum_tx_item_get_nth(l_tx_prev, TX_ITEM_TYPE_OUT, l_prev_idx); if (!l_prev_item){ - log_it(L_ERROR, "Can't find out with index %d transactions (hash=%s)", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); + log_it(L_ERROR, "Can't find out with index %d in transaction %s", l_prev_idx, dap_hash_fast_to_str_static(&l_prev_tx_hash)); continue; } uint8_t l_out_type = *(uint8_t *)l_prev_item; -- GitLab From a15cb2ef60c918a310b1ac48b9ce67f7adaddf65 Mon Sep 17 00:00:00 2001 From: "Constantin P." <papizh.konstantin@demlabs.net> Date: Thu, 9 Jan 2025 20:36:50 +0700 Subject: [PATCH 14/18] Minor upd --- modules/datum/dap_chain_datum_tx_items.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/datum/dap_chain_datum_tx_items.c b/modules/datum/dap_chain_datum_tx_items.c index b3c066ad7f..b97c953adc 100644 --- a/modules/datum/dap_chain_datum_tx_items.c +++ b/modules/datum/dap_chain_datum_tx_items.c @@ -435,11 +435,8 @@ dap_chain_tx_sig_t *dap_chain_datum_tx_item_sign_create(dap_enc_key_t *a_key, da { dap_return_val_if_fail(a_key && a_tx, NULL); size_t l_tx_size = a_tx->header.tx_items_size + sizeof(dap_chain_datum_tx_t); - dap_chain_datum_tx_t *l_tx = DAP_DUP_SIZE(a_tx, l_tx_size); - if (!l_tx) { - log_it(L_CRITICAL, "%s", c_error_memory_alloc); - return NULL; - } + dap_chain_datum_tx_t *l_tx = DAP_DUP_SIZE_RET_VAL_IF_FAIL(a_tx, l_tx_size, NULL); + l_tx->header.tx_items_size = 0; dap_sign_t *l_chain_sign = dap_sign_create(a_key, l_tx, l_tx_size, DAP_SIGN_HASH_TYPE_DEFAULT); DAP_DELETE(l_tx); -- GitLab From 6d261221f2fec0cb6d2476e63cf0acb55e8c8b09 Mon Sep 17 00:00:00 2001 From: "P. Constantin" <papizh.konstantin@demlabs.net> Date: Fri, 10 Jan 2025 13:59:56 +0700 Subject: [PATCH 15/18] 14934 port --- dap-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-sdk b/dap-sdk index d6b6934683..8f5ded5f80 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit d6b6934683168160e7d25647ceef59d9439de2c3 +Subproject commit 8f5ded5f80942684f451edd40c657a18fc28955c -- GitLab From a5a29f613f58fb0405e456461ba78a4896a9f19c Mon Sep 17 00:00:00 2001 From: "P. Constantin" <papizh.konstantin@demlabs.net> Date: Fri, 10 Jan 2025 15:07:37 +0700 Subject: [PATCH 16/18] ... --- dap-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-sdk b/dap-sdk index 8f5ded5f80..79b514ef09 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 8f5ded5f80942684f451edd40c657a18fc28955c +Subproject commit 79b514ef09c47fac567e888f35c9f7fd9f5b5c01 -- GitLab From 2f399df230137d654a7880cfcf283b81d5f7ab6d Mon Sep 17 00:00:00 2001 From: "P. Constantin" <papizh.konstantin@demlabs.net> Date: Fri, 10 Jan 2025 16:39:03 +0700 Subject: [PATCH 17/18] Sub up --- dap-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-sdk b/dap-sdk index 79b514ef09..354d33a9ce 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 79b514ef09c47fac567e888f35c9f7fd9f5b5c01 +Subproject commit 354d33a9ce73426992af706983827bc94c8c5a3f -- GitLab From c42e62ba80b49dc7b100af821043a0e1527da3e8 Mon Sep 17 00:00:00 2001 From: "P. Constantin" <papizh.konstantin@demlabs.net> Date: Fri, 10 Jan 2025 18:55:05 +0700 Subject: [PATCH 18/18] Sub up --- dap-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap-sdk b/dap-sdk index 965d123b53..bf5454cead 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 965d123b5324ae01f84855bb5817dd13d6890f5e +Subproject commit bf5454ceadc27aa0d053fb593833f960c008485b -- GitLab