Add "msatoshi_received" with the actual amount paid

This commit is contained in:
Nadav Ivgi 2018-01-26 14:06:22 +02:00
parent 5d3743acba
commit b6dc91cf99
4 changed files with 26 additions and 6 deletions

View File

@ -0,0 +1,7 @@
exports.up = db =>
db.schema.table('invoice', t =>
t.string('msatoshi_received').nullable())
exports.down = db =>
db.schema.table('invoice', t =>
t.dropColumn('msatoshi_received'))

View File

@ -14,9 +14,9 @@ class PaymentListener extends EventEmitter {
}
async pollNext(last_index) {
const { label: id, pay_index, paid_at } = await this.ln.waitanyinvoice(last_index)
const { label: id, pay_index, paid_at, msatoshi_received } = await this.ln.waitanyinvoice(last_index)
if (await this.model.markPaid(id, pay_index, paid_at)) {
if (await this.model.markPaid(id, pay_index, paid_at, msatoshi_received)) {
const invoice = await this.model.fetchInvoice(id)
debug('invoice %s paid: %o', invoice.id, invoice)
this.emit('payment', invoice)
@ -29,7 +29,7 @@ class PaymentListener extends EventEmitter {
}
register(id, timeout) {
debug('register for %s', id)
debug('register(%s)', id)
return new Promise((resolve, reject) => {
const onPay = invoice => {

View File

@ -47,11 +47,11 @@ module.exports = (db, ln) => {
db('invoice').then(rows => rows.map(format))
const fetchInvoice = id =>
db('invoice').where({ id }).first().then(r => r && format(r))
db('invoice').where({ id }).first().then(r => r && format(r))
const markPaid = (id, pay_index, paid_at) =>
const markPaid = (id, pay_index, paid_at, msatoshi_received) =>
db('invoice').where({ id, pay_index: null })
.update({ pay_index, paid_at })
.update({ pay_index, paid_at, msatoshi_received })
const getLastPaid = _ =>
db('invoice').max('pay_index as index')

View File

@ -88,6 +88,19 @@ describe('Invoice API', function() {
eq(body.completed, false) // to be deprecated
})
)
describe('msatoshi_received', () => {
let inv
before(async () => {
inv = await mkInvoice()
await lnBob.pay(inv.payreq, 432)
})
it('contains the actual amount paid', () =>
charge.get(`/invoice/${ inv.id }`)
.expect(200)
.expect(r => eq(r.body.msatoshi_received, '432'))
)
})
})
describe('GET /invoice/:invoice/wait', function() {