stackernews / stacker.news

Internet communities that pay you Bitcoin
https://stacker.news
MIT License
403 stars 105 forks source link

Fix anon payment verification #1235

Closed ekzyis closed 2 weeks ago

ekzyis commented 2 weeks ago

tACK 63280987

ekzyis commented 2 weeks ago

Oh, I missed some serialize calls

~... and I can put the logic into serialize~

No, I can't since not every serialize must verify payments (like createInvoice or cancelInvoice) so it needs to be passed in.

However, I could do this:

diff --git a/api/resolvers/serial.js b/api/resolvers/serial.js
index b036cff7..82d723a6 100644
--- a/api/resolvers/serial.js
+++ b/api/resolvers/serial.js
@@ -17,6 +17,7 @@ export default async function serialize (trx, { models, lnd, me, hash, hmac, fee, verifyPayment: verify }) {
   trx = trx.filter(q => !!q)

   let invoice
+  verify = verify !== undefined ? verify : !!hash || !me
   if (verify) {
     invoice = await verifyPayment(models, hash, hmac, fee)
     trx = [

which basically uses !!hash || !me as the default for verify and then set verifyPayment manually to false where we don't want it like for createInvoice:

diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js
index 153bf3ce..3d9746f0 100644
--- a/api/resolvers/wallet.js
+++ b/api/resolvers/wallet.js
@@ -358,7 +358,7 @@ export default {
           models.$queryRaw`SELECT * FROM create_invoice(${invoice.id}, ${hodlInvoice ? invoice.secret : null}::TEXT, ${invoice.request},
             ${expiresAt}::timestamp, ${amount * 1000}, ${user.id}::INTEGER, ${description}, NULL, NULL,
             ${invLimit}::INTEGER, ${balanceLimit})`,
-          { models }
+          { models, verifyPayment: false }
         )

         // the HMAC is only returned during invoice creation

But I think it's better to explicitly pass in verifyPayment where we want it instead of passing in verifyPayment: false where we don't want it even though the former is less DRY.