Add default behaviour to config_path and handle deployment in start.

This commit is contained in:
Alejandro Cabeza Romero 2026-02-02 17:28:11 +01:00
parent b2d7712dee
commit 4d03f0919c
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
2 changed files with 33 additions and 8 deletions

View File

@ -23,19 +23,38 @@ void LogosBlockchainModule::initLogos(LogosAPI* logosAPIInstance) {
logosAPI = logosAPIInstance;
}
int LogosBlockchainModule::start(const QString& config_path) {
int LogosBlockchainModule::start(const QString& config_path, const QString& deployment) {
if (node) {
qWarning() << "Could not execute the operation: The node is already running.";
return 1;
}
const QByteArray path = config_path.toUtf8();
const char* deployment = nullptr;
QString effective_config_path= config_path;
auto [value, error] = start_lb_node(path.constData(), deployment);
if (effective_config_path.isEmpty()) {
if (const char* env = std::getenv("LB_CONFIG_PATH"); env && *env) {
effective_config_path = QString::fromUtf8(env);
qInfo() << "Using config from LB_CONFIG_PATH:" << effective_config_path;
} else {
qCritical() << "Config path was not specified and LB_CONFIG_PATH is not set.";
return 2;
}
}
qInfo() << "Starting the node with the configuration file:" << effective_config_path;
qInfo() << "Using deployment:" << (deployment.isEmpty() ? "<default>" : deployment);
const QByteArray config_path_buffer = effective_config_path.toUtf8();
const char* config_path_ptr = effective_config_path.isEmpty() ? nullptr : config_path_buffer.constData();
const QByteArray deployment_buffer = deployment.toUtf8();
const char* deployment_ptr = deployment.isEmpty() ? nullptr : deployment_buffer.constData();
auto [value, error] = start_lb_node(config_path_ptr, deployment_ptr);
qInfo() << "Start node returned with value and error.";
if (!is_ok(&error)) {
qCritical() << "Failed to start the node. Error:" << error;
return 2;
return 3;
}
node = value;

View File

@ -2,24 +2,30 @@
#include "i_logos_blockchain_module.h"
class LogosBlockchainModule final : public ILogosBlockchainModule {
class LogosBlockchainModule final : public QObject, public PluginInterface, public ILogosBlockchainModule {
Q_OBJECT
Q_PLUGIN_METADATA(IID ILogosBlockchainModule_iid FILE "../metadata.json")
Q_INTERFACES(PluginInterface)
public:
LogosBlockchainModule();
~LogosBlockchainModule() override;
// Logos Core
[[nodiscard]] QString name() const override;
[[nodiscard]] QString version() const override;
Q_INVOKABLE void initLogos(LogosAPI*) override;
Q_INVOKABLE int start(const QString&) override;
// Logos Blockchain
Q_INVOKABLE int start(const QString& config_path, const QString& deployment) override;
Q_INVOKABLE int stop() override;
Q_INVOKABLE int subscribe() override;
Q_INVOKABLE int wallet_get_balance(const uint8_t*, const HeaderId*, BalanceResult*) override;
Q_INVOKABLE int wallet_transfer_funds(const TransferFundsArguments*, Hash*) override;
signals:
void eventResponse(const QString& eventName, const QVariantList& data);
private:
LogosBlockchainNode* node = nullptr;
};