Round invoice amounts up to nearest msatoshi
So that very small amounts are rounded to 1 msatoshi rather than to 0.
This commit is contained in:
parent
a27e283fa3
commit
3bbc5a593d
|
@ -18,6 +18,7 @@ const toMsat = async (currency, amount) =>
|
|||
big(amount)
|
||||
.div(FIXED_RATES[currency] || await getRate(currency))
|
||||
.mul(BTC_MSAT_RATIO)
|
||||
.round(0, 3) // round up to nearest msatoshi
|
||||
.toFixed(0)
|
||||
|
||||
module.exports = { getRate, toMsat }
|
||||
|
|
|
@ -54,6 +54,13 @@ describe('Invoice API', function() {
|
|||
.expect(201)
|
||||
.expect(r => ok(r.body.msatoshi == null))
|
||||
})
|
||||
|
||||
it('rounds amounts up to the nearest msatoshi', () =>
|
||||
charge.post('/invoice')
|
||||
.send({ currency: 'BTC', amount: '0.0000000000000001' })
|
||||
.expect(201)
|
||||
.expect(r => eq(r.body.msatoshi, 1))
|
||||
)
|
||||
})
|
||||
|
||||
const mkInvoice = props =>
|
||||
|
|
Loading…
Reference in New Issue