diff --git a/src/logos_blockchain_module.cpp b/src/logos_blockchain_module.cpp index d87e1fe..78c8457 100644 --- a/src/logos_blockchain_module.cpp +++ b/src/logos_blockchain_module.cpp @@ -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() ? "" : 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; diff --git a/src/logos_blockchain_module.h b/src/logos_blockchain_module.h index c6a0ce8..ef49baa 100644 --- a/src/logos_blockchain_module.h +++ b/src/logos_blockchain_module.h @@ -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; };