mirror of
https://github.com/logos-blockchain/logos-blockchain-module.git
synced 2026-07-13 10:39:32 +00:00
feat: add back new block add event handling (#32)
This commit is contained in:
parent
0256ed8547
commit
f3558372fd
@ -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!
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user