-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New methods: - `lnurlauth` - `lnurlpay` - `lnurlwithdraw` Note that `paylnaddress` now supports BIP353 and LNURL addresses. It will try with BIP353 first and fallback to LNURL.
- Loading branch information
Showing
14 changed files
with
1,010 additions
and
16 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
37 changes: 37 additions & 0 deletions
37
src/commonMain/kotlin/fr/acinq/lightning/bin/payments/AddressResolver.kt
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fr.acinq.lightning.bin.payments | ||
|
||
import fr.acinq.bitcoin.utils.Either | ||
import fr.acinq.bitcoin.utils.Try | ||
import fr.acinq.lightning.MilliSatoshi | ||
import fr.acinq.lightning.bin.payments.lnurl.LnurlHandler | ||
import fr.acinq.lightning.bin.payments.lnurl.models.LnurlPay | ||
import fr.acinq.lightning.wire.OfferTypes | ||
import io.ktor.http.* | ||
|
||
class AddressResolver(val dnsAddress: PayDnsAddress, val lnurlHandler: LnurlHandler) { | ||
|
||
suspend fun resolveLnUrl(username: String, domain: String, amount: MilliSatoshi, note: String?): Try<LnurlPay.InvoiceToPay> { | ||
val url = Url("https://$domain/.well-known/lnurlp/$username") | ||
return try { | ||
val lnurl = lnurlHandler.executeLnurl(url) | ||
val paymentParameters = lnurl as LnurlPay.PaymentParameters | ||
if (amount < paymentParameters.minSendable) throw IllegalArgumentException("amount too small (min=${paymentParameters.minSendable})") | ||
if (amount > paymentParameters.maxSendable) throw IllegalArgumentException("amount too big (max=${paymentParameters.maxSendable})") | ||
val invoice = lnurlHandler.getLnurlPayInvoice(lnurl, amount, note) | ||
Try.Success(invoice) | ||
} catch (e: Exception) { | ||
Try.Failure(e) | ||
} | ||
} | ||
|
||
suspend fun resolveAddress(username: String, domain: String, amount: MilliSatoshi, note: String?): Try<Either<LnurlPay.InvoiceToPay, OfferTypes.Offer>> { | ||
return when (val offer = dnsAddress.resolveBip353Offer(username, domain)) { | ||
null -> when (val lnurl = resolveLnUrl(username, domain, amount, note)) { | ||
is Try.Success -> Try.Success(Either.Left(lnurl.result)) | ||
is Try.Failure -> Try.Failure(lnurl.error) | ||
} | ||
else -> Try.Success(Either.Right(offer)) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.