update wallet code to prisma 5, handle prisma 5 errors on serialization
This commit is contained in:
		
							parent
							
								
									acd8a8de5a
								
							
						
					
					
						commit
						c909efb7b7
					
				@ -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)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user