tip order procedure

This commit is contained in:
Daniel Lugo 2020-12-10 20:33:40 -04:00
parent 3905565cf4
commit 3b28d86b38

View file

@ -227,19 +227,20 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
const invoicePutEndTime = performance.now() - invoicePutStartTime const invoicePutEndTime = performance.now() - invoicePutStartTime
const hash = invoice.r_hash.toString('base64')
// invoices should be settled right away so we can rely on this single // invoices should be settled right away so we can rely on this single
// subscription instead of life-long all invoices subscription // subscription instead of life-long all invoices subscription
if (order.targetType === 'post') { if (order.targetType === 'post') {
const { subscribeSingleInvoice } = LightningServices.invoices
const { postID } = order const { postID } = order
if (!Common.isPopulatedString(postID)) { if (!Common.isPopulatedString(postID)) {
throw new TypeError(`postID not a a populated string`) throw new TypeError(`postID not a a populated string`)
} }
const stream = subscribeSingleInvoice({ r_hash: hash }) const { r_hash } = invoice
// A post tip order lifecycle is short enough that we can do it like this.
const stream = LightningServices.invoices.subsribeSingleInvoice({
r_hash
})
/** /**
* @param {Common.Invoice} invoice * @param {Common.Invoice} invoice
@ -263,6 +264,9 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
stream.on('end', () => { stream.on('end', () => {
logger.warn(`Post tip, post: ${postID}, invoice stream ended`) logger.warn(`Post tip, post: ${postID}, invoice stream ended`)
}) })
stream.on('error', (/** @type {any} */ e) => {
logger.warn(`Post tip, post: ${postID}, error:`, e)
})
} }
logger.info(`[PERF] Added invoice to GunDB in ${invoicePutEndTime}ms`) logger.info(`[PERF] Added invoice to GunDB in ${invoicePutEndTime}ms`)