feat: implement LNURL payment handling in LNBits plugin
- Added a new function to handle LNURL payments, allowing users to send payments via LNURL addresses. - Integrated LNURL payment processing into the existing sendCoins function, enhancing the wallet's capabilities for Lightning Network transactions.
This commit is contained in:
parent
31f1208046
commit
7ebd809abc
1 changed files with 32 additions and 0 deletions
|
|
@ -131,12 +131,44 @@ async function getStatus(account, tx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendLNURL(account, lnurl, cryptoAtoms) {
|
||||||
|
validateConfig(account)
|
||||||
|
|
||||||
|
const paymentData = {
|
||||||
|
lnurl: lnurl,
|
||||||
|
amount: parseInt(cryptoAtoms.toString()) * 1000, // Convert satoshis to millisatoshis
|
||||||
|
comment: `Lamassu ATM - ${new Date().toISOString()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const endpoint = `${account.endpoint}/api/v1/payments/lnurl`
|
||||||
|
const result = await request(endpoint, 'POST', paymentData, account.adminKey)
|
||||||
|
|
||||||
|
if (!result.payment_hash) {
|
||||||
|
throw new Error('LNBits LNURL payment failed: No payment hash returned')
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
txid: result.payment_hash,
|
||||||
|
fee: result.fee_msat ? Math.ceil(result.fee_msat / 1000) : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendCoins(account, tx) {
|
async function sendCoins(account, tx) {
|
||||||
validateConfig(account)
|
validateConfig(account)
|
||||||
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
const { toAddress, cryptoAtoms, cryptoCode } = tx
|
||||||
|
|
||||||
await checkCryptoCode(cryptoCode)
|
await checkCryptoCode(cryptoCode)
|
||||||
|
|
||||||
|
// Handle LNURL addresses
|
||||||
|
if (isLnurl(toAddress)) {
|
||||||
|
return sendLNURL(account, toAddress, cryptoAtoms)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle bolt11 invoices
|
||||||
|
if (!isLnInvoice(toAddress)) {
|
||||||
|
throw new Error('Invalid Lightning address: must be bolt11 invoice or LNURL')
|
||||||
|
}
|
||||||
|
|
||||||
const paymentData = {
|
const paymentData = {
|
||||||
out: true,
|
out: true,
|
||||||
bolt11: toAddress
|
bolt11: toAddress
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue