Add ability to add arbitrary query string params for lnurl pays (#4995)

This commit is contained in:
benthecarman 2023-02-22 16:22:23 -06:00 committed by GitHub
parent c192ede1d8
commit 915af37ac9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -28,7 +28,7 @@ class LnURLClientTest extends BitcoinSAsyncTest {
client.makeRequest(lnurl).flatMap { client.makeRequest(lnurl).flatMap {
case pay: LnURLPayResponse => case pay: LnURLPayResponse =>
val amt = pay.minSendable.toLnCurrencyUnit val amt = pay.minSendable.toLnCurrencyUnit
client.getInvoice(pay, amt).map { inv => client.getInvoice(pay, amt, Map.empty).map { inv =>
assert(inv.amount.contains(amt)) assert(inv.amount.contains(amt))
assert(inv.lnTags.descriptionHash.exists(_.hash == pay.metadataHash)) assert(inv.lnTags.descriptionHash.exists(_.hash == pay.metadataHash))
} }

View file

@ -72,21 +72,28 @@ class LnURLClient(proxyParams: Option[Socks5ProxyParams])(implicit
def getInvoice( def getInvoice(
pay: LnURLPayResponse, pay: LnURLPayResponse,
amount: LnCurrencyUnit): Future[LnInvoice] = { amount: LnCurrencyUnit,
getInvoice(pay, amount.toMSat) extraParams: Map[String, String]): Future[LnInvoice] = {
getInvoice(pay, amount.toMSat, extraParams)
} }
def getInvoice( def getInvoice(
pay: LnURLPayResponse, pay: LnURLPayResponse,
amount: CurrencyUnit): Future[LnInvoice] = { amount: CurrencyUnit,
getInvoice(pay, MilliSatoshis(amount)) extraParams: Map[String, String]): Future[LnInvoice] = {
getInvoice(pay, MilliSatoshis(amount), extraParams)
} }
def getInvoice( def getInvoice(
pay: LnURLPayResponse, pay: LnURLPayResponse,
amount: MilliSatoshis): Future[LnInvoice] = { amount: MilliSatoshis,
extraParams: Map[String, String]): Future[LnInvoice] = {
val symbol = if (pay.callback.toString.contains("?")) "&" else "?" val symbol = if (pay.callback.toString.contains("?")) "&" else "?"
val url = s"${pay.callback}${symbol}amount=${amount.toLong}" val queryStringParams =
extraParams.map(kv => s"${kv._1}=${kv._2}").mkString("&")
val qsStr = if (queryStringParams.isEmpty) "" else s"&$queryStringParams"
val url = s"${pay.callback}${symbol}amount=${amount.toLong}$qsStr"
sendRequestAndParse[LnURLPayInvoice](Get(url)).map(_.pr) sendRequestAndParse[LnURLPayInvoice](Get(url)).map(_.pr)
} }