diff --git a/dap_chain_global_db.c b/dap_chain_global_db.c index eb45619e4d29d506d20375f38bb5c200ab0f1665..071fe2cd1914a52a0cccc7cb224a46504688871c 100644 --- a/dap_chain_global_db.c +++ b/dap_chain_global_db.c @@ -32,6 +32,15 @@ void dap_chain_global_db_obj_clean(dap_global_db_obj_t *obj) obj->value = NULL; } +/** + * Delete struct dap_global_db_obj_t + */ +void dap_chain_global_db_obj_delete(dap_global_db_obj_t *obj) +{ + dap_chain_global_db_obj_clean(obj); + DAP_DELETE(obj); +} + /** * Delete mass of struct dap_global_db_obj_t */ diff --git a/dap_chain_global_db.h b/dap_chain_global_db.h index 62c5247d14dd4f4ffd350c28a847261239beb0a6..554ba942c8d196d4c3823c3f46df18fbc5725e2b 100644 --- a/dap_chain_global_db.h +++ b/dap_chain_global_db.h @@ -5,6 +5,7 @@ #include "dap_common.h" #include "dap_config.h" +#include "dap_list.h" #define GROUP_NODE "addrs_leased" #define GROUP_ALIAS "aliases_leased" @@ -21,6 +22,10 @@ typedef struct dap_global_db_obj { * Clean struct dap_global_db_obj_t */ void dap_chain_global_db_obj_clean(dap_global_db_obj_t *obj); +/** + * Delete struct dap_global_db_obj_t + */ +void dap_chain_global_db_obj_delete(dap_global_db_obj_t *obj); /** * Delete mass of struct dap_global_db_obj_t @@ -78,7 +83,9 @@ char* dap_chain_global_db_hash_fast(const uint8_t *data, size_t data_size); // Get last timestamp in log char *dap_db_log_get_last_timestamp(void); -// Get log diff +// Get log diff as list +dap_list_t* dap_db_log_get_list(time_t first_timestamp); +// Free list getting from dap_db_log_get_list() +void dap_db_log_del_list(dap_list_t *a_list); +// Get log diff as string char* dap_db_log_get_diff(size_t *a_data_size_out); - - diff --git a/dap_chain_global_db_hist.c b/dap_chain_global_db_hist.c index e6d41774c0c80583a1868e96496e7bef8c9d3ca8..52766ebc3ae2c57bbfb7d20c1927ddbd53c50e3c 100644 --- a/dap_chain_global_db_hist.c +++ b/dap_chain_global_db_hist.c @@ -113,7 +113,38 @@ char *dap_db_log_get_last_timestamp(void) } /** - * Get log diff + * Get log diff as list + */ +dap_list_t* dap_db_log_get_list(time_t first_timestamp) +{ + dap_list_t *l_list = NULL; + char *l_first_key = dap_strdup_printf("%lld", (int64_t) first_timestamp); + size_t l_data_size_out = 0; + dap_global_db_obj_t **l_objs = dap_chain_global_db_gr_load(GROUP_HISTORY, &l_data_size_out); + for(size_t i = 0; i < l_data_size_out; i++) { + dap_global_db_obj_t *l_obj_cur = l_objs[i]; + if(strcmp(l_first_key, l_obj_cur->key) < 0) { + dap_global_db_obj_t *l_item = DAP_NEW(dap_global_db_obj_t); + l_item->key = dap_strdup(l_obj_cur->key); + l_item->value = dap_strdup(l_obj_cur->value); + l_list = dap_list_append(l_list, l_item); + } + } + DAP_DELETE(l_first_key); + dap_chain_global_db_objs_delete(l_objs); + return l_list; +} + +/** + * Free list getting from dap_db_log_get_list() + */ +void dap_db_log_del_list(dap_list_t *a_list) +{ + dap_list_free_full(a_list, dap_chain_global_db_obj_delete); +} + +/** + * Get log diff as string */ char* dap_db_log_get_diff(size_t *a_data_size_out) {