Skip to content

Commit 9dcf16f

Browse files
committed
fix: wait for node run before open order
1 parent 2230870 commit 9dcf16f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.update
3333
import kotlinx.coroutines.isActive
3434
import kotlinx.coroutines.launch
3535
import kotlinx.coroutines.withContext
36+
import kotlinx.coroutines.withTimeout
3637
import org.lightningdevkit.ldknode.ChannelDetails
3738
import to.bitkit.async.ServiceQueue
3839
import to.bitkit.data.CacheStore
@@ -52,6 +53,7 @@ import javax.inject.Named
5253
import javax.inject.Singleton
5354
import kotlin.math.ceil
5455
import kotlin.time.Duration
56+
import kotlin.time.Duration.Companion.minutes
5557
import kotlin.time.Duration.Companion.seconds
5658

5759
@Singleton
@@ -282,6 +284,11 @@ class BlocktankRepo @Inject constructor(
282284
suspend fun openChannel(orderId: String): Result<IBtOrder> = withContext(bgDispatcher) {
283285
try {
284286
Logger.debug("Opening channel for order: '$orderId'", context = TAG)
287+
288+
withTimeout(1.minutes) {
289+
lightningRepo.lightningState.first { it.nodeStatus?.isRunning ?: false }
290+
}
291+
285292
val order = coreService.blocktank.open(orderId)
286293

287294
// Update the order in state

0 commit comments

Comments
 (0)