Merge a9b7dd99e749bc85d1f516ec5849a779458cc869 into 7522b80cf7f71df90220f52d8274ea72ec6ea8f0

This commit is contained in:
Álex 2026-02-20 00:51:07 +01:00 committed by GitHub
commit 17cae29432
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 164 additions and 23 deletions

6
flake.lock generated
View File

@ -23,11 +23,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1771509425,
"narHash": "sha256-hTmDLC+RcfPyuEbE8xnhL4qAN4U5M2RojWk0YonsSFY=",
"lastModified": 1771528322,
"narHash": "sha256-nH/DtNKHWJkaV5JJjKHRSa6zTm1KG+p4iQHSlAd6o2Y=",
"owner": "logos-blockchain",
"repo": "logos-blockchain",
"rev": "9ae525d6d16c0431b61d4e4c44f29dd0397f4fd4",
"rev": "60ed77d5779af5c4d9c977e6dfbeced8cc48d8b3",
"type": "github"
},
"original": {

View File

@ -2,7 +2,6 @@
#define I_LOGOS_BLOCKCHAIN_MODULE_API_H
#include <QString>
#include <QStringList>
#include <core/interface.h>
class ILogosBlockchainModule {
@ -13,15 +12,17 @@ public:
virtual void initLogos(LogosAPI* logosAPIInstance) = 0;
// Node
virtual int generate_user_config(const QVariantMap& args) = 0;
virtual int start(const QString& config_path, const QString& deployment) = 0;
virtual int stop() = 0;
virtual QString wallet_get_balance(const QString& addressHex) = 0;
virtual QString wallet_transfer_funds(
const QString& changePublicKey,
const QStringList& senderAddresses,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex) = 0;
const QString& changePublicKey,
const QStringList& senderAddresses,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex
) = 0;
virtual QStringList wallet_get_known_addresses() = 0;
};

View File

@ -23,7 +23,7 @@ namespace {
return {};
return bytes;
}
}
} // namespace
void LogosBlockchainModule::onNewBlockCallback(const char* block) {
if (s_instance) {
@ -150,12 +150,11 @@ QString LogosBlockchainModule::wallet_get_balance(const QString& addressHex) {
return QStringLiteral("Error: Address must be 64 hex characters (32 bytes).");
}
auto [value, error] = get_balance(node,
reinterpret_cast<const uint8_t*>(bytes.constData()), nullptr);
auto [value, error] = get_balance(node, reinterpret_cast<const uint8_t*>(bytes.constData()), nullptr);
if (!is_ok(&error)) {
return QStringLiteral("Error: Failed to get balance: ") + QString::number(error);
}
return QString::number(value);
}
@ -231,8 +230,8 @@ QString LogosBlockchainModule::wallet_transfer_funds(
const QString& senderAddress,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex)
{
const QString& optionalTipHex
) {
return wallet_transfer_funds(changePublicKey, QStringList{senderAddress}, recipientAddress, amount, optionalTipHex);
}
@ -261,6 +260,144 @@ QStringList LogosBlockchainModule::wallet_get_known_addresses() {
return out;
}
namespace {
// Wrapper that owns data and provides GenerateConfigArgs
struct OwnedGenerateConfigArgs {
std::vector<QByteArray> initial_peers_data;
std::vector<const char*> initial_peers_ptrs;
uint32_t initial_peers_count_val;
QByteArray output_data;
uint16_t net_port_val;
uint16_t blend_port_val;
QByteArray http_addr_data;
QByteArray external_address_data;
bool no_public_ip_check_val;
QByteArray custom_deployment_config_path_data;
Deployment deployment_val;
QByteArray state_path_data;
// The FFI struct with pointers into owned data
GenerateConfigArgs ffi_args;
// Constructor that populates both owned data and FFI struct
explicit OwnedGenerateConfigArgs(const QVariantMap& args) {
ffi_args = {};
// initial_peers (QStringList -> const char**)
if (args.contains("initial_peers")) {
QStringList peers = args["initial_peers"].toStringList();
initial_peers_count_val = static_cast<uint32_t>(peers.size());
for (const QString& peer : peers) {
initial_peers_data.push_back(peer.toUtf8());
}
for (const QByteArray& data : initial_peers_data) {
initial_peers_ptrs.push_back(data.constData());
}
ffi_args.initial_peers = initial_peers_ptrs.data();
ffi_args.initial_peers_count = &initial_peers_count_val;
} else {
ffi_args.initial_peers = nullptr;
ffi_args.initial_peers_count = nullptr;
}
// output (QString -> const char*)
if (args.contains("output")) {
output_data = args["output"].toString().toUtf8();
ffi_args.output = output_data.constData();
} else {
ffi_args.output = nullptr;
}
// net_port (int -> const uint16_t*)
if (args.contains("net_port")) {
net_port_val = static_cast<uint16_t>(args["net_port"].toInt());
ffi_args.net_port = &net_port_val;
} else {
ffi_args.net_port = nullptr;
}
// blend_port (int -> const uint16_t*)
if (args.contains("blend_port")) {
blend_port_val = static_cast<uint16_t>(args["blend_port"].toInt());
ffi_args.blend_port = &blend_port_val;
} else {
ffi_args.blend_port = nullptr;
}
// http_addr (QString -> const char*)
if (args.contains("http_addr")) {
http_addr_data = args["http_addr"].toString().toUtf8();
ffi_args.http_addr = http_addr_data.constData();
} else {
ffi_args.http_addr = nullptr;
}
// external_address (QString -> const char*)
if (args.contains("external_address")) {
external_address_data = args["external_address"].toString().toUtf8();
ffi_args.external_address = external_address_data.constData();
} else {
ffi_args.external_address = nullptr;
}
// no_public_ip_check (bool -> const bool*)
if (args.contains("no_public_ip_check")) {
no_public_ip_check_val = args["no_public_ip_check"].toBool();
ffi_args.no_public_ip_check = &no_public_ip_check_val;
} else {
ffi_args.no_public_ip_check = nullptr;
}
// deployment (const struct Deployment*)
// Expected format: { "deployment": { "well_known_deployment": "devnet" } }
// OR: { "deployment": { "config_path": "/path/to/config" } }
if (args.contains("deployment")) {
QVariantMap deployment = args["deployment"].toMap();
if (deployment.contains("well_known_deployment")) {
deployment_val.deployment_type = DeploymentType::WellKnown;
QString wellknown = deployment["well_known_deployment"].toString();
if (wellknown == "devnet") {
deployment_val.well_known_deployment = WellKnownDeployment::Devnet;
}
deployment_val.custom_deployment_config_path = nullptr;
} else if (deployment.contains("config_path")) {
deployment_val.deployment_type = DeploymentType::Custom;
deployment_val.well_known_deployment = static_cast<WellKnownDeployment>(0);
custom_deployment_config_path_data = deployment["config_path"].toString().toUtf8();
deployment_val.custom_deployment_config_path = custom_deployment_config_path_data.constData();
}
ffi_args.deployment = &deployment_val;
} else {
ffi_args.deployment = nullptr;
}
// state_path (QString -> const char*)
if (args.contains("state_path")) {
state_path_data = args["state_path"].toString().toUtf8();
ffi_args.state_path = state_path_data.constData();
} else {
ffi_args.state_path = nullptr;
}
}
};
} // namespace
int LogosBlockchainModule::generate_user_config(const QVariantMap& args) {
const OwnedGenerateConfigArgs owned_args(args);
const OperationStatus status = ::generate_user_config(owned_args.ffi_args);
if (!is_ok(&status)) {
qCritical() << "Failed to generate user config. Error:" << status;
return 1;
}
return 0;
}
void LogosBlockchainModule::emitEvent(const QString& eventName, const QVariantList& data) {
if (!logosAPI) {
qWarning() << "LogosBlockchainModule: LogosAPI not available, cannot emit" << eventName;

View File

@ -1,6 +1,7 @@
#pragma once
#include "i_logos_blockchain_module.h"
#include <QtCore/QDebug>
#include <iostream>
#ifdef __cplusplus
extern "C" {
@ -9,7 +10,6 @@ extern "C" {
#ifdef __cplusplus
}
#endif
#include "i_logos_blockchain_module.h"
class LogosBlockchainModule final : public QObject, public PluginInterface, public ILogosBlockchainModule {
Q_OBJECT
@ -26,21 +26,24 @@ public:
Q_INVOKABLE void initLogos(LogosAPI*) override;
// Logos Blockchain
Q_INVOKABLE int generate_user_config(const QVariantMap& args) override;
Q_INVOKABLE int start(const QString& config_path, const QString& deployment) override;
Q_INVOKABLE int stop() override;
Q_INVOKABLE QString wallet_get_balance(const QString& addressHex) override;
Q_INVOKABLE QString wallet_transfer_funds(
const QString& changePublicKey,
const QStringList& senderAddresses,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex) override;
const QString& changePublicKey,
const QStringList& senderAddresses,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex
) override;
Q_INVOKABLE QString wallet_transfer_funds(
const QString& changePublicKey,
const QString& senderAddress,
const QString& recipientAddress,
const QString& amount,
const QString& optionalTipHex);
const QString& optionalTipHex
);
Q_INVOKABLE QStringList wallet_get_known_addresses() override;
signals: