nostr-cln-events

cln plugin that publishes events to nostr
git clone git://jb55.com/nostr-cln-events
Log | Files | Refs | README | LICENSE

commit 67a9c793a9fc6132c1bd955a68d83cd8abd12677
parent 4760a5af5c6f652a231920c9542c988099dda5f7
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 17 Nov 2022 21:40:52 -0800

generalize notify_pk

Diffstat:
Mnostr-events.js | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/nostr-events.js b/nostr-events.js @@ -57,6 +57,7 @@ function decode(bolt11) { async function plugin_init(params) { const relay = params.options['nostr-relay'] const privkey = params.options['nostr-key'] + const notify_pk = params.options['nostr-notify-key'] const pubkey = getPublicKey(privkey) let eventList = params.options['nostr-events'] const pool = RelayPool([relay]) @@ -73,7 +74,7 @@ async function plugin_init(params) { const evName = Object.keys(params)[0] if (!eventList.includes(evName)) return - let res = await handle_msg(evName, params) + let res = await handle_msg(notify_pk, evName, params) if (res === null) return if (typeof res === "string") @@ -200,12 +201,12 @@ function get_invoice_type(invoice) return (invoice.bolt11 && "bolt11") || (invoice.bolt12 && "bolt12") || "Unknown" } -async function process_invoice_payment(params) +async function process_invoice_payment(notify_pk, params) { const sats = mksats(params.msat) const invoice = await get_invoice(params.label) const content = `You got paid ${sats} for '${invoice.description}'` - const tags = [["p","32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"]] + const tags = [["p", notify_pk]] return {content, tags} } @@ -227,7 +228,7 @@ async function format_channel_state_changed(p) return `${node}'s channel (${p.short_channel_id}) changed from ${p.old_state} to ${p.new_state} caused by ${p.cause}.\n\n"${p.message}"` } -async function handle_msg(name, params) +async function handle_msg(notify_pk, name, params) { if (name === "sendpay_success") return await format_sendpay_success(params.sendpay_success) @@ -248,7 +249,7 @@ async function handle_msg(name, params) return await process_forward_event(params.forward_event) if (name === "invoice_payment") - return process_invoice_payment(params.invoice_payment) + return process_invoice_payment(notify_pk, params.invoice_payment) if (name === "invoice_creation") return process_invoice_creation(params.invoice_creation)