@@ -21,10 +21,9 @@ import { finalizeHodlInvoice } from '@/worker/wallet'
2121import { lnAddrOptions } from '@/lib/lnurl'
2222import { GqlAuthenticationError , GqlAuthorizationError , GqlInputError } from '@/lib/error'
2323import { getNodeSockets , getOurPubkey } from '../lnd'
24- import { canReceive , getWalletByType } from '@/wallets/common'
2524import performPaidAction from '../paidAction'
2625import performPayingAction from '../payingAction'
27- import { deleteVault , hasVault } from '@/wallets/vault '
26+ import { logContextFromBolt11 } from '@/wallets/server/logger '
2827
2928export async function getInvoice ( parent , { id } , { me, models, lnd } ) {
3029 const inv = await models . invoice . findUnique ( {
@@ -165,6 +164,10 @@ const resolvers = {
165164
166165 return [ ...userWallets , ...walletTemplates ]
167166 } ,
167+ wallet : async ( parent , { name } , { me, models } ) => {
168+ const template = await models . walletTemplate . findFirst ( { where : { name } } )
169+ return { ...template , __resolveType : 'WalletTemplate' }
170+ } ,
168171 withdrawl : getWithdrawl ,
169172 direct : async ( parent , { id } , { me, models } ) => {
170173 if ( ! me ) {
@@ -579,25 +582,7 @@ const resolvers = {
579582 throw new GqlAuthenticationError ( )
580583 }
581584
582- // TODO(wallet-v2): use UserWallet instead of Wallet table
583- const wallet = await models . wallet . findUnique ( { where : { userId : me . id , id : Number ( id ) } } )
584- if ( ! wallet ) {
585- throw new GqlInputError ( 'wallet not found' )
586- }
587-
588- const logger = walletLogger ( { wallet, models } )
589-
590- await models . $transaction ( [
591- hasVault ( wallet ) ? deleteVault ( models , wallet ) : null ,
592- // TODO(wallet-v2): use UserWallet instead of Wallet table
593- models . wallet . delete ( { where : { userId : me . id , id : Number ( id ) } } )
594- ] . filter ( Boolean ) )
595-
596- if ( canReceive ( { def : getWalletByType ( wallet . type ) , config : wallet . wallet } ) ) {
597- logger . info ( 'details for receiving deleted' )
598- }
599-
600- return true
585+ // TODO(wallet-v2): implement this
601586 } ,
602587 deleteWalletLogs : async ( parent , { wallet } , { me, models } ) => {
603588 if ( ! me ) {
@@ -776,67 +761,6 @@ const resolvers = {
776761// TODO(wallet-v2): implement wallet resolvers
777762export default resolvers
778763
779- const logContextFromBolt11 = async ( bolt11 ) => {
780- const decoded = await parsePaymentRequest ( { request : bolt11 } )
781- return {
782- bolt11,
783- amount : formatMsats ( decoded . mtokens ) ,
784- payment_hash : decoded . id ,
785- created_at : decoded . created_at ,
786- expires_at : decoded . expires_at ,
787- description : decoded . description
788- }
789- }
790-
791- export const walletLogger = ( { wallet, models, me } ) => {
792- // no-op logger if no wallet or user provided
793- if ( ! wallet && ! me ) {
794- return {
795- ok : ( ) => { } ,
796- info : ( ) => { } ,
797- error : ( ) => { } ,
798- warn : ( ) => { }
799- }
800- }
801-
802- // server implementation of wallet logger interface on client
803- const log = ( level ) => async ( message , ctx = { } ) => {
804- try {
805- let { invoiceId, withdrawalId, ...context } = ctx
806-
807- if ( context . bolt11 ) {
808- // automatically populate context from bolt11 to avoid duplicating this code
809- context = {
810- ...context ,
811- ...await logContextFromBolt11 ( context . bolt11 )
812- }
813- }
814-
815- await models . walletLog . create ( {
816- data : {
817- userId : wallet ?. userId ?? me . id ,
818- // system logs have no wallet
819- wallet : wallet ?. type ,
820- level,
821- message,
822- context,
823- invoiceId,
824- withdrawalId
825- }
826- } )
827- } catch ( err ) {
828- console . error ( 'error creating wallet log:' , err )
829- }
830- }
831-
832- return {
833- ok : ( message , context ) => log ( 'SUCCESS' ) ( message , context ) ,
834- info : ( message , context ) => log ( 'INFO' ) ( message , context ) ,
835- error : ( message , context ) => log ( 'ERROR' ) ( message , context ) ,
836- warn : ( message , context ) => log ( 'WARN' ) ( message , context )
837- }
838- }
839-
840764export async function createWithdrawal ( parent , { invoice, maxFee } , { me, models, lnd, headers, wallet, logger } ) {
841765 assertApiKeyNotPermitted ( { me } )
842766 await validateSchema ( withdrawlSchema , { invoice, maxFee } )
0 commit comments