diff --git a/CMakeLists.txt b/CMakeLists.txt index 174c156d7f99eb2ee831df7e075cec6572ec3ec7..bf38e219b3e67633ea123119ce9e9054cadca4b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ file(GLOB DAP_CHAIN_MEMPOOL_HDR *.h) add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_MEMPOOL_SRC} ${DAP_CHAIN_MEMPOOL_HDR}) -target_link_libraries(dap_chain_mempool dap_http_server dap_chain_global_db dap_core) +target_link_libraries(dap_chain_mempool dap_http_server dap_client dap_chain_global_db dap_core) target_include_directories(dap_chain_mempool INTERFACE .) set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) diff --git a/dap_chain_mempool.c b/dap_chain_mempool.c index ac6f60825ad3441eed9085d57de58d9a153e4bd9..94dcccf20137260859d7d0679c493599aa71f8f9 100644 --- a/dap_chain_mempool.c +++ b/dap_chain_mempool.c @@ -1,16 +1,45 @@ +#include <stdio.h> #include "dap_common.h" #include "dap_http_client.h" #include "dap_http_simple.h" +//#include "dap_enc_http.h" +#include "dap_enc_http.h" +//#include "dap_http.h" +#include "http_status_code.h" +#include "dap_chain_datum.h" +#include "dap_chain_global_db.h" #include "dap_chain_mempool.h" +#define FILE_MEMPOOL_DB "1.db" // TODO get from settings /** * @brief * @param cl_st HTTP server instance - * @param arg Not used + * @param arg for return code */ void chain_mempool_proc(struct dap_http_simple *cl_st, void * arg) { - + http_status_code_t * return_code = (http_status_code_t*) arg; + enc_http_delegate_t *dg = enc_http_request_decode(cl_st); + if(dg) { + char *url = dg->url_path; + char *request_str = dg->request_str; + int request_size = dg->request_size; + printf("!!***!!! chain_mempool_proc arg=%d url=%s str=%s len=%d\n", arg, url, request_str, request_size); + if(request_str && request_size > 0) { + dap_datum_mempool_t *mempool = (dap_datum_mempool_t*)request_str; + const char *a_key = "";//TODO hash(mempool) + const char *a_value = "";// TODO mempool; + if(dap_chain_global_db_set(a_key, a_value)) + *return_code = Http_Status_OK; + else + *return_code = Http_Status_InternalServerError; + } + else + *return_code = Http_Status_BadRequest; + } + else { + *return_code = Http_Status_Unauthorized; + } } /** @@ -20,6 +49,6 @@ void chain_mempool_proc(struct dap_http_simple *cl_st, void * arg) */ void dap_chain_mempool_add_proc(struct dap_http * sh, const char * url) { - /*void dap_http_simple_proc_add(dap_http_t *sh, const char * url_path, size_t reply_size_max, dap_http_simple_callback_t cb); // Add simple processor*/ + dap_chain_global_db_init(FILE_MEMPOOL_DB); dap_http_simple_proc_add(sh, url, 4096, chain_mempool_proc); } diff --git a/dap_chain_mempool.h b/dap_chain_mempool.h index da7643489f6948666c397c78eff125dc9d6bc2aa..1afc6ba21d6cb77b34397627f8bcf2d9f6bdac9e 100644 --- a/dap_chain_mempool.h +++ b/dap_chain_mempool.h @@ -1,3 +1,14 @@ #pragma once +// datum mempool structure +typedef struct dap_datum_mempool { + int16_t version; // structure version + uint16_t datum_count; // datums count + struct { + int32_t datum_size; + dap_chain_datum_t *datum; + }DAP_ALIGN_PACKED data[]; // mass of datums +}DAP_ALIGN_PACKED dap_datum_mempool_t; + + void dap_chain_mempool_add_proc(struct dap_http * sh, const char * url);