mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-21 18:24:41 +00:00
background sync updates and testing [skip ci]
This commit is contained in:
parent
ef6ed481ac
commit
44b715c9e8
3 changed files with 21 additions and 6 deletions
|
@ -80,11 +80,18 @@ String getSeedLegacy(String? language) {
|
|||
Map<int, Map<int, Map<int, String>>> 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)}");
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) {
|
||||
printV("adding subaddress");
|
||||
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex);
|
||||
if (count > 10) {
|
||||
throw Exception("Failed to add subaddress");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
addressCache[wptr!.address] ??= {};
|
||||
addressCache[wptr!.address]![accountIndex] ??= {};
|
||||
addressCache[wptr!.address]![accountIndex]![addressIndex] ??=
|
||||
|
@ -167,6 +174,8 @@ void setupBackgroundSync(
|
|||
backgroundCachePassword: backgroundCachePassword);
|
||||
}
|
||||
|
||||
bool isBackgroundSyncing() => monero.Wallet_isBackgroundSyncing(wptr!);
|
||||
|
||||
void startBackgroundSync() {
|
||||
monero.Wallet_startBackgroundSync(wptr!);
|
||||
}
|
||||
|
@ -175,6 +184,10 @@ void stopBackgroundSync(String walletPassword) {
|
|||
monero.Wallet_stopBackgroundSync(wptr!, walletPassword);
|
||||
}
|
||||
|
||||
void stopSync() {
|
||||
monero.Wallet_init(wptr!, daemonAddress: "");
|
||||
}
|
||||
|
||||
void setRefreshFromBlockHeight({required int height}) =>
|
||||
monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ abstract class MoneroWalletBase
|
|||
Timer? _autoSaveTimer;
|
||||
List<MoneroUnspent> unspentCoins;
|
||||
String _password;
|
||||
bool isBackgroundSyncing = false;
|
||||
|
||||
Future<void> init() async {
|
||||
await walletAddresses.init();
|
||||
|
@ -202,8 +203,10 @@ abstract class MoneroWalletBase
|
|||
try {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
monero_wallet.startBackgroundSync();
|
||||
isBackgroundSyncing = true;
|
||||
return;
|
||||
} catch (e) {
|
||||
isBackgroundSyncing = false;
|
||||
syncStatus = FailedSyncStatus();
|
||||
printV(e);
|
||||
rethrow;
|
||||
|
@ -280,11 +283,11 @@ abstract class MoneroWalletBase
|
|||
syncStatus = NotConnectedSyncStatus();
|
||||
_listener?.stop();
|
||||
if (isBackgroundSync) {
|
||||
isBackgroundSyncing = false;
|
||||
monero_wallet.stopBackgroundSync(password);
|
||||
return;
|
||||
}
|
||||
// TODO: find a better way to stop syncing than setting an invalid address:
|
||||
monero_wallet.setupNode(address: "");
|
||||
monero_wallet.stopSync();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -397,7 +400,7 @@ abstract class MoneroWalletBase
|
|||
Future<void> save() async {
|
||||
await walletAddresses.updateUsedSubaddress();
|
||||
|
||||
if (isEnabledAutoGenerateSubaddress) {
|
||||
if (isEnabledAutoGenerateSubaddress && !isBackgroundSyncing) {
|
||||
walletAddresses.updateUnusedSubaddress(
|
||||
accountIndex: walletAddresses.account?.id ?? 0,
|
||||
defaultLabel: walletAddresses.account?.label ?? '');
|
||||
|
|
|
@ -209,8 +209,7 @@ Future<void> 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(isBackgroundSync: true);
|
||||
await wallet.stopSync(isBackgroundSync: false);// stop regular sync process if it's been started
|
||||
syncingWallets.add(wallet);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue