Use HODL invoices#432
Conversation
7ff7e52 to
b49ffe1
Compare
b49ffe1 to
d830f97
Compare
|
Zero out your anon user's account balance and test this. Because the invoice isn't settled before the action, anon's account has an insufficient balance. This will probably require either
|
9359180 to
7621094
Compare
7621094 to
d830f97
Compare
Good catch! Fixed that now. I picked
since it required the least code and rollback is automatic which seems like the most secure solution https://files.ekzyis.com/public/sn/hodl_invoices_2.mp4 I'll keep this as a draft now though since I want to sleep over this and do another pass over the code. Maybe I missed something. |
d65bf59 to
d00ab98
Compare
|
As we were philosophizing about code style on monday ... One blanket observation about this PR that I think is worth noting is that we are introducing several more places where we are interacting with LND, ie when I imagine changing something about our interaction with lnd in the future I now have several more places to look/change. This "interaction creep" is natural and it's not obvious to me how we'd reduce the "interaction points" in this case (as I'm not the author), but it's something we always want to keep in mind; ie how easy will it be for me to change this code in the future without introducing bugs. |
d00ab98 to
9e957fb
Compare
We did? 🙈 😄
You are right that it's used in more places now but afaict, the only new place is in api/resolvers/item.js to settle the hodl invoices, no? Other than that, I only updated existing LND code in api/resolvers/wallet.js (to conditionally create HODL invoices instead of normal invoices which automatically settle) and in the worker.
I agree. I was thinking about if it's worth to also move the settlement code to the worker by confirming the invoice during item creation and adding a pgboss job. Then the worker would pick up the job and settle the invoice. Then all LND code for finalizing hodl invoices (settlement or cancellation) would be in the worker. But I don't think it's worth it since it's more changes for only moving a single line to a different file imo |
I think you're thinking about this right. It's not important that we do it just this minute but it needs to be on The List™️. |
|
Also sorry for my recent push, but bright side: it should allow you to delete a satisfying amount of duplicate code. |
fe6fb3e to
41600f8
Compare
Yep, I did. The following current logic prevents paying per invoice for logged-in stackers: api/resolvers/item.js:1123 @ 41600f8: |
61dc8e8 to
a44a4ce
Compare
|
I was thinking about adding #405 in this PR but I think it's better to do this in a separate PR now to not hold up this PR any longer. It should be fairly easy though. With the current logic, any additional paid sats will already go to the user balance. |
|
If it interests you, please also consider refactoring "invoicable" stuff into a Form error handler. |
8cb5bb7 to
c8947b0
Compare
|
Ok, this should be done now. Did a final pass on all requirements: https://files.ekzyis.com/public/sn/hodl_invoices_3.mp4 requirements:
|
|
Love seeing all these code deletions! So satisfying! |
This is done by syncing the data from LND to the Invoice table. If the columns is_held and msatsReceived are set, the frontend is told that we're ready to execute the action. We then update the user balance in the same tx as the action. We need to still keep checking the invoice for expiration though.
* renamed invoiceHash, invoiceHmac to hash, hmac since it's less verbose all over the place * form now supports `invoiceable` in its props * form then wraps `onSubmit` with `useInvoiceable` and passes optional invoice options
fe0f262 to
db278f0
Compare
|
Oh dang I just realized updating by rebasing re-authors commits. I'll stop doing that. |
|
First of all, this is AMAZING. One thing I've noticed so far: local storage isn't cleared on success ... better than losing it on failure though. |
Oh, I thought rebases only update "committed by" not "authored by"
😊
Oh, right, I'll try to think of something |
Not working yet, see FIXME in api/resolvers/item.js:72
Closes #415
TODO:
preimageto invoice tableAccording to this comment, HODL invoices are automatically canceled after they expire but I would like to see some official docs on this.
-- invoices are now canceled if they expire in
checkInvoiceof workerWorks now:
https://files.ekzyis.com/public/sn/hodl_invoices.mp4
New TODOs: