mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 18:47:38 +01:00
Add ability to add arbitrary query string params for lnurl pays (#4995)
This commit is contained in:
parent
c192ede1d8
commit
915af37ac9
2 changed files with 14 additions and 7 deletions
|
@ -28,7 +28,7 @@ class LnURLClientTest extends BitcoinSAsyncTest {
|
|||
client.makeRequest(lnurl).flatMap {
|
||||
case pay: LnURLPayResponse =>
|
||||
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.lnTags.descriptionHash.exists(_.hash == pay.metadataHash))
|
||||
}
|
||||
|
|
|
@ -72,21 +72,28 @@ class LnURLClient(proxyParams: Option[Socks5ProxyParams])(implicit
|
|||
|
||||
def getInvoice(
|
||||
pay: LnURLPayResponse,
|
||||
amount: LnCurrencyUnit): Future[LnInvoice] = {
|
||||
getInvoice(pay, amount.toMSat)
|
||||
amount: LnCurrencyUnit,
|
||||
extraParams: Map[String, String]): Future[LnInvoice] = {
|
||||
getInvoice(pay, amount.toMSat, extraParams)
|
||||
}
|
||||
|
||||
def getInvoice(
|
||||
pay: LnURLPayResponse,
|
||||
amount: CurrencyUnit): Future[LnInvoice] = {
|
||||
getInvoice(pay, MilliSatoshis(amount))
|
||||
amount: CurrencyUnit,
|
||||
extraParams: Map[String, String]): Future[LnInvoice] = {
|
||||
getInvoice(pay, MilliSatoshis(amount), extraParams)
|
||||
}
|
||||
|
||||
def getInvoice(
|
||||
pay: LnURLPayResponse,
|
||||
amount: MilliSatoshis): Future[LnInvoice] = {
|
||||
amount: MilliSatoshis,
|
||||
extraParams: Map[String, String]): Future[LnInvoice] = {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue