@@ -6,6 +6,8 @@ import com.synonym.bitkitcore.AddressType
66import com.synonym.bitkitcore.ClosedChannelDetails
77import com.synonym.bitkitcore.FeeRates
88import com.synonym.bitkitcore.LightningInvoice
9+ import com.synonym.bitkitcore.LnurlException
10+ import com.synonym.bitkitcore.LnurlPayData
911import com.synonym.bitkitcore.PreActivityMetadata
1012import com.synonym.bitkitcore.Scanner
1113import com.synonym.bitkitcore.createChannelRequestUrl
@@ -992,20 +994,20 @@ class LightningRepo @Inject constructor(
992994 runCatching { lightningService.receiveMsats(amountMsats, description, expirySeconds) }
993995 }
994996
995- @Suppress(" ForbiddenComment" )
996997 suspend fun fetchLnurlInvoice (
997- callbackUrl : String ,
998+ data : LnurlPayData ,
998999 amountMsats : ULong ,
9991000 comment : String? = null,
10001001 ): Result <LightningInvoice > {
10011002 return runCatching {
1002- // TODO use bitkit-core getLnurlInvoice if it works with callbackUrl
1003- val bolt11 = lnurlService.fetchLnurlInvoice(callbackUrl, amountMsats, comment).getOrThrow().pr
1003+ val bolt11 = coreService.getLnurlInvoiceForPayData(data, amountMsats, comment)
10041004 val decoded = (coreService.decode(bolt11) as Scanner .Lightning ).invoice
10051005 return @runCatching decoded
1006+ }.recoverCatching {
1007+ throw it.toLnurlPayInvoiceError()
10061008 }.onFailure {
10071009 Logger .error(
1008- " Failed to fetch LNURL invoice, url : '$callbackUrl ', amountMsats: '$amountMsats ', comment: '$comment '" ,
1010+ " Failed to fetch LNURL invoice, uri : '${data.uri} ', amountMsats: '$amountMsats ', comment: '$comment '" ,
10091011 it,
10101012 context = TAG ,
10111013 )
@@ -1715,11 +1717,27 @@ class NodeStopTimeoutError : AppError("Timeout waiting for node to stop")
17151717class NodeRunTimeoutError (opName : String ) : AppError(" Timeout waiting for node to run and execute: '$opName '" )
17161718class GetPaymentsError : AppError (" It wasn't possible get the payments" )
17171719class SyncUnhealthyError : AppError (" Wallet sync failed before send" )
1720+ class LnurlPayInvoiceMismatchError : AppError (" The invoice did not match the requested payment. Payment cancelled." )
17181721sealed class ProbeError (message : String ) : AppError(message) {
17191722 class NoProbeHandles : ProbeError (" No probe handles returned" )
17201723 class TimedOut : ProbeError (" Probe timed out" )
17211724}
17221725
1726+ private fun Throwable.toLnurlPayInvoiceError (): Throwable {
1727+ val lnurlPayValidationError = generateSequence(this ) { it.cause }
1728+ .firstOrNull { it.isLnurlPayValidationError() }
1729+
1730+ return if (lnurlPayValidationError != null ) LnurlPayInvoiceMismatchError () else this
1731+ }
1732+
1733+ private fun Throwable.isLnurlPayValidationError (): Boolean = when (this ) {
1734+ is LnurlException .InvalidAmount ,
1735+ is LnurlException .AmountMismatch ,
1736+ is LnurlException .MetadataMismatch -> true
1737+
1738+ else -> false
1739+ }
1740+
17231741@Stable
17241742data class LightningState (
17251743 val nodeId : String = " " ,
0 commit comments