forked from lthn/blockchain
DTOs for block and transaction details, Refactor API server
Replaces RootController and legacy info controller with new InfoController and BlockController, adds DTOs for block and transaction details, and restructures the API server to use modular components. Updates CMakeLists to include new sources and dependencies, and refactors main.cpp to use the new ApiServer entry point. Improves Swagger documentation and endpoint organization for better maintainability and extensibility.
This commit is contained in:
parent
8386b95cea
commit
df17bf1247
13 changed files with 426 additions and 168 deletions
|
|
@ -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.
|
||||
when you manually delete a folder, the toolchain is now a broken path, and CMake throws a fatal error.
|
||||
|
||||
|
|
|
|||
66
src/api/ApiServer.cpp
Normal file
66
src/api/ApiServer.cpp
Normal file
|
|
@ -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 <iostream>
|
||||
#include "version.h"
|
||||
|
||||
void ApiServer::run() {
|
||||
|
||||
/* Register Components in scope of run() method */
|
||||
Components components;
|
||||
|
||||
/* Get router component */
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
|
||||
auto docEndpoints = std::make_shared<oatpp::web::server::api::Endpoints>();
|
||||
|
||||
auto infoController = std::make_shared<InfoController>();
|
||||
docEndpoints->append(infoController->getEndpoints());
|
||||
|
||||
auto blockController = std::make_shared<BlockController>();
|
||||
docEndpoints->append(blockController->getEndpoints());
|
||||
|
||||
router->addController(infoController);
|
||||
router->addController(blockController);
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::DocumentInfo>, 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<oatpp::network::ConnectionHandler>, connectionHandler);
|
||||
|
||||
/* Get a connection provider component */
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, 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<const char*>(connectionProvider->getProperty("port").getData()));
|
||||
|
||||
/* Run server */
|
||||
server.run();
|
||||
|
||||
}
|
||||
|
|
@ -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<oatpp::network::ServerConnectionProvider>, 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<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
|
||||
return oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0", 8000, oatpp::network::Address::IP_4});
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
|
||||
return oatpp::web::server::HttpRouter::createShared();
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
return oatpp::web::server::HttpConnectionHandler::createShared(router);
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
|
||||
auto jsonMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
|
||||
jsonMapper->getSerializer()->getConfig()->useBeautifier = true;
|
||||
return jsonMapper;
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
|
||||
return oatpp::web::server::HttpRouter::createShared();
|
||||
}());
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::Resources>, swaggerResources)([] {
|
||||
return oatpp::swagger::Resources::loadResources(OATPP_SWAGGER_RES_PATH);
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
return oatpp::web::server::HttpConnectionHandler::createShared(router);
|
||||
}());
|
||||
};
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
|
||||
return oatpp::parser::json::mapping::ObjectMapper::createShared();
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::Resources>, swaggerResources)([] {
|
||||
return oatpp::swagger::Resources::loadResources(OATPP_SWAGGER_RES_PATH);
|
||||
}());
|
||||
void run();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
70
src/api/controller/BlockController.hpp
Normal file
70
src/api/controller/BlockController.hpp
Normal file
|
|
@ -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<oatpp::data::mapping::ObjectMapper>, 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<Object<BlockDetailsDto>>(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 */
|
||||
43
src/api/controller/InfoController.hpp
Normal file
43
src/api/controller/InfoController.hpp
Normal file
|
|
@ -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<oatpp::data::mapping::ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper)
|
||||
{}
|
||||
public:
|
||||
|
||||
#include "partials/info/version.hpp"
|
||||
};
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
|
||||
#endif /* InfoController_hpp */
|
||||
|
|
@ -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<InfoController> m_infoController;
|
||||
public:
|
||||
RootController(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper),
|
||||
m_infoController(std::make_shared<InfoController>(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 */
|
||||
|
|
@ -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>, 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 */
|
||||
34
src/api/controller/partials/info/version.hpp
Normal file
34
src/api/controller/partials/info/version.hpp
Normal file
|
|
@ -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<Object<VersionDto>>(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);
|
||||
}
|
||||
62
src/api/dto/BlockDetailsDto.hpp
Normal file
62
src/api/dto/BlockDetailsDto.hpp
Normal file
|
|
@ -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<Object<TransactionDetailsDto>>, transactions_details, "transactions_details");
|
||||
DTO_FIELD(UInt32, type, "type");
|
||||
};
|
||||
|
||||
#include OATPP_CODEGEN_END(DTO)
|
||||
|
||||
#endif /* BlockDetailsDto_hpp */
|
||||
92
src/api/dto/TransactionDetailsDto.hpp
Normal file
92
src/api/dto/TransactionDetailsDto.hpp
Normal file
|
|
@ -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<UInt64>, 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<String>, 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<Object<TransactionAttachmentDto>>, attachments, "attachments");
|
||||
DTO_FIELD(String, blob, "blob");
|
||||
DTO_FIELD(UInt64, blob_size, "blob_size");
|
||||
DTO_FIELD(List<Object<TransactionExtraDto>>, extra, "extra");
|
||||
DTO_FIELD(UInt64, fee, "fee");
|
||||
DTO_FIELD(String, id, "id");
|
||||
DTO_FIELD(List<Object<TransactionInputDto>>, ins, "ins");
|
||||
DTO_FIELD(Int64, keeper_block, "keeper_block");
|
||||
DTO_FIELD(String, object_in_json, "object_in_json");
|
||||
DTO_FIELD(List<Object<TransactionOutputDto>>, outs, "outs");
|
||||
DTO_FIELD(String, pub_key, "pub_key");
|
||||
DTO_FIELD(UInt64, timestamp, "timestamp");
|
||||
};
|
||||
|
||||
#include OATPP_CODEGEN_END(DTO)
|
||||
|
||||
#endif /* TransactionDetailsDto_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 */
|
||||
|
|
@ -1,76 +1,15 @@
|
|||
#include "controller/RootController.hpp"
|
||||
#include "ApiServer.hpp"
|
||||
|
||||
#include "oatpp/network/Server.hpp"
|
||||
#include "oatpp-swagger/Controller.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void run() {
|
||||
/* Register Components in scope of run() method */
|
||||
ApiServer components;
|
||||
|
||||
/* Get router component */
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
|
||||
/* Create RootController and add all of its endpoints to router */
|
||||
auto rootController = std::make_shared<RootController>();
|
||||
router->addController(rootController);
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::DocumentInfo>, 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<oatpp::network::ConnectionHandler>, connectionHandler);
|
||||
|
||||
/* Get connection provider component */
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue