From ef4307ca871adb31144ecee5fc0c71ec4ccf8931 Mon Sep 17 00:00:00 2001 From: "roman.padenkov" <roman.padenkov@demlabs.net> Date: Tue, 18 Jun 2024 16:09:23 +0700 Subject: [PATCH] ... --- dap-sdk | 2 +- modules/net/dap_chain_node_cli_cmd.c | 33 ++++++++------------ modules/net/include/dap_chain_node_cli_cmd.h | 15 +++++++++ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/dap-sdk b/dap-sdk index f2c45d6028..a17cf9dbf1 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit f2c45d60289d4fa642c56d0f3580df2183828d3f +Subproject commit a17cf9dbf1360db73794fae6455f26955cd4c548 diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 1c9e8ce9ea..0a4abac3fc 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -384,6 +384,7 @@ static int s_node_info_list_with_reply(dap_chain_net_t *a_net, dap_chain_node_ad */ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) { + json_object **json_arr_reply = (json_object **)a_str_reply; enum { CMD_NONE, CMD_NAME_CELL, CMD_ADD, CMD_FLUSH, CMD_RECORD, CMD_WRITE, CMD_READ, CMD_DELETE, CMD_DROP, CMD_GET_KEYS, CMD_GROUP_LIST @@ -414,27 +415,19 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) case CMD_NAME_CELL: { if(!arg_index || a_argc < 3) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "parameters are not valid"); - return -1; + dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR, "parameters are not valid"); + return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR; } dap_chain_t * l_chain = NULL; dap_chain_net_t * l_net = NULL; - if(dap_chain_node_cli_cmd_values_parse_net_chain(&arg_index, a_argc, a_argv, a_str_reply, &l_chain, &l_net, - CHAIN_TYPE_INVALID) < 0) - return -11; + if (dap_chain_node_cli_cmd_values_parse_net_chain_for_json(&arg_index, a_argc, a_argv, &l_chain, &l_net, CHAIN_TYPE_INVALID) < 0) + return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR; const char *l_cell_str = NULL, *l_chain_str = NULL; // find cell and chain dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-cell", &l_cell_str); - dap_cli_server_cmd_find_option_val(a_argv, arg_index, a_argc, "-chain", &l_chain_str); - - // Check for chain - if(!l_chain_str) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "%s requires parameter 'chain' to be valid", a_argv[0]); - return -12; - } - + int arg_index_n = ++arg_index; // find command (add, delete, etc) as second parameter only int cmd_num = CMD_NONE; @@ -454,23 +447,23 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) // add new node to global_db case CMD_ADD: if(!arg_index || a_argc < 7) { - dap_cli_server_cmd_set_reply_text(a_str_reply, "invalid parameters"); - return -1; + dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR, "invalid parameters"); + return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR; } dap_chain_cell_t *l_cell = dap_chain_cell_create_fill(l_chain, l_cell_id); int l_ret = (int)dap_chain_cell_file_update(l_cell); if(l_ret > 0) - dap_cli_server_cmd_set_reply_text(a_str_reply, "cell added successfully"); + dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK, "cell added successfully"); ПЕРЕДЕЛÐТЬ else - dap_cli_server_cmd_set_reply_text(a_str_reply, "can't create file for cell 0x%016"DAP_UINT64_FORMAT_X" ( %s )", - l_cell->id.uint64,l_cell->file_storage_path); + dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_CAN_CREATE_CELL_ERR, "can't create file for cell 0x%016"DAP_UINT64_FORMAT_X" ( %s )", + l_cell->id.uint64,l_cell->file_storage_path); dap_chain_cell_close(l_cell); return l_ret; //case CMD_NONE: default: - dap_cli_server_cmd_set_reply_text(a_str_reply, "command %s not recognized", a_argv[1]); - return -1; + dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_COMMAND_ERR, "command %s not recognized", a_argv[1]); + return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_COMMAND_ERR; } } } diff --git a/modules/net/include/dap_chain_node_cli_cmd.h b/modules/net/include/dap_chain_node_cli_cmd.h index c92790aa31..810f81e865 100644 --- a/modules/net/include/dap_chain_node_cli_cmd.h +++ b/modules/net/include/dap_chain_node_cli_cmd.h @@ -56,6 +56,21 @@ typedef enum s_com_parse_net_chain_err{ * global_db command */ int com_global_db(int a_argc, char **a_argv, void **a_str_reply); +typedef enum s_com_global_db_json_err { + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_OK = 0, + + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_PARAM_ERR, + + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_REQUIRE_PARAMETER_JSON = DAP_JSON_RPC_ERR_CODE_METHOD_ERR_START, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_CAN_NOT_OPEN_JSON_FILE, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_WRONG_JSON_FORMAT, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_REQUIRE_PARAMETER_NET, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_NOT_FOUNT_NET_BY_NAME, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_NOT_FOUNT_CHAIN_BY_NAME, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_NOT_FOUNT_ARRAY_ITEMS, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_INVALID_ITEMS, + DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_JSON_CAN_NOT_ADD_TRANSACTION_TO_MEMPOOL +}s_com_global_db_json_err_t; /** * Node command -- GitLab