Skip to content

Commit 9bcb59b

Browse files
committed
fix: use const for bolt11 expiry default
1 parent bfa54b9 commit 9bcb59b

8 files changed

Lines changed: 29 additions & 13 deletions

File tree

app/src/main/java/to/bitkit/env/Env.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ internal object Env {
246246
@Suppress("ConstPropertyName")
247247
object Defaults {
248248
/** Default Bolt11 invoice expiry in seconds. */
249-
const val bolt11InvoiceExpirySeconds = 3_600u
249+
const val bolt11ExpirySec = 86_400u
250250

251251
/** Recommended transaction base fee in sats */
252252
const val recommendedBaseFee = 256u

app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import javax.inject.Named
5757
import javax.inject.Singleton
5858
import kotlin.math.ceil
5959
import kotlin.time.Duration
60+
import kotlin.time.Duration.Companion.hours
6061
import kotlin.time.Duration.Companion.seconds
6162

6263
@Singleton
@@ -463,7 +464,7 @@ class BlocktankRepo @Inject constructor(
463464
val invoice = lightningRepo.createInvoice(
464465
amountSats = null,
465466
description = "blocktank-gift-code:$code",
466-
expirySeconds = Defaults.bolt11InvoiceExpirySeconds,
467+
expirySeconds = 1.hours.inWholeSeconds.toUInt(),
467468
).getOrThrow()
468469

469470
Logger.debug("Created invoice for gift code, requesting payment from LSP", context = TAG)

app/src/main/java/to/bitkit/repositories/LightningRepo.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import to.bitkit.data.SettingsStore
5858
import to.bitkit.data.backup.VssBackupClientLdk
5959
import to.bitkit.data.keychain.Keychain
6060
import to.bitkit.di.BgDispatcher
61+
import to.bitkit.env.Defaults
6162
import to.bitkit.env.Env
6263
import to.bitkit.ext.getSatsPerVByteFor
6364
import to.bitkit.ext.nowTimestamp
@@ -926,7 +927,7 @@ class LightningRepo @Inject constructor(
926927
suspend fun createInvoice(
927928
amountSats: ULong? = null,
928929
description: String,
929-
expirySeconds: UInt = 86_400u,
930+
expirySeconds: UInt = Defaults.bolt11ExpirySec,
930931
): Result<String> = executeWhenNodeRunning("createInvoice") {
931932
updateGeoBlockState()
932933
runCatching { lightningService.receive(amountSats, description, expirySeconds) }
@@ -935,7 +936,7 @@ class LightningRepo @Inject constructor(
935936
suspend fun createInvoiceMsats(
936937
amountMsats: ULong,
937938
description: String,
938-
expirySeconds: UInt = 86_400u,
939+
expirySeconds: UInt = Defaults.bolt11ExpirySec,
939940
): Result<String> = executeWhenNodeRunning("createInvoiceMsats") {
940941
updateGeoBlockState()
941942
runCatching { lightningService.receiveMsats(amountMsats, description, expirySeconds) }

app/src/main/java/to/bitkit/services/CoreService.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import org.lightningdevkit.ldknode.TransactionDetails
7070
import to.bitkit.async.ServiceQueue
7171
import to.bitkit.data.CacheStore
7272
import to.bitkit.data.SettingsStore
73+
import to.bitkit.env.Defaults
7374
import to.bitkit.env.Env
7475
import to.bitkit.ext.amountSats
7576
import to.bitkit.ext.channelId
@@ -1521,11 +1522,15 @@ class BlocktankService(
15211522
)
15221523
}
15231524

1524-
suspend fun regtestCloseChannel(fundingTxId: String, vout: UInt, forceCloseAfterS: ULong = 86_400uL): String {
1525+
suspend fun regtestCloseChannel(
1526+
fundingTxId: String,
1527+
vout: UInt,
1528+
forceCloseAfterS: UInt = Defaults.bolt11ExpirySec,
1529+
): String {
15251530
return com.synonym.bitkitcore.regtestCloseChannel(
15261531
fundingTxId = fundingTxId,
15271532
vout = vout,
1528-
forceCloseAfterS = forceCloseAfterS,
1533+
forceCloseAfterS = forceCloseAfterS.toULong(),
15291534
)
15301535
}
15311536
}

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,15 @@ class LightningService @Inject constructor(
595595
suspend fun receive(
596596
sat: ULong? = null,
597597
description: String,
598-
expirySecs: UInt = Defaults.bolt11InvoiceExpirySeconds,
598+
expirySecs: UInt = Defaults.bolt11ExpirySec,
599599
): String {
600600
return receiveMsats(amountMsat = sat?.let { it * 1000u }, description = description, expirySecs = expirySecs)
601601
}
602602

603603
suspend fun receiveMsats(
604604
amountMsat: ULong? = null,
605605
description: String,
606-
expirySecs: UInt = Defaults.bolt11InvoiceExpirySeconds,
606+
expirySecs: UInt = Defaults.bolt11ExpirySec,
607607
): String {
608608
val node = this.node ?: throw ServiceError.NodeNotSetup()
609609

app/src/main/java/to/bitkit/ui/settings/BlocktankRegtestScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fun BlocktankRegtestScreen(
270270
runCatching {
271271
val voutNum = vout.toUIntOrNull() ?: error("Invalid Vout: $vout")
272272
val closeAfter =
273-
forceCloseAfter.toULongOrNull() ?: error("Invalid Force Close After: $forceCloseAfter")
273+
forceCloseAfter.toUIntOrNull() ?: error("Invalid Force Close After: $forceCloseAfter")
274274
val closingTxId = viewModel.regtestCloseChannel(
275275
fundingTxId = fundingTxId,
276276
vout = voutNum,

app/src/main/java/to/bitkit/ui/settings/BlocktankRegtestViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package to.bitkit.ui.settings
22

33
import androidx.lifecycle.ViewModel
44
import dagger.hilt.android.lifecycle.HiltViewModel
5+
import to.bitkit.env.Defaults
56
import to.bitkit.services.CoreService
67
import javax.inject.Inject
78

@@ -28,7 +29,11 @@ class BlocktankRegtestViewModel @Inject constructor(
2829
)
2930
}
3031

31-
suspend fun regtestCloseChannel(fundingTxId: String, vout: UInt, forceCloseAfterS: ULong = 86_400uL): String {
32+
suspend fun regtestCloseChannel(
33+
fundingTxId: String,
34+
vout: UInt,
35+
forceCloseAfterS: UInt = Defaults.bolt11ExpirySec,
36+
): String {
3237
return coreService.blocktank.regtestCloseChannel(
3338
fundingTxId = fundingTxId,
3439
vout = vout,

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,11 @@ class AppViewModel @Inject constructor(
14441444
}
14451445

14461446
@Suppress("CyclomaticComplexMethod")
1447-
private suspend fun handleDecodedScan(scan: Scanner?, input: String) = when (scan) {
1447+
private suspend fun handleDecodedScan(
1448+
scan: Scanner?,
1449+
input: String,
1450+
fromMainScanner: Boolean = false,
1451+
) = when (scan) {
14481452
is Scanner.OnChain -> onScanOnchain(scan.invoice, input, fromMainScanner)
14491453
is Scanner.Lightning -> onScanLightning(scan.invoice, input, fromMainScanner)
14501454
is Scanner.LnurlPay -> onScanLnurlPay(scan.data, fromMainScanner)
@@ -2090,7 +2094,7 @@ class AppViewModel @Inject constructor(
20902094
lightningRepo.createInvoiceMsats(
20912095
amountMsats = lnurl.data.maxWithdrawable,
20922096
description = lnurl.data.defaultDescription,
2093-
expirySeconds = Defaults.bolt11InvoiceExpirySeconds,
2097+
expirySeconds = 3_600u,
20942098
)
20952099
} else {
20962100
val withdrawAmountSats = _sendUiState.value.amount.coerceAtLeast(
@@ -2100,7 +2104,7 @@ class AppViewModel @Inject constructor(
21002104
lightningRepo.createInvoice(
21012105
amountSats = withdrawAmountSats,
21022106
description = lnurl.data.defaultDescription,
2103-
expirySeconds = Defaults.bolt11InvoiceExpirySeconds,
2107+
expirySeconds = 3_600u,
21042108
)
21052109
}.getOrNull()
21062110

0 commit comments

Comments
 (0)