11import {
2- getInvoice as getInvoiceFromLnd , deletePayment , getPayment ,
3- parsePaymentRequest
2+ getInvoice as getInvoiceFromLnd , deletePayment , getPayment
43} from 'ln-service'
54import crypto , { timingSafeEqual } from 'crypto'
65import { decodeCursor , LIMIT , nextCursorEncoded } from '@/lib/cursor'
@@ -24,6 +23,8 @@ import validateWallet from '@/wallets/validate'
2423import { canReceive } from '@/wallets/common'
2524import performPaidAction from '../paidAction'
2625import performPayingAction from '../payingAction'
26+ import { parseInvoice } from '@/lib/invoices'
27+ import lnd from '@/api/lnd'
2728
2829function injectResolvers ( resolvers ) {
2930 console . group ( 'injected GraphQL resolvers:' )
@@ -721,8 +722,8 @@ export const walletLogger = ({ wallet, models }) => {
721722 const log = ( level ) => async ( message , context = { } ) => {
722723 try {
723724 if ( context ?. bolt11 ) {
724- // automatically populate context from bolt11 to avoid duplicating this code
725- const decoded = await parsePaymentRequest ( { request : context . bolt11 } )
725+ // automatically populate context from invoice to avoid duplicating this code
726+ const decoded = await parseInvoice ( { request : context . bolt11 , lnd } )
726727 context = {
727728 ...context ,
728729 amount : formatMsats ( decoded . mtokens ) ,
@@ -899,7 +900,7 @@ export async function createWithdrawal (parent, { invoice, maxFee }, { me, model
899900 // decode invoice to get amount
900901 let decoded , sockets
901902 try {
902- decoded = await parsePaymentRequest ( { request : invoice } )
903+ decoded = await parseInvoice ( { request : invoice , lnd } )
903904 } catch ( error ) {
904905 console . log ( error )
905906 throw new GqlInputError ( 'could not decode invoice' )
@@ -938,7 +939,7 @@ export async function createWithdrawal (parent, { invoice, maxFee }, { me, model
938939 throw new GqlInputError ( 'SN cannot pay an invoice that SN is proxying' )
939940 }
940941
941- return await performPayingAction ( { bolt11 : invoice , maxFee, walletId : wallet ?. id } , { me, models, lnd } )
942+ return await performPayingAction ( { invoice, maxFee, walletId : wallet ?. id } , { me, models, lnd } )
942943}
943944
944945export async function sendToLnAddr ( parent , { addr, amount, maxFee, comment, ...payer } ,
@@ -999,7 +1000,7 @@ export async function fetchLnAddrInvoice (
9991000
10001001 // decode invoice
10011002 try {
1002- const decoded = await parsePaymentRequest ( { request : res . pr } )
1003+ const decoded = await parseInvoice ( { request : res . pr , lnd } )
10031004 const ourPubkey = await getOurPubkey ( { lnd } )
10041005 if ( autoWithdraw && decoded . destination === ourPubkey && process . env . NODE_ENV === 'production' ) {
10051006 // unset lnaddr so we don't trigger another withdrawal with same destination
0 commit comments