diff --git a/README.md b/README.md index 1de03ca8..71a7ccb7 100644 --- a/README.md +++ b/README.md @@ -114,4 +114,5 @@ If you do manually delete build folders and get CMake errors (if you have compil the ConanPresets.json file has entries in the `include` property, delete them all and try again. This happens because CMakePresets.json includes ConanPresets.json, that has the list of toolchains to use that gets populated during the CMake config step, -when you manually delete a folder, the toolchain is now a broken path, and CMake throws a fatal error. \ No newline at end of file +when you manually delete a folder, the toolchain is now a broken path, and CMake throws a fatal error. + diff --git a/src/api/ApiServer.cpp b/src/api/ApiServer.cpp new file mode 100644 index 00000000..09aadf50 --- /dev/null +++ b/src/api/ApiServer.cpp @@ -0,0 +1,66 @@ +#include "ApiServer.hpp" +#include "controller/InfoController.hpp" +#include "controller/BlockController.hpp" + +#include "oatpp/network/Server.hpp" +#include "oatpp-swagger/Controller.hpp" + +#include +#include "version.h" + +void ApiServer::run() { + + /* Register Components in scope of run() method */ + Components components; + + /* Get router component */ + OATPP_COMPONENT(std::shared_ptr, router); + + auto docEndpoints = std::make_shared(); + + auto infoController = std::make_shared(); + docEndpoints->append(infoController->getEndpoints()); + + auto blockController = std::make_shared(); + docEndpoints->append(blockController->getEndpoints()); + + router->addController(infoController); + router->addController(blockController); + + OATPP_CREATE_COMPONENT(std::shared_ptr, swaggerDocumentInfo) + ([] + { + oatpp::swagger::DocumentInfo::Builder builder; + + builder + .setTitle("Lethean Blockchain API") + .setDescription("New API layer for Lethean") + .setVersion(PROJECT_VERSION) + .setContactName("Lethean") + .setContactUrl("https://lt.hn/") + .setLicenseName("EUPL-1.2") + .setLicenseUrl("https://joinup.ec.europa.eu/software/page/eupl/licence-eupl") + .addServer("http://localhost:8000", "server on localhost"); + + return builder.build(); }()); + + /* Create a Swagger-UI controller and add its endpoints to the router */ + auto swaggerController = oatpp::swagger::Controller::createShared(*docEndpoints); + router->addController(swaggerController); + + /* Get a connection handler component */ + OATPP_COMPONENT(std::shared_ptr, connectionHandler); + + /* Get a connection provider component */ + OATPP_COMPONENT(std::shared_ptr, connectionProvider); + + /* Create a server which takes provided TCP connections and passes them to the HTTP connection handler */ + oatpp::network::Server server(connectionProvider, connectionHandler); + + /* Print server port */ + OATPP_LOGI("lethean-api", "Server running, API Docs: http://127.0.0.1:%s/swagger/ui", static_cast(connectionProvider->getProperty("port").getData())); + + /* Run server */ + server.run(); + +} diff --git a/src/api/ApiServer.hpp b/src/api/ApiServer.hpp index d02e4b0b..582561c1 100644 --- a/src/api/ApiServer.hpp +++ b/src/api/ApiServer.hpp @@ -1,36 +1,50 @@ #ifndef ApiServer_hpp #define ApiServer_hpp +#include "currency_core/blockchain_storage.h" + +#include "currency_core/currency_core.h" #include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" +#include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/core/macro/component.hpp" #include "oatpp-swagger/Resources.hpp" -#include "oatpp/parser/json/mapping/ObjectMapper.hpp" -#include "oatpp-swagger/Model.hpp" class ApiServer { + public: - OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([] { - return oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0", 8000, oatpp::network::Address::IP_4}); - }()); + ApiServer() = default; + + class Components { + public: + + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([] { + return oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0", 8000, oatpp::network::Address::IP_4}); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { + return oatpp::web::server::HttpRouter::createShared(); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_COMPONENT(std::shared_ptr, router); + return oatpp::web::server::HttpConnectionHandler::createShared(router); + }()); + + OATPP_CREATE_COMPONENT(std::shared_ptr, apiObjectMapper)([] { + auto jsonMapper = oatpp::parser::json::mapping::ObjectMapper::createShared(); + jsonMapper->getSerializer()->getConfig()->useBeautifier = true; + return jsonMapper; + }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { - return oatpp::web::server::HttpRouter::createShared(); - }()); + OATPP_CREATE_COMPONENT(std::shared_ptr, swaggerResources)([] { + return oatpp::swagger::Resources::loadResources(OATPP_SWAGGER_RES_PATH); + }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { - OATPP_COMPONENT(std::shared_ptr, router); - return oatpp::web::server::HttpConnectionHandler::createShared(router); - }()); + }; - OATPP_CREATE_COMPONENT(std::shared_ptr, apiObjectMapper)([] { - return oatpp::parser::json::mapping::ObjectMapper::createShared(); - }()); - - OATPP_CREATE_COMPONENT(std::shared_ptr, swaggerResources)([] { - return oatpp::swagger::Resources::loadResources(OATPP_SWAGGER_RES_PATH); - }()); + void run(); }; diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index cb452681..ad66ec60 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -19,12 +19,17 @@ endif() add_library(lthn_api INTERFACE) add_library(lthn::api ALIAS lthn_api) -target_include_directories(lthn_api INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +# Add the current directory for API headers and the main src directory for core headers +target_include_directories(lthn_api INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src +) + include_directories(${oatpp_INCLUDE_DIRS}) include_directories(${oatpp-swagger_INCLUDE_DIRS}) -add_executable(lethean-api main.cpp) +add_executable(lethean-api main.cpp ApiServer.cpp) -target_link_libraries(lethean-api PRIVATE lthn::api PUBLIC oatpp::oatpp oatpp::oatpp-swagger) +target_link_libraries(lethean-api PRIVATE lthn::api PUBLIC common config oatpp::oatpp oatpp::oatpp-swagger) add_definitions(-DOATPP_SWAGGER_RES_PATH="${oatpp-swagger_INCLUDE_DIRS}/../bin/oatpp-swagger/res") #add_subdirectory(tests) diff --git a/src/api/controller/BlockController.hpp b/src/api/controller/BlockController.hpp new file mode 100644 index 00000000..184b1992 --- /dev/null +++ b/src/api/controller/BlockController.hpp @@ -0,0 +1,70 @@ +#ifndef BlockController_hpp +#define BlockController_hpp + +#include "../dto/BlockDetailsDto.hpp" + +#include "oatpp/web/server/api/ApiController.hpp" +#include "oatpp/core/macro/codegen.hpp" +#include "oatpp/parser/json/mapping/ObjectMapper.hpp" + +#include OATPP_CODEGEN_BEGIN(ApiController) + +/** + * Block Controller + */ +class BlockController : public oatpp::web::server::api::ApiController { +public: + BlockController(OATPP_COMPONENT(std::shared_ptr, objectMapper)) + : oatpp::web::server::api::ApiController(objectMapper) + {} +public: + + ENDPOINT_INFO(getBlockByHash) { + info->summary = "Get a block by its hash"; + info->addTag("Block"); + info->pathParams["hash"].description = "The hash of the block to retrieve"; + info->addResponse>(Status::CODE_200, "application/json"); + } + ENDPOINT("GET", "/block/{hash}", getBlockByHash, PATH(String, hash)) { + // TODO: Actually fetch the block from the blockchain core + + auto blockDetails = BlockDetailsDto::createShared(); + blockDetails->actual_timestamp = 1557345925ULL; + blockDetails->already_generated_coins = "17517253670000000000"; + blockDetails->base_reward = 1000000000000ULL; + blockDetails->blob = ""; + blockDetails->block_cumulative_size = 6794ULL; + blockDetails->block_tself_size = 0ULL; + blockDetails->cumulative_diff_adjusted = "42413051198"; + blockDetails->cumulative_diff_precise = "28881828324942"; + blockDetails->difficulty = "951296929031"; + blockDetails->effective_fee_median = 0ULL; + blockDetails->height = 51ULL; + blockDetails->id = hash; // Use the hash from the path + blockDetails->is_orphan = false; + blockDetails->miner_text_info = ""; + blockDetails->object_in_json = ""; + blockDetails->penalty = 0.0f; + blockDetails->prev_id = "37fe382c755bb8869e4f5255f2aed6a8fb503e195bb4180b65b8e1450b84cafe"; + blockDetails->summary_reward = 1001000000000ULL; + blockDetails->this_block_fee_median = 1000000000ULL; + blockDetails->timestamp = 1557345925ULL; + blockDetails->total_fee = 1000000000ULL; + blockDetails->total_txs_size = 6794ULL; + blockDetails->type = 1U; + + auto txDetails = TransactionDetailsDto::createShared(); + txDetails->id = "a6e8da986858e6825fce7a192097e6afae4e889cabe853a9c29b964985b23da8"; + txDetails->fee = 1000000000ULL; + // ... populate other txDetails fields as needed + + blockDetails->transactions_details = {txDetails}; + + return createDtoResponse(Status::CODE_200, blockDetails); + } + +}; + +#include OATPP_CODEGEN_END(ApiController) + +#endif /* BlockController_hpp */ diff --git a/src/api/controller/InfoController.hpp b/src/api/controller/InfoController.hpp new file mode 100644 index 00000000..c1eb2dc7 --- /dev/null +++ b/src/api/controller/InfoController.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Copyright (c) 2012-2013 The Boolberry developers +// Copyright (c) 2017-2025 Lethean (https://lt.hn) +// +// Licensed under the European Union Public Licence (EUPL) version 1.2. +// You may obtain a copy of the licence at: +// +// https://joinup.ec.europa.eu/software/page/eupl/licence-eupl +// +// The EUPL is a copyleft licence that is compatible with the MIT/X11 +// licence used by the original projects; the MIT terms are therefore +// considered “grandfathered” under the EUPL for this code. +// +// SPDX‑License‑Identifier: EUPL-1.2 +// + +#ifndef InfoController_hpp +#define InfoController_hpp + +#include "oatpp/web/server/api/ApiController.hpp" +#include "oatpp/core/macro/codegen.hpp" +#include "version.h" +#include "dto/VersionDto.hpp" + +#include OATPP_CODEGEN_BEGIN(ApiController) + +/** + * Info Controller + */ +class InfoController : public oatpp::web::server::api::ApiController { +public: + InfoController(OATPP_COMPONENT(std::shared_ptr, objectMapper)) + : oatpp::web::server::api::ApiController(objectMapper) + {} +public: + + #include "partials/info/version.hpp" +}; + +#include OATPP_CODEGEN_END(ApiController) + +#endif /* InfoController_hpp */ diff --git a/src/api/controller/RootController.hpp b/src/api/controller/RootController.hpp deleted file mode 100644 index 817fa833..00000000 --- a/src/api/controller/RootController.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef RootController_hpp -#define RootController_hpp - -#include "./info/InfoController.hpp" -#include "../dto/DTOs.hpp" - -#include "oatpp/web/server/api/ApiController.hpp" -#include "oatpp/core/macro/codegen.hpp" -#include "oatpp/core/macro/component.hpp" - -#include OATPP_CODEGEN_BEGIN(ApiController) - -class RootController : public oatpp::web::server::api::ApiController { -private: - std::shared_ptr m_infoController; -public: - RootController(OATPP_COMPONENT(std::shared_ptr, objectMapper)) - : oatpp::web::server::api::ApiController(objectMapper), - m_infoController(std::make_shared(objectMapper)) - {} -public: - - - ENDPOINT("GET", "/hello", root) { - auto dto = MyDto::createShared(); - dto->message = "Hello World!"; - return createDtoResponse(Status::CODE_200, dto); - } - -}; - -#include OATPP_CODEGEN_END(ApiController) - -#endif /* RootController_hpp */ diff --git a/src/api/controller/info/InfoController.hpp b/src/api/controller/info/InfoController.hpp deleted file mode 100644 index ab2ece69..00000000 --- a/src/api/controller/info/InfoController.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef InfoController_hpp -#define InfoController_hpp - -#include "oatpp/web/server/api/ApiController.hpp" -#include "oatpp/core/macro/codegen.hpp" -#include "oatpp/core/macro/component.hpp" - -#include OATPP_CODEGEN_BEGIN(ApiController) - -class InfoController : public oatpp::web::server::api::ApiController { -public: - InfoController(OATPP_COMPONENT(std::shared_ptr, objectMapper)) - : oatpp::web::server::api::ApiController(objectMapper) - {} -public: - - ENDPOINT_INFO(version) { - info->summary = "Get API version"; - info->description = "Returns the current version of the API."; - } - ENDPOINT("GET", "/version", version) { - return createResponse(Status::CODE_200, "v0.0.1"); - } - - ENDPOINT_INFO(root) { - info->summary = "Get info root"; - info->description = "Returns a placeholder for the info root."; - } - ENDPOINT("GET", "/", root) { - return createResponse(Status::CODE_200, "Info root"); - } - -}; - -#include OATPP_CODEGEN_END(ApiController) - -#endif /* InfoController_hpp */ diff --git a/src/api/controller/partials/info/version.hpp b/src/api/controller/partials/info/version.hpp new file mode 100644 index 00000000..dc2ff2e4 --- /dev/null +++ b/src/api/controller/partials/info/version.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Copyright (c) 2012-2013 The Boolberry developers +// Copyright (c) 2017-2025 Lethean (https://lt.hn) +// +// Licensed under the European Union Public Licence (EUPL) version 1.2. +// You may obtain a copy of the licence at: +// +// https://joinup.ec.europa.eu/software/page/eupl/licence-eupl +// +// The EUPL is a copyleft licence that is compatible with the MIT/X11 +// licence used by the original projects; the MIT terms are therefore +// considered “grandfathered” under the EUPL for this code. +// +// SPDX‑License‑Identifier: EUPL-1.2 +// + +ENDPOINT_INFO(version) +{ + info->addTag("Info"); + info->summary = "Get API version"; + info->description = "Returns the current version of the API."; + info->addResponse>(Status::CODE_200, "application/json"); +} +ENDPOINT("GET", "/info/version", version) +{ + auto dto = VersionDto::createShared(); + dto->version = PROJECT_VERSION; + dto->version_long = PROJECT_VERSION_LONG; + dto->major = PROJECT_MAJOR_VERSION; + dto->minor = PROJECT_MINOR_VERSION; + dto->revision = PROJECT_REVISION; + return createDtoResponse(Status::CODE_200, dto); +} diff --git a/src/api/dto/BlockDetailsDto.hpp b/src/api/dto/BlockDetailsDto.hpp new file mode 100644 index 00000000..d8ffb1a8 --- /dev/null +++ b/src/api/dto/BlockDetailsDto.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Copyright (c) 2012-2013 The Boolberry developers +// Copyright (c) 2017-2025 Lethean (https://lt.hn) +// +// Licensed under the European Union Public Licence (EUPL) version 1.2. +// You may obtain a copy of the licence at: +// +// https://joinup.ec.europa.eu/software/page/eupl/licence-eupl +// +// The EUPL is a copyleft licence that is compatible with the MIT/X11 +// licence used by the original projects; the MIT terms are therefore +// considered “grandfathered” under the EUPL for this code. +// +// SPDX‑License‑Identifier: EUPL-1.2 +// + +#ifndef BlockDetailsDto_hpp +#define BlockDetailsDto_hpp + +#include "TransactionDetailsDto.hpp" +#include "oatpp/core/macro/codegen.hpp" +#include "oatpp/core/Types.hpp" + +#include OATPP_CODEGEN_BEGIN(DTO) + +/** + * DTO for detailed block information. + */ +class BlockDetailsDto : public oatpp::DTO { + DTO_INIT(BlockDetailsDto, DTO); + + DTO_FIELD(UInt64, actual_timestamp, "actual_timestamp"); + DTO_FIELD(String, already_generated_coins, "already_generated_coins"); + DTO_FIELD(UInt64, base_reward, "base_reward"); + DTO_FIELD(String, blob, "blob"); + DTO_FIELD(UInt64, block_cumulative_size, "block_cumulative_size"); + DTO_FIELD(UInt64, block_tself_size, "block_tself_size"); + DTO_FIELD(String, cumulative_diff_adjusted, "cumulative_diff_adjusted"); + DTO_FIELD(String, cumulative_diff_precise, "cumulative_diff_precise"); + DTO_FIELD(String, difficulty, "difficulty"); + DTO_FIELD(UInt64, effective_fee_median, "effective_fee_median"); + DTO_FIELD(UInt64, height, "height"); + DTO_FIELD(String, id, "id"); + DTO_FIELD(Boolean, is_orphan, "is_orphan"); + DTO_FIELD(String, miner_text_info, "miner_text_info"); + DTO_FIELD(String, object_in_json, "object_in_json"); + DTO_FIELD(UInt64, penalty, "penalty"); + DTO_FIELD(String, pow_seed, "pow_seed"); + DTO_FIELD(String, prev_id, "prev_id"); + DTO_FIELD(UInt64, summary_reward, "summary_reward"); + DTO_FIELD(UInt64, this_block_fee_median, "this_block_fee_median"); + DTO_FIELD(UInt64, timestamp, "timestamp"); + DTO_FIELD(UInt64, total_fee, "total_fee"); + DTO_FIELD(UInt64, total_txs_size, "total_txs_size"); + DTO_FIELD(List>, transactions_details, "transactions_details"); + DTO_FIELD(UInt32, type, "type"); +}; + +#include OATPP_CODEGEN_END(DTO) + +#endif /* BlockDetailsDto_hpp */ diff --git a/src/api/dto/TransactionDetailsDto.hpp b/src/api/dto/TransactionDetailsDto.hpp new file mode 100644 index 00000000..a3168710 --- /dev/null +++ b/src/api/dto/TransactionDetailsDto.hpp @@ -0,0 +1,92 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Copyright (c) 2012-2013 The Boolberry developers +// Copyright (c) 2017-2025 Lethean (https://lt.hn) +// +// Licensed under the European Union Public Licence (EUPL) version 1.2. +// You may obtain a copy of the licence at: +// +// https://joinup.ec.europa.eu/software/page/eupl/licence-eupl +// +// The EUPL is a copyleft licence that is compatible with the MIT/X11 +// licence used by the original projects; the MIT terms are therefore +// considered “grandfathered” under the EUPL for this code. +// +// SPDX‑License‑Identifier: EUPL-1.2 +// + +#ifndef TransactionDetailsDto_hpp +#define TransactionDetailsDto_hpp + +#include "oatpp/core/macro/codegen.hpp" +#include "oatpp/core/Types.hpp" + +#include OATPP_CODEGEN_BEGIN(DTO) + +/** + * DTO for transaction attachments. + */ +class TransactionAttachmentDto : public oatpp::DTO { + DTO_INIT(TransactionAttachmentDto, DTO); + DTO_FIELD(String, type, "type"); + DTO_FIELD(String, short_view, "short_view"); + DTO_FIELD(String, details_view, "details_view"); +}; + +/** + * DTO for transaction extra data. + */ +class TransactionExtraDto : public oatpp::DTO { + DTO_INIT(TransactionExtraDto, DTO); + DTO_FIELD(String, type, "type"); + DTO_FIELD(String, short_view, "short_view"); + DTO_FIELD(String, details_view, "details_view"); +}; + +/** + * DTO for transaction inputs. + */ +class TransactionInputDto : public oatpp::DTO { + DTO_INIT(TransactionInputDto, DTO); + DTO_FIELD(UInt64, amount, "amount"); + DTO_FIELD(Vector, global_indexes, "global_indexes"); + DTO_FIELD(String, htlc_origin, "htlc_origin"); + DTO_FIELD(String, kimage_or_ms_id, "kimage_or_ms_id"); + DTO_FIELD(UInt32, multisig_count, "multisig_count"); +}; + +/** + * DTO for transaction outputs. + */ +class TransactionOutputDto : public oatpp::DTO { + DTO_INIT(TransactionOutputDto, DTO); + DTO_FIELD(UInt64, amount, "amount"); + DTO_FIELD(UInt64, global_index, "global_index"); + DTO_FIELD(Boolean, is_spent, "is_spent"); + DTO_FIELD(UInt32, minimum_sigs, "minimum_sigs"); + DTO_FIELD(Vector, pub_keys, "pub_keys"); +}; + +/** + * DTO for detailed transaction information. + */ +class TransactionDetailsDto : public oatpp::DTO { + DTO_INIT(TransactionDetailsDto, DTO); + DTO_FIELD(UInt64, amount, "amount"); + DTO_FIELD(List>, attachments, "attachments"); + DTO_FIELD(String, blob, "blob"); + DTO_FIELD(UInt64, blob_size, "blob_size"); + DTO_FIELD(List>, extra, "extra"); + DTO_FIELD(UInt64, fee, "fee"); + DTO_FIELD(String, id, "id"); + DTO_FIELD(List>, ins, "ins"); + DTO_FIELD(Int64, keeper_block, "keeper_block"); + DTO_FIELD(String, object_in_json, "object_in_json"); + DTO_FIELD(List>, outs, "outs"); + DTO_FIELD(String, pub_key, "pub_key"); + DTO_FIELD(UInt64, timestamp, "timestamp"); +}; + +#include OATPP_CODEGEN_END(DTO) + +#endif /* TransactionDetailsDto_hpp */ diff --git a/src/api/dto/DTOs.hpp b/src/api/dto/VersionDto.hpp similarity index 72% rename from src/api/dto/DTOs.hpp rename to src/api/dto/VersionDto.hpp index e8bd3111..28f5c318 100644 --- a/src/api/dto/DTOs.hpp +++ b/src/api/dto/VersionDto.hpp @@ -15,22 +15,25 @@ // SPDX‑License‑Identifier: EUPL-1.2 // -#ifndef DTOs_hpp -#define DTOs_hpp +#ifndef VersionDto_hpp +#define VersionDto_hpp #include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/Types.hpp" #include OATPP_CODEGEN_BEGIN(DTO) -class MyDto : public oatpp::DTO { - - DTO_INIT(MyDto, DTO); - - DTO_FIELD(String, message); +class VersionDto final : public oatpp::DTO +{ + DTO_INIT(VersionDto, DTO); + DTO_FIELD(String, version); + DTO_FIELD(String, version_long); + DTO_FIELD(String, major); + DTO_FIELD(String, minor); + DTO_FIELD(String, revision); }; #include OATPP_CODEGEN_END(DTO) -#endif /* DTOs_hpp */ +#endif /* VersionDto_hpp */ diff --git a/src/api/main.cpp b/src/api/main.cpp index dbea164d..eecb3004 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -1,76 +1,15 @@ -#include "controller/RootController.hpp" #include "ApiServer.hpp" - -#include "oatpp/network/Server.hpp" -#include "oatpp-swagger/Controller.hpp" - -#include - -void run() { - /* Register Components in scope of run() method */ - ApiServer components; - - /* Get router component */ - OATPP_COMPONENT(std::shared_ptr, router); - - /* Create RootController and add all of its endpoints to router */ - auto rootController = std::make_shared(); - router->addController(rootController); - - OATPP_CREATE_COMPONENT(std::shared_ptr, swaggerDocumentInfo)([] { - - oatpp::swagger::DocumentInfo::Builder builder; - - builder - .setTitle("Lethean Blockchain API") - .setDescription("New API layer for Lethean") - .setVersion("1.0") - .setContactName("Lethean") - .setContactUrl("https://lt.hn/") - - .setLicenseName("EUPL-1.2") - .setLicenseUrl("https://joinup.ec.europa.eu/software/page/eupl/licence-eupl") - - .addServer("http://localhost:8000", "server on localhost"); - - // When you are using the AUTHENTICATION() Endpoint-Macro you must add an SecurityScheme object (https://swagger.io/specification/#securitySchemeObject) - // For basic-authentication you can use the default Basic-Authorization-Security-Scheme like this - // For more complex authentication schemes you can use the oatpp::swagger::DocumentInfo::SecuritySchemeBuilder builder - // Don't forget to add info->addSecurityRequirement("basic_auth") to your ENDPOINT_INFO() Macro! - //.addSecurityScheme("basic_auth", oatpp::swagger::DocumentInfo::SecuritySchemeBuilder::DefaultBasicAuthorizationSecurityScheme()); - - return builder.build(); - -}()); - - /* Create Swagger-UI controller and add its endpoints to router */ - auto swaggerController = oatpp::swagger::Controller::createShared(rootController->getEndpoints()); - router->addController(swaggerController); - - /* Get connection handler component */ - OATPP_COMPONENT(std::shared_ptr, connectionHandler); - - /* Get connection provider component */ - OATPP_COMPONENT(std::shared_ptr, connectionProvider); - - /* Create server which takes provided TCP connections and passes them to HTTP connection handler */ - oatpp::network::Server server(connectionProvider, connectionHandler); - - /* Print server port */ - OATPP_LOGI("lethean-api", "Server running on port %s", connectionProvider->getProperty("port").getData()); - - /* Run server */ - server.run(); -} +#include "oatpp/core/base/Environment.hpp" int main(int argc, const char * argv[]) { oatpp::base::Environment::init(); - run(); - + ApiServer server; + server.run(); + /* Destroy oatpp Environment */ oatpp::base::Environment::destroy(); - + return 0; }