Skip to content

Commit 95acb9a

Browse files
authored
Merge pull request #200 from lightsparkdev/release/lightspark-sdk-v0.17.0
Merge release/lightspark-sdk-v0.17.0 into main
2 parents f41b86c + a66f7a2 commit 95acb9a

File tree

13 files changed

+273
-10
lines changed

13 files changed

+273
-10
lines changed

lightspark-sdk/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Start by installing the SDK from maven:
1717
**build.gradle:**
1818
```groovy
1919
dependencies {
20-
implementation "com.lightspark:lightspark-sdk:0.16.0"
20+
implementation "com.lightspark:lightspark-sdk:0.17.0"
2121
}
2222
```
2323

2424
or with **build.gradle.kts:**
2525
```kotlin
2626
dependencies {
27-
implementation("com.lightspark:lightspark-sdk:0.16.0")
27+
implementation("com.lightspark:lightspark-sdk:0.17.0")
2828
}
2929
```
3030

lightspark-sdk/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GROUP=com.lightspark
22
POM_ARTIFACT_ID=lightspark-sdk
33
# Don't bump this manually. Run `scripts/versions.main.kt <new_version>` to bump the version instead.
4-
VERSION_NAME=0.16.0
4+
VERSION_NAME=0.17.0
55

66
POM_DESCRIPTION=The Lightspark API SDK for Kotlin and Java.
77
POM_INCEPTION_YEAR=2023

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,11 @@ class LightsparkFuturesClient(config: ClientConfig) {
414414
*
415415
* @param nodeId The ID of the node to fund. Must be a REGTEST node.
416416
* @param amountSats The amount of funds to add to the node. Defaults to 10,000,000 SATOSHI.
417+
* @param fundingAddress: L1 address owned by funded node. If null, automatically create new funding address
417418
* @return The amount of funds added to the node.
418419
*/
419-
fun fundNode(nodeId: String, amountSats: Long?): CompletableFuture<CurrencyAmount> =
420-
coroutineScope.future { coroutinesClient.fundNode(nodeId, amountSats) }
420+
fun fundNode(nodeId: String, amountSats: Long?, fundingAddress: String? = null): CompletableFuture<CurrencyAmount> =
421+
coroutineScope.future { coroutinesClient.fundNode(nodeId, amountSats, fundingAddress) }
421422

422423
/**
423424
* Withdraws funds from the account and sends it to the requested bitcoin address.
@@ -576,6 +577,33 @@ class LightsparkFuturesClient(config: ClientConfig) {
576577
coroutinesClient.getOutgoingPaymentsForInvoice(encodedInvoice, transactionStatuses)
577578
}
578579

580+
/**
581+
* fetch outgoing payments for a given payment hash
582+
*
583+
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
584+
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
585+
*/
586+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
587+
fun getOutgoingPaymentsForPaymentHash(
588+
paymentHash: String,
589+
transactionStatuses: List<TransactionStatus>? = null
590+
): CompletableFuture<List<OutgoingPayment>> = coroutineScope.future {
591+
coroutinesClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
592+
}
593+
594+
/**
595+
* fetch invoice for a given payments hash
596+
*
597+
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
598+
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
599+
*/
600+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
601+
fun getInvoiceForPaymentHash(
602+
paymentHash: String
603+
): CompletableFuture<Invoice> = coroutineScope.future {
604+
coroutinesClient.getInvoiceForPaymentHash(paymentHash)
605+
}
606+
579607
/**
580608
* Fetch incoming payments for a given payment hash.
581609
*
@@ -592,6 +620,14 @@ class LightsparkFuturesClient(config: ClientConfig) {
592620
coroutinesClient.getIncomingPaymentsForPaymentHash(paymentHash, transactionStatuses)
593621
}
594622

623+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
624+
fun getIncomingPaymentsForInvoice(
625+
invoiceId: String,
626+
transactionStatuses: List<TransactionStatus>? = null
627+
): CompletableFuture<List<IncomingPayment>> = coroutineScope.future {
628+
coroutinesClient.getIncomingPaymentsForInvoice(invoiceId, transactionStatuses)
629+
}
630+
595631
/**
596632
* Creates an UMA invitation. If you are part of the incentive program you should use
597633
* [createUmaInvitationWithIncentives].

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

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,22 @@ class LightsparkCoroutinesClient private constructor(
729729
*
730730
* @param nodeId The ID of the node to fund. Must be a REGTEST node.
731731
* @param amountSats The amount of funds to add to the node. Defaults to 10,000,000 SATOSHI.
732+
* @param fundingAddress: L1 address owned by funded node. If null, automatically create new funding address
732733
* @return The amount of funds added to the node.
733734
*/
734-
suspend fun fundNode(nodeId: String, amountSats: Long?): CurrencyAmount {
735+
suspend fun fundNode(
736+
nodeId: String,
737+
amountSats: Long?,
738+
fundingAddress: String? = null
739+
): CurrencyAmount {
735740
requireValidAuth()
736741
return executeQuery(
737742
Query(
738743
FundNodeMutation,
739744
{
740745
add("node_id", nodeId)
741746
amountSats?.let { add("amount_sats", it) }
747+
fundingAddress?.let { add("funding_address", it)}
742748
},
743749
signingNodeId = nodeId,
744750
) {
@@ -1036,6 +1042,90 @@ class LightsparkCoroutinesClient private constructor(
10361042
)
10371043
}
10381044

1045+
/**
1046+
* fetch outgoing payments for a given payment hash
1047+
*
1048+
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
1049+
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
1050+
*/
1051+
suspend fun getOutgoingPaymentForPaymentHash(
1052+
paymentHash: String,
1053+
transactionStatuses: List<TransactionStatus>? = null,
1054+
): List<OutgoingPayment> {
1055+
requireValidAuth()
1056+
return executeQuery(
1057+
Query(
1058+
OutgoingPaymentsForPaymentHashQuery,
1059+
{
1060+
add("paymentHash", paymentHash)
1061+
transactionStatuses?.let {
1062+
add("transactionStatuses", serializerFormat.encodeToJsonElement(it))
1063+
}
1064+
},
1065+
) {
1066+
val outputJson =
1067+
requireNotNull(it["outgoing_payments_for_payment_hash"]) { "No payment output found in response" }
1068+
val paymentsJson =
1069+
requireNotNull(outputJson.jsonObject["payments"]) { "No payments found in response" }
1070+
serializerFormat.decodeFromJsonElement(paymentsJson)
1071+
},
1072+
)
1073+
}
1074+
1075+
/**
1076+
* fetch invoice for a given payment hash
1077+
*
1078+
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
1079+
*/
1080+
suspend fun getInvoiceForPaymentHash(
1081+
paymentHash: String
1082+
): Invoice {
1083+
requireValidAuth()
1084+
return executeQuery(
1085+
Query(
1086+
InvoiceForPaymentHashQuery,
1087+
{
1088+
add("paymentHash", paymentHash)
1089+
},
1090+
) {
1091+
val outputJson =
1092+
requireNotNull(it["invoice_for_payment_hash"]) { "No invoice found in response" }
1093+
val invoiceJson =
1094+
requireNotNull(outputJson.jsonObject["invoice"]) { "No invoice found in response" }
1095+
serializerFormat.decodeFromJsonElement(invoiceJson)
1096+
},
1097+
)
1098+
}
1099+
1100+
/**
1101+
* fetch invoice for a given invoice id
1102+
*
1103+
* @param invoiceId the id of the invoice for which to fetch the outgoing payments
1104+
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
1105+
*/
1106+
suspend fun getIncomingPaymentsForInvoice(
1107+
invoiceId: String,
1108+
transactionStatuses: List<TransactionStatus>? = null,
1109+
): List<IncomingPayment> {
1110+
return executeQuery(
1111+
Query(
1112+
IncomingPaymentsForInvoiceQuery,
1113+
{
1114+
add("invoiceId", invoiceId)
1115+
transactionStatuses?.let {
1116+
add("transactionStatuses", serializerFormat.encodeToJsonElement(it))
1117+
}
1118+
},
1119+
) {
1120+
val outputJson =
1121+
requireNotNull(it["incoming_payments_for_invoice"]) { "No payment output found in response" }
1122+
val paymentsJson =
1123+
requireNotNull(outputJson.jsonObject["payments"]) { "No payments found in response" }
1124+
serializerFormat.decodeFromJsonElement(paymentsJson)
1125+
}
1126+
)
1127+
}
1128+
10391129
/**
10401130
* Creates an UMA invitation. If you are part of the incentive program you should use
10411131
* [createUmaInvitationWithIncentives].

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,12 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
397397
*
398398
* @param nodeId The ID of the node to fund. Must be a REGTEST node.
399399
* @param amountSats The amount of funds to add to the node. Defaults to 10,000,000 SATOSHI.
400+
* @param fundingAddress: L1 address owned by funded node. If null, automatically create new funding address
400401
* @return The amount of funds added to the node.
401402
*/
402403
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
403-
fun fundNode(nodeId: String, amountSats: Long?): CurrencyAmount =
404-
runBlocking { asyncClient.fundNode(nodeId, amountSats) }
404+
fun fundNode(nodeId: String, amountSats: Long?, fundingAddress: String? = null): CurrencyAmount =
405+
runBlocking { asyncClient.fundNode(nodeId, amountSats, fundingAddress) }
405406

406407
/**
407408
* Withdraws funds from the account and sends it to the requested bitcoin address.
@@ -576,6 +577,35 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
576577
asyncClient.getIncomingPaymentsForPaymentHash(paymentHash, transactionStatuses)
577578
}
578579

580+
/**
581+
* fetch outgoing payments for a given payment hash
582+
*
583+
* @param paymentHash the payment hash of the invoice for which to fetch the outgoing payments
584+
* @param transactionStatuses the transaction statuses to filter the payments by. If null, all payments will be returned.
585+
*/
586+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
587+
fun getOutgoingPaymentsForPaymentHash(
588+
paymentHash: String,
589+
transactionStatuses: List<TransactionStatus>? = null
590+
): List<OutgoingPayment> = runBlocking {
591+
asyncClient.getOutgoingPaymentForPaymentHash(paymentHash, transactionStatuses)
592+
}
593+
594+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
595+
fun getIncomingPaymentsForInvoice(
596+
invoiceId: String,
597+
transactionStatuses: List<TransactionStatus>? = null
598+
): List<IncomingPayment> = runBlocking {
599+
asyncClient.getIncomingPaymentsForInvoice(invoiceId, transactionStatuses)
600+
}
601+
602+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
603+
fun getInvoiceForPaymentHash(
604+
paymentHash: String
605+
): Invoice = runBlocking {
606+
asyncClient.getInvoiceForPaymentHash(paymentHash)
607+
}
608+
579609
/**
580610
* Creates an UMA invitation. If you are part of the incentive program you should use
581611
* [createUmaInvitationWithIncentives].

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/graphql/FundNode.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ const val FundNodeMutation = """
66
mutation FundNode(
77
${'$'}node_id: ID!,
88
${'$'}amount_sats: Long
9+
${'$'}funding_address: String
910
) {
10-
fund_node(input: { node_id: ${'$'}node_id, amount_sats: ${'$'}amount_sats }) {
11+
fund_node(input: {
12+
node_id: ${'$'}node_id,
13+
amount_sats: ${'$'}amount_sats,
14+
funding_address: ${'$'}funding_address
15+
}) {
1116
amount {
1217
...CurrencyAmountFragment
1318
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lightspark.sdk.graphql
2+
3+
import com.lightspark.sdk.model.IncomingPayment
4+
5+
const val IncomingPaymentsForInvoiceQuery = """
6+
query IncomingPaymentsForInvoice(
7+
${'$'}invoiceId: Hash32!,
8+
${'$'}transactionStatuses: [TransactionStatus!] = null
9+
) {
10+
incoming_payments_for_invoice_query(input: {
11+
invoice_id: ${'$'}invoiceId,
12+
statuses: ${'$'}transactionStatuses
13+
}) {
14+
payments {
15+
...IncomingPaymentFragment
16+
}
17+
}
18+
}
19+
20+
${IncomingPayment.FRAGMENT}
21+
"""

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/graphql/IncomingPaymentsForPaymentHash.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.lightspark.sdk.graphql
33
import com.lightspark.sdk.model.IncomingPayment
44

55
const val IncomingPaymentsForPaymentHashQuery = """
6-
query OutgoingPaymentsForInvoice(
6+
query IncomingPaymentsForPaymentHash(
77
${'$'}paymentHash: Hash32!,
88
${'$'}transactionStatuses: [TransactionStatus!] = null
99
) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lightspark.sdk.graphql
2+
3+
import com.lightspark.sdk.model.Invoice
4+
5+
const val InvoiceForPaymentHashQuery = """
6+
query InvoiceForPaymentHash(
7+
${'$'}paymentHash: Hash32!,
8+
) {
9+
invoice_for_payment_hash(input: {
10+
payment_hash: ${'$'}paymentHash,
11+
}) {
12+
invoice {
13+
...InvoiceFragment
14+
}
15+
}
16+
}
17+
18+
${Invoice.FRAGMENT}
19+
"""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lightspark.sdk.graphql
2+
3+
import com.lightspark.sdk.model.OutgoingPayment
4+
5+
const val OutgoingPaymentsForPaymentHashQuery = """
6+
query OutgoingPaymentsForPaymentHash(
7+
${'$'}paymentHash: Hash32!,
8+
${'$'}transactionStatuses: [TransactionStatus!] = null
9+
) {
10+
outgoing_payments_for_payment_hash(input: {
11+
payment_hash: ${'$'}paymentHash,
12+
statuses: ${'$'}transactionStatuses
13+
}) {
14+
payments {
15+
...OutgoingPaymentFragment
16+
}
17+
}
18+
}
19+
20+
${OutgoingPayment.FRAGMENT}
21+
"""

0 commit comments

Comments
 (0)