Skip to content
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 @@ -21,6 +21,7 @@ import com.lightspark.sdk.model.InvoiceType
import com.lightspark.sdk.model.OutgoingPayment
import com.lightspark.sdk.model.PaymentDirection
import com.lightspark.sdk.model.RegionCode
import com.lightspark.sdk.model.ReleasePaymentPreimageOutput
import com.lightspark.sdk.model.RiskRating
import com.lightspark.sdk.model.TransactionStatus
import com.lightspark.sdk.model.UmaInvitation
Expand Down Expand Up @@ -116,6 +117,23 @@ class LightsparkFuturesClient(config: ClientConfig) {
): CompletableFuture<WalletDashboard?> =
coroutineScope.future { coroutinesClient.getSingleNodeDashboard(nodeId, numTransactions, bitcoinNetwork) }

/**
* Marks a payment preimage as released. To be used when the recipient has received the payment.
*
* @param invoiceId The invoice the preimage belongs to.
* @param paymentPreimage The preimage to release.
*/
fun releasePaymentPreimage(
invoiceId: String,
paymentPreimage: String
): CompletableFuture<ReleasePaymentPreimageOutput?> =
coroutineScope.future {
coroutinesClient.releasePaymentPreimage(
invoiceId,
paymentPreimage
)
}

/**
* Creates a lightning invoice for the given node.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ class LightsparkCoroutinesClient private constructor(
)
}

/**
* Marks a payment preimage as released. To be used when the recipient has received the payment.
*
* @param invoiceId The invoice the preimage belongs to.
* @param paymentPreimage The preimage to release.
*/
suspend fun releasePaymentPreimage(invoiceId: String, paymentPreimage: String): ReleasePaymentPreimageOutput {
requireValidAuth()

return executeQuery(
Query(
ReleasePaymentPreimageMutation,
{
add("invoice_id", invoiceId)
add("payment_preimage", paymentPreimage)
},
) {
val releasePaymentPreimageJson =
requireNotNull(it["release_payment_preimage"]) { "Invalid response for payment preimage release" }
serializerFormat.decodeFromJsonElement<ReleasePaymentPreimageOutput>(releasePaymentPreimageJson)
},
)
}

/**
* Creates a lightning invoice for the given node.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
bitcoinNetwork: BitcoinNetwork = defaultBitcoinNetwork,
): WalletDashboard? = runBlocking { asyncClient.getSingleNodeDashboard(nodeId, numTransactions, bitcoinNetwork) }

/**
* Marks a payment preimage as released. To be used when the recipient has received the payment.
*
* @param invoiceId The invoice the preimage belongs to.
* @param paymentPreimage The preimage to release.
*/
fun releasePaymentPreimage(
invoiceId: String,
paymentPreimage: String
): ReleasePaymentPreimageOutput = runBlocking {
asyncClient.releasePaymentPreimage(
invoiceId,
paymentPreimage
)
}

/**
* Creates a lightning invoice for the given node.
*
Expand Down