@@ -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
@@ -993,20 +995,20 @@ class LightningRepo @Inject constructor(
993995 runCatching { lightningService.receiveMsats(amountMsats, description, expirySeconds) }
994996 }
995997
996- @Suppress(" ForbiddenComment" )
997998 suspend fun fetchLnurlInvoice (
998- callbackUrl : String ,
999+ data : LnurlPayData ,
9991000 amountMsats : ULong ,
10001001 comment : String? = null,
10011002 ): Result <LightningInvoice > {
10021003 return runCatching {
1003- // TODO use bitkit-core getLnurlInvoice if it works with callbackUrl
1004- val bolt11 = lnurlService.fetchLnurlInvoice(callbackUrl, amountMsats, comment).getOrThrow().pr
1004+ val bolt11 = coreService.getLnurlInvoiceForPayData(data, amountMsats, comment)
10051005 val decoded = (coreService.decode(bolt11) as Scanner .Lightning ).invoice
10061006 return @runCatching decoded
1007+ }.recoverCatching {
1008+ throw it.toLnurlPayInvoiceError()
10071009 }.onFailure {
10081010 Logger .error(
1009- " Failed to fetch LNURL invoice, url : '$callbackUrl ', amountMsats: '$amountMsats ', comment: '$comment '" ,
1011+ " Failed to fetch LNURL invoice, uri : '${data.uri} ', amountMsats: '$amountMsats ', comment: '$comment '" ,
10101012 it,
10111013 context = TAG ,
10121014 )
@@ -1717,11 +1719,27 @@ class NodeStopTimeoutError : AppError("Timeout waiting for node to stop")
17171719class NodeRunTimeoutError (opName : String ) : AppError(" Timeout waiting for node to run and execute: '$opName '" )
17181720class GetPaymentsError : AppError (" It wasn't possible get the payments" )
17191721class SyncUnhealthyError : AppError (" Wallet sync failed before send" )
1722+ class LnurlPayInvoiceMismatchError : AppError (" The invoice did not match the requested payment. Payment cancelled." )
17201723sealed class ProbeError (message : String ) : AppError(message) {
17211724 class NoProbeHandles : ProbeError (" No probe handles returned" )
17221725 class TimedOut : ProbeError (" Probe timed out" )
17231726}
17241727
1728+ private fun Throwable.toLnurlPayInvoiceError (): Throwable {
1729+ val lnurlPayValidationError = generateSequence(this ) { it.cause }
1730+ .firstOrNull { it.isLnurlPayValidationError() }
1731+
1732+ return if (lnurlPayValidationError != null ) LnurlPayInvoiceMismatchError () else this
1733+ }
1734+
1735+ private fun Throwable.isLnurlPayValidationError (): Boolean = when (this ) {
1736+ is LnurlException .InvalidAmount ,
1737+ is LnurlException .AmountMismatch ,
1738+ is LnurlException .MetadataMismatch -> true
1739+
1740+ else -> false
1741+ }
1742+
17251743@Stable
17261744data class LightningState (
17271745 val nodeId : String = " " ,
0 commit comments