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;