1
0
Fork 0
forked from lthn/blockchain

refactors block and transaction DTOs to models, updates references in controllers

This commit is contained in:
snider 2025-10-16 17:17:18 +01:00
parent e538e6492a
commit 35f9045937
8 changed files with 132 additions and 106 deletions

View file

@ -15,9 +15,9 @@
#ifndef BlockController_hpp
#define BlockController_hpp
#include "dto/BlockDetailsDto.hpp"
#include "dto/TransactionDetailsDto.hpp"
#include "controller/ApiCoreInfoComponent.hpp"
#include "modal/block/details.hpp"
#include "modal/transaction/details.hpp"
#include "controller/ApiCoreInfo.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
@ -34,7 +34,7 @@
*/
class BlockController : public oatpp::web::server::api::ApiController {
private:
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfoComponent>, m_core_info);
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfo>, m_core_info);
public:
explicit BlockController(OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper)
@ -45,7 +45,7 @@ public:
info->summary = "Get a block by its hash or height (ID)";
info->addTag("Block");
info->pathParams["identifier"].description = "The hash (hex string) or height (integer) of the block to retrieve.";
info->addResponse<Object<BlockDetailsDto>>(Status::CODE_200, "application/json");
info->addResponse<Object<BlockDetailsModel>>(Status::CODE_200, "application/json");
info->addResponse(Status::CODE_404, "text/plain");
info->addResponse(Status::CODE_400, "text/plain");
}
@ -77,7 +77,7 @@ public:
}
// Common logic to populate the DTO
auto blockDetails = BlockDetailsDto::createShared();
auto blockDetails = BlockDetailsModel::createShared();
blockDetails->id = rpc_details.id;
blockDetails->height = rpc_details.height;
@ -99,16 +99,16 @@ public:
blockDetails->miner_text_info = rpc_details.miner_text_info;
blockDetails->type = rpc_details.type;
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsDto>>::createShared();
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsModel>>::createShared();
for(const auto& tx_rpc_info : rpc_details.transactions_details) {
auto tx_dto = TransactionDetailsDto::createShared();
tx_dto->id = tx_rpc_info.id;
tx_dto->fee = tx_rpc_info.fee;
tx_dto->amount = tx_rpc_info.amount;
tx_dto->blob_size = tx_rpc_info.blob_size;
tx_dto->keeper_block = tx_rpc_info.keeper_block;
tx_dto->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_dto);
auto tx_model = TransactionDetailsModel::createShared();
tx_model->id = tx_rpc_info.id;
tx_model->fee = tx_rpc_info.fee;
tx_model->amount = tx_rpc_info.amount;
tx_model->blob_size = tx_rpc_info.blob_size;
tx_model->keeper_block = tx_rpc_info.keeper_block;
tx_model->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_model);
}
blockDetails->transactions_details = tx_details_list;

View file

@ -15,9 +15,9 @@
#ifndef BlockByHashController_hpp
#define BlockByHashController_hpp
#include "dto/BlockDetailsDto.hpp"
#include "dto/TransactionDetailsDto.hpp"
#include "controller/ApiCoreInfoComponent.hpp"
#include "modal/block/details.hpp"
#include "modal/transaction/details.hpp"
#include "controller/ApiCoreInfo.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
@ -32,7 +32,7 @@
*/
class BlockByHashController : public oatpp::web::server::api::ApiController {
private:
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfoComponent>, m_core_info);
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfo>, m_core_info);
public:
explicit BlockByHashController(OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper)
@ -43,7 +43,7 @@ public:
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");
info->addResponse<Object<BlockDetailsModel>>(Status::CODE_200, "application/json");
info->addResponse(Status::CODE_404, "text/plain");
info->addResponse(Status::CODE_400, "text/plain");
}
@ -60,7 +60,7 @@ public:
return createResponse(Status::CODE_404, "Block not found");
}
auto blockDetails = BlockDetailsDto::createShared();
auto blockDetails = BlockDetailsModel::createShared();
blockDetails->id = rpc_details.id;
blockDetails->height = rpc_details.height;
@ -82,16 +82,16 @@ public:
blockDetails->miner_text_info = rpc_details.miner_text_info;
blockDetails->type = rpc_details.type;
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsDto>>::createShared();
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsModel>>::createShared();
for(const auto& tx_rpc_info : rpc_details.transactions_details) {
auto tx_dto = TransactionDetailsDto::createShared();
tx_dto->id = tx_rpc_info.id;
tx_dto->fee = tx_rpc_info.fee;
tx_dto->amount = tx_rpc_info.amount;
tx_dto->blob_size = tx_rpc_info.blob_size;
tx_dto->keeper_block = tx_rpc_info.keeper_block;
tx_dto->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_dto);
auto tx_model = TransactionDetailsModel::createShared();
tx_model->id = tx_rpc_info.id;
tx_model->fee = tx_rpc_info.fee;
tx_model->amount = tx_rpc_info.amount;
tx_model->blob_size = tx_rpc_info.blob_size;
tx_model->keeper_block = tx_rpc_info.keeper_block;
tx_model->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_model);
}
blockDetails->transactions_details = tx_details_list;

View file

@ -15,9 +15,9 @@
#ifndef BlockByIdController_hpp
#define BlockByIdController_hpp
#include "dto/BlockDetailsDto.hpp"
#include "dto/TransactionDetailsDto.hpp"
#include "controller/ApiCoreInfoComponent.hpp"
#include "modal/block/details.hpp"
#include "modal/transaction/details.hpp"
#include "controller/ApiCoreInfo.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
@ -32,7 +32,7 @@
*/
class BlockByIdController : public oatpp::web::server::api::ApiController {
private:
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfoComponent>, m_core_info);
OATPP_COMPONENT(std::shared_ptr<ApiCoreInfo>, m_core_info);
public:
explicit BlockByIdController(OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper)
@ -43,7 +43,7 @@ public:
info->summary = "Get a block by its ID (height)";
info->addTag("Block");
info->pathParams["id"].description = "The ID (height) of the block to retrieve";
info->addResponse<Object<BlockDetailsDto>>(Status::CODE_200, "application/json");
info->addResponse<Object<BlockDetailsModel>>(Status::CODE_200, "application/json");
info->addResponse(Status::CODE_404, "text/plain");
}
ENDPOINT("GET", "/block/id/{id}", getBlockById, PATH(UInt64, id)) {
@ -53,7 +53,7 @@ public:
return createResponse(Status::CODE_404, "Block not found");
}
auto blockDetails = BlockDetailsDto::createShared();
auto blockDetails = BlockDetailsModel::createShared();
blockDetails->id = rpc_details.id;
blockDetails->height = rpc_details.height;
@ -75,16 +75,16 @@ public:
blockDetails->miner_text_info = rpc_details.miner_text_info;
blockDetails->type = rpc_details.type;
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsDto>>::createShared();
auto tx_details_list = oatpp::List<oatpp::Object<TransactionDetailsModel>>::createShared();
for(const auto& tx_rpc_info : rpc_details.transactions_details) {
auto tx_dto = TransactionDetailsDto::createShared();
tx_dto->id = tx_rpc_info.id;
tx_dto->fee = tx_rpc_info.fee;
tx_dto->amount = tx_rpc_info.amount;
tx_dto->blob_size = tx_rpc_info.blob_size;
tx_dto->keeper_block = tx_rpc_info.keeper_block;
tx_dto->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_dto);
auto tx_model = TransactionDetailsModel::createShared();
tx_model->id = tx_rpc_info.id;
tx_model->fee = tx_rpc_info.fee;
tx_model->amount = tx_rpc_info.amount;
tx_model->blob_size = tx_rpc_info.blob_size;
tx_model->keeper_block = tx_rpc_info.keeper_block;
tx_model->timestamp = tx_rpc_info.timestamp;
tx_details_list->push_back(tx_model);
}
blockDetails->transactions_details = tx_details_list;

View file

@ -18,7 +18,7 @@
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "version.h"
#include "dto/VersionDto.hpp"
#include "modal/meta/version.hpp"
#include OATPP_CODEGEN_BEGIN(ApiController)
@ -37,17 +37,17 @@ public:
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");
info->addResponse<Object<VersionModel>>(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);
auto model = VersionModel::createShared();
model->version = PROJECT_VERSION;
model->version_long = PROJECT_VERSION_LONG;
model->major = PROJECT_MAJOR_VERSION;
model->minor = PROJECT_MINOR_VERSION;
model->revision = PROJECT_REVISION;
return createDtoResponse(Status::CODE_200, model);
}
};

View file

@ -12,20 +12,46 @@
// SPDXLicenseIdentifier: EUPL-1.2
//
#ifndef InfoVersionController_hpp
#define InfoVersionController_hpp
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "version.h"
#include "modal/meta/version.hpp"
#include OATPP_CODEGEN_BEGIN(ApiController)
/**
* Version Controller
*/
class InfoVersionController : public oatpp::web::server::api::ApiController {
public:
explicit InfoVersionController(OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper)
{}
public:
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");
info->addResponse<Object<VersionModel>>(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);
auto model = VersionModel::createShared();
model->version = PROJECT_VERSION;
model->version_long = PROJECT_VERSION_LONG;
model->major = PROJECT_MAJOR_VERSION;
model->minor = PROJECT_MINOR_VERSION;
model->revision = PROJECT_REVISION;
return createDtoResponse(Status::CODE_200, model);
}
};
#include OATPP_CODEGEN_END(ApiController)
#endif /* InfoVersionController_hpp */

View file

@ -12,20 +12,20 @@
// SPDXLicenseIdentifier: EUPL-1.2
//
#ifndef BlockDetailsDto_hpp
#define BlockDetailsDto_hpp
#ifndef BlockDetailsModel_hpp
#define BlockDetailsModel_hpp
#include "TransactionDetailsDto.hpp"
#include "../transaction/details.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* DTO for detailed block information.
* Model for detailed block information.
*/
class BlockDetailsDto : public oatpp::DTO {
DTO_INIT(BlockDetailsDto, DTO);
class BlockDetailsModel : public oatpp::DTO {
DTO_INIT(BlockDetailsModel, DTO);
DTO_FIELD(UInt64, actual_timestamp, "actual_timestamp");
DTO_FIELD(String, already_generated_coins, "already_generated_coins");
@ -50,10 +50,10 @@ class BlockDetailsDto : public oatpp::DTO {
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(List<Object<TransactionDetailsModel>>, transactions_details, "transactions_details");
DTO_FIELD(UInt32, type, "type");
};
#include OATPP_CODEGEN_END(DTO)
#endif /* BlockDetailsDto_hpp */
#endif /* BlockDetailsModel_hpp */

View file

@ -12,17 +12,17 @@
// SPDXLicenseIdentifier: EUPL-1.2
//
#ifndef VersionDto_hpp
#define VersionDto_hpp
#ifndef VersionModel_hpp
#define VersionModel_hpp
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
#include OATPP_CODEGEN_BEGIN(DTO)
class VersionDto final : public oatpp::DTO
class VersionModel final : public oatpp::DTO
{
DTO_INIT(VersionDto, DTO);
DTO_INIT(VersionModel, DTO);
DTO_FIELD(String, version);
DTO_FIELD(String, version_long);
@ -33,4 +33,4 @@ class VersionDto final : public oatpp::DTO
#include OATPP_CODEGEN_END(DTO)
#endif /* VersionDto_hpp */
#endif /* VersionModel_hpp */

View file

@ -12,8 +12,8 @@
// SPDXLicenseIdentifier: EUPL-1.2
//
#ifndef TransactionDetailsDto_hpp
#define TransactionDetailsDto_hpp
#ifndef TransactionDetailsModel_hpp
#define TransactionDetailsModel_hpp
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
@ -21,30 +21,30 @@
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* DTO for transaction attachments.
* Model for transaction attachments.
*/
class TransactionAttachmentDto : public oatpp::DTO {
DTO_INIT(TransactionAttachmentDto, DTO);
class TransactionAttachmentModel : public oatpp::DTO {
DTO_INIT(TransactionAttachmentModel, 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.
* Model for transaction extra data.
*/
class TransactionExtraDto : public oatpp::DTO {
DTO_INIT(TransactionExtraDto, DTO);
class TransactionExtraModel : public oatpp::DTO {
DTO_INIT(TransactionExtraModel, DTO);
DTO_FIELD(String, type, "type");
DTO_FIELD(String, short_view, "short_view");
DTO_FIELD(String, details_view, "details_view");
};
/**
* DTO for transaction inputs.
* Model for transaction inputs.
*/
class TransactionInputDto : public oatpp::DTO {
DTO_INIT(TransactionInputDto, DTO);
class TransactionInputModel : public oatpp::DTO {
DTO_INIT(TransactionInputModel, DTO);
DTO_FIELD(UInt64, amount, "amount");
DTO_FIELD(Vector<UInt64>, global_indexes, "global_indexes");
DTO_FIELD(String, htlc_origin, "htlc_origin");
@ -53,10 +53,10 @@ class TransactionInputDto : public oatpp::DTO {
};
/**
* DTO for transaction outputs.
* Model for transaction outputs.
*/
class TransactionOutputDto : public oatpp::DTO {
DTO_INIT(TransactionOutputDto, DTO);
class TransactionOutputModel : public oatpp::DTO {
DTO_INIT(TransactionOutputModel, DTO);
DTO_FIELD(UInt64, amount, "amount");
DTO_FIELD(UInt64, global_index, "global_index");
DTO_FIELD(Boolean, is_spent, "is_spent");
@ -65,25 +65,25 @@ class TransactionOutputDto : public oatpp::DTO {
};
/**
* DTO for detailed transaction information.
* Model for detailed transaction information.
*/
class TransactionDetailsDto : public oatpp::DTO {
DTO_INIT(TransactionDetailsDto, DTO);
class TransactionDetailsModel : public oatpp::DTO {
DTO_INIT(TransactionDetailsModel, DTO);
DTO_FIELD(UInt64, amount, "amount");
DTO_FIELD(List<Object<TransactionAttachmentDto>>, attachments, "attachments");
DTO_FIELD(List<Object<TransactionAttachmentModel>>, attachments, "attachments");
DTO_FIELD(String, blob, "blob");
DTO_FIELD(UInt64, blob_size, "blob_size");
DTO_FIELD(List<Object<TransactionExtraDto>>, extra, "extra");
DTO_FIELD(List<Object<TransactionExtraModel>>, extra, "extra");
DTO_FIELD(UInt64, fee, "fee");
DTO_FIELD(String, id, "id");
DTO_FIELD(List<Object<TransactionInputDto>>, ins, "ins");
DTO_FIELD(List<Object<TransactionInputModel>>, 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(List<Object<TransactionOutputModel>>, outs, "outs");
DTO_FIELD(String, pub_key, "pub_key");
DTO_FIELD(UInt64, timestamp, "timestamp");
};
#include OATPP_CODEGEN_END(DTO)
#endif /* TransactionDetailsDto_hpp */
#endif /* TransactionDetailsModel_hpp */