Skip to content

Commit efbdb38

Browse files
committed
Add the outgoing_payment_for_idempotency_key query.
1 parent 8134d17 commit efbdb38

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

Diff for: lightspark-sdk/src/commonJvmAndroidMain/kotlin/com/lightspark/sdk/LightsparkFuturesClient.kt

+12
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,18 @@ class LightsparkFuturesClient(config: ClientConfig) {
615615
coroutinesClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
616616
}
617617

618+
/**
619+
* Fetch outgoing payment for a given idempotency key
620+
*
621+
* @param idempotencyKey The idempotency key used when creating the payment.
622+
*/
623+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
624+
fun getOutgoingPaymentForIdempotencyKey(
625+
idempotencyKey: String,
626+
): CompletableFuture<OutgoingPayment?> = coroutineScope.future {
627+
coroutinesClient.getOutgoingPaymentForIdempotencyKey(idempotencyKey)
628+
}
629+
618630
/**
619631
* fetch invoice for a given payments hash
620632
*

Diff for: lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkCoroutinesClient.kt

+33-6
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ class LightsparkCoroutinesClient private constructor(
743743
suspend fun fundNode(
744744
nodeId: String,
745745
amountSats: Long?,
746-
fundingAddress: String? = null
746+
fundingAddress: String? = null,
747747
): CurrencyAmount {
748748
requireValidAuth()
749749
return executeQuery(
@@ -752,7 +752,7 @@ class LightsparkCoroutinesClient private constructor(
752752
{
753753
add("node_id", nodeId)
754754
amountSats?.let { add("amount_sats", it) }
755-
fundingAddress?.let { add("funding_address", it)}
755+
fundingAddress?.let { add("funding_address", it) }
756756
},
757757
signingNodeId = nodeId,
758758
) {
@@ -1062,7 +1062,7 @@ class LightsparkCoroutinesClient private constructor(
10621062

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

1093+
/**
1094+
* Fetch outgoing payment for a given idempotency key
1095+
*
1096+
* @param idempotencyKey The idempotency key used when creating the payment.
1097+
*/
1098+
suspend fun getOutgoingPaymentForIdempotencyKey(
1099+
idempotencyKey: String,
1100+
): OutgoingPayment? {
1101+
requireValidAuth()
1102+
return executeQuery(
1103+
Query(
1104+
OutgoingPaymentForIdempotencyKeyQuery,
1105+
{
1106+
add("idempotency_key", idempotencyKey)
1107+
},
1108+
) {
1109+
val outputJson =
1110+
requireNotNull(it["outgoing_payment_for_idempotency_key"]) { "No payment output found in response" }
1111+
val paymentJson = outputJson.jsonObject["payment"]
1112+
if (paymentJson == null) {
1113+
return@Query null
1114+
}
1115+
serializerFormat.decodeFromJsonElement(paymentJson)
1116+
},
1117+
)
1118+
}
1119+
10931120
/**
10941121
* fetch invoice for a given payment hash
1095-
*
1122+
*
10961123
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
10971124
*/
10981125
suspend fun getInvoiceForPaymentHash(
1099-
paymentHash: String
1126+
paymentHash: String,
11001127
): Invoice {
11011128
requireValidAuth()
11021129
return executeQuery(
@@ -1140,7 +1167,7 @@ class LightsparkCoroutinesClient private constructor(
11401167
val paymentsJson =
11411168
requireNotNull(outputJson.jsonObject["payments"]) { "No payments found in response" }
11421169
serializerFormat.decodeFromJsonElement(paymentsJson)
1143-
}
1170+
},
11441171
)
11451172
}
11461173

Diff for: lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkSyncClient.kt

+12
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,18 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
616616
asyncClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
617617
}
618618

619+
/**
620+
* Fetch outgoing payment for a given idempotency key
621+
*
622+
* @param idempotencyKey The idempotency key used when creating the payment.
623+
*/
624+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
625+
fun getOutgoingPaymentForIdempotencyKey(
626+
idempotencyKey: String,
627+
): OutgoingPayment? = runBlocking {
628+
asyncClient.getOutgoingPaymentForIdempotencyKey(idempotencyKey)
629+
}
630+
619631
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
620632
fun getIncomingPaymentsForInvoice(
621633
invoiceId: String,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lightspark.sdk.graphql
2+
3+
import com.lightspark.sdk.model.OutgoingPayment
4+
5+
const val OutgoingPaymentForIdempotencyKeyQuery = """
6+
query OutgoingPaymentForIdempotencyKey(
7+
${'$'}idempotency_key: String!
8+
) {
9+
outgoing_payment_for_idempotency_key(input: {
10+
idempotency_key: ${'$'}idempotency_key,
11+
statuses: ${'$'}transactionStatuses
12+
}) {
13+
payment {
14+
...OutgoingPaymentFragment
15+
}
16+
}
17+
}
18+
19+
${OutgoingPayment.FRAGMENT}
20+
"""

0 commit comments

Comments
 (0)