mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 02:34:59 +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 = {};
|
Map<int, Map<int, Map<int, String>>> addressCache = {};
|
||||||
|
|
||||||
String getAddress({int accountIndex = 0, int addressIndex = 0}) {
|
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) {
|
while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) {
|
||||||
printV("adding subaddress");
|
printV("adding subaddress");
|
||||||
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex);
|
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex);
|
||||||
|
if (count > 10) {
|
||||||
|
throw Exception("Failed to add subaddress");
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
addressCache[wptr!.address] ??= {};
|
addressCache[wptr!.address] ??= {};
|
||||||
addressCache[wptr!.address]![accountIndex] ??= {};
|
addressCache[wptr!.address]![accountIndex] ??= {};
|
||||||
addressCache[wptr!.address]![accountIndex]![addressIndex] ??=
|
addressCache[wptr!.address]![accountIndex]![addressIndex] ??=
|
||||||
|
@ -167,6 +174,8 @@ void setupBackgroundSync(
|
||||||
backgroundCachePassword: backgroundCachePassword);
|
backgroundCachePassword: backgroundCachePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isBackgroundSyncing() => monero.Wallet_isBackgroundSyncing(wptr!);
|
||||||
|
|
||||||
void startBackgroundSync() {
|
void startBackgroundSync() {
|
||||||
monero.Wallet_startBackgroundSync(wptr!);
|
monero.Wallet_startBackgroundSync(wptr!);
|
||||||
}
|
}
|
||||||
|
@ -175,6 +184,10 @@ void stopBackgroundSync(String walletPassword) {
|
||||||
monero.Wallet_stopBackgroundSync(wptr!, walletPassword);
|
monero.Wallet_stopBackgroundSync(wptr!, walletPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopSync() {
|
||||||
|
monero.Wallet_init(wptr!, daemonAddress: "");
|
||||||
|
}
|
||||||
|
|
||||||
void setRefreshFromBlockHeight({required int height}) =>
|
void setRefreshFromBlockHeight({required int height}) =>
|
||||||
monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
|
monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,7 @@ abstract class MoneroWalletBase
|
||||||
Timer? _autoSaveTimer;
|
Timer? _autoSaveTimer;
|
||||||
List<MoneroUnspent> unspentCoins;
|
List<MoneroUnspent> unspentCoins;
|
||||||
String _password;
|
String _password;
|
||||||
|
bool isBackgroundSyncing = false;
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await walletAddresses.init();
|
await walletAddresses.init();
|
||||||
|
@ -202,8 +203,10 @@ abstract class MoneroWalletBase
|
||||||
try {
|
try {
|
||||||
syncStatus = AttemptingSyncStatus();
|
syncStatus = AttemptingSyncStatus();
|
||||||
monero_wallet.startBackgroundSync();
|
monero_wallet.startBackgroundSync();
|
||||||
|
isBackgroundSyncing = true;
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
isBackgroundSyncing = false;
|
||||||
syncStatus = FailedSyncStatus();
|
syncStatus = FailedSyncStatus();
|
||||||
printV(e);
|
printV(e);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -280,11 +283,11 @@ abstract class MoneroWalletBase
|
||||||
syncStatus = NotConnectedSyncStatus();
|
syncStatus = NotConnectedSyncStatus();
|
||||||
_listener?.stop();
|
_listener?.stop();
|
||||||
if (isBackgroundSync) {
|
if (isBackgroundSync) {
|
||||||
|
isBackgroundSyncing = false;
|
||||||
monero_wallet.stopBackgroundSync(password);
|
monero_wallet.stopBackgroundSync(password);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: find a better way to stop syncing than setting an invalid address:
|
monero_wallet.stopSync();
|
||||||
monero_wallet.setupNode(address: "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -397,7 +400,7 @@ abstract class MoneroWalletBase
|
||||||
Future<void> save() async {
|
Future<void> save() async {
|
||||||
await walletAddresses.updateUsedSubaddress();
|
await walletAddresses.updateUsedSubaddress();
|
||||||
|
|
||||||
if (isEnabledAutoGenerateSubaddress) {
|
if (isEnabledAutoGenerateSubaddress && !isBackgroundSyncing) {
|
||||||
walletAddresses.updateUnusedSubaddress(
|
walletAddresses.updateUnusedSubaddress(
|
||||||
accountIndex: walletAddresses.account?.id ?? 0,
|
accountIndex: walletAddresses.account?.id ?? 0,
|
||||||
defaultLabel: walletAddresses.account?.label ?? '');
|
defaultLabel: walletAddresses.account?.label ?? '');
|
||||||
|
|
|
@ -209,8 +209,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
|
|
||||||
for (int i = 0; i < moneroWallets.length; i++) {
|
for (int i = 0; i < moneroWallets.length; i++) {
|
||||||
final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
||||||
final node = settingsStore.getCurrentNode(moneroWallets[i].type);
|
await wallet.stopSync(isBackgroundSync: false);// stop regular sync process if it's been started
|
||||||
await wallet.stopSync(isBackgroundSync: true);
|
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue