feat(explorer): Expose explorer API (#23)

This commit is contained in:
Álex 2026-04-17 16:08:25 +02:00 committed by GitHub
parent 16d5457aac
commit 782ef8f61c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 151 additions and 54 deletions

68
flake.lock generated
View File

@ -23,16 +23,16 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1775209920,
"narHash": "sha256-6OyLQ2jBX+Ce6PamHnvCmd8MEr9hufD/CflQ2+Ose5c=",
"lastModified": 1776356581,
"narHash": "sha256-sobcZML04NQCxSe5Vyyxj2avPPP1MjvgBbI2rzalebA=",
"owner": "logos-blockchain",
"repo": "logos-blockchain",
"rev": "b362c37d8f1a836fa782498ebd78fa4a19f648f9",
"rev": "fd7996bbdc2f77ce83bfa7d1777bbfdb3f87997b",
"type": "github"
},
"original": {
"owner": "logos-blockchain",
"ref": "feat/c-bindings/blend",
"ref": "feat/c-bindings/get-block-and-tx",
"repo": "logos-blockchain",
"type": "github"
}
@ -142,11 +142,11 @@
]
},
"locked": {
"lastModified": 1774988975,
"narHash": "sha256-wJ7Bv3TL754bZcTL2qilI0JahiVag7fLDzw8Y6Qz0pk=",
"lastModified": 1776359718,
"narHash": "sha256-G2+MbYPictF9V9864KndteaEJzd8iUMktSzCphETabw=",
"owner": "logos-co",
"repo": "logos-cpp-sdk",
"rev": "d633575677a3d19a8bf1d5ff687398dace532938",
"rev": "04b75c84b821662c9ae8f69967d4dd508e6d9e17",
"type": "github"
},
"original": {
@ -227,11 +227,11 @@
]
},
"locked": {
"lastModified": 1774958555,
"narHash": "sha256-9FMXR+YesH0JnR3DBv3BG1jtdTDWkPwMx+kIhuBpxZ4=",
"lastModified": 1776359718,
"narHash": "sha256-G2+MbYPictF9V9864KndteaEJzd8iUMktSzCphETabw=",
"owner": "logos-co",
"repo": "logos-cpp-sdk",
"rev": "38006e72400ee96a9d75e8feb102b474f80d3da5",
"rev": "04b75c84b821662c9ae8f69967d4dd508e6d9e17",
"type": "github"
},
"original": {
@ -381,11 +381,11 @@
"process-stats": "process-stats"
},
"locked": {
"lastModified": 1774967221,
"narHash": "sha256-i/8S4ldt0ikyjWrwp428Y7a7MRCIsS4R7pED0MFM52o=",
"lastModified": 1776379599,
"narHash": "sha256-F2udDQNt9LMsvVTJ+lEh7kFGWI1WYe1xUcReJAakdLY=",
"owner": "logos-co",
"repo": "logos-liblogos",
"rev": "da6ba7210e5145bfa5cb40590a2ac7e5dbbfd30d",
"rev": "e96b05b657a7871be85842e559c2635eef5c31a1",
"type": "github"
},
"original": {
@ -560,11 +560,11 @@
]
},
"locked": {
"lastModified": 1774633164,
"narHash": "sha256-TobXeKMS1RWYKo30ujYJNnrDVhu4U1JFdtL31yIOu8c=",
"lastModified": 1776369033,
"narHash": "sha256-ehePoUEd/u3Ng0TvCmjocXYJWWH6P61PA7tNpgV59lo=",
"owner": "logos-co",
"repo": "logos-module",
"rev": "8ed727449a4a6713a8c819c213b0d5d25f575580",
"rev": "194778491ef4dd36967ac40cc2fec6b8a8b1d660",
"type": "github"
},
"original": {
@ -801,11 +801,11 @@
"nixpkgs": "nixpkgs_10"
},
"locked": {
"lastModified": 1773955630,
"narHash": "sha256-KqzMoWYIVp2xMgphs7v02T/BE54RKMFxpdC2duhJKG0=",
"lastModified": 1774455309,
"narHash": "sha256-3AN7aFnArdysrbQQ2UskWzjNSFADb4hDCsnx69Fa0ng=",
"owner": "logos-co",
"repo": "logos-nix",
"rev": "0e9e6d66ab8eb34f59e45ed448f7dc29130feb88",
"rev": "e637a1f5e871244d1c2df1e3c52a067f2eb406f2",
"type": "github"
},
"original": {
@ -844,11 +844,11 @@
]
},
"locked": {
"lastModified": 1773965173,
"narHash": "sha256-toDnGXUthRcQm7vcEYzb2bLI7FE1tbfzH8Ie2Cnb9mk=",
"lastModified": 1775835037,
"narHash": "sha256-Cti0DhkzyLQs98BSzcHWMLtGXpa3n+R+5upfSw6vKdQ=",
"owner": "logos-co",
"repo": "logos-package",
"rev": "9e3730d5c0e3ec955761c05b50e3a6047ee4030b",
"rev": "ff93a0df15ceab255f27687d22d962ea2737efbe",
"type": "github"
},
"original": {
@ -871,11 +871,11 @@
]
},
"locked": {
"lastModified": 1774635434,
"narHash": "sha256-9LRXf/Wy500rNO9IhDSH+PSuadS3TguNFCbcbI4YYZU=",
"lastModified": 1776374462,
"narHash": "sha256-HMkuqSLdScAWTwXEWjhqx9Yk82GiPzPIfRaHTvjG730=",
"owner": "logos-co",
"repo": "logos-package-manager",
"rev": "e5c25989861f4487c3dc8c7b3bc0062bcbc3221f",
"rev": "9101875bc103214855bc6217834e22e66802ed86",
"type": "github"
},
"original": {
@ -941,11 +941,11 @@
]
},
"locked": {
"lastModified": 1773961597,
"narHash": "sha256-UEUlp3VRXBcj2YlOMTQdeW3qjyGJl2V3+GMf8IXwSWA=",
"lastModified": 1774455478,
"narHash": "sha256-S8IMfdDc+2Wwri0krLDsIUwSqmwanmvHAJWHOFo8ykk=",
"owner": "logos-co",
"repo": "nix-bundle-appimage",
"rev": "7343f6df1ebab357f51f23dff0af9d7e468638cb",
"rev": "2428125a4a1b34ad9119efa97edb98676283e3da",
"type": "github"
},
"original": {
@ -1009,11 +1009,11 @@
]
},
"locked": {
"lastModified": 1773961179,
"narHash": "sha256-bpaTvz//R8WFP5xnnDLv3a9l7unDmBwJjCewx3wCjzM=",
"lastModified": 1774455641,
"narHash": "sha256-HrVJguPxhIoZMCH+x8Wooa0tE6slUhgNOU6P89t2uQc=",
"owner": "logos-co",
"repo": "nix-bundle-dir",
"rev": "cd214dbf15487d80967389847ae2210468be6ebf",
"rev": "3d155cab09051703a0b02ff2de166a53c30cbca8",
"type": "github"
},
"original": {
@ -1506,11 +1506,11 @@
]
},
"locked": {
"lastModified": 1774455550,
"narHash": "sha256-T30DJXAMb+hezgnmlZe9qqa9LL5oolvuAdF5fIVz8A0=",
"lastModified": 1775744159,
"narHash": "sha256-hTVAnDREBQOVHML6KU3K7Ge0CRBqnFIg7uYL7qDnD8o=",
"owner": "logos-co",
"repo": "process-stats",
"rev": "8213ad456b4ac074a214f24fc2b378b1bdbb0234",
"rev": "33ace1270f90c89b3565e803139c0970fcd1ce8f",
"type": "github"
},
"original": {

View File

@ -7,7 +7,7 @@
logos-liblogos.url = "github:logos-co/logos-liblogos";
logos-core.url = "github:logos-co/logos-cpp-sdk";
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=0.2.1";
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=feat/c-bindings/get-block-and-tx";
logos-module-viewer.url = "github:logos-co/logos-module-viewer";
};

View File

@ -31,6 +31,12 @@ public:
const QString& lockedNoteIdHex,
const QStringList& locators
) = 0;
// Explorer
virtual QString get_block(const QString& headerIdHex) = 0;
virtual QString get_blocks(quint64 fromSlot, quint64 toSlot) = 0;
virtual QString get_transaction(const QString& txHashHex) = 0;
virtual QString get_cryptarchia_info() = 0;
};
#define ILogosBlockchainModule_iid "org.logos.ilogosblockchainmodule"

View File

@ -2,6 +2,8 @@
#include "logos_api_client.h"
#include <QByteArray>
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariant>
// Define static member
@ -74,13 +76,14 @@ int LogosBlockchainModule::start(const QString& config_path, const QString& depl
}
// Set LOGOS_BLOCKCHAIN_CIRCUITS env variable (use QDir for correct path separator on all platforms)
QString circuits_path = QDir(logosAPI->property("modulePath").toString()).filePath(QStringLiteral("circuits"));
const QString circuits_path =
QDir(logosAPI->property("modulePath").toString()).filePath(QStringLiteral("circuits"));
qputenv("LOGOS_BLOCKCHAIN_CIRCUITS", circuits_path.toUtf8());
qInfo() << "LOGOS_BLOCKCHAIN_CIRCUITS set to:" << circuits_path;
QString effective_config_path = config_path;
if (effective_config_path.isEmpty()) {
const char* env = std::getenv("LB_CONFIG_PATH");
const char* env = std::getenv("LB_CONFIG_PATH"); // NOLINT: Move definition to if-statement
if (env && *env) {
effective_config_path = QString::fromUtf8(env);
qInfo() << "Using config from LB_CONFIG_PATH:" << effective_config_path;
@ -146,7 +149,7 @@ QString LogosBlockchainModule::wallet_get_balance(const QString& addressHex) {
return QStringLiteral("Error: The node is not running.");
}
QByteArray bytes = parseAddressHex(addressHex);
const QByteArray bytes = parseAddressHex(addressHex);
if (bytes.isEmpty() || bytes.size() != kAddressBytes) {
return QStringLiteral("Error: Address must be 64 hex characters (32 bytes).");
}
@ -176,11 +179,11 @@ QString LogosBlockchainModule::wallet_transfer_funds(
return QStringLiteral("Error: Invalid amount (positive integer required).");
}
QByteArray changeBytes = parseAddressHex(changePublicKey);
const QByteArray changeBytes = parseAddressHex(changePublicKey);
if (changeBytes.isEmpty() || changeBytes.size() != kAddressBytes) {
return QStringLiteral("Error: Invalid changePublicKey (64 hex characters required).");
}
QByteArray recipientBytes = parseAddressHex(recipientAddress);
const QByteArray recipientBytes = parseAddressHex(recipientAddress);
if (recipientBytes.isEmpty() || recipientBytes.size() != kAddressBytes) {
return QStringLiteral("Error: Invalid recipientAddress (64 hex characters required).");
}
@ -199,7 +202,7 @@ QString LogosBlockchainModule::wallet_transfer_funds(
for (const QByteArray& b : fundingBytes)
fundingPtrs.append(reinterpret_cast<const uint8_t*>(b.constData()));
QByteArray tipBytes;
QByteArray tipBytes; // NOLINT: Needs to be outside of scope for lifetime
const HeaderId* optional_tip = nullptr;
if (!optionalTipHex.isEmpty()) {
tipBytes = parseAddressHex(optionalTipHex);
@ -219,10 +222,10 @@ QString LogosBlockchainModule::wallet_transfer_funds(
auto [value, error] = transfer_funds(node, &args);
if (!is_ok(&error)) {
return QStringLiteral("Error: Failed to transfer funds: ") + QString::number(static_cast<int>(error));
return QStringLiteral("Error: Failed to transfer funds: ") + QString::number(error);
}
// value is Hash (32 bytes); convert to hex string
QByteArray hashBytes(reinterpret_cast<const char*>(&value), kAddressBytes);
const QByteArray hashBytes(reinterpret_cast<const char*>(&value), kAddressBytes);
return QString::fromUtf8(hashBytes.toHex());
}
@ -249,7 +252,7 @@ QStringList LogosBlockchainModule::wallet_get_known_addresses() {
}
// Each address is kAddressBytes (32) byte
for (size_t i = 0; i < value.len; ++i) {
const uint8_t* ptr = value.addresses[i];
const uint8_t* ptr = value.addresses[i]; // NOLINT: Move definition to if-statement
if (ptr) {
QByteArray addr(reinterpret_cast<const char*>(ptr), kAddressBytes);
out.append(QString::fromUtf8(addr.toHex()));
@ -272,19 +275,19 @@ int LogosBlockchainModule::blend_join_as_core_node(
return 1;
}
QByteArray providerIdBytes = parseAddressHex(providerIdHex);
const QByteArray providerIdBytes = parseAddressHex(providerIdHex);
if (providerIdBytes.isEmpty() || providerIdBytes.size() != kAddressBytes) {
qCritical() << "blend_join_as_core_node: Invalid providerId (64 hex characters required).";
return 2;
}
QByteArray zkIdBytes = parseAddressHex(zkIdHex);
const QByteArray zkIdBytes = parseAddressHex(zkIdHex);
if (zkIdBytes.isEmpty() || zkIdBytes.size() != kAddressBytes) {
qCritical() << "blend_join_as_core_node: Invalid zkId (64 hex characters required).";
return 3;
}
QByteArray lockedNoteIdBytes = parseAddressHex(lockedNoteIdHex);
const QByteArray lockedNoteIdBytes = parseAddressHex(lockedNoteIdHex);
if (lockedNoteIdBytes.isEmpty() || lockedNoteIdBytes.size() != kAddressBytes) {
qCritical() << "blend_join_as_core_node: Invalid lockedNoteId (64 hex characters required).";
return 4;
@ -315,11 +318,94 @@ int LogosBlockchainModule::blend_join_as_core_node(
return 5;
}
QByteArray declarationIdBytes(reinterpret_cast<const char*>(&value), sizeof(value));
const QByteArray declarationIdBytes(reinterpret_cast<const char*>(&value), sizeof(value));
qInfo() << "Successfully joined as core node. DeclarationId:" << declarationIdBytes.toHex();
return 0;
}
QString LogosBlockchainModule::get_block(const QString& headerIdHex) {
if (!node) {
return QStringLiteral("Error: The node is not running.");
}
const QByteArray bytes = parseAddressHex(headerIdHex);
if (bytes.isEmpty() || bytes.size() != kAddressBytes) {
return QStringLiteral("Error: Header ID must be 64 hex characters (32 bytes).");
}
auto [value, error] = ::get_block(node, reinterpret_cast<const HeaderId*>(bytes.constData()));
if (!is_ok(&error)) {
qWarning() << "Failed to get block. Error:" << error;
return QStringLiteral("Error: Failed to get block: ") + QString::number(error);
}
const QString result = QString::fromUtf8(value);
free_cstring(value);
return result;
}
QString LogosBlockchainModule::get_transaction(const QString& txHashHex) {
if (!node) {
return QStringLiteral("Error: The node is not running.");
}
const QByteArray bytes = parseAddressHex(txHashHex);
if (bytes.isEmpty() || bytes.size() != kAddressBytes) {
return QStringLiteral("Error: Transaction hash must be 64 hex characters (32 bytes).");
}
auto [value, error] = ::get_transaction(node, reinterpret_cast<const TxHash*>(bytes.constData()));
if (!is_ok(&error)) {
qWarning() << "Failed to get transaction. Error:" << error;
return QStringLiteral("Error: Failed to get transaction: ") + QString::number(error);
}
const QString result = QString::fromUtf8(value);
free_cstring(value);
return result;
}
QString LogosBlockchainModule::get_blocks(const quint64 fromSlot, const quint64 toSlot) {
if (!node) {
return QStringLiteral("Error: The node is not running.");
}
auto [value, error] = ::get_blocks(node, fromSlot, toSlot);
if (!is_ok(&error)) {
qWarning() << "Failed to get blocks. Error:" << error;
return QStringLiteral("Error: Failed to get blocks: ") + QString::number(error);
}
const QString result = QString::fromUtf8(value);
free_cstring(value);
return result;
}
QString LogosBlockchainModule::get_cryptarchia_info() {
if (!node) {
return QStringLiteral("Error: The node is not running.");
}
auto [value, error] = ::get_cryptarchia_info(node);
if (!is_ok(&error)) {
qWarning() << "Failed to get cryptarchia info. Error:" << error;
return QStringLiteral("Error: Failed to get cryptarchia info: ") + QString::number(error);
}
QJsonObject obj;
obj[QStringLiteral("lib")] =
QString::fromUtf8(QByteArray(reinterpret_cast<const char*>(value->lib), kAddressBytes).toHex());
obj[QStringLiteral("tip")] =
QString::fromUtf8(QByteArray(reinterpret_cast<const char*>(value->tip), kAddressBytes).toHex());
obj[QStringLiteral("slot")] = static_cast<qint64>(value->slot);
obj[QStringLiteral("height")] = static_cast<qint64>(value->height);
obj[QStringLiteral("mode")] =
(value->mode == State::Online) ? QStringLiteral("Online") : QStringLiteral("Bootstrapping");
free_cryptarchia_info(value);
return QJsonDocument(obj).toJson(QJsonDocument::Compact);
}
namespace {
// Wrapper that owns data and provides GenerateConfigArgs
struct OwnedGenerateConfigArgs {
@ -333,16 +419,14 @@ namespace {
QByteArray external_address_data;
bool no_public_ip_check_val;
QByteArray custom_deployment_config_path_data;
Deployment deployment_val;
Deployment deployment_val{};
QByteArray state_path_data;
// The FFI struct with pointers into owned data
GenerateConfigArgs ffi_args;
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();
@ -414,11 +498,12 @@ namespace {
// Expected format: { "deployment": { "well_known_deployment": "devnet" } }
// OR: { "deployment": { "config_path": "/path/to/config" } }
if (args.contains("deployment")) {
QVariantMap deployment = args["deployment"].toMap();
const QVariantMap deployment = args["deployment"].toMap(); // NOLINT: Move definition to if-statement
if (deployment.contains("well_known_deployment")) {
deployment_val.deployment_type = DeploymentType::WellKnown;
QString wellknown = deployment["well_known_deployment"].toString();
const QString wellknown =
deployment["well_known_deployment"].toString(); // NOLINT: Move definition to if-statement
if (wellknown == "devnet") {
deployment_val.well_known_deployment = WellKnownDeployment::Devnet;
}

View File

@ -53,6 +53,12 @@ public:
const QStringList& locators
) override;
// Explorer
Q_INVOKABLE QString get_block(const QString& headerIdHex) override;
Q_INVOKABLE QString get_blocks(quint64 fromSlot, quint64 toSlot) override;
Q_INVOKABLE QString get_transaction(const QString& txHashHex) override;
Q_INVOKABLE QString get_cryptarchia_info() override;
signals:
void eventResponse(const QString& eventName, const QVariantList& data);