feat: lnurl support

This commit is contained in:
Rafael Taranto 2024-02-29 13:23:49 +00:00
parent 83d18f9a10
commit 45fa1a8d93
4 changed files with 52 additions and 26 deletions

View file

@ -21,7 +21,7 @@ const logger = new winston.Logger({
})
],
rewriters: [
(...[,, meta]) => meta instanceof Error ? { message: meta.message, stack: meta.stack } : meta
(...[,, meta]) => meta instanceof Error ? { message: meta.message, stack: meta.stack, meta } : meta
],
exitOnError: false
})

View file

@ -92,8 +92,12 @@ function getGaloyWallet (token, endpoint, walletId) {
})
}
function isLightning (address) {
return address.substr(0, 2) === 'ln'
function isLnInvoice (address) {
return address.startsWith('lnbc')
}
function isLnurl (address) {
return address.startsWith('lnurl')
}
function sendFundsOnChain (walletId, address, cryptoAtoms, token, endpoint) {
@ -116,6 +120,23 @@ function sendFundsOnChain (walletId, address, cryptoAtoms, token, endpoint) {
})
}
function sendFundsLNURL (walletId, lnurl, cryptoAtoms, token, endpoint) {
const sendLnNoAmount = {
'operationName': 'lnurlPaymentSend',
'query': `mutation lnurlPaymentSend($input: LnurlPaymentSendInput!) {
lnurlPaymentSend(input: $input) {
errors {
message
path
}
status
}
}`,
'variables': { 'input': { 'lnurl': `${lnurl}`, 'walletId': `${walletId}`, 'amount': `${cryptoAtoms}` } }
}
return request(sendLnNoAmount, token, endpoint).then(result => result.data.lnurlPaymentSend)
}
function sendFundsLN (walletId, invoice, cryptoAtoms, token, endpoint) {
const sendLnNoAmount = {
'operationName': 'lnNoAmountInvoicePaymentSend',
@ -155,9 +176,12 @@ function sendCoins (account, tx, settings, operatorId) {
return checkCryptoCode(cryptoCode)
.then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId))
.then(wallet => {
if (isLightning(toAddress)) {
if (isLnInvoice(toAddress)) {
return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
}
if (isLnurl(toAddress)) {
return sendFundsLNURL(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
}
return sendFundsOnChain(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint)
})
.then(result => {
@ -272,7 +296,7 @@ function getStatus (account, tx, requested, settings, operatorId) {
return checkCryptoCode(cryptoCode)
.then(() => {
const address = coinUtils.parseUrl(cryptoCode, account.environment, toAddress, false)
if (isLightning(address)) {
if (isLnInvoice(address)) {
return getInvoiceStatus(account.apiSecret, account.endpoint, address)
.then(it => {
const isPaid = it === 'PAID'