feat: add back new block add event handling (#32)

This commit is contained in:
Khushboo-dev-cpp 2026-06-12 17:04:44 +02:00 committed by GitHub
parent 0256ed8547
commit f3558372fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -205,8 +205,7 @@ void LogosBlockchainModule::on_new_block_callback(const char* block) {
fprintf(stderr, "Received new block: %s\n", block);
json j;
j["block"] = std::string(block);
if (s_instance->emitEvent)
s_instance->emitEvent("newBlock", j.dump());
s_instance->newBlock(j.dump());
// SAFETY:
// We are getting an owned pointer here which is freed after this callback is called, so there is no need to
// free the resource here as we are copying the data!

View File

@ -1,10 +1,11 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include <logos_module_context.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -13,16 +14,11 @@ extern "C" {
}
#endif
class LogosBlockchainModule {
class LogosBlockchainModule : public LogosModuleContext {
public:
LogosBlockchainModule();
~LogosBlockchainModule();
// Wired automatically by the generated glue layer.
// Call this to emit named events to other modules / the host application.
// Data is a JSON-encoded string (object or array).
std::function<void(const std::string& eventName, const std::string& data)> emitEvent;
// ---- Node ----
// Lifecycle
@ -57,6 +53,11 @@ public:
// Cryptarchia
std::string get_cryptarchia_info();
logos_events:
// Fired by on_new_block_callback when the Rust node delivers a new block.
// blockJson is the full block serialized as JSON.
void newBlock(const std::string& blockJson);
private:
LogosBlockchainNode* node = nullptr;