From 485887f1410b3d31e2b812a64c67a8bd01c4a897 Mon Sep 17 00:00:00 2001 From: Aleksandr Lysikov <lysikov@inbox.ru> Date: Sun, 12 May 2019 19:10:13 +0500 Subject: [PATCH] added new command print_log --- dap_chain_net.c | 16 ---------------- dap_chain_node_cli.c | 4 ++++ dap_chain_node_cli_cmd.c | 40 +++++++++++++++++++++++++++++++++++++--- dap_chain_node_cli_cmd.h | 3 +++ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/dap_chain_net.c b/dap_chain_net.c index fdf4ca9b82..cd2df9fb4e 100644 --- a/dap_chain_net.c +++ b/dap_chain_net.c @@ -242,22 +242,6 @@ dap_chain_net_t * dap_chain_net_new(const char * a_id, const char * a_name , DAP_DELETE(ret); return NULL; } - else if(strcmp(a_node_role, "master") == 0) { - PVT(ret)->node_role.enums = MASTER; - log_it(L_NOTICE, "Node role \"root\" selected"); - } - else if(strcmp(a_node_role, "archive") == 0) { - PVT(ret)->node_role.enums = ARCHIVE; - log_it(L_NOTICE, "Node role \"root\" selected"); - } - else if(strcmp(a_node_role, "full") == 0) { - PVT(ret)->node_role.enums = FULL; - log_it(L_NOTICE, "Node role \"root\" selected"); - } - else if(strcmp(a_node_role, "ligth") == 0) { - PVT(ret)->node_role.enums = LIGHT; - log_it(L_NOTICE, "Node role \"root\" selected"); - } } else { log_it (L_ERROR, "Wrong id format (\"%s\"). Must be like \"0x0123456789ABCDE\"" , a_id ); DAP_DELETE(ret); diff --git a/dap_chain_node_cli.c b/dap_chain_node_cli.c index 9b84aefe79..be7a283764 100644 --- a/dap_chain_node_cli.c +++ b/dap_chain_node_cli.c @@ -515,6 +515,10 @@ int dap_chain_node_cli_init(dap_config_t * g_config) dap_chain_node_cli_cmd_item_create ("tx_verify", com_tx_verify, "Verifing transaction", "tx_verify -wallet <wallet name> [-path <wallet path>]\n" ); + // Log + dap_chain_node_cli_cmd_item_create ("print_log", com_print_log, "Print log info", + "print_log [ts_after <timestamp >] [limit <line numbers>]\n" ); + // init client for handshake diff --git a/dap_chain_node_cli_cmd.c b/dap_chain_node_cli_cmd.c index cfaad25feb..71e410f37c 100644 --- a/dap_chain_node_cli_cmd.c +++ b/dap_chain_node_cli_cmd.c @@ -1904,7 +1904,7 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) const char * l_certs_str = NULL; dap_chain_cert_t ** l_certs = NULL; - size_t l_certs_count = 0; + size_t l_certs_size = 0; const char * l_chain_str = NULL; dap_chain_t * l_chain; @@ -1950,7 +1950,7 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) // Load certs dap_chain_cert_parse_str_list(l_certs_str,&l_certs,&l_certs_size); - if(!l_certs_count) { + if(!l_certs_size) { dap_chain_node_cli_set_reply_text(str_reply, "token_emit command requres at least one valid certificate to sign the basic transaction of emission"); return -5; @@ -2035,7 +2035,7 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) dap_chain_datum_tx_add_item(&l_tx, (const uint8_t*) l_out); // Sign all that we have with certs - for(size_t i = 0; i < l_certs_count; i++) { + for(size_t i = 0; i < l_certs_size; i++) { if(dap_chain_datum_tx_add_sign_item(&l_tx, l_certs[i]->enc_key) < 0) { dap_chain_node_cli_set_reply_text(str_reply, "No private key for certificate=%s", l_certs[i]->name); @@ -2228,3 +2228,37 @@ int com_tx_verify(int argc, const char ** argv, char **str_reply) dap_chain_node_cli_set_reply_text(str_reply, "command not defined, enter \"help <cmd name>\""); return -1; } + +/** + * print_log command + * + * Print log info + * print_log [ts_after <timestamp >] [limit <line numbers>] + */ +int com_print_log(int argc, const char ** argv, char **str_reply) +{ + int arg_index = 1; + const char * l_str_ts_after = NULL; + const char * l_str_limit = NULL; + int64_t l_ts_after = 0; + int32_t l_limit = 0; + dap_chain_node_cli_find_option_val(argv, arg_index, argc, "ts_after", &l_str_ts_after); + dap_chain_node_cli_find_option_val(argv, arg_index, argc, "limit", &l_str_limit); + + l_ts_after = (l_str_ts_after) ? strtoll(l_str_ts_after, 0, 10) : -1; + l_limit = (l_str_limit) ? strtol(l_str_limit, 0, 10) : -1; + + if(l_ts_after<0 || !l_str_ts_after) { + dap_chain_node_cli_set_reply_text(str_reply, "requires valid parameter 'l_ts_after'"); + return -1; + } + if(!l_limit) { + dap_chain_node_cli_set_reply_text(str_reply, "requires valid parameter 'limit'"); + return -1; + } + + char *l_str_ret = NULL; + dap_chain_node_cli_set_reply_text(str_reply, l_str_ret); + return -1; +} + diff --git a/dap_chain_node_cli_cmd.h b/dap_chain_node_cli_cmd.h index 3428ccb42a..47a195186f 100644 --- a/dap_chain_node_cli_cmd.h +++ b/dap_chain_node_cli_cmd.h @@ -111,5 +111,8 @@ int com_tx_cond_create(int argc, const char ** argv, char **str_reply); */ int com_tx_verify(int argc, const char ** argv, char **str_reply); +// Print log info +int com_print_log(int argc, const char ** argv, char **str_reply); + int com_mempool_list(int argc, const char ** argv, char ** a_str_reply); int com_mempool_proc(int argc, const char ** argv, char ** a_str_reply); -- GitLab