diff --git a/CMakeLists.txt b/CMakeLists.txt index 40330f339a6c485bfe21d38e1ed4e91c22957826..685992e884dc94285a448b2fa9a2f633cb469005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ endif() # Networking if (CELLFRAME_MODULES MATCHES "network") message("[+] Module 'network'") - set(CELLFRAME_LIBS ${CELLFRAME_LIBS} dap_server_core dap_enc_server dap_http_server dap_udp_server dap_session + set(CELLFRAME_LIBS ${CELLFRAME_LIBS} dap_server_core dap_json_rpc dap_enc_server dap_http_server dap_udp_server dap_session dap_stream dap_stream_ch dap_client dap_stream_ch_chain dap_stream_ch_chain_net dap_chain_net dap_chain_mempool magic) endif() diff --git a/dap-sdk/net/server/CMakeLists.txt b/dap-sdk/net/server/CMakeLists.txt index dfc4ed963be9cd4d6bfd7e7d7dbaa46d5bbf32e8..498ed08f7e69ff297e6a347ddc215c5cdfc56b08 100644 --- a/dap-sdk/net/server/CMakeLists.txt +++ b/dap-sdk/net/server/CMakeLists.txt @@ -7,6 +7,7 @@ endif() add_subdirectory(http_server) add_subdirectory(enc_server) +add_subdirectory(json_rpc) if (BUILD_LIB_DAP_SERVER_TESTS) enable_testing() diff --git a/dap-sdk/net/server/json_rpc/CMakeLists.txt b/dap-sdk/net/server/json_rpc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c6ac9cea29ad497ba58da6433ec80bfb2b8e1d3 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/CMakeLists.txt @@ -0,0 +1,17 @@ +project(dap_json_rpc C) +cmake_minimum_required(VERSION 3.0) + +add_definitions ("-D_GNU_SOURCE") +add_definitions("-Dfpic") + +file(GLOB JSON_RPC_HEADERS include/*.h) +file(GLOB JSON_RPC_SRCS src/*.c) + +include_directories(${PROJECT_NAME} include/) + +add_library(${PROJECT_NAME} STATIC ${JSON_RPC_HEADERS} ${JSON_RPC_SRCS}) +target_include_directories(${PROJECT_NAME} INTERFACE . include/) +target_include_directories(${PROJECT_NAME} PUBLIC include) + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_server_core dap_http_server dap_client json-c ) +#target_link_libraries(${PROJECT_NAME} dap_core)# dap_http_server json-c) diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc.h new file mode 100644 index 0000000000000000000000000000000000000000..8032fa93860dc67564100bfe949135da45d5d591 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc.h @@ -0,0 +1,47 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + + +#pragma once +#include "dap_http_simple.h" +#include "include/http_status_code.h" +#include "dap_strfuncs.h" +#include "dap_json_rpc_request.h" +#include "dap_json_rpc_request_handler.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef enum dap_json_rpc_version{ + RPC_VERSION_1 +}dap_json_rpc_version_t; + +int dap_json_rpc_init(); +void dap_json_rpc_deinit(); +void dap_json_rpc_add_proc_http(struct dap_http *sh, const char *URL); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_errors.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_errors.h new file mode 100644 index 0000000000000000000000000000000000000000..c0811b0afbdbfb33a61de35f6a67879f143d2eb0 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_errors.h @@ -0,0 +1,70 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "dap_common.h" +#include "dap_strfuncs.h" +#include "utlist.h" +#include "json-c/json.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct dap_json_rpc_error +{ + int code_error; + char *msg; + void *next; +}dap_json_rpc_error_t; + +typedef struct dap_json_rpc_error_JSON +{ + json_object *obj_code; + json_object *obj_msg; +}dap_json_rpc_error_JSON_t; + +int dap_json_rpc_error_init(void); +void dap_json_rpc_error_deinit(void); + +dap_json_rpc_error_JSON_t * dap_json_rpc_error_JSON_create(); +void dap_json_rpc_error_JSON_free(dap_json_rpc_error_JSON_t *a_error_json); +dap_json_rpc_error_JSON_t * dap_json_rpc_error_JSON_add_data(int code, const char *msg); + +int dap_json_rpc_error_add(int a_code_error, const char *a_msg); + +dap_json_rpc_error_t *dap_json_rpc_error_search_by_code(int a_code_error); + +char *dap_json_rpc_error_get_json(dap_json_rpc_error_t *a_error); + +dap_json_rpc_error_t *dap_json_rpc_create_from_json(const char *a_json); + +dap_json_rpc_error_t *dap_json_rpc_create_from_json_object(json_object *a_jobj); + +void dap_json_rpc_add_standart_erros(void); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_notification.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_notification.h new file mode 100644 index 0000000000000000000000000000000000000000..239ac8ecfea0bef24862d386b0ac6216aeb02819 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_notification.h @@ -0,0 +1,49 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once + +#include "dap_json_rpc_request.h" +#include "uthash.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (notification_handler_func_t)(dap_json_rpc_params_t *a_param); + +typedef struct dap_json_rpc_notification_handler +{ + char *method; + notification_handler_func_t *func; + UT_hash_handle hh; +}dap_json_rpc_notification_handler_t; + +int dap_json_rpc_notification_registration(const char *a_method, notification_handler_func_t *a_notification_func); +void dap_json_rpc_notification_unregistration(const char *a_method); + +void dap_json_rpc_notification_handler(const char *a_name_method, dap_json_rpc_params_t *a_params); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_params.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_params.h new file mode 100644 index 0000000000000000000000000000000000000000..9068f4a0ff217aee3e8a8533599c558882140601 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_params.h @@ -0,0 +1,73 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "dap_common.h" +#include "dap_strfuncs.h" +#include "json-c/json.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef enum dap_json_rpc_type_param{ + TYPE_PARAM_NULL, + TYPE_PARAM_STRING, + TYPE_PARAM_INTEGER, + TYPE_PARAM_DOUBLE, + TYPE_PARAM_BOOLEAN +}dap_json_rpc_type_param_t; + +typedef struct dap_json_rpc_param +{ + void *value_param; + enum dap_json_rpc_type_param type; +}dap_json_rpc_param_t; + +typedef struct dap_json_rpc_params +{ + uint32_t lenght; + dap_json_rpc_param_t **params; +}dap_json_rpc_params_t; + +dap_json_rpc_params_t* dap_json_rpc_params_create(void); + +void dap_json_rpc_params_add_data(dap_json_rpc_params_t *a_params, const void *a_value, + dap_json_rpc_type_param_t a_type); +void dap_json_rpc_params_add_param(dap_json_rpc_params_t *a_params, dap_json_rpc_param_t *a_param); + +void dap_json_rpc_params_remove_all(dap_json_rpc_params_t *a_params); + +uint32_t dap_json_rpc_params_lenght(dap_json_rpc_params_t *a_params); +void *dap_json_rpc_params_get(dap_json_rpc_params_t *a_params, uint32_t index); +dap_json_rpc_type_param_t dap_json_rpc_params_get_type_param(dap_json_rpc_params_t *a_params, uint32_t index); + +void dap_json_rpc_param_remove(dap_json_rpc_param_t *param); + +dap_json_rpc_params_t * dap_json_rpc_params_create_from_array_list(json_object *a_array_list); +char *dap_json_rpc_params_get_string_json(dap_json_rpc_params_t * a_params); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request.h new file mode 100644 index 0000000000000000000000000000000000000000..9182f64c757982166eaf5e6c6557a1a281aa5e4c --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request.h @@ -0,0 +1,57 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once +#include "dap_common.h" +#include "dap_json_rpc_params.h" +#include "json-c/json.h" +#include "dap_json_rpc_response_handler.h" +#include "dap_string.h" +#include "dap_client_http.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct dap_json_rpc_request +{ + char* method; + dap_json_rpc_params_t *params; + uint64_t id; +}dap_json_rpc_request_t; + +int dap_json_rpc_request_init(const char *a_url_service); + +dap_json_rpc_request_t *dap_json_rpc_request_creation(const char *a_method, dap_json_rpc_params_t *a_params, int64_t a_id); + +dap_json_rpc_request_t *dap_json_rpc_request_from_json(const char *a_data); +char *dap_json_rpc_request_to_json(const dap_json_rpc_request_t *a_request); + +void dap_json_rpc_request_send(dap_json_rpc_request_t *a_request, dap_json_rpc_response_handler_func_t *response_handler, + const char *a_uplink_addr, const uint16_t a_uplink_port, + dap_client_http_callback_error_t func_error); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request_handler.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request_handler.h new file mode 100644 index 0000000000000000000000000000000000000000..64f9adc60e9ef37180c78894436ddd8235df4c50 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_request_handler.h @@ -0,0 +1,56 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "dap_common.h" +#include "dap_strfuncs.h" +#include "dap_json_rpc_request.h" +#include "dap_json_rpc_params.h" +#include "dap_http_simple.h" +#include "dap_json_rpc_errors.h" +#include "dap_json_rpc_response.h" +#include "dap_json_rpc_notification.h" +#include "uthash.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (handler_func_t)(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +typedef struct dap_json_rpc_request_handler +{ + char *name; + handler_func_t *func; + UT_hash_handle hh; +}dap_json_rpc_request_handler_t; + +int dap_json_rpc_registration_request_handler(const char *a_name, handler_func_t *a_func); +int dap_json_rpc_unregistration_request_handler(const char *a_name); + +void dap_json_rpc_request_handler(dap_json_rpc_request_t *a_request, dap_http_simple_t *a_client); +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response.h new file mode 100644 index 0000000000000000000000000000000000000000..40ef6ac826e0b774eea4b2ea04a65ecfdbf693f0 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response.h @@ -0,0 +1,74 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "dap_http_simple.h" +#include "dap_json_rpc_errors.h" +#include "json-c/json.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef enum dap_json_rpc_response_type_result{ + TYPE_RESPONSE_NULL, + TYPE_RESPONSE_STRING, + TYPE_RESPONSE_INTEGER, + TYPE_RESPONSE_DOUBLE, + TYPE_RESPONSE_BOOLEAN +}dap_json_rpc_response_type_result_t; + +typedef struct dap_json_rpc_response_JSON +{ + json_object *obj_result; + json_object *obj_error; + dap_json_rpc_error_JSON_t *struct_error; + json_object *obj_id; +}dap_json_rpc_request_JSON_t; + +void dap_json_rpc_request_JSON_free(dap_json_rpc_request_JSON_t *l_request_JSON); + +typedef struct dap_json_rpc_response +{ + dap_json_rpc_response_type_result_t type_result; + char* result_string; + int64_t result_int; + double result_double; + bool result_boolean; + dap_json_rpc_error_t* error; + int64_t id; +}dap_json_rpc_response_t; + + +void dap_json_rpc_response_free(dap_json_rpc_response_t *a_response); + +void dap_json_rpc_response_send(dap_json_rpc_response_t *a_response, dap_http_simple_t *a_client); + +dap_json_rpc_response_t *dap_json_rpc_response_from_json(char *a_data_json); + + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response_handler.h b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response_handler.h new file mode 100644 index 0000000000000000000000000000000000000000..1861ac2ce9a8bd08b738b498389529d356a9769f --- /dev/null +++ b/dap-sdk/net/server/json_rpc/include/dap_json_rpc_response_handler.h @@ -0,0 +1,55 @@ +/* + * Authors: + * Alexey V. Stratulat <alexey.stratulat@demlabs.net> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk + * Copyright (c) 2017-2020 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "dap_json_rpc_response.h" +#include "uthash.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (dap_json_rpc_response_handler_func_t)(dap_json_rpc_response_t *a_response); + +typedef struct dap_json_rpc_response_handler +{ + dap_json_rpc_response_handler_func_t *func; + uint64_t id; + UT_hash_handle hh; +}dap_json_rpc_response_handler_t; + +int dap_json_rpc_response_registration_with_id(uint64_t a_id, dap_json_rpc_response_handler_func_t *func); +uint64_t dap_json_rpc_response_registration(dap_json_rpc_response_handler_func_t *func); +void dap_json_rpc_response_unregistration(uint64_t a_id); + +void dap_json_rpc_response_handler(dap_json_rpc_response_t *a_response); + +uint64_t dap_json_rpc_response_get_new_id(void); + +void dap_json_rpc_response_accepted(void *a_data, size_t a_size_data, void *a_obj); + +#ifdef __cplusplus +} +#endif diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc.c new file mode 100644 index 0000000000000000000000000000000000000000..57832ccd9438745f63b2b641dacd9382e9ce5a98 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc.c @@ -0,0 +1,35 @@ +#include "dap_json_rpc.h" + +#define LOG_TAG "dap_json_rpc_rpc" + +static bool init_module = false; + +int dap_json_rpc_init() +{ + init_module = true; + return 0; +} + +void dap_json_rpc_deinit() +{ + // +} + +void _json_rpc_http_proc(struct dap_http_simple *a_client, void *a_arg) +{ + log_it(L_DEBUG, "Proc json_rpc request"); + http_status_code_t *l_http_code = (http_status_code_t*)a_arg; + dap_json_rpc_request_t *l_request = dap_json_rpc_request_from_json(a_client->request); + if (l_request){ + dap_json_rpc_request_handler(l_request, a_client); + } else { + *l_http_code = Http_Status_NotFound; + } + *l_http_code = Http_Status_OK; +} + +void dap_json_rpc_add_proc_http(struct dap_http *sh, const char *URL) +{ + dap_http_simple_proc_add(sh, URL, 140000, _json_rpc_http_proc); + dap_json_rpc_request_init(URL); +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_errors.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_errors.c new file mode 100644 index 0000000000000000000000000000000000000000..6d465ddcc6553e861eede6ab1ccd7870f9b97696 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_errors.c @@ -0,0 +1,120 @@ +#include "dap_json_rpc_errors.h" + +#define LOG_TAG "dap_json_rpc_errors" + +static dap_json_rpc_error_t *s_errors; +int _dap_json_rpc_error_cmp_by_code(dap_json_rpc_error_t *a_error, int a_code_error); + +int dap_json_rpc_error_init(void) +{ + s_errors = NULL; + return 0; +} +void dap_json_rpc_error_deinit(void) +{ + dap_json_rpc_error_t *err, *tmp; + if (s_errors != NULL){ + LL_FOREACH_SAFE(s_errors, err, tmp){ + LL_DELETE(s_errors, err); + DAP_FREE(err->msg); + DAP_FREE(err); + } + } +} + +dap_json_rpc_error_JSON_t * dap_json_rpc_error_JSON_create() +{ + dap_json_rpc_error_JSON_t *l_json = DAP_NEW(dap_json_rpc_error_JSON_t); + l_json->obj_msg = NULL; + l_json->obj_code = NULL; + return l_json; +} +void dap_json_rpc_error_JSON_free(dap_json_rpc_error_JSON_t *a_error_json) +{ + json_object_put(a_error_json->obj_code); + json_object_put(a_error_json->obj_msg); + DAP_FREE(a_error_json); +} +dap_json_rpc_error_JSON_t * dap_json_rpc_error_JSON_add_data(int code, const char *msg) +{ + dap_json_rpc_error_JSON_t *l_json_err = dap_json_rpc_error_JSON_create(); + l_json_err->obj_code = json_object_new_int(code); + l_json_err->obj_msg = json_object_new_string(msg); + return l_json_err; +} + +int dap_json_rpc_error_add(int a_code_error, const char *a_msg) +{ + dap_json_rpc_error_t *l_el_search =dap_json_rpc_error_search_by_code(a_code_error); + if (l_el_search != NULL) + return 1; + dap_json_rpc_error_t *l_error = DAP_NEW(dap_json_rpc_error_t); + l_error->code_error = a_code_error; + l_error->msg = dap_strdup(a_msg); + LL_APPEND(s_errors, l_error); + log_it(L_NOTICE, "Registration type error. Code error: %d message: %s", a_code_error, a_msg); + return 0; +} + +int _dap_json_rpc_error_cmp_by_code(dap_json_rpc_error_t *a_error, int a_code_error) +{ + if (a_error->code_error == a_code_error) + return 0; + if (a_error->code_error < a_code_error) + return -1; + if (a_error->code_error > a_code_error) + return 1; +} + +dap_json_rpc_error_t *dap_json_rpc_error_search_by_code(int a_code_error) +{ + dap_json_rpc_error_t *l_element = NULL; + LL_SEARCH(s_errors, l_element, a_code_error, _dap_json_rpc_error_cmp_by_code); + return l_element; +} + +char *dap_json_rpc_error_get_json(dap_json_rpc_error_t *a_error) +{ + log_it(L_NOTICE, "Translation JSON string to struct dap_json_rpc_error"); + json_object *l_jobj_code = json_object_new_int64(a_error->code_error); + json_object *l_jobj_msg = json_object_new_string(a_error->msg); + json_object *l_jobj = json_object_new_object(); + json_object_object_add(l_jobj, "code", l_jobj_code); + json_object_object_add(l_jobj, "message", l_jobj_msg); + json_object *l_jobj_err = json_object_new_object(); + json_object_object_add(l_jobj_err, "error", l_jobj); + char *l_json_str = dap_strdup(json_object_to_json_string(l_jobj_err)); + json_object_put(l_jobj_err); + json_object_put(l_jobj_code); + json_object_put(l_jobj_msg); + json_object_put(l_jobj); + return l_json_str; +} + +dap_json_rpc_error_t *dap_json_rpc_create_from_json(const char *a_json) +{ + log_it(L_NOTICE, "Translation struct dap_json_rpc_error to JSON string"); + json_object *l_jobj = json_tokener_parse(a_json); + dap_json_rpc_error_t *l_error = dap_json_rpc_create_from_json_object(l_jobj); + json_object_put(l_jobj); + return l_error; +} + +void dap_json_rpc_add_standart_erros(void) +{ + log_it(L_DEBUG, "Registration standart type erros"); + dap_json_rpc_error_add(0, "Unknown error"); + dap_json_rpc_error_add(1, "Not found handler for this request"); +} + +dap_json_rpc_error_t *dap_json_rpc_create_from_json_object(json_object *a_jobj) +{ + dap_json_rpc_error_t *l_error = DAP_NEW(dap_json_rpc_error_t); + json_object *l_jobj_code_eror = json_object_object_get(a_jobj, "code"); + json_object *l_jobj_msg = json_object_object_get(a_jobj, "message"); + l_error->code_error = json_object_get_int64(l_jobj_code_eror); + l_error->msg = dap_strdup(json_object_get_string(l_jobj_msg)); + json_object_put(l_jobj_code_eror); + json_object_put(l_jobj_msg); + return l_error; +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_notification.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_notification.c new file mode 100644 index 0000000000000000000000000000000000000000..8c4e973bab1d1e57ab1c9b94c61f4b834b556b65 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_notification.c @@ -0,0 +1,44 @@ +#include "dap_json_rpc_notification.h" + +#define LOG_TAG "dap_json_rpc_notification" + +static dap_json_rpc_notification_handler_t *s_handler_notifications = NULL; + + +int dap_json_rpc_notification_registration(const char *a_method, notification_handler_func_t *a_notification_func) +{ + dap_json_rpc_notification_handler_t *l_handler; + HASH_FIND_STR(s_handler_notifications, a_method, l_handler); + if (l_handler == 0){ + l_handler = DAP_NEW(dap_json_rpc_notification_handler_t); + l_handler->method = dap_strdup(a_method); + l_handler->func = a_notification_func; + HASH_ADD_STR(s_handler_notifications, method, l_handler); + log_it(L_NOTICE, "Registration method %s for handler notification", a_method); + return 0; + } + return 1; +} +void dap_json_rpc_notification_unregistration(const char *a_method) +{ + dap_json_rpc_notification_handler_t *l_handler; + HASH_FIND_STR(s_handler_notifications, a_method, l_handler); + if (l_handler != NULL){ + HASH_DEL(s_handler_notifications, l_handler); + DAP_FREE(l_handler->method); + DAP_FREE(l_handler); + log_it(L_NOTICE, "Unregistration method %s. This method handler notification", a_method); + } +} + +void dap_json_rpc_notification_handler(const char *a_name_method, dap_json_rpc_params_t *a_params) +{ + dap_json_rpc_notification_handler_t *l_handler = NULL; + HASH_FIND_STR(s_handler_notifications, a_name_method, l_handler); + if (l_handler != NULL){ + l_handler->func(a_params); + log_it(L_DEBUG, "Call method handling notfication: %s", a_name_method); + } else { + log_it(L_NOTICE, "Not found method %s. This method handler notification"); + } +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_params.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_params.c new file mode 100644 index 0000000000000000000000000000000000000000..07d3835e8eb5269cebd9485dc6b7c1e1c4f831f8 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_params.c @@ -0,0 +1,160 @@ +#include "dap_json_rpc_params.h" + +#define LOG_TAG "dap_json_rpc_params" + +dap_json_rpc_params_t* dap_json_rpc_params_create(void) +{ + dap_json_rpc_params_t *l_params = DAP_NEW(dap_json_rpc_params_t); + l_params->lenght = 0; + return l_params; +} + + +void dap_json_rpc_params_add_data(dap_json_rpc_params_t *a_params, const void *a_value, + dap_json_rpc_type_param_t a_type) +{ + log_it(L_DEBUG, "Add data in params"); + dap_json_rpc_param_t *l_param = DAP_NEW(dap_json_rpc_param_t); + //l_param->name_param = dap_strdup(a_name); + l_param->type = a_type; + size_t l_len_value; + switch (a_type) { + case TYPE_PARAM_STRING: + l_param->value_param = dap_strdup((char*)a_value); + break; + case TYPE_PARAM_BOOLEAN: + l_len_value = sizeof(bool); + l_param->value_param = DAP_NEW(bool); + memcpy(l_param->value_param, a_value, l_len_value); + break; + case TYPE_PARAM_INTEGER: + l_len_value = sizeof(int64_t); + l_param->value_param = DAP_NEW(int64_t); + memcpy(l_param->value_param, a_value, l_len_value); + break; + case TYPE_PARAM_DOUBLE: + l_len_value = sizeof(double); + l_param->value_param = DAP_NEW(double); + memcpy(l_param->value_param, a_value, l_len_value); + break; + default: + l_param->value_param = NULL; + break; + } + dap_json_rpc_params_add_param(a_params, l_param); +} +void dap_json_rpc_params_add_param(dap_json_rpc_params_t *a_params, dap_json_rpc_param_t *a_param) +{ + uint32_t l_len_new_params = a_params->lenght + 1; + dap_json_rpc_param_t **l_new_params = DAP_NEW_SIZE(dap_json_rpc_param_t*, l_len_new_params); + memcpy(l_new_params, a_params->params, sizeof(dap_json_rpc_param_t*) * a_params->lenght); + memcpy(l_new_params+a_params->lenght, &a_param, sizeof(dap_json_rpc_param_t*)); + if (a_params->lenght != 0) + DAP_FREE(a_params->params); + a_params->params = l_new_params; + a_params->lenght++; +} + +void dap_json_rpc_params_remove_all(dap_json_rpc_params_t *a_params) +{ + log_it(L_DEBUG, "Clean params"); + for (uint32_t i=0x0 ; i < dap_json_rpc_params_lenght(a_params); i++){ + dap_json_rpc_param_remove(a_params->params[i]); + } + DAP_FREE(a_params); +} + +uint32_t dap_json_rpc_params_lenght(dap_json_rpc_params_t *a_params) +{ + return a_params->lenght; +} + +void *dap_json_rpc_params_get(dap_json_rpc_params_t *a_params, uint32_t index) +{ + if (a_params->lenght > index) + return a_params->params[index]->value_param; + return NULL; +} + +dap_json_rpc_type_param_t dap_json_rpc_params_get_type_param(dap_json_rpc_params_t *a_params, uint32_t index) +{ + if (a_params->lenght > index) + return a_params->params[index]->type; + return TYPE_PARAM_NULL; +} + +void dap_json_rpc_param_remove(dap_json_rpc_param_t *param) +{ + DAP_FREE(param->value_param); + DAP_FREE(param); +} + +dap_json_rpc_params_t * dap_json_rpc_params_create_from_array_list(json_object *a_array_list) +{ + log_it(L_NOTICE, "Translation json_object to dap_json_rpc_params"); + if (a_array_list == NULL) + return NULL; + dap_json_rpc_params_t *l_params = dap_json_rpc_params_create(); + int l_lenght = json_object_array_length(a_array_list); + for (int i = 0; i < l_lenght; i++){ + json_object *l_jobj = json_object_array_get_idx(a_array_list, i); + json_type l_jobj_type = json_object_get_type(l_jobj); + char *l_str_tmp = NULL; + bool l_bool_tmp; + int64_t l_int_tmp; + double l_double_tmp; + switch (l_jobj_type) { + case json_type_string: + l_str_tmp = dap_strdup(json_object_get_string(l_jobj)); + dap_json_rpc_params_add_data(l_params, l_str_tmp, TYPE_PARAM_STRING); + DAP_FREE(l_str_tmp); + break; + case json_type_boolean: + l_bool_tmp = json_object_get_boolean(l_jobj); + dap_json_rpc_params_add_data(l_params, &l_bool_tmp, TYPE_PARAM_BOOLEAN); + break; + case json_type_int: + l_int_tmp = json_object_get_int64(l_jobj); + dap_json_rpc_params_add_data(l_params, &l_int_tmp, TYPE_PARAM_INTEGER); + break; + case json_type_double: + l_double_tmp = json_object_get_double(l_jobj); + dap_json_rpc_params_add_data(l_params, &l_double_tmp, TYPE_PARAM_DOUBLE); + break; + default: + dap_json_rpc_params_add_data(l_params, NULL, TYPE_PARAM_NULL); + } + } + return l_params; +} + +char *dap_json_rpc_params_get_string_json(dap_json_rpc_params_t * a_params) +{ + log_it(L_NOTICE, "Translation struct params to JSON string"); + json_object *l_jobj_array = json_object_new_array(); + for (uint32_t i = 0; i <= a_params->lenght; i++){ + json_object *l_jobj_tmp = NULL; + switch (a_params->params[i]->type) { + case TYPE_PARAM_NULL: + l_jobj_tmp = json_object_new_object(); + break; + case TYPE_PARAM_STRING: + l_jobj_tmp = json_object_new_string((char*)a_params->params[i]->value_param); + break; + case TYPE_PARAM_INTEGER: + l_jobj_tmp = json_object_new_int64(*((int64_t*)a_params->params[i]->value_param)); + break; + case TYPE_PARAM_DOUBLE: + l_jobj_tmp = json_object_new_double(*((double*)a_params->params[i]->value_param)); + break; + case TYPE_PARAM_BOOLEAN: + l_jobj_tmp = json_object_new_boolean(*((bool*)a_params->params[i]->value_param)); + break; + } + json_object_array_add(l_jobj_array, l_jobj_tmp); + json_object_put(l_jobj_tmp); + }; + char *l_str = dap_strjoin(NULL, "\"params\":", json_object_to_json_string(l_jobj_array), NULL); + json_object_put(l_jobj_array); + return l_str; +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request.c new file mode 100644 index 0000000000000000000000000000000000000000..1754423f852b97fe8d3f8ad8e5f19533dd43530c --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request.c @@ -0,0 +1,85 @@ +#include "dap_json_rpc_request.h" + +#define LOG_TAG "dap_json_rpc_request" + +static char *s_url_service = NULL; + +int dap_json_rpc_request_init(const char *a_url_service) +{ + if (s_url_service == NULL){ + s_url_service = dap_strdup(a_url_service); + return 0; + } + return 1; +} + +dap_json_rpc_request_t *dap_json_rpc_request_creation(const char *a_method, dap_json_rpc_params_t *a_params, int64_t a_id) +{ + dap_json_rpc_request_t *l_request = DAP_NEW(dap_json_rpc_request_t); + l_request->method = dap_strdup(a_method); + l_request->params = a_params; + l_request->id = a_id; + return l_request; +} + +dap_json_rpc_request_t *dap_json_rpc_request_from_json(const char *a_data) +{ + log_it(L_DEBUG, "Translation JSON string to struct dap_json_rpc_request"); + enum json_tokener_error l_jterr; + json_object *l_jobj = json_tokener_parse_verbose(a_data, &l_jterr); + json_object *l_jobj_id = NULL; + json_object *l_jobj_method = NULL; + json_object *l_jobj_params = NULL; + dap_json_rpc_request_t *l_request = DAP_NEW(dap_json_rpc_request_t); + l_request->params = NULL; + bool l_err_parse_request = false; + if (l_jterr == json_tokener_success){ + if (json_object_object_get_ex(l_jobj, "id", &l_jobj_id)){ + l_request->id = json_object_get_int64(l_jobj_id); + }else{ + log_it(L_ERROR, "Error parse JSON string, Can't searching id request"); + l_err_parse_request = true; + } + if (json_object_object_get_ex(l_jobj, "method", &l_jobj_method)){ + l_request->method = dap_strdup(json_object_get_string(l_jobj_method)); + }else{ + log_it(L_ERROR, "Error parse JSON string, Can't searching method for request with id: %lu", l_request->id); + l_err_parse_request = true; + } + if (json_object_object_get_ex(l_jobj, "params", &l_jobj_params) && !l_err_parse_request){ + l_request->params = dap_json_rpc_params_create_from_array_list(l_jobj_params); + }else{ + log_it(L_ERROR, "Error parse JSON string, Can't searching array params for request with id: %lu", l_request->id); + l_err_parse_request = true; + } + } else { + log_it(L_ERROR, "Error parse json tokener: %s", json_tokener_error_desc(l_jterr)); + l_err_parse_request = true; + } + if (l_err_parse_request){ + DAP_FREE(l_request->method); + DAP_FREE(l_request); + return NULL; + } + return l_request; + +} +char *dap_json_rpc_request_to_json(const dap_json_rpc_request_t *a_request) +{ + log_it(L_DEBUG, "Translation struct dap_json_rpc_request to JSON string"); + char *l_str = dap_strjoin(NULL, "{\"method=\":", "\"", a_request->method, "\"", "\"", "\"params\":", + dap_json_rpc_params_get_string_json(a_request->params), ", \"id\": ", a_request->id, "}", NULL); + return l_str; +} + +void dap_json_rpc_request_send(dap_json_rpc_request_t *a_request, dap_json_rpc_response_handler_func_t *response_handler, + const char *a_uplink_addr, const uint16_t a_uplink_port, + dap_client_http_callback_error_t func_error) +{ + uint64_t l_id_response = dap_json_rpc_response_registration(response_handler); + a_request->id = l_id_response; + char *l_str = dap_json_rpc_request_to_json(a_request); + log_it(L_NOTICE, "Sending request in address: %s", a_uplink_addr); + dap_client_http_request(a_uplink_addr, a_uplink_port, "POST", "application/json", s_url_service, l_str, strlen(l_str), + NULL, dap_json_rpc_response_accepted, func_error, NULL, NULL); +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request_handler.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request_handler.c new file mode 100644 index 0000000000000000000000000000000000000000..593c9c2104cf11600a7c501dcbdbfd2433d22c4e --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_request_handler.c @@ -0,0 +1,58 @@ +#include "dap_json_rpc_request_handler.h" + +#define LOG_TAG "dap_json_rpc_request_handler" + +static dap_json_rpc_request_handler_t *s_handler_hash_table = NULL; + +int dap_json_rpc_registration_request_handler(const char *a_name, handler_func_t *a_func) +{ + dap_json_rpc_request_handler_t *l_handler; + HASH_FIND_STR(s_handler_hash_table, a_name, l_handler); + if (l_handler == NULL){ + l_handler = DAP_NEW(dap_json_rpc_request_handler_t); + l_handler->name = dap_strdup(a_name); + l_handler->func = a_func; + HASH_ADD_STR(s_handler_hash_table, name, l_handler); + log_it(L_NOTICE, "Registration handler for request name: %s", a_name); + return 0; + } + return 1; +} +int dap_json_rpc_unregistration_request_handler(const char *a_name) +{ + dap_json_rpc_request_handler_t *l_handler; + HASH_FIND_STR(s_handler_hash_table, a_name, l_handler); + if (l_handler == NULL){ + return 1; + } else { + log_it(L_NOTICE, "Unregistration for handler request name: %s", a_name); + HASH_DEL(s_handler_hash_table, l_handler); + DAP_FREE(l_handler->name); + DAP_FREE(l_handler); + return 0; + } +} + +void dap_json_rpc_request_handler(dap_json_rpc_request_t *a_request, dap_http_simple_t *a_client) +{ + log_it(L_DEBUG, "Processing request"); + if (a_request->id == 0){ + dap_json_rpc_notification_handler(a_request->method, a_request->params); + } else { + dap_json_rpc_response_t *l_response = DAP_NEW(dap_json_rpc_response_t); + l_response->id = a_request->id; + dap_json_rpc_request_handler_t *l_handler = NULL; + HASH_FIND_STR(s_handler_hash_table, a_request->method, l_handler); + if (l_handler == NULL){ + dap_json_rpc_error_t *l_err = dap_json_rpc_error_search_by_code(1); + l_response->type_result = TYPE_RESPONSE_NULL; + l_response->error = l_err; + log_it(L_NOTICE, "Can't processing the request. Handler %s not registration. ", a_request->method); + } else { + l_response->error = NULL; + l_handler->func(a_request->params, l_response); + log_it(L_NOTICE, "Calling handler request name: %s", a_request->method); + } + dap_json_rpc_response_send(l_response, a_client); + } +} diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response.c new file mode 100644 index 0000000000000000000000000000000000000000..ee3e4b3e16766825ed06ea5188967fb722a6e34f --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response.c @@ -0,0 +1,106 @@ +#include "dap_json_rpc_response.h" + +#define LOG_TAG "dap_json_rpc_response" + +void dap_json_rpc_request_JSON_free(dap_json_rpc_request_JSON_t *l_request_JSON) +{ + json_object_put(l_request_JSON->obj_error); + if (l_request_JSON->struct_error) + dap_json_rpc_error_JSON_free(l_request_JSON->struct_error); + json_object_put(l_request_JSON->obj_id); + json_object_put(l_request_JSON->obj_result); + DAP_FREE(l_request_JSON); +} + +void dap_json_rpc_response_free(dap_json_rpc_response_t *a_response) +{ + DAP_FREE(a_response->error); + if (a_response->type_result == TYPE_RESPONSE_STRING){ + DAP_FREE(a_response->result_string); + } + DAP_FREE(a_response); +} + +void dap_json_rpc_response_send(dap_json_rpc_response_t *a_response, dap_http_simple_t *a_client) +{ + dap_json_rpc_request_JSON_t *l_JSON = DAP_NEW(dap_json_rpc_request_JSON_t); + json_object *l_jobj = json_object_new_object(); + l_JSON->obj_id = json_object_new_int64(a_response->id); + l_JSON->obj_error = NULL; + l_JSON->obj_result = NULL; + l_JSON->struct_error = NULL; + char *str_response = NULL; + if (a_response->error == NULL){ + switch (a_response->type_result) { + case TYPE_RESPONSE_STRING: + l_JSON->obj_result = json_object_new_string(a_response->result_string); + break; + case TYPE_RESPONSE_DOUBLE: + l_JSON->obj_result = json_object_new_double(a_response->result_double); + break; + case TYPE_RESPONSE_BOOLEAN: + l_JSON->obj_result = json_object_new_boolean(a_response->result_boolean); + break; + case TYPE_RESPONSE_INTEGER: + l_JSON->obj_result = json_object_new_int64(a_response->result_int); + break; + } + }else{ + l_JSON->struct_error = dap_json_rpc_error_JSON_add_data(a_response->error->code_error, a_response->error->msg); + l_JSON->obj_error = json_object_new_object(); + json_object_object_add(l_JSON->obj_error, "code", l_JSON->struct_error->obj_code); + json_object_object_add(l_JSON->obj_error, "message", l_JSON->struct_error->obj_msg); + } + json_object_object_add(l_jobj, "result", l_JSON->obj_result); + json_object_object_add(l_jobj, "id", l_JSON->obj_id); + json_object_object_add(l_jobj, "error", l_JSON->obj_error); + str_response = dap_strdup(json_object_to_json_string(l_jobj)); + dap_http_simple_reply(a_client, str_response, strlen(str_response)); + DAP_FREE(str_response); + json_object_put(l_jobj); + dap_json_rpc_request_JSON_free(l_JSON); +} + +dap_json_rpc_response_t *dap_json_rpc_response_from_json(char *a_data_json) +{ + json_object *l_jobj = json_tokener_parse(a_data_json); + json_object *l_jobj_result = json_object_object_get(l_jobj, "result"); + json_object *l_jobj_error = json_object_object_get(l_jobj, "error"); + json_object *l_jobj_id = json_object_object_get(l_jobj, "id"); + dap_json_rpc_response_t *l_response = DAP_NEW(dap_json_rpc_response_t); + l_response->id = json_object_get_int64(l_jobj_id); + if (json_object_is_type(l_jobj_error, json_type_null)){ + l_response->error = NULL; + switch(json_object_get_type(l_jobj_result)){ + case json_type_int: + l_response->type_result = TYPE_RESPONSE_INTEGER; + l_response->result_int = json_object_get_int64(l_jobj_result); + break; + case json_type_double: + l_response->type_result = TYPE_RESPONSE_DOUBLE; + l_response->result_double = json_object_get_double(l_jobj_result); + break; + case json_type_boolean: + l_response->type_result = TYPE_RESPONSE_BOOLEAN; + l_response->result_boolean = json_object_get_boolean(l_jobj_result); + break; + case json_type_string: + l_response->type_result = TYPE_RESPONSE_STRING; + l_response->result_string = dap_strdup(json_object_get_string(l_jobj_result)); + break; + default: + l_response->type_result = TYPE_RESPONSE_NULL; + break; + } + } else { + l_response->error = dap_json_rpc_create_from_json_object(l_jobj_error); + l_response->type_result = TYPE_RESPONSE_NULL; + } + json_object_put(l_jobj_id); + json_object_put(l_jobj_error); + json_object_put(l_jobj_result); + json_object_put(l_jobj); + return l_response; +} + + diff --git a/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response_handler.c b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response_handler.c new file mode 100644 index 0000000000000000000000000000000000000000..4419221d31e689ce06d101e563f764d3bf8f1138 --- /dev/null +++ b/dap-sdk/net/server/json_rpc/src/dap_json_rpc_response_handler.c @@ -0,0 +1,69 @@ +#include "dap_json_rpc_response_handler.h" + +#define LOG_TAG "dap_json_rpc_response_handler" + +static dap_json_rpc_response_handler_t *s_response_handlers = NULL; +static uint64_t s_delta = 0; + +int dap_json_rpc_response_registration_with_id(uint64_t a_id, dap_json_rpc_response_handler_func_t *func) +{ + dap_json_rpc_response_handler_t *l_handler = NULL; + HASH_FIND_INT(s_response_handlers, &a_id, l_handler); + if (l_handler == NULL){ + l_handler = DAP_NEW(dap_json_rpc_response_handler_t); + l_handler->id = a_id; + l_handler->func = func; + HASH_ADD_INT(s_response_handlers, id, l_handler); + log_it(L_NOTICE, "Registrayion handler response with id: %d", a_id); + return 0; + } + return 1; +} +uint64_t dap_json_rpc_response_registration(dap_json_rpc_response_handler_func_t *func) +{ + uint64_t l_id_registration_response = dap_json_rpc_response_get_new_id(); + int res = dap_json_rpc_response_registration_with_id(l_id_registration_response, func); + return res; +} +void dap_json_rpc_response_unregistration(uint64_t a_id) +{ + dap_json_rpc_response_handler_t *l_handler = NULL; + HASH_FIND_INT(s_response_handlers, &a_id, l_handler); + if (l_handler != NULL){ + HASH_DEL(s_response_handlers, l_handler); + DAP_FREE(l_handler); + log_it(L_NOTICE, "Unregistrayion handler response with id: %d", a_id); + } +} + +void dap_json_rpc_response_handler(dap_json_rpc_response_t *a_response) +{ + dap_json_rpc_response_handler_t *l_handler = NULL; + HASH_FIND_INT(s_response_handlers, (void*)a_response->id, l_handler); + if (l_handler != NULL){ + log_it(L_NOTICE, "Calling handler response id: %d", a_response->id); + l_handler->func(a_response); + dap_json_rpc_response_unregistration(a_response->id); + } else { + log_it(L_NOTICE, "Can't calling handler response id: %d. This handler not found", a_response->id); + } +} + +uint64_t dap_json_rpc_response_get_new_id(void) +{ + uint64_t l_ret = s_delta; + s_delta++; + return l_ret; +} + +void dap_json_rpc_response_accepted(void *a_data, size_t a_size_data, void *a_obj) +{ + (void) a_obj; + log_it(L_NOTICE, "Pre handling response"); + char *l_str = DAP_NEW_SIZE(char, a_size_data); + memcpy(l_str, a_data, a_size_data); + dap_json_rpc_response_t *l_response = dap_json_rpc_response_from_json(l_str); + DAP_FREE(l_str); + dap_json_rpc_response_handler(l_response); + dap_json_rpc_response_free(l_response); +} diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 6d1abf4cf3a5c10ff884a89ed9cc27c5d21277ac..a1199002a6e2a782954b38c5939c95d845f0fb39 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -7,6 +7,7 @@ endif() # Chains if (CELLFRAME_MODULES MATCHES "chains") add_subdirectory(chain) + add_subdirectory(chain/btc_rpc) add_subdirectory(wallet) add_subdirectory(global-db) endif() diff --git a/modules/chain/btc_rpc/CMakeLists.txt b/modules/chain/btc_rpc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e9ded64a179d2bda42ee9430c581d9fc0fc3ce0 --- /dev/null +++ b/modules/chain/btc_rpc/CMakeLists.txt @@ -0,0 +1,18 @@ +project(dap_chain_btc_rpc C) +cmake_minimum_required(VERSION 3.0) + +add_definitions ("-D_GNU_SOURCE") +add_definitions("-Dfpic") + +file(GLOB BTC_RPC_HEADERS include/*.h) +file(GLOB BTC_RPC_SRCS *.c) + +include_directories(${PROJECT_NAME} include/) + +add_library(${PROJECT_NAME} STATIC ${BTC_RPC_HEADERS} ${BTC_RPC_SRCS}) +target_include_directories(${PROJECT_NAME} INTERFACE . include/) +target_include_directories(${PROJECT_NAME} PUBLIC include) + +target_link_libraries(${PROJECT_NAME} dap_core dap_json_rpc) +#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_server_core dap_http_server dap_client json-c ) +#target_link_libraries(${PROJECT_NAME} dap_core)# dap_http_server json-c) diff --git a/modules/chain/btc_rpc/dap_chain_btc_rpc.c b/modules/chain/btc_rpc/dap_chain_btc_rpc.c new file mode 100644 index 0000000000000000000000000000000000000000..448528116b41719aa8000aa430b130b82a4e334c --- /dev/null +++ b/modules/chain/btc_rpc/dap_chain_btc_rpc.c @@ -0,0 +1,9 @@ +#include "dap_chain_btc_rpc.h" + +int dap_chain_btc_rpc_init(){ + dap_chain_btc_rpc_registration_handlers(); + return 0; +} +void dap_chain_btc_rpc_deinit(){ + dap_chain_btc_rpc_unregistration_handlers(); +} diff --git a/modules/chain/btc_rpc/dap_chain_btc_rpc_handlers.c b/modules/chain/btc_rpc/dap_chain_btc_rpc_handlers.c new file mode 100644 index 0000000000000000000000000000000000000000..e39ce1a2e702aa9f0b3fe55bf0952526c5241c17 --- /dev/null +++ b/modules/chain/btc_rpc/dap_chain_btc_rpc_handlers.c @@ -0,0 +1,143 @@ +#include "dap_chain_btc_rpc_handlers.h" + +void dap_chain_btc_rpc_registration_handlers(){ + dap_json_rpc_registration_request_handler("addmultisigaddress", dap_chain_btc_rpc_handler_addmultisigaddress); + dap_json_rpc_registration_request_handler("addnode", dap_chain_btc_rpc_handler_addnode); + dap_json_rpc_registration_request_handler("backupwallet", dap_chain_btc_rpc_handler_backupwallet); + dap_json_rpc_registration_request_handler("createmultisig", dap_chain_btc_rpc_handler_createmultisig); + dap_json_rpc_registration_request_handler("createrawtransaction", dap_chain_btc_rpc_handler_createrawtransaction); + dap_json_rpc_registration_request_handler("decoderawtransaction", dap_chain_btc_rpc_handler_decoderawtransaction); + dap_json_rpc_registration_request_handler("dumpprivkey", dap_chain_btc_rpc_handler_dumpprivkey); + dap_json_rpc_registration_request_handler("dumpwallet", dap_chain_btc_rpc_handler_dumpwallet); + dap_json_rpc_registration_request_handler("encryptwallet", dap_chain_btc_rpc_handler_encryptwallet); + dap_json_rpc_registration_request_handler("getaccount", dap_chain_btc_rpc_handler_getaccount); + dap_json_rpc_registration_request_handler("getaccountaddress", dap_chain_btc_rpc_handler_getaccountaddress); + dap_json_rpc_registration_request_handler("getaddednodeinfo", dap_chain_btc_rpc_handler_getaddednodeinfo); + dap_json_rpc_registration_request_handler("getaddressesbyaccount", dap_chain_btc_rpc_handler_getaddressesbyaccount); + dap_json_rpc_registration_request_handler("getbalance", dap_chain_btc_rpc_handler_getbalance); + dap_json_rpc_registration_request_handler("getbestblockhash", dap_chain_btc_rpc_handler_getbestblockhash); + dap_json_rpc_registration_request_handler("getblock", dap_chain_btc_rpc_handler_getblock); + dap_json_rpc_registration_request_handler("getblockcount", dap_chain_btc_rpc_handler_getblockcount); + dap_json_rpc_registration_request_handler("getblockhash", dap_chain_btc_rpc_handler_getblockhash); + dap_json_rpc_registration_request_handler("getblocknumber", dap_chain_btc_rpc_handler_getblocknumber); + dap_json_rpc_registration_request_handler("getblocktemplate", dap_chain_btc_rpc_handler_getblocktemplate); + dap_json_rpc_registration_request_handler("getconnectioncount", dap_chain_btc_rpc_handler_getconnectioncount); + dap_json_rpc_registration_request_handler("getdifficulty", dap_chain_btc_rpc_handler_getdifficulty); + dap_json_rpc_registration_request_handler("getgenerate", dap_chain_btc_rpc_handler_getgenerate); + dap_json_rpc_registration_request_handler("gethashespersec", dap_chain_btc_rpc_handler_gethashespersec); + dap_json_rpc_registration_request_handler("getinfo", dap_chain_btc_rpc_handler_getinfo); + dap_json_rpc_registration_request_handler("getmemorypool", dap_chain_btc_rpc_handler_getmemorypool); + dap_json_rpc_registration_request_handler("getmininginfo", dap_chain_btc_rpc_handler_getmininginfo); + dap_json_rpc_registration_request_handler("getnewaddress", dap_chain_btc_rpc_handler_getnewaddress); + dap_json_rpc_registration_request_handler("getpeerinfo", dap_chain_btc_rpc_handler_getpeerinfo); + dap_json_rpc_registration_request_handler("getrawchangeaddress", dap_chain_btc_rpc_handler_getrawchangeaddress); + dap_json_rpc_registration_request_handler("getrawmempool", dap_chain_btc_rpc_handler_getrawmempool); + dap_json_rpc_registration_request_handler("getrawtransaction", dap_chain_btc_rpc_handler_getrawtransaction); + dap_json_rpc_registration_request_handler("getreceivedbyaccount", dap_chain_btc_rpc_handler_getreceivedbyaccount); + dap_json_rpc_registration_request_handler("getreceivedbyaddress", dap_chain_btc_rpc_handler_getreceivedbyaddress); + dap_json_rpc_registration_request_handler("gettransaction", dap_chain_btc_rpc_handler_gettransaction); + dap_json_rpc_registration_request_handler("gettxout", dap_chain_btc_rpc_handler_gettxout); + dap_json_rpc_registration_request_handler("gettxoutsetinfo", dap_chain_btc_rpc_handler_gettxoutsetinfo); + dap_json_rpc_registration_request_handler("getwork", dap_chain_btc_rpc_handler_getwork); + dap_json_rpc_registration_request_handler("help", dap_chain_btc_rpc_handler_help); + dap_json_rpc_registration_request_handler("importprivkey", dap_chain_btc_rpc_handler_importprivkey); + dap_json_rpc_registration_request_handler("invalidateblock", dap_chain_btc_rpc_handler_invalidateblock); + dap_json_rpc_registration_request_handler("keypoolrefill", dap_chain_btc_rpc_handler_keypoolrefill); + dap_json_rpc_registration_request_handler("listaccounts", dap_chain_btc_rpc_handler_listaccounts); + dap_json_rpc_registration_request_handler("listaddressgroupings", dap_chain_btc_rpc_handler_listaddressgroupings); + dap_json_rpc_registration_request_handler("listreceivedbyaccount", dap_chain_btc_rpc_handler_listreceivedbyaccount); + dap_json_rpc_registration_request_handler("listreceivedbyaddress", dap_chain_btc_rpc_handler_listreceivedbyaddress); + dap_json_rpc_registration_request_handler("listsinceblock", dap_chain_btc_rpc_handler_listsinceblock); + dap_json_rpc_registration_request_handler("listtransactions", dap_chain_btc_rpc_handler_listtransactions); + dap_json_rpc_registration_request_handler("listunspent", dap_chain_btc_rpc_handler_listunspent); + dap_json_rpc_registration_request_handler("listlockunspent", dap_chain_btc_rpc_handler_listlockunspent); + dap_json_rpc_registration_request_handler("lockunspent", dap_chain_btc_rpc_handler_lockunspent); + dap_json_rpc_registration_request_handler("move", dap_chain_btc_rpc_handler_move); + dap_json_rpc_registration_request_handler("sendfrom", dap_chain_btc_rpc_handler_sendfrom); + dap_json_rpc_registration_request_handler("sendmany", dap_chain_btc_rpc_handler_sendmany); + dap_json_rpc_registration_request_handler("sendrawtransaction", dap_chain_btc_rpc_handler_sendrawtransaction); + dap_json_rpc_registration_request_handler("sendtoaddress", dap_chain_btc_rpc_handler_sendtoaddress); + dap_json_rpc_registration_request_handler("setaccount", dap_chain_btc_rpc_handler_setaccount); + dap_json_rpc_registration_request_handler("setgenerate", dap_chain_btc_rpc_handler_setgenerate); + dap_json_rpc_registration_request_handler("settxfee", dap_chain_btc_rpc_handler_settxfee); + dap_json_rpc_registration_request_handler("signmessage", dap_chain_btc_rpc_handler_signmessage); + dap_json_rpc_registration_request_handler("signrawtransaction", dap_chain_btc_rpc_handler_signrawtransaction); + dap_json_rpc_registration_request_handler("stop", dap_chain_btc_rpc_handler_stop); + dap_json_rpc_registration_request_handler("submitblock", dap_chain_btc_rpc_handler_submitblock); + dap_json_rpc_registration_request_handler("validateaddress", dap_chain_btc_rpc_handler_validateaddress); + dap_json_rpc_registration_request_handler("verifymessage", dap_chain_btc_rpc_handler_verifymessage); + dap_json_rpc_registration_request_handler("walletlock", dap_chain_btc_rpc_handler_walletlock); + dap_json_rpc_registration_request_handler("walletpassphrase", dap_chain_btc_rpc_handler_walletpassphrase); + dap_json_rpc_registration_request_handler("walletpassphrasechange", dap_chain_btc_rpc_handler_walletpassphrasechange); +} + +void dap_chain_btc_rpc_unregistration_handlers(){ + dap_json_rpc_unregistration_request_handler("addmultisigaddress"); + dap_json_rpc_unregistration_request_handler("addnode"); + dap_json_rpc_unregistration_request_handler("backupwallet"); + dap_json_rpc_unregistration_request_handler("createmultisig"); + dap_json_rpc_unregistration_request_handler("createrawtransaction"); + dap_json_rpc_unregistration_request_handler("decoderawtransaction"); + dap_json_rpc_unregistration_request_handler("dumpprivkey"); + dap_json_rpc_unregistration_request_handler("dumpwallet"); + dap_json_rpc_unregistration_request_handler("encryptwallet"); + dap_json_rpc_unregistration_request_handler("getaccount"); + dap_json_rpc_unregistration_request_handler("getaccountaddress"); + dap_json_rpc_unregistration_request_handler("getaddednodeinfo"); + dap_json_rpc_unregistration_request_handler("getaddressesbyaccount"); + dap_json_rpc_unregistration_request_handler("getbalance"); + dap_json_rpc_unregistration_request_handler("getbestblockhash"); + dap_json_rpc_unregistration_request_handler("getblock"); + dap_json_rpc_unregistration_request_handler("getblockcount"); + dap_json_rpc_unregistration_request_handler("getblockhash"); + dap_json_rpc_unregistration_request_handler("getblocknumber"); + dap_json_rpc_unregistration_request_handler("getblocktemplate"); + dap_json_rpc_unregistration_request_handler("getconnectioncount"); + dap_json_rpc_unregistration_request_handler("getdifficulty"); + dap_json_rpc_unregistration_request_handler("getgenerate"); + dap_json_rpc_unregistration_request_handler("gethashespersec"); + dap_json_rpc_unregistration_request_handler("getinfo"); + dap_json_rpc_unregistration_request_handler("getmemorypool"); + dap_json_rpc_unregistration_request_handler("getmininginfo"); + dap_json_rpc_unregistration_request_handler("getnewaddress"); + dap_json_rpc_unregistration_request_handler("getpeerinfo"); + dap_json_rpc_unregistration_request_handler("getrawchangeaddress"); + dap_json_rpc_unregistration_request_handler("getrawmempool"); + dap_json_rpc_unregistration_request_handler("getrawtransaction"); + dap_json_rpc_unregistration_request_handler("getreceivedbyaccount"); + dap_json_rpc_unregistration_request_handler("getreceivedbyaddress"); + dap_json_rpc_unregistration_request_handler("gettransaction"); + dap_json_rpc_unregistration_request_handler("gettxout"); + dap_json_rpc_unregistration_request_handler("gettxoutsetinfo"); + dap_json_rpc_unregistration_request_handler("getwork"); + dap_json_rpc_unregistration_request_handler("help"); + dap_json_rpc_unregistration_request_handler("importprivkey"); + dap_json_rpc_unregistration_request_handler("invalidateblock"); + dap_json_rpc_unregistration_request_handler("keypoolrefill"); + dap_json_rpc_unregistration_request_handler("listaccounts"); + dap_json_rpc_unregistration_request_handler("listaddressgroupings"); + dap_json_rpc_unregistration_request_handler("listreceivedbyaccount"); + dap_json_rpc_unregistration_request_handler("listreceivedbyaddress"); + dap_json_rpc_unregistration_request_handler("listsinceblock"); + dap_json_rpc_unregistration_request_handler("listtransactions"); + dap_json_rpc_unregistration_request_handler("listunspent"); + dap_json_rpc_unregistration_request_handler("listlockunspent"); + dap_json_rpc_unregistration_request_handler("lockunspent"); + dap_json_rpc_unregistration_request_handler("move"); + dap_json_rpc_unregistration_request_handler("sendfrom"); + dap_json_rpc_unregistration_request_handler("sendmany"); + dap_json_rpc_unregistration_request_handler("sendrawtransaction"); + dap_json_rpc_unregistration_request_handler("sendtoaddress"); + dap_json_rpc_unregistration_request_handler("setaccount"); + dap_json_rpc_unregistration_request_handler("setgenerate"); + dap_json_rpc_unregistration_request_handler("settxfee"); + dap_json_rpc_unregistration_request_handler("signmessage"); + dap_json_rpc_unregistration_request_handler("signrawtransaction"); + dap_json_rpc_unregistration_request_handler("stop"); + dap_json_rpc_unregistration_request_handler("submitblock"); + dap_json_rpc_unregistration_request_handler("validateaddress"); + dap_json_rpc_unregistration_request_handler("verifymessage"); + dap_json_rpc_unregistration_request_handler("walletlock"); + dap_json_rpc_unregistration_request_handler("walletpassphrase"); + dap_json_rpc_unregistration_request_handler("walletpassphrasechange"); +} diff --git a/modules/chain/btc_rpc/include/dap_chain_btc_rpc.h b/modules/chain/btc_rpc/include/dap_chain_btc_rpc.h new file mode 100644 index 0000000000000000000000000000000000000000..1196448f3ed1a4f94a81d491c3e3c9ace35cd16d --- /dev/null +++ b/modules/chain/btc_rpc/include/dap_chain_btc_rpc.h @@ -0,0 +1,5 @@ +#pragma once +#include "dap_chain_btc_rpc_handlers.h" + +int dap_chain_btc_rpc_init(); +void dap_chain_btc_rpc_deinit(); diff --git a/modules/chain/btc_rpc/include/dap_chain_btc_rpc_handlers.h b/modules/chain/btc_rpc/include/dap_chain_btc_rpc_handlers.h new file mode 100644 index 0000000000000000000000000000000000000000..601c9dd1ff4aed16aec43cd25e18f7e1bc051752 --- /dev/null +++ b/modules/chain/btc_rpc/include/dap_chain_btc_rpc_handlers.h @@ -0,0 +1,84 @@ +#pragma once + +#include "dap_json_rpc_request_handler.h" + +void dap_chain_btc_rpc_registration_handlers(); +void dap_chain_btc_rpc_unregistration_handlers(); + +void dap_chain_btc_rpc_handler_addmultisigaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_addnode(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_backupwallet(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_createmultisig(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_createrawtransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_decoderawtransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_dumpprivkey(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_dumpwallet(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_encryptwallet(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getaccountaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getaddednodeinfo(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getaddressesbyaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getbalance(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getbestblockhash(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getblock(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getblockcount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getblockhash(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getblocknumber(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getblocktemplate(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getconnectioncount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getdifficulty(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getgenerate(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_gethashespersec(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getinfo(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getmemorypool(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getmininginfo(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_getnewaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getpeerinfo(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getrawchangeaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getrawmempool(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getrawtransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getreceivedbyaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getreceivedbyaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_gettransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_gettxout(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_gettxoutsetinfo(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_getwork(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_help(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_importprivkey(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_invalidateblock(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_keypoolrefill(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listaccounts(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listaddressgroupings(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listreceivedbyaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_listreceivedbyaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listreceivedbyaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listsinceblock(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listtransactions(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listunspent(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_listlockunspent(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_lockunspent(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_move(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_sendfrom(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_sendmany(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_sendrawtransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_sendtoaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_setaccount(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_setgenerate(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_settxfee(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_signmessage(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_signrawtransaction(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_stop(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_submitblock(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +void dap_chain_btc_rpc_handler_validateaddress(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_verifymessage(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_walletlock(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_walletpassphrase(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); +void dap_chain_btc_rpc_handler_walletpassphrasechange(dap_json_rpc_params_t *a_params, dap_json_rpc_response_t *a_response); + +