Skip to content

adding sending / receiving vasp methods for demo #204

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import me.uma.protocol.createCounterPartyDataOptions
import me.uma.protocol.createPayeeData
import me.uma.protocol.identifier

class Vasp2(
class ReceivingVasp(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call :-)

private val config: UmaConfig,
private val uma: UmaProtocolHelper,
private val lightsparkClient: LightsparkCoroutinesClient,
Expand All @@ -47,6 +47,14 @@ class Vasp2(
private val coroutineScope = CoroutineScope(Dispatchers.IO)
private lateinit var senderUmaVersion: String

suspend fun createInvoice(call: ApplicationCall): String {
return "OK"
}

suspend fun createAndSendInvoice(call: ApplicationCall): String {
return "OK"
}

suspend fun handleLnurlp(call: ApplicationCall): String {
val username = call.parameters["username"]

Expand Down Expand Up @@ -155,7 +163,7 @@ class Vasp2(
}

val lnurlInvoiceCreator = object : UmaInvoiceCreator {
override fun createUmaInvoice(amountMsats: Long, metadata: String): CompletableFuture<String> {
override fun createUmaInvoice(amountMsats: Long, metadata: String, receiverIdentifier: String?,): CompletableFuture<String> {
return coroutineScope.future {
lightsparkClient.createLnurlInvoice(config.nodeID, amountMsats, metadata).data.encodedPaymentRequest
}
Expand Down Expand Up @@ -334,17 +342,25 @@ class Vasp2(
private fun getReceivingVaspDomain(call: ApplicationCall) = config.vaspDomain ?: call.originWithPort()
}

fun Routing.registerVasp2Routes(vasp2: Vasp2) {
fun Routing.registerReceivingVaspRoutes(receivingVasp: ReceivingVasp) {
get("/.well-known/lnurlp/{username}") {
call.debugLog(vasp2.handleLnurlp(call))
call.debugLog(receivingVasp.handleLnurlp(call))
}

get("/api/uma/payreq/{uuid}") {
call.debugLog(vasp2.handleLnurlPayreq(call))
get("/api/lnurl/payreq/{uuid}") {
call.debugLog(receivingVasp.handleLnurlPayreq(call))
}

post("/api/uma/payreq/{uuid}") {
call.debugLog(vasp2.handleUmaPayreq(call))
call.debugLog(receivingVasp.handleUmaPayreq(call))
}

get("/api/uma/create_invoice") {
call.debugLog(receivingVasp.createInvoice(call));
}

get("/api/uma/create_and_send_invoice") {
call.debugLog(receivingVasp.createAndSendInvoice(call))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import me.uma.protocol.createPayerData
import me.uma.selectHighestSupportedVersion
import me.uma.utils.serialFormat

class Vasp1(
class SendingVasp(
private val config: UmaConfig,
private val uma: UmaProtocolHelper,
private val lightsparkClient: LightsparkCoroutinesClient,
Expand All @@ -75,6 +75,14 @@ class Vasp1(
private val nonceCache = InMemoryNonceCache(Clock.System.now().epochSeconds)
private lateinit var receiverUmaVersion: String

suspend fun payInvoice(call: ApplicationCall): String {
return "OK"
}

suspend fun requestInvoicePayment(call: ApplicationCall): String {
return "OK"
}

suspend fun handleClientUmaLookup(call: ApplicationCall): String {
val receiverAddress = call.parameters["receiver"]
if (receiverAddress == null) {
Expand Down Expand Up @@ -500,17 +508,25 @@ class Vasp1(
}
}

fun Routing.registerVasp1Routes(vasp1: Vasp1) {
fun Routing.registerSendingVaspRoutes(sendingVasp: SendingVasp) {
get("/api/umalookup/{receiver}") {
call.debugLog(vasp1.handleClientUmaLookup(call))
call.debugLog(sendingVasp.handleClientUmaLookup(call))
}

get("/api/umapayreq/{callbackUuid}") {
call.debugLog(vasp1.handleClientUmaPayReq(call))
call.debugLog(sendingVasp.handleClientUmaPayReq(call))
}

post("/api/sendpayment/{callbackUuid}") {
call.debugLog(vasp1.handleClientSendPayment(call))
call.debugLog(sendingVasp.handleClientSendPayment(call))
}

post("/api/uma/pay_invoice") {
call.debugLog(sendingVasp.payInvoice(call))
}

post("/api/uma/request_invoice_payment") {
call.debugLog(sendingVasp.requestInvoicePayment(call))
}
}

Expand Down
20 changes: 8 additions & 12 deletions umaserverdemo/src/main/kotlin/com/lightspark/plugins/Routing.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package com.lightspark.plugins

import com.lightspark.UmaConfig
import com.lightspark.Vasp1
import com.lightspark.Vasp2
import com.lightspark.SendingVasp
import com.lightspark.ReceivingVasp
import com.lightspark.debugLog
import com.lightspark.handlePubKeyRequest
import com.lightspark.isDomainLocalhost
import com.lightspark.originWithPort
import com.lightspark.registerVasp1Routes
import com.lightspark.registerVasp2Routes
import com.lightspark.registerSendingVaspRoutes
import com.lightspark.registerReceivingVaspRoutes
import com.lightspark.sdk.ClientConfig
import com.lightspark.sdk.LightsparkCoroutinesClient
import com.lightspark.sdk.auth.AccountApiTokenAuthProvider
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.request.ContentTransformationException
import io.ktor.server.request.receive
import io.ktor.server.request.receiveText
import io.ktor.server.response.respond
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import kotlinx.datetime.Clock
import kotlinx.serialization.json.JsonObject
import me.uma.InMemoryNonceCache
import me.uma.InMemoryPublicKeyCache
import me.uma.UmaProtocolHelper
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.buildJsonObject
Expand All @@ -44,12 +40,12 @@ fun Application.configureRouting(
authProvider = AccountApiTokenAuthProvider(config.apiClientID, config.apiClientSecret),
),
)
val vasp1 = Vasp1(config, uma, client)
val vasp2 = Vasp2(config, uma, client)
val sendingVasp = SendingVasp(config, uma, client)
val receivingVasp = ReceivingVasp(config, uma, client)

routing {
registerVasp1Routes(vasp1)
registerVasp2Routes(vasp2)
registerSendingVaspRoutes(sendingVasp)
registerReceivingVaspRoutes(receivingVasp)

get("/.well-known/lnurlpubkey") {
call.debugLog(handlePubKeyRequest(call, config))
Expand Down