Skip to content

Commit 143d7bc

Browse files
committed
move server-only libs to api/lib
1 parent 7eb5234 commit 143d7bc

File tree

17 files changed

+66
-66
lines changed

17 files changed

+66
-66
lines changed
File renamed without changes.

lib/bolt/bolt12.js renamed to api/lib/bolt/bolt12.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable camelcase */
22

3-
import { payViaBolt12PaymentRequest, decodeBolt12Invoice } from '@/lib/lndk'
3+
import { payViaBolt12PaymentRequest, decodeBolt12Invoice } from '@/api/lib/lndk'
44
import { isBolt12Invoice, isBolt12Offer, isBolt12 } from '@/lib/bolt/bolt12-info'
55
import { toPositiveNumber } from '@/lib/format'
66
export { isBolt12Invoice, isBolt12Offer, isBolt12 }

api/lib/bolt/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* eslint-disable camelcase */
2+
import { payBolt12, parseBolt12, isBolt12Invoice, isBolt12Offer } from '@/api/lib/bolt/bolt12'
3+
import { payBolt11, parseBolt11, isBolt11 } from '@/api/lib/bolt/bolt11'
4+
import { estimateBolt12RouteFee } from '@/api/lib/lndk'
5+
import { estimateRouteFee } from '@/api/lnd'
6+
7+
export async function payInvoice ({ lnd, request: invoice, max_fee, max_fee_mtokens, ...args }) {
8+
if (isBolt12Invoice(invoice)) {
9+
return await payBolt12({ lnd, request: invoice, max_fee, max_fee_mtokens, ...args })
10+
} else if (isBolt11(invoice)) {
11+
return await payBolt11({ lnd, request: invoice, max_fee, max_fee_mtokens, ...args })
12+
} else if (isBolt12Offer(invoice)) {
13+
throw new Error('cannot pay bolt12 offer directly, please fetch a bolt12 invoice from the offer first')
14+
} else {
15+
throw new Error('unknown invoice type')
16+
}
17+
}
18+
19+
export async function parseInvoice ({ lnd, request }) {
20+
if (isBolt12Invoice(request)) {
21+
return await parseBolt12({ lnd, request })
22+
} else if (isBolt11(request)) {
23+
return await parseBolt11({ request })
24+
} else if (isBolt12Offer(request)) {
25+
throw new Error('bolt12 offer instead of invoice, please fetch a bolt12 invoice from the offer first')
26+
} else {
27+
throw new Error('unknown invoice type')
28+
}
29+
}
30+
31+
export async function estimateFees ({ lnd, destination, tokens, mtokens, request, timeout }) {
32+
if (isBolt12Invoice(request)) {
33+
return await estimateBolt12RouteFee({ lnd, destination, tokens, mtokens, request, timeout })
34+
} else if (isBolt11(request)) {
35+
return await estimateRouteFee({ lnd, destination, tokens, request, mtokens, timeout })
36+
} else if (isBolt12Offer(request)) {
37+
throw new Error('bolt12 offer instead of invoice, please fetch a bolt12 invoice from the offer first')
38+
} else {
39+
throw new Error('unknown invoice type')
40+
}
41+
}

lib/lndk.js renamed to api/lib/lndk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { satsToMsats, toPositiveNumber } from '@/lib/format'
22
import { loadPackageDefinition } from '@grpc/grpc-js'
3-
import LNDK_RPC_PROTO from '@/lib/lndkrpc-proto'
3+
import LNDK_RPC_PROTO from '@/api/lib/lndkrpc-proto'
44
import protobuf from 'protobufjs'
55
import grpcCredentials from 'lightning/lnd_grpc/grpc_credentials'
66
import { grpcSslCipherSuites } from 'lightning/grpc/index'
File renamed without changes.

api/lnd/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cachedFetcher } from '@/lib/fetch'
22
import { toPositiveNumber } from '@/lib/format'
33
import { authenticatedLndGrpc } from '@/lib/lnd'
4-
import { enableLNDK } from '@/lib/lndk'
4+
import { enableLNDK } from '@/api/lib/lndk'
55
import { getIdentity, getHeight, getWalletInfo, getNode, getPayment } from 'ln-service'
66
import { datePivot } from '@/lib/time'
77
import { LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'

api/paidAction/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createHmac } from '@/api/resolvers/wallet'
55
import { Prisma } from '@prisma/client'
66
import { createWrappedInvoice, createInvoice as createUserInvoice } from '@/wallets/server'
77
import { assertBelowMaxPendingInvoices, assertBelowMaxPendingDirectPayments } from './lib/assert'
8-
import { parseBolt11 } from '@/lib/bolt/bolt11'
8+
import { parseBolt11 } from '@/api/lib/bolt/bolt11'
99

1010
import * as ITEM_CREATE from './itemCreate'
1111
import * as ITEM_UPDATE from './itemUpdate'

api/payingAction/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LND_PATHFINDING_TIME_PREF_PPM, LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'
22
import { msatsToSats, satsToMsats, toPositiveBigInt } from '@/lib/format'
33
import { Prisma } from '@prisma/client'
4-
import { payInvoice, parseInvoice } from '@/lib/bolt'
4+
import { payInvoice, parseInvoice } from '@/api/lib/bolt'
55

66
// paying actions are completely distinct from paid actions
77
// and there's only one paying action: send

api/resolvers/wallet.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { amountSchema, validateSchema, withdrawlSchema, lnAddrSchema } from '@/lib/validate'
1414
import assertGofacYourself from './ofac'
1515
import assertApiKeyNotPermitted from './apiKey'
16-
import { getInvoiceDescription } from '@/lib/bolt/bolt-info'
16+
import { getInvoiceDescription } from '@/lib/bolt'
1717
import { finalizeHodlInvoice } from '@/worker/wallet'
1818
import walletDefs from '@/wallets/server'
1919
import { generateResolverName, generateTypeDefName } from '@/wallets/graphql'
@@ -24,10 +24,10 @@ import validateWallet from '@/wallets/validate'
2424
import { canReceive, getWalletByType } from '@/wallets/common'
2525
import performPaidAction from '../paidAction'
2626
import performPayingAction from '../payingAction'
27-
import { parseInvoice } from '@/lib/bolt'
27+
import { parseInvoice } from '@/api/lib/bolt'
2828
import lnd from '@/api/lnd'
29-
import { isBolt12Offer } from '@/lib/bolt/bolt12'
30-
import { fetchBolt12InvoiceFromOffer } from '@/lib/lndk'
29+
import { isBolt12Offer } from '@/api/lib/bolt/bolt12'
30+
import { fetchBolt12InvoiceFromOffer } from '@/api/lib/lndk'
3131
import { timeoutSignal, withTimeout } from '@/lib/time'
3232

3333
function injectResolvers (resolvers) {

components/bolt11-info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AccordianItem from './accordian-item'
22
import { CopyInput } from './form'
3-
import { getInvoiceDescription, getInvoicePaymentHash } from '@/lib/bolt/bolt-info'
3+
import { getInvoiceDescription, getInvoicePaymentHash } from '@/lib/bolt'
44

55
export default ({ bolt11, preimage, children }) => {
66
let description, paymentHash

0 commit comments

Comments
 (0)