-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add withdraw to bolt12, improve checks and naming
- Loading branch information
1 parent
f927fc5
commit 494061c
Showing
18 changed files
with
248 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
/* eslint-disable camelcase */ | ||
import { payBolt12, parseBolt12, isBolt12Invoice } from './bolt12' | ||
import { payBolt11, parseBolt11 } from './bolt11' | ||
import { payBolt12, parseBolt12, isBolt12Invoice, isBolt12Offer } from './bolt12' | ||
import { payBolt11, parseBolt11, isBolt11 } from './bolt11' | ||
import { estimateBolt12RouteFee } from '@/lib/lndk' | ||
import { estimateRouteFee } from '@/api/lnd' | ||
|
||
export async function payInvoice ({ lnd, request: invoice, max_fee, ...args }) { | ||
if (isBolt12Invoice(invoice)) { | ||
return await payBolt12({ lnd, request: invoice, max_fee, ...args }) | ||
} else { | ||
} else if (isBolt11(invoice)) { | ||
return await payBolt11({ lnd, request: invoice, max_fee, ...args }) | ||
} else if (isBolt12Offer(invoice)) { | ||
throw new Error('cannot pay bolt12 offer directly, please fetch a bolt12 invoice from the offer first') | ||
} else { | ||
throw new Error('unknown invoice type') | ||
} | ||
} | ||
|
||
export async function parseInvoice ({ lnd, request }) { | ||
if (isBolt12Invoice(request)) { | ||
return await parseBolt12({ lnd, request }) | ||
} else { | ||
} else if (isBolt11(request)) { | ||
return await parseBolt11({ request }) | ||
} else if (isBolt12Offer(request)) { | ||
throw new Error('bolt12 offer instead of invoice, please fetch a bolt12 invoice from the offer first') | ||
} else { | ||
throw new Error('unknown invoice type') | ||
} | ||
} | ||
|
||
export async function estimateFees ({ lnd, destination, tokens, mtokens, request, timeout }) { | ||
if (isBolt12Invoice(request)) { | ||
return await estimateBolt12RouteFee({ lnd, destination, tokens, mtokens, request, timeout }) | ||
} else { | ||
} else if (isBolt11(request)) { | ||
return await estimateRouteFee({ lnd, destination, tokens, request, mtokens, timeout }) | ||
} else if (isBolt12Offer(request)) { | ||
throw new Error('bolt12 offer instead of invoice, please fetch a bolt12 invoice from the offer first') | ||
} else { | ||
throw new Error('unknown invoice type') | ||
} | ||
} |
Oops, something went wrong.