From 90bf0dc760e681c431b66a6db52b6c7646942d9a Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Tue, 18 Mar 2025 17:45:50 +0700
Subject: [PATCH 1/2] ...

---
 modules/type/dag/dap_chain_cs_dag.c         | 60 ++++++++++++++++++---
 modules/type/dag/include/dap_chain_cs_dag.h |  1 +
 2 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c
index c5abe99b23..746328f148 100644
--- a/modules/type/dag/dap_chain_cs_dag.c
+++ b/modules/type/dag/dap_chain_cs_dag.c
@@ -1680,13 +1680,51 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
             case SUBCMD_EVENT_LIST: {
                 json_object * json_obj_event_list = json_object_new_object();
                 json_object * json_arr_obj_event = json_object_new_array();
-                const char *l_limit_str = NULL, *l_offset_str = NULL, *l_head_str = NULL;
+                const char *l_limit_str = NULL, *l_offset_str = NULL, *l_head_str = NULL, *l_from_date_str = NULL, *l_to_date_str = NULL,
+                            *l_from_hash_str = NULL, l_to_hash_str = NULL;
+                dap_hash_fast_t l_from_hash = {}, l_to_hash = {};
+                dap_time_t l_from_time = 0, l_to_time = 0;
                 dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-limit", &l_limit_str);
                 dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-offset", &l_offset_str);
+                dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-from_date", &l_from_date_str);
+                dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-to_date", &l_to_date_str);
+                dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-from_hash", &l_from_hash_str);
+                dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-to_hash", &l_to_hash_str);
                 bool l_head = dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-head", &l_head_str) ? true : false;
                 char *ptr;
-                size_t l_limit = l_limit_str ? strtoull(l_limit_str, &ptr, 10) : 0;
-                size_t l_offset = l_offset_str ? strtoull(l_offset_str, &ptr, 10) : 0;                
+                size_t l_limit = l_limit_str ? strtoull(l_limit_str, &ptr, 10) : 1000;
+                size_t l_offset = l_offset_str ? strtoull(l_offset_str, &ptr, 10) : 0; 
+                
+                if (l_from_hash_str) {
+                    if (dap_chain_hash_fast_from_str(l_from_hash_str, &l_from_hash)) {
+                        dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR, "Can't convert \"%s\" to hash", l_from_hash_str);
+                        return DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR;
+                    }
+                }
+                if (l_to_hash_str) {
+                    if (dap_chain_hash_fast_from_str(l_to_hash_str, &l_to_hash)) {
+                        dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR, "Can't convert \"%s\" to hash", l_to_hash_str);
+                        return DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR;
+                    }
+                }
+
+                if (l_from_date_str) {
+                    l_from_time = dap_time_from_str_simplified(l_from_date_str);
+                    if (!l_from_time) {
+                        dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR, "Can't convert \"%s\" to date", l_from_date_str);
+                        return DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR;
+                    }
+                }
+                if (l_to_date_str) {
+                    l_to_time = dap_time_from_str_simplified(l_to_date_str);
+                    if (!l_to_time) {
+                        dap_json_rpc_error_add(*a_json_arr_reply, DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR, "Can't convert \"%s\" to date", l_to_date_str);
+                        return DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR;
+                    }
+                    struct tm *l_localtime = localtime((time_t *)&l_to_time);
+                    l_localtime->tm_mday += 1;  // + 1 day to end date, got it inclusive
+                    l_to_time = mktime(l_localtime);
+                }
 
                 if (l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) {
                     char * l_gdb_group_events = DAP_CHAIN_CS_DAG(l_chain)->gdb_group_events_round_new;
@@ -1727,7 +1765,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                     dap_chain_cs_dag_event_item_t * l_event_item = NULL,*l_event_item_tmp = NULL;
                     if (l_head){
                         HASH_ITER(hh, PVT(l_dag)->events, l_event_item, l_event_item_tmp) {
-                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end) {
+                            dap_time_t l_ts = l_event_item->event->header.ts_created;
+                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end || 
+                                (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
                                 i_tmp++;
@@ -1738,7 +1778,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                     else {
                         l_event_item = HASH_LAST(PVT(l_dag)->events);
                         for(; l_event_item; l_event_item = l_event_item->hh.prev){
-                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end) {
+                            dap_time_t l_ts = l_event_item->event->header.ts_created;
+                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end ||
+                                (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
                                 i_tmp++;
@@ -1766,7 +1808,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                     size_t i_tmp = 0;
                     if (l_head){
                         HASH_ITER(hh, PVT(l_dag)->events_treshold, l_event_item, l_event_item_tmp) {
-                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end) {
+                            dap_time_t l_ts = l_event_item->event->header.ts_created;
+                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end ||
+                                (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
                                 i_tmp++;
@@ -1777,7 +1821,9 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                     else {
                         l_event_item = HASH_LAST(PVT(l_dag)->events);
                         for(; l_event_item; l_event_item = l_event_item->hh.prev){
-                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end) {
+                            dap_time_t l_ts = l_event_item->event->header.ts_created;
+                            if (i_tmp < l_arr_start || i_tmp >= l_arr_end ||
+                                (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
                                 i_tmp++;
diff --git a/modules/type/dag/include/dap_chain_cs_dag.h b/modules/type/dag/include/dap_chain_cs_dag.h
index f28f7baf3c..66b876b02e 100644
--- a/modules/type/dag/include/dap_chain_cs_dag.h
+++ b/modules/type/dag/include/dap_chain_cs_dag.h
@@ -85,6 +85,7 @@ typedef enum s_com_dag_err{
     DAP_CHAIN_NODE_CLI_COM_DAG_CERT_ERR,
     DAP_CHAIN_NODE_CLI_COM_DAG_FIND_EVENT_ERR,
     DAP_CHAIN_NODE_CLI_COM_DAG_UNDEF_SUB_ERR,
+    DAP_CHAIN_NODE_CLI_COM_DAG_CONVERT_ERR,
 
     /* add custom codes here */
 
-- 
GitLab


From e65629d22ef9d59f9886d8bf8a3925ed987948b3 Mon Sep 17 00:00:00 2001
From: "roman.padenkov" <roman.padenkov@demlabs.net>
Date: Wed, 19 Mar 2025 14:48:56 +0700
Subject: [PATCH 2/2] ...

---
 modules/type/dag/dap_chain_cs_dag.c | 43 +++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c
index 746328f148..64ce2f8fc1 100644
--- a/modules/type/dag/dap_chain_cs_dag.c
+++ b/modules/type/dag/dap_chain_cs_dag.c
@@ -159,7 +159,8 @@ int dap_chain_cs_dag_init()
             "\tdoesn't changes after sign add to event. \n\n"
         "dag event dump -net <net_name> [-chain <chain_name>] -event <event_hash> -from {events | events_lasts | threshold | round.new  | round.<Round_id_in_hex>} [-H {hex | base58(default)}]\n"
             "\tDump event info\n\n"
-        "dag event list -net <net_name> [-chain <chain_name>] -from {events | events_lasts | threshold | round.new | round.<Round_id_in_hex>} [-limit] [-offset] [-head]\n\n"
+        "dag event list -net <net_name> [-chain <chain_name>] -from {events | events_lasts | threshold | round.new | round.<Round_id_in_hex>} [-limit] [-offset] [-head]"
+                            " [-from_hash <event_hash>] [-to_hash <event_hash>] [-from_date <YYMMDD>] [-to_date <YYMMDD>]\n\n"
             "\tShow event list \n\n"
         "dag event count -net <net_name> [-chain <chain_name>]\n"
             "\tShow count event \n\n"
@@ -1681,7 +1682,8 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                 json_object * json_obj_event_list = json_object_new_object();
                 json_object * json_arr_obj_event = json_object_new_array();
                 const char *l_limit_str = NULL, *l_offset_str = NULL, *l_head_str = NULL, *l_from_date_str = NULL, *l_to_date_str = NULL,
-                            *l_from_hash_str = NULL, l_to_hash_str = NULL;
+                            *l_from_hash_str = NULL, *l_to_hash_str = NULL;
+                bool l_hash_flag = false;
                 dap_hash_fast_t l_from_hash = {}, l_to_hash = {};
                 dap_time_t l_from_time = 0, l_to_time = 0;
                 dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-limit", &l_limit_str);
@@ -1770,8 +1772,16 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                                 (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
+                                if (l_from_hash_str && !l_hash_flag) {
+                                   if (!dap_hash_fast_compare(&l_from_hash, &l_event_item->hash))
+                                       continue;
+                                   l_hash_flag = true;
+                                }
                                 i_tmp++;
-                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);                           
+                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);
+                                if (l_to_hash_str && dap_hash_fast_compare(&l_to_hash, &l_event_item->hash))
+                                    break;
+
                             }
                         }
                     }
@@ -1783,8 +1793,15 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                                 (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
+                                if (l_from_hash_str && !l_hash_flag) {
+                                   if (!dap_hash_fast_compare(&l_from_hash, &l_event_item->hash))
+                                       continue;
+                                   l_hash_flag = true;
+                                }
                                 i_tmp++;
-                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);                           
+                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);
+                                if (l_to_hash_str && dap_hash_fast_compare(&l_to_hash, &l_event_item->hash))
+                                    break;
                             }
                         }
                     }
@@ -1813,8 +1830,15 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                                 (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
+                                if (l_from_hash_str && !l_hash_flag) {
+                                   if (!dap_hash_fast_compare(&l_from_hash, &l_event_item->hash))
+                                       continue;
+                                   l_hash_flag = true;
+                                }
                                 i_tmp++;
-                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);                           
+                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);
+                                if (l_to_hash_str && dap_hash_fast_compare(&l_to_hash, &l_event_item->hash))
+                                    break;
                             }
                         }
                     }
@@ -1826,8 +1850,15 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
                                 (l_from_time && l_ts < l_from_time) || (l_to_time && l_ts >= l_to_time)) {
                                 i_tmp++;
                             } else {
+                                if (l_from_hash_str && !l_hash_flag) {
+                                   if (!dap_hash_fast_compare(&l_from_hash, &l_event_item->hash))
+                                       continue;
+                                   l_hash_flag = true;
+                                }
                                 i_tmp++;
-                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);                           
+                                s_json_dag_pack_event(json_arr_obj_event, l_event_item, i_tmp);
+                                if (l_to_hash_str && dap_hash_fast_compare(&l_to_hash, &l_event_item->hash))
+                                    break;
                             }
                         }
                     }
-- 
GitLab