Skip to content

Commit

Permalink
Make the invoice description and expiry configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Nov 28, 2017
1 parent 6b634f1 commit 68ff299
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions migrations/0000_01_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ exports.up = db =>
t.string ('rhash').notNullable().unique()
t.string ('payreq').notNullable()
t.bool ('completed').notNullable()
t.string ('description').nullable()
t.string ('metadata').nullable()
t.integer('created_at').notNullable()
t.integer('expires_at').notNullable()
t.integer('completed_at').nullable()
})

Expand Down
21 changes: 13 additions & 8 deletions model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ const debug = require('debug')('lightning-strike')
, format = invoice => ({ ...invoice, completed: !!invoice.completed, metadata: JSON.parse(invoice.metadata) })
, now = _ => Date.now() / 1000 | 0

const defaultDesc = process.env.INVOICE_DESC_DEFAULT || 'Lightning Strike invoice'

module.exports = ({ db, ln }) => {
const peerid = ln.getinfo().then(info => info.id)

const newInvoice = async ({ msatoshi, currency, amount, metadata, webhook }) => {
// @TODO validation: either msat or currency/amount are required, specifying both should error.
const newInvoice = async props => {
// @TODO validation
const { currency, amount, expiry, metadata, webhook } = props

, id = nanoid()
, msatoshi = props.msatoshi ? ''+props.msatoshi : await toMsat(currency, amount)
, description = props.description || defaultDesc

if (!msatoshi) msatoshi = await toMsat(currency, amount)
, { rhash, bolt11, expiry_time } = await ln.invoice(msatoshi, id, description, expiry)

const id = nanoid()
, { rhash, bolt11: payreq } = await ln.invoice(msatoshi, id, 'ln-strike')
, invoice = {
id, metadata, msatoshi: ''+msatoshi
id, description, metadata, msatoshi
, quoted_currency: currency, quoted_amount: amount
, rhash, payreq, peerid: (await peerid)
, rhash, payreq: bolt11, peerid: (await peerid)
, expires_at: expiry_time, created_at: now()
, completed: false
, created_at: now()
}

debug('saving invoice:', invoice)
Expand Down
2 changes: 1 addition & 1 deletion views/checkout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ meta(name='viewport', content='width=device-width, initial-scale=1')

if !completed
meta(name='invoice-poll-url', content=settings.url+'checkout/'+id+'/wait')
meta(name='invoice-expiry', content=created_at + 15 * 60 * 1000)
meta(name='invoice-expiry', content=expires_at)
//- invoices don't really expire yet, just for the looks & feel
mixin css(path)
Expand Down

0 comments on commit 68ff299

Please sign in to comment.