@@ -119,28 +119,27 @@ class LightningRepo @Inject constructor(
119119 ): Result <T > = withContext(bgDispatcher) {
120120 Logger .verbose(" Operation called: $operationName " , context = TAG )
121121
122- if (_lightningState .value.nodeLifecycleState.isRunning()) {
122+ val nodeLifecycleState = _lightningState .value.nodeLifecycleState
123+ if (nodeLifecycleState.isRunning()) {
123124 return @withContext executeOperation(operationName, operation)
124125 }
125126
126127 // If node is not in a state that can become running, fail fast
127- if (! _lightningState .value. nodeLifecycleState.canRun()) {
128+ if (! nodeLifecycleState.canRun()) {
128129 return @withContext Result .failure(
129- Exception (
130- " Cannot execute $operationName : Node is ${_lightningState .value.nodeLifecycleState} and not starting"
131- )
130+ Exception (" Cannot execute '$operationName ': node is '$nodeLifecycleState ' and not starting" )
132131 )
133132 }
134133
135134 val nodeRunning = withTimeoutOrNull(waitTimeout) {
136- if (_lightningState .value. nodeLifecycleState.isRunning()) {
135+ if (nodeLifecycleState.isRunning()) {
137136 return @withTimeoutOrNull true
138137 }
139138
140139 // Otherwise, wait for it to transition to running state
141- Logger .verbose(" Waiting for node runs to execute $operationName " , context = TAG )
140+ Logger .verbose(" Waiting for node to run before executing ' $operationName ' " , context = TAG )
142141 _lightningState .first { it.nodeLifecycleState.isRunning() }
143- Logger .debug(" Operation executed: $operationName " , context = TAG )
142+ Logger .debug(" Operation executed: ' $operationName ' " , context = TAG )
144143 true
145144 } ? : false
146145
@@ -159,7 +158,7 @@ class LightningRepo @Inject constructor(
159158 // Cancellation is expected during pull-to-refresh, rethrow per Kotlin best practices
160159 throw e
161160 } catch (e: Throwable ) {
162- Logger .error(" $operationName error " , e, context = TAG )
161+ Logger .error(" Error executing ' $operationName ' " , e, context = TAG )
163162 Result .failure(e)
164163 }
165164 }
@@ -312,7 +311,7 @@ class LightningRepo @Inject constructor(
312311 }
313312 }
314313
315- suspend fun sync (): Result <Unit > = executeWhenNodeRunning(" Sync " ) {
314+ suspend fun sync (): Result <Unit > = executeWhenNodeRunning(" sync " ) {
316315 // If sync is in progress, mark pending and skip
317316 if (! syncMutex.tryLock()) {
318317 syncPending.set(true )
@@ -531,7 +530,7 @@ class LightningRepo @Inject constructor(
531530 return @withContext Result .success(Unit )
532531 }
533532
534- suspend fun connectToTrustedPeers (): Result <Unit > = executeWhenNodeRunning(" Connect to trusted peers " ) {
533+ suspend fun connectToTrustedPeers (): Result <Unit > = executeWhenNodeRunning(" connectToTrustedPeers " ) {
535534 lightningService.connectToTrustedPeers()
536535 Result .success(Unit )
537536 }
@@ -544,13 +543,13 @@ class LightningRepo @Inject constructor(
544543 Result .success(Unit )
545544 }
546545
547- suspend fun disconnectPeer (peer : PeerDetails ): Result <Unit > = executeWhenNodeRunning(" Disconnect peer " ) {
546+ suspend fun disconnectPeer (peer : PeerDetails ): Result <Unit > = executeWhenNodeRunning(" disconnectPeer " ) {
548547 lightningService.disconnectPeer(peer)
549548 syncState()
550549 Result .success(Unit )
551550 }
552551
553- suspend fun newAddress (): Result <String > = executeWhenNodeRunning(" New address " ) {
552+ suspend fun newAddress (): Result <String > = executeWhenNodeRunning(" newAddress " ) {
554553 val address = lightningService.newAddress()
555554 Result .success(address)
556555 }
@@ -559,7 +558,7 @@ class LightningRepo @Inject constructor(
559558 amountSats : ULong? = null,
560559 description : String ,
561560 expirySeconds : UInt = 86_400u,
562- ): Result <String > = executeWhenNodeRunning(" Create invoice " ) {
561+ ): Result <String > = executeWhenNodeRunning(" createInvoice " ) {
563562 updateGeoBlockState()
564563 val invoice = lightningService.receive(amountSats, description, expirySeconds)
565564 Result .success(invoice)
@@ -631,12 +630,14 @@ class LightningRepo @Inject constructor(
631630 Logger .error(" Error requesting lnurl auth, k1: $k1 , callback: $callback , domain: $domain " , it)
632631 }
633632
634- suspend fun payInvoice (bolt11 : String , sats : ULong? = null): Result <PaymentId > =
635- executeWhenNodeRunning(" Pay invoice" ) {
636- val paymentId = lightningService.send(bolt11 = bolt11, sats = sats)
637- syncState()
638- Result .success(paymentId)
639- }
633+ suspend fun payInvoice (
634+ bolt11 : String ,
635+ sats : ULong? = null,
636+ ): Result <PaymentId > = executeWhenNodeRunning(" payInvoice" ) {
637+ val paymentId = lightningService.send(bolt11 = bolt11, sats = sats)
638+ syncState()
639+ Result .success(paymentId)
640+ }
640641
641642 @Suppress(" LongParameterList" )
642643 suspend fun sendOnChain (
@@ -649,46 +650,45 @@ class LightningRepo @Inject constructor(
649650 channelId : String? = null,
650651 isMaxAmount : Boolean = false,
651652 tags : List <String > = emptyList(),
652- ): Result <Txid > =
653- executeWhenNodeRunning(" sendOnChain" ) {
654- require(address.isNotEmpty()) { " Send address cannot be empty" }
653+ ): Result <Txid > = executeWhenNodeRunning(" sendOnChain" ) {
654+ require(address.isNotEmpty()) { " Send address cannot be empty" }
655655
656- val transactionSpeed = speed ? : settingsStore.data.first().defaultTransactionSpeed
657- val satsPerVByte = getFeeRateForSpeed(transactionSpeed, feeRates).getOrThrow().toUInt()
656+ val transactionSpeed = speed ? : settingsStore.data.first().defaultTransactionSpeed
657+ val satsPerVByte = getFeeRateForSpeed(transactionSpeed, feeRates).getOrThrow().toUInt()
658658
659- // if utxos are manually specified, use them, otherwise run auto coin select if enabled
660- val finalUtxosToSpend = utxosToSpend ? : determineUtxosToSpend(
661- sats = sats,
662- satsPerVByte = satsPerVByte,
663- )
659+ // if utxos are manually specified, use them, otherwise run auto coin select if enabled
660+ val finalUtxosToSpend = utxosToSpend ? : determineUtxosToSpend(
661+ sats = sats,
662+ satsPerVByte = satsPerVByte,
663+ )
664664
665- Logger .debug(" UTXOs selected to spend: $finalUtxosToSpend " , context = TAG )
665+ Logger .debug(" UTXOs selected to spend: $finalUtxosToSpend " , context = TAG )
666666
667- val txId = lightningService.send(
668- address = address,
669- sats = sats,
670- satsPerVByte = satsPerVByte,
671- utxosToSpend = finalUtxosToSpend,
672- isMaxAmount = isMaxAmount
673- )
667+ val txId = lightningService.send(
668+ address = address,
669+ sats = sats,
670+ satsPerVByte = satsPerVByte,
671+ utxosToSpend = finalUtxosToSpend,
672+ isMaxAmount = isMaxAmount
673+ )
674674
675- val preActivityMetadata = PreActivityMetadata (
676- paymentId = txId,
677- createdAt = nowTimestamp().toEpochMilli().toULong(),
678- tags = tags,
679- paymentHash = null ,
680- txId = txId,
681- address = address,
682- isReceive = false ,
683- feeRate = satsPerVByte.toULong(),
684- isTransfer = isTransfer,
685- channelId = channelId ? : " " ,
686- )
687- preActivityMetadataRepo.addPreActivityMetadata(preActivityMetadata)
675+ val preActivityMetadata = PreActivityMetadata (
676+ paymentId = txId,
677+ createdAt = nowTimestamp().toEpochMilli().toULong(),
678+ tags = tags,
679+ paymentHash = null ,
680+ txId = txId,
681+ address = address,
682+ isReceive = false ,
683+ feeRate = satsPerVByte.toULong(),
684+ isTransfer = isTransfer,
685+ channelId = channelId ? : " " ,
686+ )
687+ preActivityMetadataRepo.addPreActivityMetadata(preActivityMetadata)
688688
689- syncState()
690- Result .success(txId)
691- }
689+ syncState()
690+ Result .success(txId)
691+ }
692692
693693 suspend fun determineUtxosToSpend (
694694 sats : ULong ,
@@ -731,7 +731,7 @@ class LightningRepo @Inject constructor(
731731 Result .success(payments)
732732 }
733733
734- suspend fun getAddressBalance (address : String ): Result <ULong > = executeWhenNodeRunning(" Get address balance " ) {
734+ suspend fun getAddressBalance (address : String ): Result <ULong > = executeWhenNodeRunning(" getAddressBalance " ) {
735735 runCatching {
736736 lightningService.getAddressBalance(address)
737737 }
@@ -787,7 +787,7 @@ class LightningRepo @Inject constructor(
787787
788788 suspend fun calculateCpfpFeeRate (
789789 parentTxId : Txid ,
790- ): Result <ULong > = executeWhenNodeRunning(" Calculate CPFP fee rate " ) {
790+ ): Result <ULong > = executeWhenNodeRunning(" calculateCpfpFeeRate " ) {
791791 Result .success(lightningService.calculateCpfpFeeRate(parentTxid = parentTxId).toSatPerVbCeil())
792792 }
793793
@@ -796,7 +796,7 @@ class LightningRepo @Inject constructor(
796796 channelAmountSats : ULong ,
797797 pushToCounterpartySats : ULong? = null,
798798 channelConfig : ChannelConfig ? = null,
799- ): Result <OpenChannelResult > = executeWhenNodeRunning(" Open channel " ) {
799+ ): Result <OpenChannelResult > = executeWhenNodeRunning(" openChannel " ) {
800800 val result = lightningService.openChannel(peer, channelAmountSats, pushToCounterpartySats, channelConfig)
801801 syncState()
802802 result
@@ -931,25 +931,19 @@ class LightningRepo @Inject constructor(
931931 try {
932932 if (originalTxId.isBlank()) {
933933 return @executeWhenNodeRunning Result .failure(
934- IllegalArgumentException (
935- " originalTxId is null or empty: $originalTxId "
936- )
934+ IllegalArgumentException (" originalTxId is null or empty: $originalTxId " )
937935 )
938936 }
939937
940938 if (destinationAddress.isBlank()) {
941939 return @executeWhenNodeRunning Result .failure(
942- IllegalArgumentException (
943- " destinationAddress is null or empty: $destinationAddress "
944- )
940+ IllegalArgumentException (" destinationAddress is null or empty: $destinationAddress " )
945941 )
946942 }
947943
948944 if (satsPerVByte <= 0u ) {
949945 return @executeWhenNodeRunning Result .failure(
950- IllegalArgumentException (
951- " satsPerVByte invalid: $satsPerVByte "
952- )
946+ IllegalArgumentException (" satsPerVByte invalid: $satsPerVByte " )
953947 )
954948 }
955949
0 commit comments