mirror of
https://github.com/logos-blockchain/logos-blockchain-module.git
synced 2026-08-11 08:43:36 +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);
|
fprintf(stderr, "Received new block: %s\n", block);
|
||||||
json j;
|
json j;
|
||||||
j["block"] = std::string(block);
|
j["block"] = std::string(block);
|
||||||
if (s_instance->emitEvent)
|
s_instance->newBlock(j.dump());
|
||||||
s_instance->emitEvent("newBlock", j.dump());
|
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// We are getting an owned pointer here which is freed after this callback is called, so there is no need to
|
// 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!
|
// free the resource here as we are copying the data!
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <logos_module_context.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -13,16 +14,11 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class LogosBlockchainModule {
|
class LogosBlockchainModule : public LogosModuleContext {
|
||||||
public:
|
public:
|
||||||
LogosBlockchainModule();
|
LogosBlockchainModule();
|
||||||
~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 ----
|
// ---- Node ----
|
||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
@ -57,6 +53,11 @@ public:
|
|||||||
// Cryptarchia
|
// Cryptarchia
|
||||||
std::string get_cryptarchia_info();
|
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:
|
private:
|
||||||
LogosBlockchainNode* node = nullptr;
|
LogosBlockchainNode* node = nullptr;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user