|
1 | 1 | /* eslint-disable camelcase */ |
2 | | - |
3 | | -import { payViaPaymentRequest, parsePaymentRequest } from 'ln-service' |
| 2 | +import { payBolt12, parseBolt12, isBolt12Invoice } from './bolt12' |
| 3 | +import { payBolt11, parseBolt11 } from './bolt11' |
| 4 | +import { estimateBolt12RouteFee } from '@/lib/lndk' |
4 | 5 | import { estimateRouteFee } from '@/api/lnd' |
5 | 6 |
|
6 | | -import { payViaBolt12PaymentRequest, parseBolt12Request, estimateBolt12RouteFee } from '@/lib/lndk' |
7 | | - |
8 | | -export function isBolt11 (request) { |
9 | | - return request.startsWith('lnbc') || request.startsWith('lntb') || request.startsWith('lntbs') || request.startsWith('lnbcrt') |
10 | | -} |
11 | | - |
12 | | -export function parseBolt11 ({ request }) { |
13 | | - if (!isBolt11(request)) throw new Error('not a bolt11 invoice') |
14 | | - return parsePaymentRequest({ request }) |
15 | | -} |
16 | | - |
17 | | -export function payBolt11 ({ lnd, request, max_fee, ...args }) { |
18 | | - if (!isBolt11(request)) throw new Error('not a bolt11 invoice') |
19 | | - |
20 | | - return payViaPaymentRequest({ |
21 | | - lnd, |
22 | | - request, |
23 | | - max_fee, |
24 | | - ...args |
25 | | - }) |
26 | | -} |
27 | | - |
28 | | -export function isBolt12Offer (invoice) { |
29 | | - return invoice.startsWith('lno1') |
30 | | -} |
31 | | - |
32 | | -export function isBolt12Invoice (invoice) { |
33 | | - console.log('isBolt12Invoice', invoice) |
34 | | - console.trace() |
35 | | - return invoice.startsWith('lni1') |
36 | | -} |
37 | | - |
38 | | -export async function payBolt12 ({ lnd, request: invoice, max_fee }) { |
39 | | - if (!isBolt12Invoice(invoice)) throw new Error('not a bolt12 invoice') |
40 | | - |
41 | | - if (!invoice) throw new Error('No invoice in bolt12, please use prefetchBolt12Invoice') |
42 | | - return await payViaBolt12PaymentRequest({ lnd, request: invoice, max_fee }) |
43 | | -} |
44 | | - |
45 | | -export function parseBolt12 ({ lnd, request: invoice }) { |
46 | | - if (!isBolt12Invoice(invoice)) throw new Error('not a bolt12 request') |
47 | | - return parseBolt12Request({ lnd, request: invoice }) |
48 | | -} |
49 | | - |
50 | 7 | export async function payInvoice ({ lnd, request: invoice, max_fee, ...args }) { |
51 | 8 | if (isBolt12Invoice(invoice)) { |
52 | 9 | return await payBolt12({ lnd, request: invoice, max_fee, ...args }) |
|
0 commit comments