Add int return type fixes.

This commit is contained in:
Alejandro Cabeza Romero 2026-06-16 14:54:55 +02:00
parent 654bf55e43
commit 6c70a23963
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
3 changed files with 62 additions and 62 deletions

View File

@ -238,13 +238,13 @@ LogosBlockchainModule::~LogosBlockchainModule() {
// Lifecycle
int LogosBlockchainModule::generate_user_config(const std::string& json_args) {
std::string LogosBlockchainModule::generate_user_config(const std::string& json_args) {
json parsed_args;
try {
parsed_args = json::parse(json_args);
} catch (const json::parse_error& e) {
fprintf(stderr, "Failed to parse JSON args: %s\n", e.what());
return 1;
return "1";
}
const OwnedGenerateConfigArgs owned_args(parsed_args);
@ -252,16 +252,16 @@ int LogosBlockchainModule::generate_user_config(const std::string& json_args) {
const OperationStatus status = ::generate_user_config(owned_args.ffi_args);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to generate user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::start(const std::string& config_path, const std::string& deployment) {
std::string LogosBlockchainModule::start(const std::string& config_path, const std::string& deployment) {
if (node) {
fprintf(stderr, "Could not execute the operation: The node is already running.\n");
return 1;
return "1";
}
const char* module_path_env = std::getenv("LOGOS_MODULE_PATH");
@ -280,7 +280,7 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
fprintf(stderr, "Using config from LB_CONFIG_PATH: %s\n", effective_config_path.c_str());
} else {
fprintf(stderr, "Config path was not specified and LB_CONFIG_PATH is not set.\n");
return 3;
return "3";
}
}
@ -294,7 +294,7 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
fprintf(stderr, "Start node returned with value and error.\n");
if (!is_ok(&error)) {
fprintf(stderr, "Failed to start the node. Error: %d\n", error);
return 4;
return "4";
}
node = value;
@ -302,23 +302,23 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
if (!node) {
fprintf(stderr, "Could not subscribe to block events: The node is not running.\n");
return 4;
return "4";
}
s_instance = this;
const OperationStatus subscribe_status = subscribe_to_new_blocks(node, on_new_block_callback);
if (!is_ok(&subscribe_status)) {
fprintf(stderr, "Failed to subscribe to new blocks. Error: %d\n", subscribe_status);
return 5;
return "5";
}
return 0;
return "0";
}
int LogosBlockchainModule::stop() {
std::string LogosBlockchainModule::stop() {
if (!node) {
fprintf(stderr, "Could not execute the operation: The node is not running.\n");
return 1;
return "1";
}
s_instance = nullptr;
@ -331,36 +331,36 @@ int LogosBlockchainModule::stop() {
}
node = nullptr;
return 0;
return "0";
}
// Config management
int LogosBlockchainModule::update_user_config(const std::string& user_config_path, const std::string& keystore_path) {
std::string LogosBlockchainModule::update_user_config(const std::string& user_config_path, const std::string& keystore_path) {
const std::string config = localPathFromFileUrl(user_config_path);
const std::string keystore = localPathFromFileUrl(keystore_path);
const OperationStatus status = ::update_user_config(config.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to update user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::migrate_user_config(const std::string& output_path, const std::string& keystore_path) {
std::string LogosBlockchainModule::migrate_user_config(const std::string& output_path, const std::string& keystore_path) {
const std::string output = localPathFromFileUrl(output_path);
const std::string keystore = localPathFromFileUrl(keystore_path);
const OperationStatus status = ::migrate_user_config(output.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to migrate user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::migrate_user_config_0_1_2(
std::string LogosBlockchainModule::migrate_user_config_0_1_2(
const std::string& new_config_path,
const std::string& old_config_path,
const std::string& keystore_path
@ -373,12 +373,12 @@ int LogosBlockchainModule::migrate_user_config_0_1_2(
::migrate_user_config_0_1_2(new_config.c_str(), old_config.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to migrate 0.1.2 config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::participate(
std::string LogosBlockchainModule::participate(
const std::string& config_path,
const std::string& keystore_path,
const std::string& output_dir,
@ -393,9 +393,9 @@ int LogosBlockchainModule::participate(
::participate(config.c_str(), keystore.c_str(), output.c_str(), external_address_ptr);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to generate participation data. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
// Keystore
@ -429,7 +429,7 @@ std::string LogosBlockchainModule::generate_key(
return result;
}
int LogosBlockchainModule::add_key(
std::string LogosBlockchainModule::add_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_type,
@ -439,7 +439,7 @@ int LogosBlockchainModule::add_key(
KeyType type{};
if (!parse_key_type(key_type, type)) {
fprintf(stderr, "Invalid key_type (expected \"ed25519\" or \"zk\").\n");
return 1;
return "1";
}
const std::string config = localPathFromFileUrl(user_config_path);
@ -450,12 +450,12 @@ int LogosBlockchainModule::add_key(
::add_key(config.c_str(), keystore.c_str(), type, key_hex.c_str(), key_title_ptr);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to add key. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::remove_key(
std::string LogosBlockchainModule::remove_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_title
@ -466,9 +466,9 @@ int LogosBlockchainModule::remove_key(
const OperationStatus status = ::remove_key(config.c_str(), keystore.c_str(), key_title.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to remove key. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
// Identity

View File

@ -22,19 +22,19 @@ public:
// ---- Node ----
// Lifecycle
int generate_user_config(const std::string& json_args);
int start(const std::string& config_path, const std::string& deployment);
int stop();
std::string generate_user_config(const std::string& json_args);
std::string start(const std::string& config_path, const std::string& deployment);
std::string stop();
// Config management
int update_user_config(const std::string& user_config_path, const std::string& keystore_path);
int migrate_user_config(const std::string& output_path, const std::string& keystore_path);
int migrate_user_config_0_1_2(
std::string update_user_config(const std::string& user_config_path, const std::string& keystore_path);
std::string migrate_user_config(const std::string& output_path, const std::string& keystore_path);
std::string migrate_user_config_0_1_2(
const std::string& new_config_path,
const std::string& old_config_path,
const std::string& keystore_path
);
int participate(
std::string participate(
const std::string& config_path,
const std::string& keystore_path,
const std::string& output_dir,
@ -49,14 +49,14 @@ public:
const std::string& key_type,
const std::string& key_title
);
int add_key(
std::string add_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_type,
const std::string& key_hex,
const std::string& key_title
);
int remove_key(
std::string remove_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_title

View File

@ -77,7 +77,7 @@ LOGOS_TEST(generate_user_config_returns_0_on_success) {
t.mockCFunction("generate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/test-config.json"})"), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/test-config.json"})"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("generate_user_config"));
}
@ -87,7 +87,7 @@ LOGOS_TEST(generate_user_config_returns_1_on_failure) {
t.mockCFunction("generate_user_config").returns(1);
LOGOS_ASSERT_EQ(module.generate_user_config("{}"), 1);
LOGOS_ASSERT_EQ(module.generate_user_config("{}"), std::string("1"));
}
LOGOS_TEST(generate_user_config_from_json_string) {
@ -96,7 +96,7 @@ LOGOS_TEST(generate_user_config_from_json_string) {
t.mockCFunction("generate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/out.json"})"), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/out.json"})"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("generate_user_config"));
}
@ -119,7 +119,7 @@ LOGOS_TEST(generate_user_config_with_all_fields) {
"kms_file": "/tmp/kms.yaml"
})";
LOGOS_ASSERT_EQ(module.generate_user_config(args), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(args), std::string("0"));
}
// ============================================================================
@ -129,7 +129,7 @@ LOGOS_TEST(generate_user_config_with_all_fields) {
LOGOS_TEST(stop_without_node_returns_1) {
auto t = LogosTestContext("blockchain_module");
LogosBlockchainModule module;
LOGOS_ASSERT_EQ(module.stop(), 1);
LOGOS_ASSERT_EQ(module.stop(), std::string("1"));
}
LOGOS_TEST(wallet_get_balance_without_node_returns_error) {
@ -216,7 +216,7 @@ LOGOS_TEST(start_returns_1_when_already_running) {
auto* module = createStartedModule(t, tmpDir);
LOGOS_ASSERT_TRUE(module != nullptr);
LOGOS_ASSERT_EQ(module->start("/tmp/config.json", ""), 1);
LOGOS_ASSERT_EQ(module->start("/tmp/config.json", ""), std::string("1"));
delete module;
}
@ -226,7 +226,7 @@ LOGOS_TEST(stop_succeeds_with_running_node) {
auto* module = createStartedModule(t, tmpDir);
LOGOS_ASSERT_TRUE(module != nullptr);
LOGOS_ASSERT_EQ(module->stop(), 0);
LOGOS_ASSERT_EQ(module->stop(), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("stop_node"));
delete module;
}
@ -777,7 +777,7 @@ LOGOS_TEST(update_user_config_returns_0_on_success) {
t.mockCFunction("update_user_config").returns(0);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("update_user_config"));
}
@ -787,7 +787,7 @@ LOGOS_TEST(update_user_config_returns_1_on_failure) {
t.mockCFunction("update_user_config").returns(1);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(migrate_user_config_returns_0_on_success) {
@ -796,7 +796,7 @@ LOGOS_TEST(migrate_user_config_returns_0_on_success) {
t.mockCFunction("migrate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("migrate_user_config"));
}
@ -806,7 +806,7 @@ LOGOS_TEST(migrate_user_config_returns_1_on_failure) {
t.mockCFunction("migrate_user_config").returns(1);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(migrate_user_config_0_1_2_returns_0_on_success) {
@ -815,7 +815,7 @@ LOGOS_TEST(migrate_user_config_0_1_2_returns_0_on_success) {
t.mockCFunction("migrate_user_config_0_1_2").returns(0);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("migrate_user_config_0_1_2"));
}
@ -825,7 +825,7 @@ LOGOS_TEST(migrate_user_config_0_1_2_returns_1_on_failure) {
t.mockCFunction("migrate_user_config_0_1_2").returns(1);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(participate_returns_0_on_success) {
@ -834,7 +834,7 @@ LOGOS_TEST(participate_returns_0_on_success) {
t.mockCFunction("participate").returns(0);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", ""), 0);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", ""), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("participate"));
}
@ -844,7 +844,7 @@ LOGOS_TEST(participate_returns_1_on_failure) {
t.mockCFunction("participate").returns(1);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", "1.2.3.4"), 1);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", "1.2.3.4"), std::string("1"));
}
// ============================================================================
@ -901,7 +901,7 @@ LOGOS_TEST(add_key_returns_0_on_success) {
t.mockCFunction("add_key").returns(0);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "ed25519", VALID_HEX, ""), 0);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "ed25519", VALID_HEX, ""), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("add_key"));
}
@ -909,7 +909,7 @@ LOGOS_TEST(add_key_rejects_invalid_key_type) {
auto t = LogosTestContext("blockchain_module");
LogosBlockchainModule module;
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "bogus", VALID_HEX, ""), 1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "bogus", VALID_HEX, ""), std::string("1"));
LOGOS_ASSERT_FALSE(t.cFunctionCalled("add_key"));
}
@ -919,7 +919,7 @@ LOGOS_TEST(add_key_returns_1_on_failure) {
t.mockCFunction("add_key").returns(1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "zk", VALID_HEX, "title"), 1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "zk", VALID_HEX, "title"), std::string("1"));
}
LOGOS_TEST(remove_key_returns_0_on_success) {
@ -928,7 +928,7 @@ LOGOS_TEST(remove_key_returns_0_on_success) {
t.mockCFunction("remove_key").returns(0);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), 0);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("remove_key"));
}
@ -938,7 +938,7 @@ LOGOS_TEST(remove_key_returns_1_on_failure) {
t.mockCFunction("remove_key").returns(1);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), 1);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), std::string("1"));
}
// ============================================================================