From 08aed18f194c1ed3f9bda3498ae748918ad5692c Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Thu, 26 Dec 2024 16:31:00 -0500 Subject: [PATCH] monero background sync view key update --- cw_bitcoin/lib/electrum_wallet.dart | 2 +- cw_core/lib/wallet_base.dart | 4 +- cw_evm/lib/evm_chain_wallet.dart | 2 +- cw_monero/lib/api/wallet.dart | 68 +++++++++++++++++--------- cw_monero/lib/monero_wallet.dart | 75 +++++++++++++++++------------ cw_nano/lib/nano_wallet.dart | 2 +- cw_solana/lib/solana_wallet.dart | 2 +- cw_tron/lib/tron_wallet.dart | 2 +- cw_wownero/lib/api/wallet.dart | 66 +++++++++++++++++-------- cw_wownero/lib/wownero_wallet.dart | 18 ++++++- lib/entities/background_tasks.dart | 42 ++++++++++------ 11 files changed, 186 insertions(+), 97 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index df413c2b1..bc6173d42 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -453,7 +453,7 @@ abstract class ElectrumWalletBase @action @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { try { if (syncStatus is SyncronizingSyncStatus) { return; diff --git a/cw_core/lib/wallet_base.dart b/cw_core/lib/wallet_base.dart index 16c794a25..44d370e59 100644 --- a/cw_core/lib/wallet_base.dart +++ b/cw_core/lib/wallet_base.dart @@ -65,9 +65,9 @@ abstract class WalletBase connectToPowNode({required Node node}) async {} - Future startSync(); + Future startSync({bool isBackgroundSync = false}); - Future stopSync() async {} + Future stopSync({bool isBackgroundSync = false}) async {} Future createTransaction(Object credentials); diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart index dca16539c..d7bd74947 100644 --- a/cw_evm/lib/evm_chain_wallet.dart +++ b/cw_evm/lib/evm_chain_wallet.dart @@ -300,7 +300,7 @@ abstract class EVMChainWalletBase @action @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { try { syncStatus = AttemptingSyncStatus(); await _updateBalance(); diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 78153a654..1c7e8c684 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -32,8 +32,7 @@ String getFilename() => monero.Wallet_filename(wptr!); String getSeed() { // monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed); - final cakepolyseed = - monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed"); + final cakepolyseed = monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed"); if (cakepolyseed != "") { return cakepolyseed; } @@ -48,11 +47,21 @@ String getSeed() { String getSeedLegacy(String? language) { var legacy = monero.Wallet_seed(wptr!, seedOffset: ''); switch (language) { - case "Chinese (Traditional)": language = "Chinese (simplified)"; break; - case "Chinese (Simplified)": language = "Chinese (simplified)"; break; - case "Korean": language = "English"; break; - case "Czech": language = "English"; break; - case "Japanese": language = "English"; break; + case "Chinese (Traditional)": + language = "Chinese (simplified)"; + break; + case "Chinese (Simplified)": + language = "Chinese (simplified)"; + break; + case "Korean": + language = "English"; + break; + case "Czech": + language = "English"; + break; + case "Japanese": + language = "English"; + break; } if (monero.Wallet_status(wptr!) != 0) { monero.Wallet_setSeedLanguage(wptr!, language: language ?? "English"); @@ -72,14 +81,14 @@ Map>> addressCache = {}; String getAddress({int accountIndex = 0, int addressIndex = 0}) { // printV("getaddress: ${accountIndex}/${addressIndex}: ${monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex)}: ${monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex)}"); - while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex)-1 < addressIndex) { + while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) { printV("adding subaddress"); monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex); } addressCache[wptr!.address] ??= {}; addressCache[wptr!.address]![accountIndex] ??= {}; - addressCache[wptr!.address]![accountIndex]![addressIndex] ??= monero.Wallet_address(wptr!, - accountIndex: accountIndex, addressIndex: addressIndex); + addressCache[wptr!.address]![accountIndex]![addressIndex] ??= + monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex); return addressCache[wptr!.address]![accountIndex]![addressIndex]!; } @@ -132,7 +141,8 @@ Future setupNodeSync( if (kDebugMode) { monero.Wallet_init3( - wptr!, argv0: '', + wptr!, + argv0: '', defaultLogBaseName: 'moneroc', console: true, logPath: '', @@ -147,17 +157,32 @@ void startRefreshSync() { monero.Wallet_startRefresh(wptr!); } +void setupBackgroundSync( + {required int backgroundSyncType, + required String walletPassword, + required String backgroundCachePassword}) { + monero.Wallet_setupBackgroundSync(wptr!, + backgroundSyncType: backgroundSyncType, + walletPassword: walletPassword, + backgroundCachePassword: backgroundCachePassword); +} + +void startBackgroundSync() { + monero.Wallet_startBackgroundSync(wptr!); +} + +void stopBackgroundSync(String walletPassword) { + monero.Wallet_stopBackgroundSync(wptr!, walletPassword); +} void setRefreshFromBlockHeight({required int height}) => - monero.Wallet_setRefreshFromBlockHeight(wptr!, - refresh_from_block_height: height); + monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height); void setRecoveringFromSeed({required bool isRecovery}) => monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery); final storeMutex = Mutex(); - int lastStorePointer = 0; int lastStoreHeight = 0; void storeSync({bool force = false}) async { @@ -167,7 +192,7 @@ void storeSync({bool force = false}) async { }); if (lastStorePointer == wptr!.address && lastStoreHeight + 5000 > monero.Wallet_blockChainHeight(wptr!) && - !synchronized && + !synchronized && !force) { return; } @@ -227,8 +252,7 @@ class SyncListener { _cachedBlockchainHeight = 0; _lastKnownBlockHeight = 0; _initialSyncHeight = 0; - _updateSyncInfoTimer ??= - Timer.periodic(Duration(milliseconds: 1200), (_) async { + _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { if (isNewTransactionExist()) { onNewTransaction(); } @@ -267,8 +291,8 @@ class SyncListener { void stop() => _updateSyncInfoTimer?.cancel(); } -SyncListener setListeners(void Function(int, int, double) onNewBlock, - void Function() onNewTransaction) { +SyncListener setListeners( + void Function(int, int, double) onNewBlock, void Function() onNewTransaction) { final listener = SyncListener(onNewBlock, onNewTransaction); // setListenerNative(); return listener; @@ -330,8 +354,7 @@ String getSubaddressLabel(int accountIndex, int addressIndex) { accountIndex: accountIndex, addressIndex: addressIndex); } -Future setTrustedDaemon(bool trusted) async => - monero.Wallet_setTrustedDaemon(wptr!, arg: trusted); +Future setTrustedDaemon(bool trusted) async => monero.Wallet_setTrustedDaemon(wptr!, arg: trusted); Future trustedDaemon() async => monero.Wallet_trustedDaemon(wptr!); @@ -340,5 +363,6 @@ String signMessage(String message, {String address = ""}) { } bool verifyMessage(String message, String address, String signature) { - return monero.Wallet_verifySignedMessage(wptr!, message: message, address: address, signature: signature); + return monero.Wallet_verifySignedMessage(wptr!, + message: message, address: address, signature: signature); } diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 098d4ac3d..f06efabed 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -158,10 +158,10 @@ abstract class MoneroWalletBase } } - _autoSaveTimer = Timer.periodic( - Duration(seconds: _autoSaveInterval), (_) async => await save()); + _autoSaveTimer = + Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save()); // update transaction details after restore - walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id??0); + walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id ?? 0); } @override @@ -197,7 +197,19 @@ abstract class MoneroWalletBase } @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { + if (isBackgroundSync) { + try { + syncStatus = AttemptingSyncStatus(); + monero_wallet.startBackgroundSync(); + return; + } catch (e) { + syncStatus = FailedSyncStatus(); + printV(e); + rethrow; + } + } + try { _assertInitialHeight(); } catch (_) { @@ -219,6 +231,11 @@ abstract class MoneroWalletBase try { syncStatus = AttemptingSyncStatus(); monero_wallet.startRefresh(); + monero_wallet.setupBackgroundSync( + backgroundSyncType: 2, + walletPassword: password, + backgroundCachePassword: "testing-cache-password", + ); _setListeners(); _listener?.start(); } catch (e) { @@ -259,9 +276,13 @@ abstract class MoneroWalletBase } @override - Future stopSync() async { + Future stopSync({bool isBackgroundSync = false}) async { syncStatus = NotConnectedSyncStatus(); _listener?.stop(); + if (isBackgroundSync) { + monero_wallet.stopBackgroundSync(password); + return; + } // TODO: find a better way to stop syncing than setting an invalid address: monero_wallet.setupNode(address: ""); } @@ -307,8 +328,7 @@ abstract class MoneroWalletBase throw MoneroTransactionCreationException('You do not have enough XMR to send this amount.'); } - if (inputs.isEmpty) MoneroTransactionCreationException( - 'No inputs selected'); + if (inputs.isEmpty) MoneroTransactionCreationException('No inputs selected'); final moneroOutputs = outputs.map((output) { final outputAddress = output.isParsedAddress ? output.extractedAddress : output.address; @@ -336,17 +356,14 @@ abstract class MoneroWalletBase // 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.'); // } - final estimatedFee = - calculateEstimatedFee(_credentials.priority, formattedAmount); - if (inputs.isEmpty) MoneroTransactionCreationException( - 'No inputs selected'); - pendingTransactionDescription = - await transaction_history.createTransaction( - address: address!, - amount: amount, - priorityRaw: _credentials.priority.serialize(), - accountIndex: walletAddresses.account!.id, - preferredInputs: inputs); + final estimatedFee = calculateEstimatedFee(_credentials.priority, formattedAmount); + if (inputs.isEmpty) MoneroTransactionCreationException('No inputs selected'); + pendingTransactionDescription = await transaction_history.createTransaction( + address: address!, + amount: amount, + priorityRaw: _credentials.priority.serialize(), + accountIndex: walletAddresses.account!.id, + preferredInputs: inputs); } // final status = monero.PendingTransaction_status(pendingTransactionDescription); @@ -498,7 +515,8 @@ abstract class MoneroWalletBase for (var i = 0; i < coinCount; i++) { final coin = getCoin(i); final coinSpent = monero.CoinsInfo_spent(coin); - if (coinSpent == false && monero.CoinsInfo_subaddrAccount(coin) == walletAddresses.account!.id) { + if (coinSpent == false && + monero.CoinsInfo_subaddrAccount(coin) == walletAddresses.account!.id) { final unspent = MoneroUnspent( monero.CoinsInfo_address(coin), monero.CoinsInfo_hash(coin), @@ -600,8 +618,7 @@ abstract class MoneroWalletBase Future> fetchTransactions() async { transaction_history.refreshTransactions(); return (await _getAllTransactionsOfAccount(walletAddresses.account?.id)) - .fold>( - {}, + .fold>({}, (Map acc, MoneroTransactionInfo tx) { acc[tx.id] = tx; return acc; @@ -630,15 +647,12 @@ abstract class MoneroWalletBase monero_wallet.getSubaddressLabel(accountIndex, addressIndex); Future> _getAllTransactionsOfAccount(int? accountIndex) async => - (await transaction_history - .getAllTransactions()) + (await transaction_history.getAllTransactions()) .map( (row) => MoneroTransactionInfo( row.hash, row.blockheight, - row.isSpend - ? TransactionDirection.outgoing - : TransactionDirection.incoming, + row.isSpend ? TransactionDirection.outgoing : TransactionDirection.incoming, row.timeStamp, row.isPending, row.amount, @@ -708,8 +722,7 @@ abstract class MoneroWalletBase void _askForUpdateBalance() { final unlockedBalance = _getUnlockedBalance(); - final fullBalance = monero_wallet.getFullBalance( - accountIndex: walletAddresses.account!.id); + final fullBalance = monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id); final frozenBalance = _getFrozenBalance(); if (balance[currency]!.fullBalance != fullBalance || balance[currency]!.unlockedBalance != unlockedBalance || @@ -730,8 +743,7 @@ abstract class MoneroWalletBase var frozenBalance = 0; for (var coin in unspentCoinsInfo.values.where((element) => - element.walletId == id && - element.accountIndex == walletAddresses.account!.id)) { + element.walletId == id && element.accountIndex == walletAddresses.account!.id)) { if (coin.isFrozen && !coin.isSending) frozenBalance += coin.value; } return frozenBalance; @@ -805,8 +817,7 @@ abstract class MoneroWalletBase } void setLedgerConnection(LedgerConnection connection) { - final dummyWPtr = wptr ?? - monero.WalletManager_openWallet(wmPtr, path: '', password: ''); + final dummyWPtr = wptr ?? monero.WalletManager_openWallet(wmPtr, path: '', password: ''); enableLedgerExchange(dummyWPtr, connection); } } diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index b48335857..1461bf628 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -343,7 +343,7 @@ abstract class NanoWalletBase @action @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { try { syncStatus = AttemptingSyncStatus(); diff --git a/cw_solana/lib/solana_wallet.dart b/cw_solana/lib/solana_wallet.dart index 33a2e7df4..e10c1a71a 100644 --- a/cw_solana/lib/solana_wallet.dart +++ b/cw_solana/lib/solana_wallet.dart @@ -367,7 +367,7 @@ abstract class SolanaWalletBase @action @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { try { syncStatus = AttemptingSyncStatus(); diff --git a/cw_tron/lib/tron_wallet.dart b/cw_tron/lib/tron_wallet.dart index cfa80f0d3..92f169279 100644 --- a/cw_tron/lib/tron_wallet.dart +++ b/cw_tron/lib/tron_wallet.dart @@ -273,7 +273,7 @@ abstract class TronWalletBase @action @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { try { syncStatus = AttemptingSyncStatus(); await _updateBalance(); diff --git a/cw_wownero/lib/api/wallet.dart b/cw_wownero/lib/api/wallet.dart index 21dcd04c7..fb031c489 100644 --- a/cw_wownero/lib/api/wallet.dart +++ b/cw_wownero/lib/api/wallet.dart @@ -33,8 +33,7 @@ String getFilename() => wownero.Wallet_filename(wptr!); String getSeed() { // wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed); - final cakepolyseed = - wownero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed"); + final cakepolyseed = wownero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed"); if (cakepolyseed != "") { return cakepolyseed; } @@ -49,11 +48,21 @@ String getSeed() { String getSeedLegacy(String? language) { var legacy = wownero.Wallet_seed(wptr!, seedOffset: ''); switch (language) { - case "Chinese (Traditional)": language = "Chinese (simplified)"; break; - case "Chinese (Simplified)": language = "Chinese (simplified)"; break; - case "Korean": language = "English"; break; - case "Czech": language = "English"; break; - case "Japanese": language = "English"; break; + case "Chinese (Traditional)": + language = "Chinese (simplified)"; + break; + case "Chinese (Simplified)": + language = "Chinese (simplified)"; + break; + case "Korean": + language = "English"; + break; + case "Czech": + language = "English"; + break; + case "Japanese": + language = "English"; + break; } if (wownero.Wallet_status(wptr!) != 0) { wownero.Wallet_setSeedLanguage(wptr!, language: language ?? "English"); @@ -68,17 +77,18 @@ String getSeedLegacy(String? language) { } return legacy; } + Map>> addressCache = {}; String getAddress({int accountIndex = 0, int addressIndex = 1}) { - while (wownero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex)-1 < addressIndex) { + while (wownero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) { printV("adding subaddress"); wownero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex); } addressCache[wptr!.address] ??= {}; addressCache[wptr!.address]![accountIndex] ??= {}; - addressCache[wptr!.address]![accountIndex]![addressIndex] ??= wownero.Wallet_address(wptr!, - accountIndex: accountIndex, addressIndex: addressIndex); + addressCache[wptr!.address]![accountIndex]![addressIndex] ??= + wownero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex); return addressCache[wptr!.address]![accountIndex]![addressIndex]!; } @@ -138,13 +148,30 @@ void startRefreshSync() { wownero.Wallet_startRefresh(wptr!); } +void setupBackgroundSync( + {required int backgroundSyncType, + required String walletPassword, + required String backgroundCachePassword}) { + wownero.Wallet_setupBackgroundSync(wptr!, + backgroundSyncType: backgroundSyncType, + walletPassword: walletPassword, + backgroundCachePassword: backgroundCachePassword); +} + +void startBackgroundSync() { + wownero.Wallet_startBackgroundSync(wptr!); +} + +void stopBackgroundSync(String password) { + wownero.Wallet_stopBackgroundSync(wptr!, password); +} + Future connectToNode() async { return true; } void setRefreshFromBlockHeight({required int height}) => - wownero.Wallet_setRefreshFromBlockHeight(wptr!, - refresh_from_block_height: height); + wownero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height); void setRecoveringFromSeed({required bool isRecovery}) => wownero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery); @@ -219,8 +246,7 @@ class SyncListener { _cachedBlockchainHeight = 0; _lastKnownBlockHeight = 0; _initialSyncHeight = 0; - _updateSyncInfoTimer ??= - Timer.periodic(Duration(milliseconds: 1200), (_) async { + _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { if (isNewTransactionExist()) { onNewTransaction(); } @@ -259,8 +285,8 @@ class SyncListener { void stop() => _updateSyncInfoTimer?.cancel(); } -SyncListener setListeners(void Function(int, int, double) onNewBlock, - void Function() onNewTransaction) { +SyncListener setListeners( + void Function(int, int, double) onNewBlock, void Function() onNewTransaction) { final listener = SyncListener(onNewBlock, onNewTransaction); // setListenerNative(); return listener; @@ -322,8 +348,7 @@ String getSubaddressLabel(int accountIndex, int addressIndex) { accountIndex: accountIndex, addressIndex: addressIndex); } -Future setTrustedDaemon(bool trusted) async => - wownero.Wallet_setTrustedDaemon(wptr!, arg: trusted); +Future setTrustedDaemon(bool trusted) async => wownero.Wallet_setTrustedDaemon(wptr!, arg: trusted); Future trustedDaemon() async => wownero.Wallet_trustedDaemon(wptr!); @@ -332,5 +357,6 @@ String signMessage(String message, {String address = ""}) { } bool verifyMessage(String message, String address, String signature) { - return wownero.Wallet_verifySignedMessage(wptr!, message: message, address: address, signature: signature); -} \ No newline at end of file + return wownero.Wallet_verifySignedMessage(wptr!, + message: message, address: address, signature: signature); +} diff --git a/cw_wownero/lib/wownero_wallet.dart b/cw_wownero/lib/wownero_wallet.dart index c4c79af11..963edf8fa 100644 --- a/cw_wownero/lib/wownero_wallet.dart +++ b/cw_wownero/lib/wownero_wallet.dart @@ -51,7 +51,9 @@ abstract class WowneroWalletBase extends WalletBase with Store { WowneroWalletBase( - {required WalletInfo walletInfo, required Box unspentCoinsInfo, required String password}) + {required WalletInfo walletInfo, + required Box unspentCoinsInfo, + required String password}) : balance = ObservableMap.of({ CryptoCurrency.wow: WowneroBalance( fullBalance: wownero_wallet.getFullBalance(accountIndex: 0), @@ -191,7 +193,19 @@ abstract class WowneroWalletBase } @override - Future startSync() async { + Future startSync({bool isBackgroundSync = false}) async { + if (isBackgroundSync) { + try { + syncStatus = AttemptingSyncStatus(); + wownero_wallet.startBackgroundSync(); + return; + } catch (e) { + syncStatus = FailedSyncStatus(); + printV(e); + rethrow; + } + } + try { _assertInitialHeight(); } catch (_) { diff --git a/lib/entities/background_tasks.dart b/lib/entities/background_tasks.dart index 4a1420af5..f5f9853ae 100644 --- a/lib/entities/background_tasks.dart +++ b/lib/entities/background_tasks.dart @@ -128,6 +128,8 @@ Future onStart(ServiceInstance service) async { Timer? _syncTimer; Timer? _stuckSyncTimer; Timer? _queueTimer; + List syncingWallets = []; + List standbyWallets = []; // commented because the behavior appears to be bugged: // DartPluginRegistrant.ensureInitialized(); @@ -135,19 +137,34 @@ Future onStart(ServiceInstance service) async { final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); - service.on('stopService').listen((event) async { + service.on("stopService").listen((event) async { printV("STOPPING BACKGROUND SERVICE"); _syncTimer?.cancel(); _stuckSyncTimer?.cancel(); _queueTimer?.cancel(); + try { + // stop all syncing wallets: + for (int i = 0; i < syncingWallets.length; i++) { + final wallet = syncingWallets[i]; + await wallet.stopSync(isBackgroundSync: true); + } + // stop all standby wallets (just in case): + for (int i = 0; i < standbyWallets.length; i++) { + final wallet = standbyWallets[i]; + await wallet.stopSync(isBackgroundSync: true); + } + } catch (e) { + printV("error stopping sync: $e"); + } + // stop the service itself: await service.stopSelf(); }); - service.on('status').listen((event) async { + service.on("status").listen((event) async { printV(event); }); - service.on('setForeground').listen((event) async { + service.on("setForeground").listen((event) async { bgSyncStarted = false; _syncTimer?.cancel(); setNotificationStandby(flutterLocalNotificationsPlugin); @@ -158,7 +175,7 @@ Future onStart(ServiceInstance service) async { }); // we have entered the background, start the sync: - service.on('setBackground').listen((event) async { + service.on("setBackground").listen((event) async { if (bgSyncStarted) { return; } @@ -184,9 +201,6 @@ Future onStart(ServiceInstance service) async { final settingsStore = getIt.get(); final walletListViewModel = getIt.get(); - List syncingWallets = []; - List standbyWallets = []; - // get all Monero / Wownero wallets and add them final List moneroWallets = walletListViewModel.wallets .where((element) => [WalletType.monero, WalletType.wownero].contains(element.type)) @@ -195,7 +209,7 @@ Future onStart(ServiceInstance service) async { for (int i = 0; i < moneroWallets.length; i++) { final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name); final node = settingsStore.getCurrentNode(moneroWallets[i].type); - await wallet.stopSync(); + await wallet.stopSync(isBackgroundSync: true); syncingWallets.add(wallet); } @@ -271,7 +285,7 @@ Future onStart(ServiceInstance service) async { printV("${wallet.name} NOT CONNECTED"); final node = settingsStore.getCurrentNode(wallet.type); await wallet.connectToNode(node: node); - wallet.startSync(); + wallet.startSync(isBackgroundSync: true); printV("STARTED SYNC"); } @@ -281,7 +295,7 @@ Future onStart(ServiceInstance service) async { syncedTicks = 0; printV("WALLET $i SYNCED"); try { - await wallet.stopSync(); + await wallet.stopSync(isBackgroundSync: true); } catch (e) { printV("error stopping sync: $e"); } @@ -329,7 +343,7 @@ Future onStart(ServiceInstance service) async { } } else { if (syncStatus is! NotConnectedSyncStatus) { - wallet.stopSync(); + wallet.stopSync(isBackgroundSync: true); } if (progress < SYNC_THRESHOLD) { content = "$progressPercent - Waiting in sync queue"; @@ -395,7 +409,7 @@ Future onStart(ServiceInstance service) async { if (syncStatus is NotConnectedSyncStatus) { final node = settingsStore.getCurrentNode(wallet.type); await wallet.connectToNode(node: node); - await wallet.startSync(); + await wallet.startSync(isBackgroundSync: true); } // wait a while before checking progress: @@ -427,7 +441,7 @@ Future onStart(ServiceInstance service) async { printV("syncing appears to be stuck, restarting..."); try { stuckWallets.add(wallet.name); - await wallet.stopSync(); + await wallet.stopSync(isBackgroundSync: true); } catch (e) { printV("error restarting sync: $e"); } @@ -439,7 +453,7 @@ Future onStart(ServiceInstance service) async { stuckWallets = []; return; } - wallet.startSync(); + wallet.startSync(isBackgroundSync: true); } }); });