Open adambor opened 2 years ago
invoices without amounts are used for overpayment purposes, that's part of the LN protocol
if you want to see how much was paid, please use getInvoice or subscribeToInvoice
technically speaking in LN protocol any invoice can be overpaid
Yep, I get that, and that's how I fixed the issue. I just think that when you specify a non-zero amount for an invoice, that function call should either return the invoice of that non-zero amount or throw an error, not return an invoice without any amount... In this case it can result in underpayment, not overpayment.
is the problem that you used an incorrect number for the amount? it should be a JS number not a string
Yep, using string instead of the number, so that looks like it is a source of the issue. Very much unpredictable with strings, for smaller amounts it works, for larger it overflows and tries to create negative value invoice, and for super large ones it creates an invoice without an amount. Maybe there should be a type check? I am just trying to make sure no one else falls for this, because this resulted in some amount of BTC getting stolen from me.
Yeah I think it could type check but this is a general issue with JS in general that large numbers are undefined in their behavior and types aren't built in to the language
There is also typescript support that you could look at, I don't use that myself but potentially it can help with type enforcement
Yep, those pesky JS numbers, that's also why I am not using them at all and rather resort to js-big-decimal library and that's also a reason I am passing that number as string instead of number. Will be looking to move the whole codebase to typescript soon. But I think that simple type check might save someone some money :)
I think another approach is to specify the amount as mtokens, this takes a string and that's how you can specify large numbers
I added validation of tokens to be numeric here https://github.com/alexbosworth/lightning/commit/7bd1794cf0c5bdc61e0c1541651907ccc7795bf4
But the real way to stop problems is to totally lock down user input and that has to live at the application level
When I create a hodl invoice by:
Following response is returned (payment request without an amount, but tokens returned are 1.045e+86):
If I use createInvoice the response then is (at least the tokens returned are 0):
However this might lead to some bugs in implementation (like it happened for me) expecting that when the invoice is paid I should increment the user's balance by 1.045e+86, even though the user might've just paid 1 sat.
I would expect the lib to throw an error in such a case, and not an invoice without an amount.