From 3b1473caef1c44f9a9a251e0ad1529cf42fbcb4e Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Mon, 28 Oct 2024 13:40:38 -0300 Subject: [PATCH] fix: collect descriptor result --- .../jvsena42/floresta/domain/bitcoin/WalletManager.kt | 8 ++++---- .../jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/jvsena42/floresta/domain/bitcoin/WalletManager.kt b/app/src/main/java/com/github/jvsena42/floresta/domain/bitcoin/WalletManager.kt index 104390b..f5435b0 100644 --- a/app/src/main/java/com/github/jvsena42/floresta/domain/bitcoin/WalletManager.kt +++ b/app/src/main/java/com/github/jvsena42/floresta/domain/bitcoin/WalletManager.kt @@ -10,7 +10,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.launch import org.bitcoindevkit.Address import org.bitcoindevkit.AddressInfo @@ -99,7 +99,7 @@ class WalletManager( ) walletRepository.saveMnemonic(mnemonic.toString()) - florestaRpc.loadDescriptor(descriptor.toString()).first() + florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull() } suspend fun loadWallet(): Result { @@ -120,7 +120,7 @@ class WalletManager( connection = dbConnection ) - florestaRpc.loadDescriptor(descriptor.toString()).first() + florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull() Log.d(TAG, "loadWallet: in network ${wallet.network()}") @@ -158,7 +158,7 @@ class WalletManager( changeDescriptor.toStringWithSecret() ) walletRepository.saveMnemonic(mnemonic.toString()) - florestaRpc.loadDescriptor(descriptor.toString()).first() + florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull() } private suspend fun fullScan() { diff --git a/app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt b/app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt index a7dac0b..b4e78ec 100644 --- a/app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt +++ b/app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt @@ -9,6 +9,7 @@ import com.google.gson.Gson import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flow import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody @@ -44,7 +45,7 @@ class FlorestaRpcImpl( Log.d(TAG, "loadDescriptor: loading initial block: ${result.result.ibd}") if (result.result.ibd) { delay(10.seconds) - loadDescriptor(descriptor).first() + loadDescriptor(descriptor).firstOrNull() } else { emit( sendJsonRpcRequest( @@ -56,7 +57,7 @@ class FlorestaRpcImpl( } }.onFailure { delay(30.seconds) - loadDescriptor(descriptor).first() + loadDescriptor(descriptor).firstOrNull() } } @@ -70,6 +71,7 @@ class FlorestaRpcImpl( arguments ).fold( onSuccess = { json -> + Log.d(TAG, "getPeerInfo: ") emit( Result.success( gson.fromJson(json.toString(), GetPeerInfoResponse::class.java)