Skip to content

Commit d8157b5

Browse files
Merge pull request #229 from lightsparkdev/aaryaman/lpt-263-create-releasepaymentpreimage-function
Added releasePaymentPreimage functions to all 3 kotlin clients
2 parents 242a9ba + 934e765 commit d8157b5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

lightspark-sdk/src/commonJvmAndroidMain/kotlin/com/lightspark/sdk/LightsparkFuturesClient.kt

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lightspark.sdk.model.InvoiceType
2121
import com.lightspark.sdk.model.OutgoingPayment
2222
import com.lightspark.sdk.model.PaymentDirection
2323
import com.lightspark.sdk.model.RegionCode
24+
import com.lightspark.sdk.model.ReleasePaymentPreimageOutput
2425
import com.lightspark.sdk.model.RiskRating
2526
import com.lightspark.sdk.model.TransactionStatus
2627
import com.lightspark.sdk.model.UmaInvitation
@@ -116,6 +117,23 @@ class LightsparkFuturesClient(config: ClientConfig) {
116117
): CompletableFuture<WalletDashboard?> =
117118
coroutineScope.future { coroutinesClient.getSingleNodeDashboard(nodeId, numTransactions, bitcoinNetwork) }
118119

120+
/**
121+
* Marks a payment preimage as released. To be used when the recipient has received the payment.
122+
*
123+
* @param invoiceId The invoice the preimage belongs to.
124+
* @param paymentPreimage The preimage to release.
125+
*/
126+
fun releasePaymentPreimage(
127+
invoiceId: String,
128+
paymentPreimage: String
129+
): CompletableFuture<ReleasePaymentPreimageOutput?> =
130+
coroutineScope.future {
131+
coroutinesClient.releasePaymentPreimage(
132+
invoiceId,
133+
paymentPreimage
134+
)
135+
}
136+
119137
/**
120138
* Creates a lightning invoice for the given node.
121139
*

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkCoroutinesClient.kt

+24
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,30 @@ class LightsparkCoroutinesClient private constructor(
172172
)
173173
}
174174

175+
/**
176+
* Marks a payment preimage as released. To be used when the recipient has received the payment.
177+
*
178+
* @param invoiceId The invoice the preimage belongs to.
179+
* @param paymentPreimage The preimage to release.
180+
*/
181+
suspend fun releasePaymentPreimage(invoiceId: String, paymentPreimage: String): ReleasePaymentPreimageOutput {
182+
requireValidAuth()
183+
184+
return executeQuery(
185+
Query(
186+
ReleasePaymentPreimageMutation,
187+
{
188+
add("invoice_id", invoiceId)
189+
add("payment_preimage", paymentPreimage)
190+
},
191+
) {
192+
val releasePaymentPreimageJson =
193+
requireNotNull(it["release_payment_preimage"]) { "Invalid response for payment preimage release" }
194+
serializerFormat.decodeFromJsonElement<ReleasePaymentPreimageOutput>(releasePaymentPreimageJson)
195+
},
196+
)
197+
}
198+
175199
/**
176200
* Creates a lightning invoice for the given node.
177201
*

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkSyncClient.kt

+16
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
9898
bitcoinNetwork: BitcoinNetwork = defaultBitcoinNetwork,
9999
): WalletDashboard? = runBlocking { asyncClient.getSingleNodeDashboard(nodeId, numTransactions, bitcoinNetwork) }
100100

101+
/**
102+
* Marks a payment preimage as released. To be used when the recipient has received the payment.
103+
*
104+
* @param invoiceId The invoice the preimage belongs to.
105+
* @param paymentPreimage The preimage to release.
106+
*/
107+
fun releasePaymentPreimage(
108+
invoiceId: String,
109+
paymentPreimage: String
110+
): ReleasePaymentPreimageOutput = runBlocking {
111+
asyncClient.releasePaymentPreimage(
112+
invoiceId,
113+
paymentPreimage
114+
)
115+
}
116+
101117
/**
102118
* Creates a lightning invoice for the given node.
103119
*

0 commit comments

Comments
 (0)