From c909efb7b7443e9cfa3478b2b5003390eb887633 Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 31 Jul 2023 08:31:40 -0500 Subject: [PATCH] update wallet code to prisma 5, handle prisma 5 errors on serialization --- api/resolvers/serial.js | 10 +++++----- api/resolvers/wallet.js | 2 +- pages/api/lnurlp/[username]/pay.js | 2 +- worker/wallet.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/resolvers/serial.js b/api/resolvers/serial.js index ec7d6bcb..46bcc205 100644 --- a/api/resolvers/serial.js +++ b/api/resolvers/serial.js @@ -35,17 +35,17 @@ async function serialize (models, call) { if (error.message.includes('SN_REVOKED_OR_EXHAUSTED')) { bail(new Error('faucet has been revoked or is exhausted')) } - if (error.message.includes('23514')) { - bail(new Error('constraint failure')) - } if (error.message.includes('SN_INV_PENDING_LIMIT')) { bail(new Error('too many pending invoices')) } if (error.message.includes('SN_INV_EXCEED_BALANCE')) { bail(new Error('pending invoices must not cause balance to exceed 1m sats')) } - if (error.message.includes('40001')) { - throw new Error('wallet balance serialization failure - retry again') + if (error.message.includes('40001') || error.code === 'P2034') { + throw new Error('wallet balance serialization failure - try again') + } + if (error.message.includes('23514') || ['P2002', 'P2003', 'P2004'].includes(error.code)) { + bail(new Error('constraint failure')) } bail(error) } diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index b4878aa6..d4e762ee 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -211,7 +211,7 @@ export default { const [inv] = await serialize(models, models.$queryRaw`SELECT * FROM create_invoice(${invoice.id}, ${invoice.request}, - ${expiresAt}, ${amount * 1000}, ${me.id}::INTEGER, ${description})`) + ${expiresAt}::timestamp, ${amount * 1000}, ${me.id}::INTEGER, ${description})`) return inv } catch (error) { diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index fa664cb3..46dcae51 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -47,7 +47,7 @@ export default async ({ query: { username, amount, nostr } }, res) => { await serialize(models, models.$queryRaw`SELECT * FROM create_invoice(${invoice.id}, ${invoice.request}, - ${expiresAt}, ${Number(amount)}, ${user.id}::INTEGER, ${noteStr || description})`) + ${expiresAt}::timestamp, ${Number(amount)}, ${user.id}::INTEGER, ${noteStr || description})`) return res.status(200).json({ pr: invoice.request, diff --git a/worker/wallet.js b/worker/wallet.js index ddae92d9..6602d373 100644 --- a/worker/wallet.js +++ b/worker/wallet.js @@ -60,7 +60,7 @@ function checkWithdrawal ({ boss, models, lnd }) { const fee = Number(wdrwl.payment.fee_mtokens) const paid = Number(wdrwl.payment.mtokens) - fee await serialize(models, models.$executeRaw` - SELECT confirm_withdrawl(${id}, ${paid}, ${fee})`) + SELECT confirm_withdrawl(${id}::INTEGER, ${paid}, ${fee})`) } else if (wdrwl?.is_failed || notFound) { let status = 'UNKNOWN_FAILURE' if (wdrwl?.failed.is_insufficient_balance) { @@ -73,7 +73,7 @@ function checkWithdrawal ({ boss, models, lnd }) { status = 'ROUTE_NOT_FOUND' } await serialize(models, models.$executeRaw` - SELECT reverse_withdrawl(${id}, ${status})`) + SELECT reverse_withdrawl(${id}::INTEGER, ${status})`) } else { // we need to requeue to check again in 5 seconds await boss.send('checkWithdrawal', { id, hash }, walletOptions)