From 796e6eb1a92f87703e126aaae58790def2cd8907 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Mon, 4 Mar 2024 18:46:12 +0700
Subject: [PATCH 01/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 0a9c2b7b1..72eb281bc 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -120,7 +120,7 @@ static dap_chain_atom_ptr_t *s_callback_atom_iter_get_lasts( dap_chain_atom_iter
                                                                   size_t ** a_lasts_size_ptr );  //    Get list of linked blocks
 //Get list of hashes
 static dap_list_t *s_block_parse_str_list(char *a_hash_str, size_t * a_hash_size, dap_chain_t * a_chain);
-
+static void s_blocks_print_list_str(char **a_str_reply, dap_list_t *a_block_list);
 // Delete iterator
 static void s_callback_atom_iter_delete(dap_chain_atom_iter_t * a_atom_iter );                  //    Get the fisrt block
 
@@ -1036,6 +1036,8 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             }
             // NOTE: This call will modify source string
             l_block_list = s_block_parse_str_list((char *)l_hash_str, &l_hashes_count, l_chain);
+            s_blocks_print_list_str(a_str_reply, l_block_list);
+            return -22;
             if (!l_block_list || !l_hashes_count) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply,
                         "Block fee collection requires at least one hash to create a transaction");
@@ -1058,6 +1060,12 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
         }break;
 
         case SUBCMD_AUTOCOLLECT: {
+            /*const char *l_renew = NULL;
+            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "renew", &l_renew);
+            if(l_renew){
+
+            }*/
+
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
                 return -14;
@@ -1119,6 +1127,17 @@ static dap_list_t *s_block_parse_str_list(char *a_hash_str, size_t *a_hash_size,
     return l_block_list;
 }
 
+static void s_blocks_print_list_str(char **a_str_reply, dap_list_t *a_block_list)
+{
+    for (dap_list_t *it = a_block_list; it; it = it->next) {
+        dap_hash_fast_t *l_block_hash = it->data;
+        char l_block_hash_str[DAP_HASH_FAST_STR_SIZE];
+        dap_hash_fast_to_str(l_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE);
+        dap_cli_server_cmd_set_reply_text(a_str_reply, "%s,",l_block_hash_str);
+    }
+    dap_cli_server_cmd_set_reply_text(a_str_reply, "test test test,");
+}
+
 /**
  * @brief s_callback_delete
  * @details Destructor for blocks consensus chain
-- 
GitLab


From 27b26967034f833a80b99803d6af09d8167f1221 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Mon, 4 Mar 2024 19:00:27 +0700
Subject: [PATCH 02/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 39 ++++++++++++++++++++---
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 72eb281bc..41295e80b 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1060,11 +1060,40 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
         }break;
 
         case SUBCMD_AUTOCOLLECT: {
-            /*const char *l_renew = NULL;
-            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "renew", &l_renew);
-            if(l_renew){
+            for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
+                const char * l_cert_name = NULL;
+                dap_pkey_t * l_pub_key = NULL;
+                dap_hash_fast_t l_pkey_hash = {};
+                dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
+                dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
+                l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
+                if (!l_pub_key) {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply,
+                            "Corrupted certificate \"%s\" have no public key data", l_cert_name);
+                    return -20;
+                }
 
-            }*/
+                if (!l_pub_key) {
+                        bool l_found = false;
+                        // TODO optimize performance by precalculated sign hashes in block cache
+                        for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
+                            dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
+                            dap_hash_fast_t l_sign_pkey_hash;
+                            dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                            if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
+                                l_found = true;
+                                break;
+                            }
+                        }
+                        if (!l_found)
+                            continue;
+                    } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                        continue;
+                    if (l_unspent_flag) {
+                        if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                            continue;
+                    }                
+            }
 
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
@@ -1135,7 +1164,7 @@ static void s_blocks_print_list_str(char **a_str_reply, dap_list_t *a_block_list
         dap_hash_fast_to_str(l_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE);
         dap_cli_server_cmd_set_reply_text(a_str_reply, "%s,",l_block_hash_str);
     }
-    dap_cli_server_cmd_set_reply_text(a_str_reply, "test test test,");
+    
 }
 
 /**
-- 
GitLab


From a57673f37881e48357bfbc0712d61844140eaf06 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Wed, 6 Mar 2024 09:36:27 +0700
Subject: [PATCH 03/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 56 +++++++++++------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 41295e80b..f32724996 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1060,39 +1060,39 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
         }break;
 
         case SUBCMD_AUTOCOLLECT: {
+            const char * l_cert_name = NULL;
+            dap_pkey_t * l_pub_key = NULL;
+            dap_hash_fast_t l_pkey_hash = {};
+            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
+            dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
+            l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
+            if (!l_pub_key) {
+                dap_cli_server_cmd_set_reply_text(a_str_reply,
+                        "Corrupted certificate \"%s\" have no public key data", l_cert_name);
+                return -20;
+            }
             for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
-                const char * l_cert_name = NULL;
-                dap_pkey_t * l_pub_key = NULL;
-                dap_hash_fast_t l_pkey_hash = {};
-                dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
-                dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
-                l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
-                if (!l_pub_key) {
-                    dap_cli_server_cmd_set_reply_text(a_str_reply,
-                            "Corrupted certificate \"%s\" have no public key data", l_cert_name);
-                    return -20;
-                }
 
                 if (!l_pub_key) {
-                        bool l_found = false;
-                        // TODO optimize performance by precalculated sign hashes in block cache
-                        for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
-                            dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
-                            dap_hash_fast_t l_sign_pkey_hash;
-                            dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
-                            if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
-                                l_found = true;
-                                break;
-                            }
+                    bool l_found = false;
+                    for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
+                        dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
+                        dap_hash_fast_t l_sign_pkey_hash;
+                        dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                        if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
+                            l_found = true;
+                            break;
                         }
-                        if (!l_found)
-                            continue;
-                    } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                    }
+                    if (!l_found)
                         continue;
-                    if (l_unspent_flag) {
-                        if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
-                            continue;
-                    }                
+                } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                    continue;
+                if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                    continue;
+                dap_string_append_printf(l_str_tmp, "\t%s: ts_create=%s\n", l_block_cache->block_hash_str, l_buf);
+                l_block_count++;
+
             }
 
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
-- 
GitLab


From c7e8606c64c31526e4418a57b21abb10aa75231a Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Wed, 6 Mar 2024 19:53:12 +0700
Subject: [PATCH 04/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 60 ++++++++++++++++++++---
 1 file changed, 52 insertions(+), 8 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index f32724996..d21bf7e66 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -509,6 +509,12 @@ static void s_print_autocollect_table(dap_chain_net_t *a_net, dap_string_t *a_re
         dap_string_append(a_reply_str, "Empty\n");
 }
 
+static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t UNUSED_ARG a_id,
+                                void *a_atom, size_t a_atom_size)
+{
+    
+}
+
 /**
  * @brief s_cli_blocks
  * @param argc
@@ -1061,6 +1067,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
 
         case SUBCMD_AUTOCOLLECT: {
             const char * l_cert_name = NULL;
+            dap_list_t *l_block_list_fee = NULL, *l_block_list_rew = NULL;
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
@@ -1072,7 +1079,34 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                 return -20;
             }
             for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
-
+                bool l_found_fee = true;
+                bool l_found_rew = true;
+                dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
+                dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0);
+                if (!l_pub_key) {
+                    dap_hash_fast_t l_sign_pkey_hash;
+                    dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                    if (!dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash))
+                        l_found_fee = false;
+                } else if (!dap_pkey_compare_with_sign(l_pub_key, l_sign))
+                    l_found_fee = false;
+                
+                for (size_t i = 0; i < l_block_cache->datum_count; i++) {
+                    if (l_block_cache->datum[i]->header.type_id != DAP_CHAIN_DATUM_TX)
+                        l_found_fee = false;
+                    dap_chain_datum_tx_t *l_tx = (dap_chain_datum_tx_t *)l_block_cache->datum[i]->data;
+                    int l_out_idx_tmp = 0;
+                    if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp))
+                        l_found_fee = false;
+                    if (!dap_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) {
+                        if(l_found_fee)
+                            l_block_list_fee = dap_list_append(l_block_list_fee, l_block_cache->block_hash_str); 
+                        break;
+                    }
+                } 
+                 
+                if (l_ts < DAP_REWARD_INIT_TIMESTAMP)
+                        l_found_rew = false;
                 if (!l_pub_key) {
                     bool l_found = false;
                     for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
@@ -1084,16 +1118,26 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                             break;
                         }
                     }
-                    if (!l_found)
-                        continue;
+                    if(!l_found)
+                        l_found_rew = false;
                 } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
-                    continue;
+                    l_found_rew = false;
                 if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
-                    continue;
-                dap_string_append_printf(l_str_tmp, "\t%s: ts_create=%s\n", l_block_cache->block_hash_str, l_buf);
-                l_block_count++;
-
+                    l_found_rew = false;
+                if(l_found_rew)
+                    l_block_list_rew = dap_list_append(l_block_list_rew, l_block_cache->block_hash_str);               
             }
+            
+            size_t l_objs_fee_count = 0;
+            size_t l_objs_rew_count = 0;
+            char *l_group_fee = dap_chain_cs_blocks_get_fee_group(l_net->pub.name);
+            char *l_group_rew = dap_chain_cs_blocks_get_reward_group(l_net->pub.name);
+            dap_global_db_obj_t *l_objs_fee = dap_global_db_get_all_sync(l_group_fee, &l_objs_fee_count);
+            dap_global_db_obj_t *l_objs_rew = dap_global_db_get_all_sync(l_group_rew, &l_objs_rew_count);
+            DAP_DELETE(l_group_fee);
+            DAP_DELETE(l_group_rew);
+
+
 
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
-- 
GitLab


From fe712a16f685b9ab6e010880a21f40fbcb564317 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Tue, 12 Mar 2024 11:55:37 +0700
Subject: [PATCH 05/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index d21bf7e66..b485e104e 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -512,6 +512,8 @@ static void s_print_autocollect_table(dap_chain_net_t *a_net, dap_string_t *a_re
 static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t UNUSED_ARG a_id,
                                 void *a_atom, size_t a_atom_size)
 {
+
+    
     
 }
 
-- 
GitLab


From 4d02b7e643f94d4d868382923997cdbed762871a Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 15 Mar 2024 19:12:14 +0700
Subject: [PATCH 06/18] ...

---
 .../consensus/esbocs/dap_chain_cs_esbocs.c    | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 9bc9aec68..e18e4397b 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -327,6 +327,46 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
     dap_global_db_objs_delete(l_objs, l_objs_count);
 }
 
+void dap_chain_esbocs_add_block_collect(const dap_chain_block_t *a_block_ptr, size_t a_block_size,)
+{
+    dap_sign_t *l_sign = dap_chain_block_sign_get(a_block_ptr, a_block_size, 0);
+    if (dap_pkey_match_sign(PVT(l_session->esbocs)->block_sign_pkey, l_sign)) {
+        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
+        assert(l_block_cache);
+        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
+        assert(l_net);
+        uint256_t l_value_fee = uint256_0;
+        dap_list_t *l_list_used_out = dap_chain_block_get_list_tx_cond_outs_with_val(
+                                        l_net->pub.ledger, l_block_cache, &l_value_fee);
+        if (!IS_ZERO_256(l_value_fee)) {
+            char *l_fee_group = dap_chain_cs_blocks_get_fee_group(a_chain->net_name);
+            dap_global_db_set(l_fee_group, l_block_cache->block_hash_str, &l_value_fee, sizeof(l_value_fee),
+                              false, s_check_db_collect_callback, l_session);
+            DAP_DELETE(l_fee_group);
+        }
+        dap_list_free_full(l_list_used_out, NULL);
+    }
+    if (dap_chain_block_sign_match_pkey(a_atom, a_atom_size, PVT(l_session->esbocs)->block_sign_pkey)) {
+        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
+        assert(l_block_cache);
+        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
+        assert(l_net);
+        if (!dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash,
+                                      &l_session->my_signing_addr.data.hash_fast)) {
+            uint256_t l_value_reward = a_chain->callback_calc_reward(a_chain, &l_block_cache->block_hash,
+                                                                     PVT(l_session->esbocs)->block_sign_pkey);
+            if (!IS_ZERO_256(l_value_reward)) {
+                char *l_reward_group = dap_chain_cs_blocks_get_reward_group(a_chain->net_name);
+                dap_global_db_set(l_reward_group, l_block_cache->block_hash_str, &l_value_reward, sizeof(l_value_reward),
+                                  false, s_check_db_collect_callback, l_session);
+                DAP_DELETE(l_reward_group);
+            }
+        }
+    }    
+}
+
 static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t UNUSED_ARG a_id,
                                 void *a_atom, size_t a_atom_size)
 {
-- 
GitLab


From 58ae039001bdcc8dd5bcf4bca713a74a03b5e3d3 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Mon, 18 Mar 2024 12:03:19 +0700
Subject: [PATCH 07/18] ...

---
 modules/consensus/esbocs/dap_chain_cs_esbocs.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index e18e4397b..667e236fe 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -326,13 +326,19 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
     }
     dap_global_db_objs_delete(l_objs, l_objs_count);
 }
-
-void dap_chain_esbocs_add_block_collect(const dap_chain_block_t *a_block_ptr, size_t a_block_size,)
+uint256_t collectiong_level;
+uint256_t minimum_fee;
+dap_chain_t chain;
+dap_enc_key_t * blocks_sign_key;
+dap_chain_addr_t * collecting_addr;
+
+void dap_chain_esbocs_add_block_collect(dap_chain_t *a_chain, const dap_chain_block_t *a_block_ptr, size_t a_block_size,dap_pkey_t *a_block_sign_pkey,
+                                        dap_chain_hash_fast_t *a_last_block_hash)
 {
     dap_sign_t *l_sign = dap_chain_block_sign_get(a_block_ptr, a_block_size, 0);
-    if (dap_pkey_match_sign(PVT(l_session->esbocs)->block_sign_pkey, l_sign)) {
+    if (dap_pkey_match_sign(a_block_sign_pkey, l_sign)) {
         dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, a_last_block_hash);
         assert(l_block_cache);
         dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
         assert(l_net);
-- 
GitLab


From b9ad40567423f2a3508ef0bb2e707b6175db0050 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Wed, 20 Mar 2024 19:28:03 +0700
Subject: [PATCH 08/18] ...

---
 .../consensus/esbocs/dap_chain_cs_esbocs.c    | 118 ++++++++----------
 .../esbocs/include/dap_chain_cs_esbocs.h      |  11 ++
 modules/type/blocks/dap_chain_cs_blocks.c     |  92 +++++++-------
 3 files changed, 112 insertions(+), 109 deletions(-)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 667e236fe..1a3763ccb 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -287,8 +287,7 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
     }
     log_it(L_NOTICE, "The block %s was successfully added to autocollect %s list", a_key, l_fee_collect ? "fee" : "reward");
     assert(a_value_size == sizeof(uint256_t));
-    dap_chain_esbocs_session_t *l_session = a_arg;
-    dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_session->esbocs);
+    dap_chain_esbocs_block_collect_t *l_block_collect_params = a_arg;
     bool l_level_reached = false;
     uint256_t l_value_total = uint256_0;
     size_t l_objs_count = 0;
@@ -296,7 +295,7 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
     if (l_objs_count >= 10) {
         for (size_t i = 0; i < l_objs_count; i++) {
             SUM_256_256(l_value_total, *(uint256_t*)l_objs[i].value, &l_value_total);
-            if (compare256(l_value_total, l_esbocs_pvt->collecting_level) >= 0) {
+            if (compare256(l_value_total, l_block_collect_params->collectiong_level) >= 0) {
                 l_level_reached = true;
                 break;
             }
@@ -309,13 +308,13 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
             dap_chain_hash_fast_from_hex_str(l_objs[i].key, &block_hash);
             l_block_list = dap_list_append(l_block_list, DAP_DUP(&block_hash));
         }
-        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_session->chain);
+        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_block_collect_params->chain);
         char *l_tx_hash_str = l_fee_collect ?
-                    dap_chain_mempool_tx_coll_fee_create(l_blocks, l_esbocs_pvt->blocks_sign_key,
-                                     l_esbocs_pvt->collecting_addr, l_block_list, l_esbocs_pvt->minimum_fee, "hex")
+                    dap_chain_mempool_tx_coll_fee_create(l_blocks, l_block_collect_params->blocks_sign_key,
+                                     l_block_collect_params->collecting_addr, l_block_list, l_block_collect_params->minimum_fee, "hex")
                   :
-                    dap_chain_mempool_tx_reward_create(l_blocks, l_esbocs_pvt->blocks_sign_key,
-                                     l_esbocs_pvt->collecting_addr, l_block_list, l_esbocs_pvt->minimum_fee, "hex");
+                    dap_chain_mempool_tx_reward_create(l_blocks, l_block_collect_params->blocks_sign_key,
+                                     l_block_collect_params->collecting_addr, l_block_list, l_block_collect_params->minimum_fee, "hex");
         if (l_tx_hash_str) {
             log_it(L_NOTICE, "%s collect transaction successfully created, hash = %s",
                             l_fee_collect ? "Fee" : "Reward", l_tx_hash_str);
@@ -324,49 +323,63 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
             log_it(L_ERROR, "%s collect transaction creation error", l_fee_collect ? "Fee" : "Reward");
         dap_global_db_del_sync(a_group, NULL);
     }
+    DAP_DELETE(l_block_collect_params);
     dap_global_db_objs_delete(l_objs, l_objs_count);
 }
-uint256_t collectiong_level;
-uint256_t minimum_fee;
-dap_chain_t chain;
-dap_enc_key_t * blocks_sign_key;
-dap_chain_addr_t * collecting_addr;
-
-void dap_chain_esbocs_add_block_collect(dap_chain_t *a_chain, const dap_chain_block_t *a_block_ptr, size_t a_block_size,dap_pkey_t *a_block_sign_pkey,
-                                        dap_chain_hash_fast_t *a_last_block_hash)
+
+
+void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
+                                        dap_chain_hash_fast_t *a_last_block_hash, dap_chain_esbocs_block_collect_t *a_block_collect_params)
 {
+    dap_chain_t *l_chain = a_block_collect_params->chain;
     dap_sign_t *l_sign = dap_chain_block_sign_get(a_block_ptr, a_block_size, 0);
-    if (dap_pkey_match_sign(a_block_sign_pkey, l_sign)) {
-        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
+    if (dap_pkey_match_sign(a_block_collect_params->block_sign_pkey, l_sign)) {
+        dap_chain_esbocs_block_collect_t *l_block_collect_params = DAP_NEW_Z(dap_chain_esbocs_block_collect_t);
+        l_block_collect_params->collectiong_level = a_block_collect_params->collectiong_level;
+        l_block_collect_params->minimum_fee = a_block_collect_params->minimum_fee;
+        l_block_collect_params->chain = a_block_collect_params->chain;
+        l_block_collect_params->blocks_sign_key = a_block_collect_params->blocks_sign_key;
+        l_block_collect_params->block_sign_pkey = a_block_collect_params->block_sign_pkey;
+        l_block_collect_params->collecting_addr = a_block_collect_params->collecting_addr;
+
+        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_chain);
         dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, a_last_block_hash);
         assert(l_block_cache);
-        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
+        dap_chain_net_t *l_net = dap_chain_net_by_id(l_chain->net_id);
         assert(l_net);
         uint256_t l_value_fee = uint256_0;
         dap_list_t *l_list_used_out = dap_chain_block_get_list_tx_cond_outs_with_val(
                                         l_net->pub.ledger, l_block_cache, &l_value_fee);
         if (!IS_ZERO_256(l_value_fee)) {
-            char *l_fee_group = dap_chain_cs_blocks_get_fee_group(a_chain->net_name);
+            char *l_fee_group = dap_chain_cs_blocks_get_fee_group(l_chain->net_name);
             dap_global_db_set(l_fee_group, l_block_cache->block_hash_str, &l_value_fee, sizeof(l_value_fee),
-                              false, s_check_db_collect_callback, l_session);
+                              false, s_check_db_collect_callback, l_block_collect_params);
             DAP_DELETE(l_fee_group);
         }
         dap_list_free_full(l_list_used_out, NULL);
     }
-    if (dap_chain_block_sign_match_pkey(a_atom, a_atom_size, PVT(l_session->esbocs)->block_sign_pkey)) {
-        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
+    if (dap_chain_block_sign_match_pkey(a_block_ptr, a_block_size, a_block_collect_params->block_sign_pkey)) {
+        dap_chain_esbocs_block_collect_t *l_block_collect_params = DAP_NEW_Z(dap_chain_esbocs_block_collect_t);
+        l_block_collect_params->collectiong_level = a_block_collect_params->collectiong_level;
+        l_block_collect_params->minimum_fee = a_block_collect_params->minimum_fee;
+        l_block_collect_params->chain = a_block_collect_params->chain;
+        l_block_collect_params->blocks_sign_key = a_block_collect_params->blocks_sign_key;
+        l_block_collect_params->block_sign_pkey = a_block_collect_params->block_sign_pkey;
+        l_block_collect_params->collecting_addr = a_block_collect_params->collecting_addr;
+
+        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_chain);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, a_last_block_hash);
         assert(l_block_cache);
-        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
+        dap_chain_net_t *l_net = dap_chain_net_by_id(l_chain->net_id);
         assert(l_net);
         if (!dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash,
-                                      &l_session->my_signing_addr.data.hash_fast)) {
-            uint256_t l_value_reward = a_chain->callback_calc_reward(a_chain, &l_block_cache->block_hash,
-                                                                     PVT(l_session->esbocs)->block_sign_pkey);
+                                       &l_block_collect_params->collecting_addr->data.hash_fast)) {
+            uint256_t l_value_reward = l_chain->callback_calc_reward(l_chain, &l_block_cache->block_hash,
+                                                                     l_block_collect_params->block_sign_pkey);
             if (!IS_ZERO_256(l_value_reward)) {
-                char *l_reward_group = dap_chain_cs_blocks_get_reward_group(a_chain->net_name);
+                char *l_reward_group = dap_chain_cs_blocks_get_reward_group(l_chain->net_name);
                 dap_global_db_set(l_reward_group, l_block_cache->block_hash_str, &l_value_reward, sizeof(l_value_reward),
-                                  false, s_check_db_collect_callback, l_session);
+                                  false, s_check_db_collect_callback, l_block_collect_params);
                 DAP_DELETE(l_reward_group);
             }
         }
@@ -386,42 +399,15 @@ static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cel
     pthread_mutex_unlock(&l_session->mutex);
     if (!PVT(l_session->esbocs)->collecting_addr)
         return;
-    dap_sign_t *l_sign = dap_chain_block_sign_get(a_atom, a_atom_size, 0);
-    if (dap_pkey_match_sign(PVT(l_session->esbocs)->block_sign_pkey, l_sign)) {
-        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
-        assert(l_block_cache);
-        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
-        assert(l_net);
-        uint256_t l_value_fee = uint256_0;
-        dap_list_t *l_list_used_out = dap_chain_block_get_list_tx_cond_outs_with_val(
-                                        l_net->pub.ledger, l_block_cache, &l_value_fee);
-        if (!IS_ZERO_256(l_value_fee)) {
-            char *l_fee_group = dap_chain_cs_blocks_get_fee_group(a_chain->net_name);
-            dap_global_db_set(l_fee_group, l_block_cache->block_hash_str, &l_value_fee, sizeof(l_value_fee),
-                              false, s_check_db_collect_callback, l_session);
-            DAP_DELETE(l_fee_group);
-        }
-        dap_list_free_full(l_list_used_out, NULL);
-    }
-    if (dap_chain_block_sign_match_pkey(a_atom, a_atom_size, PVT(l_session->esbocs)->block_sign_pkey)) {
-        dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
-        assert(l_block_cache);
-        dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
-        assert(l_net);
-        if (!dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash,
-                                      &l_session->my_signing_addr.data.hash_fast)) {
-            uint256_t l_value_reward = a_chain->callback_calc_reward(a_chain, &l_block_cache->block_hash,
-                                                                     PVT(l_session->esbocs)->block_sign_pkey);
-            if (!IS_ZERO_256(l_value_reward)) {
-                char *l_reward_group = dap_chain_cs_blocks_get_reward_group(a_chain->net_name);
-                dap_global_db_set(l_reward_group, l_block_cache->block_hash_str, &l_value_reward, sizeof(l_value_reward),
-                                  false, s_check_db_collect_callback, l_session);
-                DAP_DELETE(l_reward_group);
-            }
-        }
-    }
+    dap_chain_esbocs_block_collect_t l_block_collect_params = (dap_chain_esbocs_block_collect_t){
+            .collectiong_level = PVT(l_session->esbocs)->collecting_level,
+            .minimum_fee = PVT(l_session->esbocs)->minimum_fee,
+            .chain = a_chain,
+            .blocks_sign_key = PVT(l_session->esbocs)->blocks_sign_key,
+            .block_sign_pkey = PVT(l_session->esbocs)->block_sign_pkey,
+            .collecting_addr = PVT(l_session->esbocs)->collecting_addr
+    };
+    dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_last_block_hash, &l_block_collect_params);
 }
 
 /* *** Temporary added section for over-consensus sync. Remove this after global DB sync refactoring *** */
diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
index f4ece45bc..6e028907a 100644
--- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
+++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
@@ -184,6 +184,15 @@ typedef struct dap_chain_esbocs_session {
     struct dap_chain_esbocs_session *prev;
 } dap_chain_esbocs_session_t;
 
+typedef struct dap_chain_esbocs_block_collect{
+    uint256_t collectiong_level;
+    uint256_t minimum_fee;
+    dap_chain_t *chain;
+    dap_enc_key_t * blocks_sign_key;
+    dap_pkey_t * block_sign_pkey;
+    dap_chain_addr_t * collecting_addr;
+}dap_chain_esbocs_block_collect_t;
+
 #define DAP_CHAIN_ESBOCS(a) ((dap_chain_esbocs_t *)(a)->_inheritor)
 
 int dap_chain_cs_esbocs_init();
@@ -195,3 +204,5 @@ void dap_chain_esbocs_start_timer(dap_chain_net_id_t a_net_id);
 dap_pkey_t *dap_chain_esbocs_get_sign_pkey(dap_chain_net_id_t a_net_id);
 uint256_t dap_chain_esbocs_get_fee(dap_chain_net_id_t a_net_id);
 bool dap_chain_esbocs_get_autocollect_status(dap_chain_net_id_t a_net_id);
+void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
+                                        dap_chain_hash_fast_t *a_last_block_hash, dap_chain_esbocs_block_collect_t *a_block_collect_params);
diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index b485e104e..b90070adf 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -509,13 +509,6 @@ static void s_print_autocollect_table(dap_chain_net_t *a_net, dap_string_t *a_re
         dap_string_append(a_reply_str, "Empty\n");
 }
 
-static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t UNUSED_ARG a_id,
-                                void *a_atom, size_t a_atom_size)
-{
-
-    
-    
-}
 
 /**
  * @brief s_cli_blocks
@@ -1069,7 +1062,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
 
         case SUBCMD_AUTOCOLLECT: {
             const char * l_cert_name = NULL;
-            dap_list_t *l_block_list_fee = NULL, *l_block_list_rew = NULL;
+            dap_list_t *l_block_list = NULL;
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
@@ -1080,65 +1073,78 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                         "Corrupted certificate \"%s\" have no public key data", l_cert_name);
                 return -20;
             }
+            dap_chain_esbocs_block_collect_t l_block_collect_params = (dap_chain_esbocs_block_collect_t){
+                    .collectiong_level = l_chain->,
+                    .minimum_fee = l_chain->callback_get_minimum_fee,
+                    .chain = l_chain,
+                    .blocks_sign_key = l_chain->PVT(l_session->esbocs)->blocks_sign_key,
+                    .block_sign_pkey = PVT(l_session->esbocs)->block_sign_pkey,
+                    .collecting_addr = PVT(l_session->esbocs)->collecting_addr
+            };
+            //Cleare gdb
+            size_t l_objs_fee_count = 0;
+            size_t l_objs_rew_count = 0;
+            char *l_group_fee = dap_chain_cs_blocks_get_fee_group(l_net->pub.name);
+            char *l_group_rew = dap_chain_cs_blocks_get_reward_group(l_net->pub.name);
+            dap_global_db_obj_t *l_objs_fee = dap_global_db_get_all_sync(l_group_fee, &l_objs_fee_count);
+            dap_global_db_obj_t *l_objs_rew = dap_global_db_get_all_sync(l_group_rew, &l_objs_rew_count);
+            if(l_objs_fee_count)dap_global_db_objs_delete(l_objs_fee,l_objs_fee_count);
+            if(l_objs_rew_count)dap_global_db_objs_delete(l_objs_rew,l_objs_rew_count);
+            DAP_DELETE(l_group_fee);
+            DAP_DELETE(l_group_rew);
             for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
-                bool l_found_fee = true;
-                bool l_found_rew = true;
+                bool l_found_fee = false;
                 dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
                 dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0);
                 if (!l_pub_key) {
                     dap_hash_fast_t l_sign_pkey_hash;
                     dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
                     if (!dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash))
-                        l_found_fee = false;
+                        continue;
                 } else if (!dap_pkey_compare_with_sign(l_pub_key, l_sign))
-                    l_found_fee = false;
+                    continue;
                 
                 for (size_t i = 0; i < l_block_cache->datum_count; i++) {
                     if (l_block_cache->datum[i]->header.type_id != DAP_CHAIN_DATUM_TX)
-                        l_found_fee = false;
+                        continue;
                     dap_chain_datum_tx_t *l_tx = (dap_chain_datum_tx_t *)l_block_cache->datum[i]->data;
                     int l_out_idx_tmp = 0;
                     if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp))
-                        l_found_fee = false;
+                        continue;
                     if (!dap_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) {
-                        if(l_found_fee)
-                            l_block_list_fee = dap_list_append(l_block_list_fee, l_block_cache->block_hash_str); 
+                            l_found_fee = true;
+                            l_block_list = dap_list_append(l_block_list, l_block_cache->block_hash_str);
                         break;
                     }
                 } 
                  
                 if (l_ts < DAP_REWARD_INIT_TIMESTAMP)
-                        l_found_rew = false;
-                if (!l_pub_key) {
-                    bool l_found = false;
-                    for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
-                        dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
-                        dap_hash_fast_t l_sign_pkey_hash;
-                        dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
-                        if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
-                            l_found = true;
-                            break;
+                        continue;
+                if(!l_found_fee)
+                {
+                    if (!l_pub_key) {
+                        bool l_found = false;
+                        for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
+                            dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
+                            dap_hash_fast_t l_sign_pkey_hash;
+                            dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                            if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
+                                l_found = true;
+                                break;
+                            }
                         }
-                    }
-                    if(!l_found)
-                        l_found_rew = false;
-                } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
-                    l_found_rew = false;
-                if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
-                    l_found_rew = false;
-                if(l_found_rew)
-                    l_block_list_rew = dap_list_append(l_block_list_rew, l_block_cache->block_hash_str);               
+                        if(!l_found)
+                            continue;
+                    } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                        continue;
+                    if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                        continue;
+                    l_block_list = dap_list_append(l_block_list, l_block_cache->block_hash_str);
+                }
             }
             
-            size_t l_objs_fee_count = 0;
-            size_t l_objs_rew_count = 0;
-            char *l_group_fee = dap_chain_cs_blocks_get_fee_group(l_net->pub.name);
-            char *l_group_rew = dap_chain_cs_blocks_get_reward_group(l_net->pub.name);
-            dap_global_db_obj_t *l_objs_fee = dap_global_db_get_all_sync(l_group_fee, &l_objs_fee_count);
-            dap_global_db_obj_t *l_objs_rew = dap_global_db_get_all_sync(l_group_rew, &l_objs_rew_count);
-            DAP_DELETE(l_group_fee);
-            DAP_DELETE(l_group_rew);
 
+            dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_last_block_hash, &l_block_collect_params);
 
 
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
-- 
GitLab


From a3806c221776f71dff69e7bd80c0a43a0d4a941e Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Thu, 21 Mar 2024 20:10:47 +0700
Subject: [PATCH 09/18] ...

---
 modules/chain/include/dap_chain.h             |  2 ++
 .../consensus/esbocs/dap_chain_cs_esbocs.c    | 10 +++++++++
 modules/type/blocks/dap_chain_cs_blocks.c     | 22 +++++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/modules/chain/include/dap_chain.h b/modules/chain/include/dap_chain.h
index 85614a4da..46f2ef439 100644
--- a/modules/chain/include/dap_chain.h
+++ b/modules/chain/include/dap_chain.h
@@ -115,6 +115,7 @@ typedef dap_list_t *(*dap_chain_callback_get_list)(dap_chain_t *a_chain, size_t
 typedef dap_list_t *(*dap_chain_callback_get_poa_certs)(dap_chain_t *a_chain, size_t *a_auth_certs_count, uint16_t *count_verify);
 typedef void (*dap_chain_callback_set_min_validators_count)(dap_chain_t *a_chain,  uint16_t a_new_value);
 typedef uint256_t (*dap_chain_callback_get_minimum_fee)(dap_chain_t *a_chain);
+typedef uint256_t (*dap_chain_callback_get_collectiong_level)(dap_chain_t *a_chain);
 typedef dap_enc_key_t* (*dap_chain_callback_get_signing_certificate)(dap_chain_t *a_chain);
 typedef void (*dap_chain_callback_load_from_gdb)(dap_chain_t *a_chain);
 typedef uint256_t (*dap_chain_callback_calc_reward)(dap_chain_t *a_chain, dap_hash_fast_t *a_block_hash, dap_pkey_t *a_block_sign_pkey);
@@ -196,6 +197,7 @@ typedef struct dap_chain {
     dap_chain_callback_get_poa_certs callback_get_poa_certs;
     dap_chain_callback_set_min_validators_count callback_set_min_validators_count;
     dap_chain_callback_get_minimum_fee callback_get_minimum_fee;
+    dap_chain_callback_get_collectiong_level callback_get_collectiong_level;
     dap_chain_callback_get_signing_certificate callback_get_signing_certificate;
     dap_chain_callback_calc_reward callback_calc_reward;
     dap_chain_callback_load_from_gdb callback_load_from_gdb;
diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 1a3763ccb..6a96fd6a1 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -178,6 +178,7 @@ static int s_callback_new(dap_chain_t *a_chain, dap_config_t *a_chain_cfg)
     l_esbocs->chain = a_chain;
     a_chain->callback_set_min_validators_count = s_callback_set_min_validators_count;
     a_chain->callback_get_minimum_fee = s_callback_get_minimum_fee;
+    a_chain->callback_get_collectiong_level = s_callback_get_collectiong_level;
     a_chain->callback_get_signing_certificate = s_callback_get_sign_key;
 
     l_esbocs->_pvt = DAP_NEW_Z(dap_chain_esbocs_pvt_t);
@@ -705,6 +706,15 @@ static uint256_t s_callback_get_minimum_fee(dap_chain_t *a_chain)
     return l_esbocs_pvt->minimum_fee;
 }
 
+static uint256_t s_callback_get_collectiong_level(dap_chain_t *a_chain)
+{
+    dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
+    dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks);
+    dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs);
+
+    return l_esbocs_pvt->collecting_level;
+}
+
 static dap_enc_key_t *s_callback_get_sign_key(dap_chain_t *a_chain)
 {
     dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain);
diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index b90070adf..dc69e7154 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1061,11 +1061,21 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
         }break;
 
         case SUBCMD_AUTOCOLLECT: {
-            const char * l_cert_name = NULL;
+            const char * l_cert_name  = NULL, * l_addr_str = NULL;
             dap_list_t *l_block_list = NULL;
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
+            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
+            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
+            if(!l_cert_name) {
+                dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block %s autocollect renew' requires parameter '-cert'", l_subcmd_str);
+                return -20;
+            }
+            if (!l_addr_str) {
+                dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block %s autocollect renew' requires parameter '-addr'", l_addr_str);
+                return -20;
+            }
             dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
             l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
             if (!l_pub_key) {
@@ -1074,11 +1084,11 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                 return -20;
             }
             dap_chain_esbocs_block_collect_t l_block_collect_params = (dap_chain_esbocs_block_collect_t){
-                    .collectiong_level = l_chain->,
+                    .collectiong_level = l_chain->callback_get_collectiong_level,
                     .minimum_fee = l_chain->callback_get_minimum_fee,
                     .chain = l_chain,
-                    .blocks_sign_key = l_chain->PVT(l_session->esbocs)->blocks_sign_key,
-                    .block_sign_pkey = PVT(l_session->esbocs)->block_sign_pkey,
+                    .blocks_sign_key = l_cert->enc_key,
+                    .block_sign_pkey = l_pub_key,
                     .collecting_addr = PVT(l_session->esbocs)->collecting_addr
             };
             //Cleare gdb
@@ -1141,12 +1151,10 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                         continue;
                     l_block_list = dap_list_append(l_block_list, l_block_cache->block_hash_str);
                 }
-            }
-            
+            }            
 
             dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_last_block_hash, &l_block_collect_params);
 
-
             if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
                 return -14;
-- 
GitLab


From 570c3f9fc6d5f85fbf6b166beed851124c41eecd Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 22 Mar 2024 15:45:14 +0700
Subject: [PATCH 10/18] finished add cli command

---
 modules/type/blocks/dap_chain_cs_blocks.c | 191 +++++++++++-----------
 1 file changed, 98 insertions(+), 93 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index dc69e7154..7ffc940ce 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1065,105 +1065,110 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             dap_list_t *l_block_list = NULL;
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
-            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
-            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
-            dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
-            if(!l_cert_name) {
-                dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block %s autocollect renew' requires parameter '-cert'", l_subcmd_str);
-                return -20;
-            }
-            if (!l_addr_str) {
-                dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block %s autocollect renew' requires parameter '-addr'", l_addr_str);
-                return -20;
-            }
-            dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
-            l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
-            if (!l_pub_key) {
-                dap_cli_server_cmd_set_reply_text(a_str_reply,
-                        "Corrupted certificate \"%s\" have no public key data", l_cert_name);
-                return -20;
-            }
-            dap_chain_esbocs_block_collect_t l_block_collect_params = (dap_chain_esbocs_block_collect_t){
-                    .collectiong_level = l_chain->callback_get_collectiong_level,
-                    .minimum_fee = l_chain->callback_get_minimum_fee,
-                    .chain = l_chain,
-                    .blocks_sign_key = l_cert->enc_key,
-                    .block_sign_pkey = l_pub_key,
-                    .collecting_addr = PVT(l_session->esbocs)->collecting_addr
-            };
-            //Cleare gdb
-            size_t l_objs_fee_count = 0;
-            size_t l_objs_rew_count = 0;
-            char *l_group_fee = dap_chain_cs_blocks_get_fee_group(l_net->pub.name);
-            char *l_group_rew = dap_chain_cs_blocks_get_reward_group(l_net->pub.name);
-            dap_global_db_obj_t *l_objs_fee = dap_global_db_get_all_sync(l_group_fee, &l_objs_fee_count);
-            dap_global_db_obj_t *l_objs_rew = dap_global_db_get_all_sync(l_group_rew, &l_objs_rew_count);
-            if(l_objs_fee_count)dap_global_db_objs_delete(l_objs_fee,l_objs_fee_count);
-            if(l_objs_rew_count)dap_global_db_objs_delete(l_objs_rew,l_objs_rew_count);
-            DAP_DELETE(l_group_fee);
-            DAP_DELETE(l_group_rew);
-            for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
-                bool l_found_fee = false;
-                dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
-                dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0);
+            dap_chain_addr_t *l_addr = NULL;
+            dap_chain_hash_fast_t l_last_block_hash;            
+            int fl_renew = dap_cli_server_cmd_check_option(a_argv, arg_index,a_argc, "renew");
+            if(fl_renew)
+            {
+                dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
+                dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
+                l_addr = dap_chain_addr_from_str(l_addr_str);
+                if(!l_cert_name) {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect renew' requires parameter '-cert'", l_subcmd_str);
+                    return -20;
+                }
+                if (!l_addr_str) {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect renew' requires parameter '-addr'", l_addr_str);
+                    return -20;
+                }
+                dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
+                l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
                 if (!l_pub_key) {
-                    dap_hash_fast_t l_sign_pkey_hash;
-                    dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
-                    if (!dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash))
-                        continue;
-                } else if (!dap_pkey_compare_with_sign(l_pub_key, l_sign))
-                    continue;
-                
-                for (size_t i = 0; i < l_block_cache->datum_count; i++) {
-                    if (l_block_cache->datum[i]->header.type_id != DAP_CHAIN_DATUM_TX)
-                        continue;
-                    dap_chain_datum_tx_t *l_tx = (dap_chain_datum_tx_t *)l_block_cache->datum[i]->data;
-                    int l_out_idx_tmp = 0;
-                    if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp))
-                        continue;
-                    if (!dap_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) {
-                            l_found_fee = true;
-                            l_block_list = dap_list_append(l_block_list, l_block_cache->block_hash_str);
-                        break;
-                    }
-                } 
-                 
-                if (l_ts < DAP_REWARD_INIT_TIMESTAMP)
-                        continue;
-                if(!l_found_fee)
-                {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply,
+                            "Corrupted certificate \"%s\" have no public key data", l_cert_name);
+                    return -20;
+                }
+                dap_chain_esbocs_block_collect_t l_block_collect_params = (dap_chain_esbocs_block_collect_t){
+                        .collectiong_level = l_chain->callback_get_collectiong_level,
+                        .minimum_fee = l_chain->callback_get_minimum_fee,
+                        .chain = l_chain,
+                        .blocks_sign_key = l_cert->enc_key,
+                        .block_sign_pkey = l_pub_key,
+                        .collecting_addr = l_addr
+                };
+                //Cleare gdb
+                size_t l_objs_fee_count = 0;
+                size_t l_objs_rew_count = 0;
+                char *l_group_fee = dap_chain_cs_blocks_get_fee_group(l_net->pub.name);
+                char *l_group_rew = dap_chain_cs_blocks_get_reward_group(l_net->pub.name);
+                dap_global_db_obj_t *l_objs_fee = dap_global_db_get_all_sync(l_group_fee, &l_objs_fee_count);
+                dap_global_db_obj_t *l_objs_rew = dap_global_db_get_all_sync(l_group_rew, &l_objs_rew_count);
+                if(l_objs_fee_count)dap_global_db_objs_delete(l_objs_fee,l_objs_fee_count);
+                if(l_objs_rew_count)dap_global_db_objs_delete(l_objs_rew,l_objs_rew_count);
+                DAP_DELETE(l_group_fee);
+                DAP_DELETE(l_group_rew);
+                s_get_last_block_hash(l_chain, &l_last_block_hash);
+                for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
+                    bool l_found_fee = false;
+                    dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
+                    dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0);
                     if (!l_pub_key) {
-                        bool l_found = false;
-                        for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
-                            dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
-                            dap_hash_fast_t l_sign_pkey_hash;
-                            dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
-                            if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
-                                l_found = true;
-                                break;
-                            }
-                        }
-                        if(!l_found)
+                        dap_hash_fast_t l_sign_pkey_hash;
+                        dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                        if (!dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash))
                             continue;
-                    } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
-                        continue;
-                    if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                    } else if (!dap_pkey_compare_with_sign(l_pub_key, l_sign))
                         continue;
-                    l_block_list = dap_list_append(l_block_list, l_block_cache->block_hash_str);
+                    for (size_t i = 0; i < l_block_cache->datum_count; i++) {
+                        if (l_block_cache->datum[i]->header.type_id != DAP_CHAIN_DATUM_TX)
+                            continue;
+                        dap_chain_datum_tx_t *l_tx = (dap_chain_datum_tx_t *)l_block_cache->datum[i]->data;
+                        int l_out_idx_tmp = 0;
+                        if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp))
+                            continue;
+                        if (!dap_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) {
+                                l_found_fee = true;
+                            break;
+                        }
+                    } 
+                    if (l_ts < DAP_REWARD_INIT_TIMESTAMP)
+                            continue;
+                    if(!l_found_fee)
+                    {
+                        if (!l_pub_key) {
+                            bool l_found = false;
+                            for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
+                                dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
+                                dap_hash_fast_t l_sign_pkey_hash;
+                                dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                                if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
+                                    l_found = true;
+                                    break;
+                                }
+                            }
+                            if(!l_found)
+                                continue;
+                        } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                            continue;
+                        if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                            continue;
+                        l_found_fee = true;
+                    }
+                    if(l_found_fee)
+                        dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_last_block_hash, &l_block_collect_params);
+                }                
+            }else{
+                if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
+                    return -14;
                 }
-            }            
-
-            dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_last_block_hash, &l_block_collect_params);
+                dap_string_t *l_reply_str = dap_string_new("");
+                s_print_autocollect_table(l_net, l_reply_str, "Fees");
+                s_print_autocollect_table(l_net, l_reply_str, "Rewards");
+                dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_reply_str->str);
+                dap_string_free(l_reply_str, true);
+            }   
 
-            if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
-                dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
-                return -14;
-            }
-            dap_string_t *l_reply_str = dap_string_new("");
-            s_print_autocollect_table(l_net, l_reply_str, "Fees");
-            s_print_autocollect_table(l_net, l_reply_str, "Rewards");
-            dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_reply_str->str);
-            dap_string_free(l_reply_str, true);
         } break;
 
         case SUBCMD_UNDEFINED:
-- 
GitLab


From 863bc5f26138fd36d27c15dad9175d8ddf166bd0 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 22 Mar 2024 17:21:41 +0700
Subject: [PATCH 11/18] ...

---
 modules/consensus/esbocs/dap_chain_cs_esbocs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 6a96fd6a1..0f5cbc152 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -59,6 +59,7 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf
 static size_t s_callback_block_sign(dap_chain_cs_blocks_t *a_blocks, dap_chain_block_t **a_block_ptr, size_t a_block_size);
 static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_block_t *a_block, size_t a_block_size);
 static uint256_t s_callback_get_minimum_fee(dap_chain_t *a_chain);
+static uint256_t s_callback_get_collectiong_level(dap_chain_t *a_chain);
 static dap_enc_key_t *s_callback_get_sign_key(dap_chain_t *a_chain);
 static void s_callback_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_new_value);
 static void s_db_change_notifier(dap_global_db_context_t *a_context, dap_store_obj_t *a_obj, void * a_arg);
-- 
GitLab


From aa02847f3be11eb52d4525b9ad2a59be02889767 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Sun, 24 Mar 2024 16:26:35 +0700
Subject: [PATCH 12/18] ...

---
 modules/consensus/esbocs/dap_chain_cs_esbocs.c         | 10 ++++++----
 modules/consensus/esbocs/include/dap_chain_cs_esbocs.h |  2 +-
 modules/type/blocks/dap_chain_cs_blocks.c              |  5 ++---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 0f5cbc152..f7bec8eac 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -331,8 +331,10 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
 
 
 void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
-                                        dap_chain_hash_fast_t *a_last_block_hash, dap_chain_esbocs_block_collect_t *a_block_collect_params)
+                                        dap_chain_esbocs_block_collect_t *a_block_collect_params)
 {
+    dap_hash_fast_t l_last_block_hash;
+    s_get_last_block_hash(a_block_collect_params->chain, &l_last_block_hash);
     dap_chain_t *l_chain = a_block_collect_params->chain;
     dap_sign_t *l_sign = dap_chain_block_sign_get(a_block_ptr, a_block_size, 0);
     if (dap_pkey_match_sign(a_block_collect_params->block_sign_pkey, l_sign)) {
@@ -345,7 +347,7 @@ void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a
         l_block_collect_params->collecting_addr = a_block_collect_params->collecting_addr;
 
         dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, a_last_block_hash);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
         assert(l_block_cache);
         dap_chain_net_t *l_net = dap_chain_net_by_id(l_chain->net_id);
         assert(l_net);
@@ -370,7 +372,7 @@ void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a
         l_block_collect_params->collecting_addr = a_block_collect_params->collecting_addr;
 
         dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(l_chain);
-        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, a_last_block_hash);
+        dap_chain_block_cache_t *l_block_cache = dap_chain_block_cache_get_by_hash(l_blocks, &l_last_block_hash);
         assert(l_block_cache);
         dap_chain_net_t *l_net = dap_chain_net_by_id(l_chain->net_id);
         assert(l_net);
@@ -409,7 +411,7 @@ static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cel
             .block_sign_pkey = PVT(l_session->esbocs)->block_sign_pkey,
             .collecting_addr = PVT(l_session->esbocs)->collecting_addr
     };
-    dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_last_block_hash, &l_block_collect_params);
+    dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_block_collect_params);
 }
 
 /* *** Temporary added section for over-consensus sync. Remove this after global DB sync refactoring *** */
diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
index 6e028907a..f0d19416c 100644
--- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
+++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
@@ -205,4 +205,4 @@ dap_pkey_t *dap_chain_esbocs_get_sign_pkey(dap_chain_net_id_t a_net_id);
 uint256_t dap_chain_esbocs_get_fee(dap_chain_net_id_t a_net_id);
 bool dap_chain_esbocs_get_autocollect_status(dap_chain_net_id_t a_net_id);
 void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
-                                        dap_chain_hash_fast_t *a_last_block_hash, dap_chain_esbocs_block_collect_t *a_block_collect_params);
+                                        dap_chain_esbocs_block_collect_t *a_block_collect_params);
diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 7ffc940ce..d8f7ebf44 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1066,7 +1066,6 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_chain_addr_t *l_addr = NULL;
-            dap_chain_hash_fast_t l_last_block_hash;            
             int fl_renew = dap_cli_server_cmd_check_option(a_argv, arg_index,a_argc, "renew");
             if(fl_renew)
             {
@@ -1107,7 +1106,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                 if(l_objs_rew_count)dap_global_db_objs_delete(l_objs_rew,l_objs_rew_count);
                 DAP_DELETE(l_group_fee);
                 DAP_DELETE(l_group_rew);
-                s_get_last_block_hash(l_chain, &l_last_block_hash);
+
                 for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
                     bool l_found_fee = false;
                     dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
@@ -1155,7 +1154,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                         l_found_fee = true;
                     }
                     if(l_found_fee)
-                        dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_last_block_hash, &l_block_collect_params);
+                        dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_block_collect_params);
                 }                
             }else{
                 if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
-- 
GitLab


From 86990ff36bc700cb6f65d9a630e0b604059a11c9 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Sun, 24 Mar 2024 16:42:50 +0700
Subject: [PATCH 13/18] changed out help for block command

---
 modules/type/blocks/dap_chain_cs_blocks.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index d8f7ebf44..310c4fc71 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -202,7 +202,10 @@ int dap_chain_cs_blocks_init()
         "Rewards and fees autocollect status:\n"
             "block -net <net_name> -chain <chain_name> autocollect status\n"
                 "\t\t Show rewards and fees automatic collecting status (enabled or not)."
-                    " Show prepared blocks for collecting rewards and fees if status is enabled\n"
+                    " Show prepared blocks for collecting rewards and fees if status is enabled\n\n"
+            "block -net <net_name> -chain <chain_name> autocollect renew\n"
+                "\t\t Update reward and fees block table."
+                    " Automatic collection of commission in case of triggering of the setting\n\n"
                                         );
     if( dap_chain_block_cache_init() ) {
         log_it(L_WARNING, "Can't init blocks cache");
@@ -1062,7 +1065,6 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
 
         case SUBCMD_AUTOCOLLECT: {
             const char * l_cert_name  = NULL, * l_addr_str = NULL;
-            dap_list_t *l_block_list = NULL;
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_chain_addr_t *l_addr = NULL;
-- 
GitLab


From d8ed6c584bc7d43310b3dbfaf0d94d42ee1b817c Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Mon, 25 Mar 2024 16:32:19 +0700
Subject: [PATCH 14/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 310c4fc71..5f056dd14 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -204,6 +204,7 @@ int dap_chain_cs_blocks_init()
                 "\t\t Show rewards and fees automatic collecting status (enabled or not)."
                     " Show prepared blocks for collecting rewards and fees if status is enabled\n\n"
             "block -net <net_name> -chain <chain_name> autocollect renew\n"
+            " -cert <priv_cert_name> -addr <addr>\n"
                 "\t\t Update reward and fees block table."
                     " Automatic collection of commission in case of triggering of the setting\n\n"
                                         );
@@ -1069,7 +1070,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             dap_hash_fast_t l_pkey_hash = {};
             dap_chain_addr_t *l_addr = NULL;
             int fl_renew = dap_cli_server_cmd_check_option(a_argv, arg_index,a_argc, "renew");
-            if(fl_renew)
+            if(fl_renew != -1)
             {
                 dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cert", &l_cert_name);
                 dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-addr", &l_addr_str);
@@ -1083,6 +1084,10 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                     return -20;
                 }
                 dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
+                if (!l_cert) {
+                    dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't find \"%s\" certificate", l_cert_name);
+                    return -20;
+                }
                 l_pub_key = dap_pkey_from_enc_key(l_cert->enc_key);
                 if (!l_pub_key) {
                     dap_cli_server_cmd_set_reply_text(a_str_reply,
-- 
GitLab


From 504ea2d00aeb5fc17d17522b9191d8a264b08ee2 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 29 Mar 2024 17:47:46 +0700
Subject: [PATCH 15/18] ...

---
 .../consensus/esbocs/dap_chain_cs_esbocs.c    |  9 ++-
 .../esbocs/include/dap_chain_cs_esbocs.h      |  2 +-
 modules/type/blocks/dap_chain_cs_blocks.c     | 60 +++++++++++--------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index f7bec8eac..ee3c90057 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -329,15 +329,14 @@ static void s_check_db_collect_callback(dap_global_db_context_t UNUSED_ARG *a_gl
     dap_global_db_objs_delete(l_objs, l_objs_count);
 }
 
-
 void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
-                                        dap_chain_esbocs_block_collect_t *a_block_collect_params)
+                                        dap_chain_esbocs_block_collect_t *a_block_collect_params,int a_type)
 {
     dap_hash_fast_t l_last_block_hash;
     s_get_last_block_hash(a_block_collect_params->chain, &l_last_block_hash);
     dap_chain_t *l_chain = a_block_collect_params->chain;
     dap_sign_t *l_sign = dap_chain_block_sign_get(a_block_ptr, a_block_size, 0);
-    if (dap_pkey_match_sign(a_block_collect_params->block_sign_pkey, l_sign)) {
+    if (dap_pkey_match_sign(a_block_collect_params->block_sign_pkey, l_sign)&&(!a_type||a_type==1)) {
         dap_chain_esbocs_block_collect_t *l_block_collect_params = DAP_NEW_Z(dap_chain_esbocs_block_collect_t);
         l_block_collect_params->collectiong_level = a_block_collect_params->collectiong_level;
         l_block_collect_params->minimum_fee = a_block_collect_params->minimum_fee;
@@ -362,7 +361,7 @@ void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a
         }
         dap_list_free_full(l_list_used_out, NULL);
     }
-    if (dap_chain_block_sign_match_pkey(a_block_ptr, a_block_size, a_block_collect_params->block_sign_pkey)) {
+    if (dap_chain_block_sign_match_pkey(a_block_ptr, a_block_size, a_block_collect_params->block_sign_pkey)&&(!a_type||a_type==2)) {
         dap_chain_esbocs_block_collect_t *l_block_collect_params = DAP_NEW_Z(dap_chain_esbocs_block_collect_t);
         l_block_collect_params->collectiong_level = a_block_collect_params->collectiong_level;
         l_block_collect_params->minimum_fee = a_block_collect_params->minimum_fee;
@@ -411,7 +410,7 @@ static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cel
             .block_sign_pkey = PVT(l_session->esbocs)->block_sign_pkey,
             .collecting_addr = PVT(l_session->esbocs)->collecting_addr
     };
-    dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_block_collect_params);
+    dap_chain_esbocs_add_block_collect(a_atom, a_atom_size, &l_block_collect_params,0);
 }
 
 /* *** Temporary added section for over-consensus sync. Remove this after global DB sync refactoring *** */
diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
index f0d19416c..b04329716 100644
--- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
+++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h
@@ -205,4 +205,4 @@ dap_pkey_t *dap_chain_esbocs_get_sign_pkey(dap_chain_net_id_t a_net_id);
 uint256_t dap_chain_esbocs_get_fee(dap_chain_net_id_t a_net_id);
 bool dap_chain_esbocs_get_autocollect_status(dap_chain_net_id_t a_net_id);
 void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
-                                        dap_chain_esbocs_block_collect_t *a_block_collect_params);
+                                        dap_chain_esbocs_block_collect_t *a_block_collect_params,int a_type);
diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 5f056dd14..45073d098 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -203,6 +203,7 @@ int dap_chain_cs_blocks_init()
             "block -net <net_name> -chain <chain_name> autocollect status\n"
                 "\t\t Show rewards and fees automatic collecting status (enabled or not)."
                     " Show prepared blocks for collecting rewards and fees if status is enabled\n\n"
+        "Rewards and fees autocollect renew:\n"
             "block -net <net_name> -chain <chain_name> autocollect renew\n"
             " -cert <priv_cert_name> -addr <addr>\n"
                 "\t\t Update reward and fees block table."
@@ -1069,6 +1070,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             dap_pkey_t * l_pub_key = NULL;
             dap_hash_fast_t l_pkey_hash = {};
             dap_chain_addr_t *l_addr = NULL;
+            size_t l_block_count = 0;
             int fl_renew = dap_cli_server_cmd_check_option(a_argv, arg_index,a_argc, "renew");
             if(fl_renew != -1)
             {
@@ -1113,9 +1115,9 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                 if(l_objs_rew_count)dap_global_db_objs_delete(l_objs_rew,l_objs_rew_count);
                 DAP_DELETE(l_group_fee);
                 DAP_DELETE(l_group_rew);
+                dap_string_t *l_str_tmp = dap_string_new(NULL);
 
                 for (dap_chain_block_cache_t *l_block_cache = PVT(l_blocks)->blocks; l_block_cache; l_block_cache = l_block_cache->hh.next) {
-                    bool l_found_fee = false;
                     dap_time_t l_ts = l_block_cache->block->hdr.ts_created;
                     dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, 0);
                     if (!l_pub_key) {
@@ -1133,36 +1135,46 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                         if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp))
                             continue;
                         if (!dap_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) {
-                                l_found_fee = true;
+                            dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_block_collect_params,1);
+                            char l_buf[50];
+                            dap_time_to_str_rfc822(l_buf, 50, l_ts);
+                            dap_string_append_printf(l_str_tmp, "fee - \t%s: ts_create=%s\n", l_block_cache->block_hash_str, l_buf);
+                            l_block_count++;
                             break;
                         }
                     } 
                     if (l_ts < DAP_REWARD_INIT_TIMESTAMP)
                             continue;
-                    if(!l_found_fee)
-                    {
-                        if (!l_pub_key) {
-                            bool l_found = false;
-                            for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
-                                dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
-                                dap_hash_fast_t l_sign_pkey_hash;
-                                dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
-                                if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
-                                    l_found = true;
-                                    break;
-                                }
+                    
+                    if (!l_pub_key) {
+                        bool l_found = false;
+                        for (size_t i = 0; i < l_block_cache->sign_count ; i++) {
+                            dap_sign_t *l_sign = dap_chain_block_sign_get(l_block_cache->block, l_block_cache->block_size, i);
+                            dap_hash_fast_t l_sign_pkey_hash;
+                            dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash);
+                            if (dap_hash_fast_compare(&l_pkey_hash, &l_sign_pkey_hash)) {
+                                l_found = true;
+                                break;
                             }
-                            if(!l_found)
-                                continue;
-                        } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
-                            continue;
-                        if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                        }
+                        if(!l_found)
                             continue;
-                        l_found_fee = true;
-                    }
-                    if(l_found_fee)
-                        dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_block_collect_params);
-                }                
+                    } else if (!dap_chain_block_sign_match_pkey(l_block_cache->block, l_block_cache->block_size, l_pub_key))
+                        continue;
+                    if (dap_ledger_is_used_reward(l_net->pub.ledger, &l_block_cache->block_hash, &l_pkey_hash))
+                        continue;
+                    dap_chain_esbocs_add_block_collect(l_block_cache->block, l_block_cache->block_size, &l_block_collect_params,2);
+                    {   
+                        char l_buf[50];
+                        dap_time_to_str_rfc822(l_buf, 50, l_ts);
+                        dap_string_append_printf(l_str_tmp, "rewards - \t%s: ts_create=%s\n", l_block_cache->block_hash_str, l_buf);
+                        l_block_count++; 
+                    }                   
+                }
+                dap_string_append_printf(l_str_tmp, "%s.%s: Have %"DAP_UINT64_FORMAT_U" blocks\n",
+                                     l_net->pub.name, l_chain->name, l_block_count);
+                dap_string_free(l_str_tmp, true);
+
             }else{
                 if (dap_cli_server_cmd_check_option(a_argv, arg_index, a_argc, "status") == -1) {
                     dap_cli_server_cmd_set_reply_text(a_str_reply, "Command 'block autocollect' requires subcommand 'status'");
-- 
GitLab


From 096125ae7a396868983965e12b710f6ab9f09af6 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 29 Mar 2024 22:59:05 +0700
Subject: [PATCH 16/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 45073d098..159ef583b 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -203,6 +203,7 @@ int dap_chain_cs_blocks_init()
             "block -net <net_name> -chain <chain_name> autocollect status\n"
                 "\t\t Show rewards and fees automatic collecting status (enabled or not)."
                     " Show prepared blocks for collecting rewards and fees if status is enabled\n\n"
+
         "Rewards and fees autocollect renew:\n"
             "block -net <net_name> -chain <chain_name> autocollect renew\n"
             " -cert <priv_cert_name> -addr <addr>\n"
-- 
GitLab


From 1b7a81376ca9cb1d2aea26d65795cee1ebb5a359 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Fri, 29 Mar 2024 23:08:02 +0700
Subject: [PATCH 17/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 159ef583b..514a424bd 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -1174,6 +1174,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
                 }
                 dap_string_append_printf(l_str_tmp, "%s.%s: Have %"DAP_UINT64_FORMAT_U" blocks\n",
                                      l_net->pub.name, l_chain->name, l_block_count);
+                dap_cli_server_cmd_set_reply_text(a_str_reply, "%s", l_str_tmp->str);
                 dap_string_free(l_str_tmp, true);
 
             }else{
-- 
GitLab


From 840b02299cccedaeb95b86f0de812b5793b9222d Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Mon, 8 Apr 2024 14:48:22 +0700
Subject: [PATCH 18/18] ...

---
 modules/type/blocks/dap_chain_cs_blocks.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c
index 514a424bd..f50007528 100644
--- a/modules/type/blocks/dap_chain_cs_blocks.c
+++ b/modules/type/blocks/dap_chain_cs_blocks.c
@@ -120,7 +120,6 @@ static dap_chain_atom_ptr_t *s_callback_atom_iter_get_lasts( dap_chain_atom_iter
                                                                   size_t ** a_lasts_size_ptr );  //    Get list of linked blocks
 //Get list of hashes
 static dap_list_t *s_block_parse_str_list(char *a_hash_str, size_t * a_hash_size, dap_chain_t * a_chain);
-static void s_blocks_print_list_str(char **a_str_reply, dap_list_t *a_block_list);
 // Delete iterator
 static void s_callback_atom_iter_delete(dap_chain_atom_iter_t * a_atom_iter );                  //    Get the fisrt block
 
@@ -1043,8 +1042,6 @@ static int s_cli_blocks(int a_argc, char ** a_argv, void **reply)
             }
             // NOTE: This call will modify source string
             l_block_list = s_block_parse_str_list((char *)l_hash_str, &l_hashes_count, l_chain);
-            s_blocks_print_list_str(a_str_reply, l_block_list);
-            return -22;
             if (!l_block_list || !l_hashes_count) {
                 dap_cli_server_cmd_set_reply_text(a_str_reply,
                         "Block fee collection requires at least one hash to create a transaction");
@@ -1241,16 +1238,6 @@ static dap_list_t *s_block_parse_str_list(char *a_hash_str, size_t *a_hash_size,
     return l_block_list;
 }
 
-static void s_blocks_print_list_str(char **a_str_reply, dap_list_t *a_block_list)
-{
-    for (dap_list_t *it = a_block_list; it; it = it->next) {
-        dap_hash_fast_t *l_block_hash = it->data;
-        char l_block_hash_str[DAP_HASH_FAST_STR_SIZE];
-        dap_hash_fast_to_str(l_block_hash, l_block_hash_str, DAP_HASH_FAST_STR_SIZE);
-        dap_cli_server_cmd_set_reply_text(a_str_reply, "%s,",l_block_hash_str);
-    }
-    
-}
 
 /**
  * @brief s_callback_delete
-- 
GitLab