From 052d41d073a13654c891b6bd259545a1ba330285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Danil=C4=8Denko?= Date: Tue, 15 Oct 2024 15:49:47 +0200 Subject: [PATCH] Validate wallet after it's created --- .../walletManager/WalletManager.kt | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/tari/android/wallet/application/walletManager/WalletManager.kt b/app/src/main/java/com/tari/android/wallet/application/walletManager/WalletManager.kt index b2d57ae4f..4893d9c71 100644 --- a/app/src/main/java/com/tari/android/wallet/application/walletManager/WalletManager.kt +++ b/app/src/main/java/com/tari/android/wallet/application/walletManager/WalletManager.kt @@ -227,20 +227,7 @@ class WalletManager @Inject constructor( baseNodeKeyFFI.destroy() logger.i("baseNodeSync:addBaseNodePeer ${if (addBaseNodeResult) "success" else "failed"}") - try { - logger.i("baseNodeSync:wallet validation:start Tx and TXO validation") - walletValidationStatusMap.clear() - walletValidationStatusMap[WalletValidationType.TXO] = WalletValidationResult(wallet.startTXOValidation(), null) - walletValidationStatusMap[WalletValidationType.TX] = WalletValidationResult(wallet.startTxValidation(), null) - logger.i( - "baseNodeSync:wallet validation:started Tx and TXO validation with " + - "request keys: ${Gson().toJson(walletValidationStatusMap.map { it.value.requestKey })}" - ) - } catch (e: Throwable) { - logger.i("baseNodeSync:wallet validation:error: ${e.message}") - walletValidationStatusMap.clear() - baseNodeStateHandler.updateSyncState(BaseNodeSyncState.Failed) - } + validateWallet() } break } catch (e: Throwable) { @@ -570,10 +557,33 @@ class WalletManager @Inject constructor( } } + validateWallet() + saveWalletAddressToSharedPrefs() } } + private fun validateWallet() { + applicationScope.launch(Dispatchers.IO) { + doOnWalletRunning { wallet -> + try { + logger.i("baseNodeSync:wallet validation:start Tx and TXO validation") + walletValidationStatusMap.clear() + walletValidationStatusMap[WalletValidationType.TXO] = WalletValidationResult(wallet.startTXOValidation(), null) + walletValidationStatusMap[WalletValidationType.TX] = WalletValidationResult(wallet.startTxValidation(), null) + logger.i( + "baseNodeSync:wallet validation:started Tx and TXO validation with " + + "request keys: ${Gson().toJson(walletValidationStatusMap.map { it.value.requestKey })}" + ) + } catch (e: Throwable) { + logger.i("baseNodeSync:wallet validation:error: ${e.message}") + walletValidationStatusMap.clear() + baseNodeStateHandler.updateSyncState(BaseNodeSyncState.Failed) + } + } + } + } + private fun postTxNotification(tx: Tx) { txReceivedNotificationDelayedAction?.dispose() inboundTxEventNotificationTxs.add(tx)