Skip to content

Commit d2d6001

Browse files
authored
Merge pull request #12 from jvsena42/update-daemon-2
Update daemon 2
2 parents c8edcdd + ec64173 commit d2d6001

File tree

8 files changed

+39
-24
lines changed

8 files changed

+39
-24
lines changed

app/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ android {
1818
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1919
}
2020

21+
lint {
22+
abortOnError = false
23+
}
24+
2125
buildTypes {
2226
release {
2327
isMinifyEnabled = false

app/src/main/java/com/florestad/Florestad.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@file:Suppress("NAME_SHADOWING")
55

6-
package uniffi.floresta;
6+
package com.florestad
77

88
// Common helper code.
99
//

app/src/main/java/com/github/jvsena42/floresta/domain/bitcoin/WalletManager.kt

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import com.github.jvsena42.floresta.domain.model.TxType
99
import kotlinx.coroutines.CoroutineScope
1010
import kotlinx.coroutines.Dispatchers
1111
import kotlinx.coroutines.SupervisorJob
12+
import kotlinx.coroutines.delay
13+
import kotlinx.coroutines.flow.firstOrNull
1214
import kotlinx.coroutines.launch
1315
import org.bitcoindevkit.Address
1416
import org.bitcoindevkit.AddressInfo
@@ -27,6 +29,7 @@ import org.bitcoindevkit.WordCount
2729
import org.rustbitcoin.bitcoin.Amount
2830
import org.rustbitcoin.bitcoin.FeeRate
2931
import org.rustbitcoin.bitcoin.Network
32+
import kotlin.time.Duration.Companion.seconds
3033
import org.bitcoindevkit.ChainPosition as BdkChainPosition
3134

3235
class WalletManager(
@@ -96,7 +99,7 @@ class WalletManager(
9699
)
97100

98101
walletRepository.saveMnemonic(mnemonic.toString())
99-
florestaRpc.loadDescriptor(descriptor.toString())
102+
florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull()
100103
}
101104

102105
suspend fun loadWallet(): Result<Unit> {
@@ -117,8 +120,6 @@ class WalletManager(
117120
connection = dbConnection
118121
)
119122

120-
florestaRpc.loadDescriptor(descriptor.toString())
121-
122123
Log.d(TAG, "loadWallet: in network ${wallet.network()}")
123124

124125
return Result.success(Unit)
@@ -155,26 +156,34 @@ class WalletManager(
155156
changeDescriptor.toStringWithSecret()
156157
)
157158
walletRepository.saveMnemonic(mnemonic.toString())
158-
florestaRpc.loadDescriptor(descriptor.toString())
159+
florestaRpc.loadDescriptor(descriptor.toString()).firstOrNull()
159160
}
160161

161-
private fun fullScan() {
162-
val fullScanRequest = wallet.startFullScan().build()
163-
val update: Update = blockchainClient.fullScan(
164-
fullScanRequest = fullScanRequest,
165-
stopGap = 100u,
166-
batchSize = 10u,
167-
fetchPrevTxouts = true
168-
)
169-
wallet.applyUpdate(update)
170-
wallet.persist(dbConnection)
162+
private suspend fun fullScan() {
163+
Log.d(TAG, "fullScan: ")
164+
try {
165+
val fullScanRequest = wallet.startFullScan().build()
166+
val update: Update = blockchainClient.fullScan(
167+
fullScanRequest = fullScanRequest,
168+
stopGap = 20u,
169+
batchSize = 10u,
170+
fetchPrevTxouts = true
171+
)
172+
wallet.applyUpdate(update)
173+
wallet.persist(dbConnection)
174+
} catch (e: Exception) {
175+
Log.e(TAG, "fullScan error:", e)
176+
}
171177
}
172178

173-
fun sync() {
179+
suspend fun sync() {
180+
if (!walletRepository.doesWalletExist()) return
181+
174182
if (fullScanRequired) {
175183
Log.d(TAG, "sync: fullScanRequired")
176-
fullScan()
177184
fullScanRequired = false
185+
delay(15.seconds)
186+
fullScan()
178187
} else {
179188
Log.d(TAG, "sync: normal sync")
180189
val syncRequest = wallet.startSyncWithRevealedSpks().build()

app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaDaemon.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.github.jvsena42.floresta.domain.floresta
22

33
import android.util.Log
4+
import com.florestad.Florestad
45
import com.github.jvsena42.floresta.domain.bitcoin.WalletRepository
5-
import com.github.jvsena42.floresta.presentation.util.filterInternalBrackets
66
import org.bitcoindevkit.Descriptor
77
import org.rustbitcoin.bitcoin.Network
8-
import uniffi.floresta.Config
9-
import uniffi.floresta.Florestad
10-
import uniffi.floresta.Network as FlorestaNetwork
8+
import com.florestad.Config
9+
import com.florestad.Network as FlorestaNetwork
1110
import kotlin.let
1211

1312
interface FlorestaDaemon {

app/src/main/java/com/github/jvsena42/floresta/domain/floresta/FlorestaRpcImpl.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.google.gson.Gson
99
import kotlinx.coroutines.delay
1010
import kotlinx.coroutines.flow.Flow
1111
import kotlinx.coroutines.flow.first
12+
import kotlinx.coroutines.flow.firstOrNull
1213
import kotlinx.coroutines.flow.flow
1314
import okhttp3.MediaType.Companion.toMediaTypeOrNull
1415
import okhttp3.RequestBody.Companion.toRequestBody
@@ -41,9 +42,10 @@ class FlorestaRpcImpl(
4142
arguments.put(descriptor)
4243

4344
getBlockchainInfo().first().onSuccess { result ->
45+
Log.d(TAG, "loadDescriptor: loading initial block: ${result.result.ibd}")
4446
if (result.result.ibd) {
4547
delay(10.seconds)
46-
loadDescriptor(descriptor)
48+
loadDescriptor(descriptor).firstOrNull()
4749
} else {
4850
emit(
4951
sendJsonRpcRequest(
@@ -55,7 +57,7 @@ class FlorestaRpcImpl(
5557
}
5658
}.onFailure {
5759
delay(30.seconds)
58-
loadDescriptor(descriptor)
60+
loadDescriptor(descriptor).firstOrNull()
5961
}
6062
}
6163

@@ -69,6 +71,7 @@ class FlorestaRpcImpl(
6971
arguments
7072
).fold(
7173
onSuccess = { json ->
74+
Log.d(TAG, "getPeerInfo: ")
7275
emit(
7376
Result.success(
7477
gson.fromJson(json.toString(), GetPeerInfoResponse::class.java)

app/src/main/java/com/github/jvsena42/floresta/presentation/ui/screens/home/HomeViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class HomeViewModel(
6464
} else {
6565
Log.d(TAG, "setup: Wallet does not exists")
6666
walletManager.createWallet()
67+
// walletManager.recoverWallet("bird unique ridge dose run problem scare label teach return inflict struggle")
6768
}
6869
}
6970

@@ -72,7 +73,6 @@ class HomeViewModel(
7273
delay(5.seconds)
7374
updateUI()
7475
walletManager.sync()
75-
delay(5.seconds)
7676
syncInLoop()
7777
}
7878
}
2.99 KB
Binary file not shown.
-10.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)