feat(blend): Join as core node (#22)

This commit is contained in:
Álex 2026-04-17 11:01:18 +02:00 committed by GitHub
parent a574eb61bf
commit 16d5457aac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 101 additions and 7 deletions

View File

@ -14,3 +14,25 @@ This will reduce friction when working on the project.
* Use `nix build` to build the package
* Use `nix run` to launch the module-viewer and check your module loads properly
* Use `nix develop` to setup your IDE
### Troubleshooting
#### Nix + IDE Integration
If your IDE reports that a file doesn't belong to the project or that files cannot be found, the CMake cache
is likely missing the Nix-provided paths. This happens when the IDE runs CMake on its own, outside the Nix
environment, leaving the required paths empty.
To fix it:
1. **Regenerate the cache from within the Nix shell**
This provides the required Nix paths and writes them into `build/CMakeCache.txt`:
```bash
nix develop -c just configure
```
2. **Reload the CMake project without resetting the cache**
If on RustRover: Open the CMake tool window (**View → Tool Windows → CMake**) and click the **Reload** button (↺) in the toolbar.
> Resetting the cache would wipe the paths you just wrote, so make sure to reload only.

15
flake.lock generated
View File

@ -23,16 +23,16 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1772549761,
"narHash": "sha256-NRwUEv7Uf/Tge8y4sDZ/par+iM2/ZqxFEINpiyIqUL8=",
"lastModified": 1775209920,
"narHash": "sha256-6OyLQ2jBX+Ce6PamHnvCmd8MEr9hufD/CflQ2+Ose5c=",
"owner": "logos-blockchain",
"repo": "logos-blockchain",
"rev": "1e0fcb1c4bc92149dfab09c1c08115662d8b2c23",
"rev": "b362c37d8f1a836fa782498ebd78fa4a19f648f9",
"type": "github"
},
"original": {
"owner": "logos-blockchain",
"ref": "0.2.1",
"ref": "feat/c-bindings/blend",
"repo": "logos-blockchain",
"type": "github"
}
@ -1539,16 +1539,17 @@
]
},
"locked": {
"lastModified": 1771556776,
"narHash": "sha256-zKprqMQDl3xVfhSSYvgru1IGXjFdxryWk+KqK0I20Xk=",
"lastModified": 1772775058,
"narHash": "sha256-i+I9RYN8kYb9/9kibkxd0avkkislD1tyWojSVgIy160=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "8b3f46b8a6d17ab46e533a5e3d5b1cc2ff228860",
"rev": "629bbb7f9d02787a54e28398b411da849246253b",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "629bbb7f9d02787a54e28398b411da849246253b",
"type": "github"
}
}

View File

@ -25,6 +25,12 @@ public:
const QString& optionalTipHex
) = 0;
virtual QStringList wallet_get_known_addresses() = 0;
virtual int blend_join_as_core_node(
const QString& providerIdHex,
const QString& zkIdHex,
const QString& lockedNoteIdHex,
const QStringList& locators
) = 0;
};
#define ILogosBlockchainModule_iid "org.logos.ilogosblockchainmodule"

View File

@ -261,6 +261,65 @@ QStringList LogosBlockchainModule::wallet_get_known_addresses() {
return out;
}
int LogosBlockchainModule::blend_join_as_core_node(
const QString& providerIdHex,
const QString& zkIdHex,
const QString& lockedNoteIdHex,
const QStringList& locators
) {
if (!node) {
qWarning() << "Could not execute the operation: The node is not running.";
return 1;
}
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);
if (zkIdBytes.isEmpty() || zkIdBytes.size() != kAddressBytes) {
qCritical() << "blend_join_as_core_node: Invalid zkId (64 hex characters required).";
return 3;
}
QByteArray lockedNoteIdBytes = parseAddressHex(lockedNoteIdHex);
if (lockedNoteIdBytes.isEmpty() || lockedNoteIdBytes.size() != kAddressBytes) {
qCritical() << "blend_join_as_core_node: Invalid lockedNoteId (64 hex characters required).";
return 4;
}
// QString is UTF-16, but the FFI requires UTF-8.
// locatorsData owns the converted buffers, while locatorsPtrs holds raw pointers into them for the FFI call.
// Using reserve() prevents reallocation, keeping the constData() pointers stable.
std::vector<QByteArray> locatorsData;
std::vector<const char*> locatorsPtrs;
locatorsData.reserve(locators.size());
locatorsPtrs.reserve(locators.size());
for (const QString& locator : locators) {
locatorsData.push_back(locator.toUtf8());
locatorsPtrs.push_back(locatorsData.back().constData());
}
auto [value, error] = ::blend_join_as_core_node(
node,
reinterpret_cast<const uint8_t*>(providerIdBytes.constData()),
reinterpret_cast<const uint8_t*>(zkIdBytes.constData()),
reinterpret_cast<const uint8_t*>(lockedNoteIdBytes.constData()),
locatorsPtrs.data(),
locatorsPtrs.size()
);
if (!is_ok(&error)) {
qCritical() << "Failed to join as core node. Error:" << error;
return 5;
}
QByteArray declarationIdBytes(reinterpret_cast<const char*>(&value), sizeof(value));
qInfo() << "Successfully joined as core node. DeclarationId:" << declarationIdBytes.toHex();
return 0;
}
namespace {
// Wrapper that owns data and provides GenerateConfigArgs
struct OwnedGenerateConfigArgs {

View File

@ -46,6 +46,12 @@ public:
const QString& optionalTipHex
);
Q_INVOKABLE QStringList wallet_get_known_addresses() override;
Q_INVOKABLE int blend_join_as_core_node(
const QString& providerIdHex,
const QString& zkIdHex,
const QString& lockedNoteIdHex,
const QStringList& locators
) override;
signals:
void eventResponse(const QString& eventName, const QVariantList& data);