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:
Nadav Ivgi 2018-03-26 01:10:49 +03:00
parent a27e283fa3
commit 3bbc5a593d
2 changed files with 8 additions and 0 deletions

View File

@ -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 }

View File

@ -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 =>