Skip to content

Commit

Permalink
fix: collect descriptor result
Browse files Browse the repository at this point in the history
  • Loading branch information
jvsena42 committed Oct 28, 2024
1 parent 57a1769 commit 3b1473c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,7 +99,7 @@ class WalletManager(
)

walletRepository.saveMnemonic(mnemonic.toString())
florestaRpc.loadDescriptor(descriptor.toString()).first()
florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull()
}

suspend fun loadWallet(): Result<Unit> {
Expand All @@ -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()}")

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -56,7 +57,7 @@ class FlorestaRpcImpl(
}
}.onFailure {
delay(30.seconds)
loadDescriptor(descriptor).first()
loadDescriptor(descriptor).firstOrNull()
}
}

Expand All @@ -70,6 +71,7 @@ class FlorestaRpcImpl(
arguments
).fold(
onSuccess = { json ->
Log.d(TAG, "getPeerInfo: ")
emit(
Result.success(
gson.fromJson(json.toString(), GetPeerInfoResponse::class.java)
Expand Down

0 comments on commit 3b1473c

Please sign in to comment.