@@ -29,6 +29,7 @@ import org.lightningdevkit.ldknode.Address
2929import org.lightningdevkit.ldknode.BalanceDetails
3030import org.lightningdevkit.ldknode.BestBlock
3131import org.lightningdevkit.ldknode.ChannelConfig
32+ import org.lightningdevkit.ldknode.ChannelDataMigration
3233import org.lightningdevkit.ldknode.ChannelDetails
3334import org.lightningdevkit.ldknode.ClosureReason
3435import org.lightningdevkit.ldknode.Event
@@ -167,10 +168,11 @@ class LightningRepo @Inject constructor(
167168 walletIndex : Int ,
168169 customServerUrl : String? = null,
169170 customRgsServerUrl : String? = null,
171+ channelMigration : ChannelDataMigration ? = null,
170172 ) = withContext(bgDispatcher) {
171173 return @withContext try {
172174 val trustedPeers = getTrustedPeersFromBlocktank()
173- lightningService.setup(walletIndex, customServerUrl, customRgsServerUrl, trustedPeers)
175+ lightningService.setup(walletIndex, customServerUrl, customRgsServerUrl, trustedPeers, channelMigration )
174176 Result .success(Unit )
175177 } catch (e: Throwable ) {
176178 Logger .error(" Node setup error" , e, context = TAG )
@@ -196,6 +198,7 @@ class LightningRepo @Inject constructor(
196198 customServerUrl : String? = null,
197199 customRgsServerUrl : String? = null,
198200 eventHandler : NodeEventHandler ? = null,
201+ channelMigration : ChannelDataMigration ? = null,
199202 ): Result <Unit > = withContext(bgDispatcher) {
200203 if (_isRecoveryMode .value) {
201204 return @withContext Result .failure(RecoveryModeException ())
@@ -214,7 +217,7 @@ class LightningRepo @Inject constructor(
214217
215218 // Setup if needed
216219 if (lightningService.node == null ) {
217- val setupResult = setup(walletIndex, customServerUrl, customRgsServerUrl)
220+ val setupResult = setup(walletIndex, customServerUrl, customRgsServerUrl, channelMigration )
218221 if (setupResult.isFailure) {
219222 _lightningState .update {
220223 it.copy(
@@ -264,6 +267,7 @@ class LightningRepo @Inject constructor(
264267 shouldRetry = false ,
265268 customServerUrl = customServerUrl,
266269 customRgsServerUrl = customRgsServerUrl,
270+ channelMigration = channelMigration,
267271 )
268272 } else {
269273 Logger .error(" Node start error" , e, context = TAG )
@@ -311,6 +315,19 @@ class LightningRepo @Inject constructor(
311315 }
312316 }
313317
318+ suspend fun restart (): Result <Unit > = withContext(bgDispatcher) {
319+ stop().onFailure {
320+ Logger .error(" Failed to stop node during restart" , it, context = TAG )
321+ return @withContext Result .failure(it)
322+ }
323+ delay(500 )
324+ start(shouldRetry = false ).onFailure {
325+ Logger .error(" Failed to start node during restart" , it, context = TAG )
326+ return @withContext Result .failure(it)
327+ }
328+ Result .success(Unit )
329+ }
330+
314331 suspend fun sync (): Result <Unit > = executeWhenNodeRunning(" sync" ) {
315332 // If sync is in progress, mark pending and skip
316333 if (! syncMutex.tryLock()) {
0 commit comments