Skip to content

Instantly share code, notes, and snippets.

@wbobeirne
Last active May 29, 2019 18:13
Show Gist options
  • Save wbobeirne/a0f8e587887d615648f906aac993febf to your computer and use it in GitHub Desktop.
Save wbobeirne/a0f8e587887d615648f906aac993febf to your computer and use it in GitHub Desktop.
initNode().then(() => {
/* ... */
// Subscribe to all invoices, mark posts as paid
const stream = node.subscribeInvoices() as any as Readable<Invoice>;
stream.on('data', chunk => {
// Skip unpaid / irrelevant invoice updates
if (!chunk.settled || !chunk.amtPaidSat || !chunk.memo) return;
// Extract post id from memo, skip if we can't find an id
const id = parseInt(chunk.memo.replace('Lightning Posts post #', ''), 10);
if (!id) return;
// Mark the invoice as paid!
postsManager.markPostPaid(id);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment