Skip to content

Add the outgoing_payment_for_idempotency_key query. #213

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 1 commit into from
Feb 12, 2025
Merged
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
@@ -615,6 +615,18 @@ class LightsparkFuturesClient(config: ClientConfig) {
coroutinesClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
}

/**
* Fetch outgoing payment for a given idempotency key
*
* @param idempotencyKey The idempotency key used when creating the payment.
*/
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
fun getOutgoingPaymentForIdempotencyKey(
idempotencyKey: String,
): CompletableFuture<OutgoingPayment?> = coroutineScope.future {
coroutinesClient.getOutgoingPaymentForIdempotencyKey(idempotencyKey)
}

/**
* fetch invoice for a given payments hash
*
Original file line number Diff line number Diff line change
@@ -743,7 +743,7 @@ class LightsparkCoroutinesClient private constructor(
suspend fun fundNode(
nodeId: String,
amountSats: Long?,
fundingAddress: String? = null
fundingAddress: String? = null,
): CurrencyAmount {
requireValidAuth()
return executeQuery(
@@ -752,7 +752,7 @@ class LightsparkCoroutinesClient private constructor(
{
add("node_id", nodeId)
amountSats?.let { add("amount_sats", it) }
fundingAddress?.let { add("funding_address", it)}
fundingAddress?.let { add("funding_address", it) }
},
signingNodeId = nodeId,
) {
@@ -1062,7 +1062,7 @@ class LightsparkCoroutinesClient private constructor(

/**
* fetch outgoing payments for a given payment hash
*
*
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
*/
@@ -1090,13 +1090,40 @@ class LightsparkCoroutinesClient private constructor(
)
}

/**
* Fetch outgoing payment for a given idempotency key
*
* @param idempotencyKey The idempotency key used when creating the payment.
*/
suspend fun getOutgoingPaymentForIdempotencyKey(
idempotencyKey: String,
): OutgoingPayment? {
requireValidAuth()
return executeQuery(
Query(
OutgoingPaymentForIdempotencyKeyQuery,
{
add("idempotency_key", idempotencyKey)
},
) {
val outputJson =
requireNotNull(it["outgoing_payment_for_idempotency_key"]) { "No payment output found in response" }
val paymentJson = outputJson.jsonObject["payment"]
if (paymentJson == null) {
return@Query null
}
serializerFormat.decodeFromJsonElement(paymentJson)
},
)
}

/**
* fetch invoice for a given payment hash
*
*
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
*/
suspend fun getInvoiceForPaymentHash(
paymentHash: String
paymentHash: String,
): Invoice {
requireValidAuth()
return executeQuery(
@@ -1140,7 +1167,7 @@ class LightsparkCoroutinesClient private constructor(
val paymentsJson =
requireNotNull(outputJson.jsonObject["payments"]) { "No payments found in response" }
serializerFormat.decodeFromJsonElement(paymentsJson)
}
},
)
}

Original file line number Diff line number Diff line change
@@ -616,6 +616,18 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
asyncClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
}

/**
* Fetch outgoing payment for a given idempotency key
*
* @param idempotencyKey The idempotency key used when creating the payment.
*/
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
fun getOutgoingPaymentForIdempotencyKey(
idempotencyKey: String,
): OutgoingPayment? = runBlocking {
asyncClient.getOutgoingPaymentForIdempotencyKey(idempotencyKey)
}

@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
fun getIncomingPaymentsForInvoice(
invoiceId: String,
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.lightspark.sdk.graphql

import com.lightspark.sdk.model.OutgoingPayment

const val OutgoingPaymentForIdempotencyKeyQuery = """
query OutgoingPaymentForIdempotencyKey(
${'$'}idempotency_key: String!
) {
outgoing_payment_for_idempotency_key(input: {
idempotency_key: ${'$'}idempotency_key,
statuses: ${'$'}transactionStatuses
}) {
payment {
...OutgoingPaymentFragment
}
}
}

${OutgoingPayment.FRAGMENT}
"""