mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
Add plugin notification topic "block_processed".
Changelog-Added: Plugins: Added notification topic "block_processed".
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/log.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <math.h>
|
||||
#include <wallet/txfilter.h>
|
||||
|
||||
@@ -818,9 +819,13 @@ static void get_new_block(struct bitcoind *bitcoind,
|
||||
/* Unexpected predecessor? Free predecessor, refetch it. */
|
||||
if (!bitcoin_blkid_eq(&topo->tip->blkid, &blk->hdr.prev_hash))
|
||||
remove_tip(topo);
|
||||
else
|
||||
else {
|
||||
add_tip(topo, new_block(topo, blk, topo->tip->height + 1));
|
||||
|
||||
/* tell plugins a new block was processed */
|
||||
notify_block_processed(topo->ld, topo->tip);
|
||||
}
|
||||
|
||||
/* Try for next one. */
|
||||
try_extend_tip(topo);
|
||||
}
|
||||
|
||||
@@ -582,6 +582,32 @@ void notify_balance_snapshot(struct lightningd *ld,
|
||||
plugins_notify(ld->plugins, take(n));
|
||||
}
|
||||
|
||||
static void block_processed_notification_serialize(struct json_stream *stream,
|
||||
struct block *block)
|
||||
{
|
||||
json_object_start(stream, "block");
|
||||
json_add_string(stream, "hash",
|
||||
type_to_string(tmpctx, struct bitcoin_blkid, &block->blkid));
|
||||
json_add_u32(stream, "height", block->height);
|
||||
json_object_end(stream);
|
||||
}
|
||||
|
||||
REGISTER_NOTIFICATION(block_processed,
|
||||
block_processed_notification_serialize);
|
||||
|
||||
void notify_block_processed(struct lightningd *ld,
|
||||
const struct block *block)
|
||||
{
|
||||
void (*serialize)(struct json_stream *,
|
||||
const struct block *block) = block_processed_notification_gen.serialize;
|
||||
|
||||
struct jsonrpc_notification *n =
|
||||
jsonrpc_notification_start(NULL, "block_processed");
|
||||
serialize(n->stream, block);
|
||||
jsonrpc_notification_end(n);
|
||||
plugins_notify(ld->plugins, take(n));
|
||||
}
|
||||
|
||||
static void openchannel_peer_sigs_serialize(struct json_stream *stream,
|
||||
const struct channel_id *cid,
|
||||
const struct wally_psbt *psbt)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
||||
#include "config.h"
|
||||
#include <common/coin_mvt.h>
|
||||
#include <lightningd/chaintopology.h>
|
||||
#include <lightningd/pay.h>
|
||||
#include <lightningd/plugin.h>
|
||||
|
||||
@@ -86,6 +87,9 @@ void notify_coin_mvt(struct lightningd *ld,
|
||||
void notify_balance_snapshot(struct lightningd *ld,
|
||||
const struct balance_snapshot *snap);
|
||||
|
||||
void notify_block_processed(struct lightningd *ld,
|
||||
const struct block *block);
|
||||
|
||||
void notify_openchannel_peer_sigs(struct lightningd *ld,
|
||||
const struct channel_id *cid,
|
||||
const struct wally_psbt *psbt);
|
||||
|
||||
Reference in New Issue
Block a user