-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathbolt11.js
28 lines (25 loc) · 1.04 KB
/
bolt11.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* eslint-disable camelcase */
import { payViaPaymentRequest, parsePaymentRequest } from 'ln-service'
import { isBolt11 } from '@/lib/bolt/bolt11-tags'
import { estimateRouteFee } from '@/api/lnd'
export { isBolt11 }
export async function parseBolt11 ({ request }) {
if (!isBolt11(request)) throw new Error('not a bolt11 invoice')
return parsePaymentRequest({ request })
}
export async function payBolt11 ({ lnd, request, max_fee, max_fee_mtokens, ...args }) {
if (!lnd) throw new Error('lnd required') // check if forgot to pass lnd
if (!isBolt11(request)) throw new Error('not a bolt11 invoice')
return payViaPaymentRequest({
lnd,
request,
max_fee,
max_fee_mtokens,
...args
})
}
export async function estimateBolt11RouteFee ({ lnd, destination, tokens, mtokens, request, timeout }) {
if (!lnd) throw new Error('lnd required') // check if forgot to pass lnd
if (request && !isBolt11(request)) throw new Error('not a bolt11 request')
return await estimateRouteFee({ lnd, destination, tokens, mtokens, request, timeout })
}