mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
Plugins: Add a notification for invoice payment
Similarly to the 'invoice_payment' hook
This commit is contained in:
committed by
ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
2235d3b9d7
commit
b5bb7f191f
@@ -1,7 +1,4 @@
|
||||
#include "invoice.h"
|
||||
#include "json.h"
|
||||
#include "jsonrpc.h"
|
||||
#include "lightningd.h"
|
||||
#include <bitcoin/address.h>
|
||||
#include <bitcoin/base58.h>
|
||||
#include <bitcoin/script.h>
|
||||
@@ -25,7 +22,11 @@
|
||||
#include <inttypes.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
#include <lightningd/json.h>
|
||||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/log.h>
|
||||
#include <lightningd/notification.h>
|
||||
#include <lightningd/options.h>
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <lightningd/peer_htlcs.h>
|
||||
@@ -173,6 +174,10 @@ invoice_payment_hook_cb(struct invoice_payment_hook_payload *payload,
|
||||
struct invoice invoice;
|
||||
enum onion_type failcode;
|
||||
|
||||
/* We notify here to benefit from the payload and because the hook callback is
|
||||
* called even if the hook is not registered. */
|
||||
notify_invoice_payment(ld, payload->msat, payload->preimage, payload->label);
|
||||
|
||||
tal_del_destructor2(payload->hin, invoice_payload_remove_hin, payload);
|
||||
/* We want to free this, whatever happens. */
|
||||
tal_steal(tmpctx, payload);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "lightningd/notification.h"
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <lightningd/json.h>
|
||||
#include <lightningd/notification.h>
|
||||
|
||||
const char *notification_topics[] = {
|
||||
"connect",
|
||||
"disconnect",
|
||||
"warning"
|
||||
"warning",
|
||||
"invoice_payment"
|
||||
};
|
||||
|
||||
bool notifications_have_topic(const char *topic)
|
||||
@@ -59,4 +60,19 @@ void notify_warning(struct lightningd *ld, struct log_entry *l)
|
||||
json_object_end(n->stream); /* .warning */
|
||||
jsonrpc_notification_end(n);
|
||||
plugins_notify(ld->plugins, take(n));
|
||||
}
|
||||
}
|
||||
|
||||
void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount,
|
||||
struct preimage preimage, const struct json_escape *label)
|
||||
{
|
||||
struct jsonrpc_notification *n =
|
||||
jsonrpc_notification_start(NULL, notification_topics[3]);
|
||||
json_object_start(n->stream, notification_topics[3]);
|
||||
json_add_string(n->stream, "msat",
|
||||
type_to_string(tmpctx, struct amount_msat, &amount));
|
||||
json_add_hex(n->stream, "preimage", &preimage, sizeof(preimage));
|
||||
json_add_escaped_string(n->stream, "label", label);
|
||||
json_object_end(n->stream);
|
||||
jsonrpc_notification_end(n);
|
||||
plugins_notify(ld->plugins, take(n));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
||||
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
||||
#include "config.h"
|
||||
#include <ccan/json_escape/json_escape.h>
|
||||
#include <common/amount.h>
|
||||
#include <lightningd/jsonrpc.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
#include <lightningd/log.h>
|
||||
@@ -14,4 +16,7 @@ void notify_disconnect(struct lightningd *ld, struct node_id *nodeid);
|
||||
|
||||
void notify_warning(struct lightningd *ld, struct log_entry *l);
|
||||
|
||||
void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount,
|
||||
struct preimage preimage, const struct json_escape *label);
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */
|
||||
|
||||
@@ -287,6 +287,10 @@ void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEE
|
||||
/* Generated stub for notify_disconnect */
|
||||
void notify_disconnect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED)
|
||||
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); }
|
||||
/* Generated stub for notify_invoice_payment */
|
||||
void notify_invoice_payment(struct lightningd *ld UNNEEDED, struct amount_msat amount UNNEEDED,
|
||||
struct preimage preimage UNNEEDED, const struct json_escape *label UNNEEDED)
|
||||
{ fprintf(stderr, "notify_invoice_payment called!\n"); abort(); }
|
||||
/* Generated stub for onchaind_funding_spent */
|
||||
enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user