From f3558372fdffd7925f2c2667aadfe1b208d731f9 Mon Sep 17 00:00:00 2001 From: Khushboo-dev-cpp <60327365+Khushboo-dev-cpp@users.noreply.github.com> Date: Fri, 12 Jun 2026 17:04:44 +0200 Subject: [PATCH] feat: add back new block add event handling (#32) --- src/logos_blockchain_module.cpp | 3 +-- src/logos_blockchain_module.h | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/logos_blockchain_module.cpp b/src/logos_blockchain_module.cpp index 873f944..bbfa972 100644 --- a/src/logos_blockchain_module.cpp +++ b/src/logos_blockchain_module.cpp @@ -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! diff --git a/src/logos_blockchain_module.h b/src/logos_blockchain_module.h index acf66d2..a2ae1d5 100644 --- a/src/logos_blockchain_module.h +++ b/src/logos_blockchain_module.h @@ -1,10 +1,11 @@ #pragma once #include -#include #include #include +#include + #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 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;