Skip to content

Commit

Permalink
Enhance background sync and wallet initialization across multiple wal…
Browse files Browse the repository at this point in the history
…let types

- Improve error handling and status checks during background sync
- Modify zano init method to not conflict with default init()
- Add dev tools for background sync monitoring and manual rescan
  • Loading branch information
MrCyjaneK committed Feb 21, 2025
1 parent b39f8f5 commit ce81a26
Show file tree
Hide file tree
Showing 20 changed files with 323 additions and 105 deletions.
2 changes: 1 addition & 1 deletion cw_haven/lib/haven_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ abstract class HavenWalletBase
}

@override
Future<void> startSync() async {
Future<void> startSync({bool isBackgroundSync = false}) async {
try {
_setInitialHeight();
} catch (_) {}
Expand Down
2 changes: 1 addition & 1 deletion cw_monero/lib/api/account_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ List<monero.SubaddressAccountRow> getAllAccount() {
int size = monero.SubaddressAccount_getAll_size(subaddressAccount!);
if (size == 0) {
monero.Wallet_addSubaddressAccount(wptr!);
return getAllAccount();
return [];
}
return List.generate(size, (index) {
return monero.SubaddressAccount_getAll_byIndex(subaddressAccount!, index: index);
Expand Down
14 changes: 2 additions & 12 deletions cw_monero/lib/api/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ String getAddress({int accountIndex = 0, int addressIndex = 0}) {
int count = 0;

while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) {
printV("adding subaddress");
monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex);
if (count > 50) {
throw Exception("Failed to add subaddress");
if (count > 10) {
break;
}
count++;
}
Expand Down Expand Up @@ -198,15 +197,6 @@ void setupBackgroundSync(
backgroundCachePassword: backgroundCachePassword);
}

bool isBackgroundSyncing() => monero.Wallet_isBackgroundSyncing(wptr!);

void startBackgroundSync() {
monero.Wallet_startBackgroundSync(wptr!);
}

void stopBackgroundSync(String walletPassword) {
monero.Wallet_stopBackgroundSync(wptr!, walletPassword);
}

void stopSync() {
monero.Wallet_init(wptr!, daemonAddress: "");
Expand Down
30 changes: 24 additions & 6 deletions cw_monero/lib/monero_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,22 @@ abstract class MoneroWalletBase
walletPassword: password,
backgroundCachePassword: "testing-cache-password",
);
monero_wallet.startBackgroundSync();
monero.Wallet_startBackgroundSync(wptr!);
final status = monero.Wallet_status(wptr!);
if (status != 0) {
final err = monero.Wallet_errorString(wptr!);
printV("unable to start background sync: $err");
throw Exception("unable to start background sync: $err");
}
isBackgroundSyncing = true;
} else {
monero_wallet.stopBackgroundSync(password);
monero.Wallet_stopBackgroundSync(wptr!, password);
final status = monero.Wallet_status(wptr!);
if (status != 0) {
final err = monero.Wallet_errorString(wptr!);
printV("unable to stop background sync: $err");
throw Exception("unable to stop background sync: $err");
}
isBackgroundSyncing = false;
}
monero_wallet.startRefresh();
Expand Down Expand Up @@ -291,14 +303,20 @@ abstract class MoneroWalletBase

@override
Future<void> stopSync({bool isBackgroundSync = false}) async {
syncStatus = NotConnectedSyncStatus();
_listener?.stop();
if (isBackgroundSync) {
print("Stopping background sync");
monero.Wallet_stopBackgroundSync(wptr!, password);
final status = monero.Wallet_status(wptr!);
if (status != 0) {
final err = monero.Wallet_errorString(wptr!);
printV("unable to stop background sync: $err");
throw Exception("unable to stop background sync: $err");
}
isBackgroundSyncing = false;
monero_wallet.stopWallet();
monero_wallet.stopBackgroundSync(password);
return;
}
syncStatus = NotConnectedSyncStatus();
_listener?.stop();
monero_wallet.stopSync();
_autoSaveTimer?.cancel();
monero_wallet.closeCurrentWallet();
Expand Down
4 changes: 2 additions & 2 deletions cw_monero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
resolved-ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
resolved-ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cw_monero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: 65608c09e9093f1cd42c6afd8e9131016c82574b
ref: 991a0d0c97bce6ae8671dc763dd03876dfa9ea8a
path: impls/monero.dart
mutex: ^3.1.0
ledger_flutter_plus: ^1.4.1
Expand Down
6 changes: 5 additions & 1 deletion cw_wownero/lib/api/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ String getPassphrase() {
}

String getAddress({int accountIndex = 0, int addressIndex = 1}) {
int count = 0;
while (wownero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) {
printV("adding subaddress");
wownero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex);
count++;
if (count > 10) {
break;
}
}
addressCache[wptr!.address] ??= {};
addressCache[wptr!.address]![accountIndex] ??= {};
Expand Down
4 changes: 2 additions & 2 deletions cw_wownero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
resolved-ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
resolved-ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cw_wownero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: 65608c09e9093f1cd42c6afd8e9131016c82574b # monero_c hash
ref: 991a0d0c97bce6ae8671dc763dd03876dfa9ea8a # monero_c hash
path: impls/monero.dart
mutex: ^3.1.0

Expand Down
21 changes: 15 additions & 6 deletions cw_zano/lib/zano_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ abstract class ZanoWalletBase
wallet.seed = await createWalletResult.seed(wallet);
wallet.passphrase = await wallet.getPassphrase();
}
await wallet.init(createWalletResult.wi.address);
await wallet.zanoInit(createWalletResult.wi.address);
return wallet;
}

Expand All @@ -159,7 +159,7 @@ abstract class ZanoWalletBase
wallet.seed = await createWalletResult.seed(wallet);
wallet.passphrase = await wallet.getPassphrase();
}
await wallet.init(createWalletResult.wi.address);
await wallet.zanoInit(createWalletResult.wi.address);
return wallet;
}

Expand All @@ -169,15 +169,15 @@ abstract class ZanoWalletBase
if (ZanoWalletApi.openWalletCache[path] != null) {
final wallet = ZanoWallet(walletInfo, password);
await wallet.parseCreateWalletResult(ZanoWalletApi.openWalletCache[path]!).then((_) {
unawaited(wallet.init(ZanoWalletApi.openWalletCache[path]!.wi.address));
unawaited(wallet.zanoInit(ZanoWalletApi.openWalletCache[path]!.wi.address));
});
return wallet;
} else {
final wallet = ZanoWallet(walletInfo, password);
await wallet.initWallet();
final createWalletResult = await wallet.loadWallet(path, password);
await wallet.parseCreateWalletResult(createWalletResult).then((_) {
unawaited(wallet.init(createWalletResult.wi.address));
unawaited(wallet.zanoInit(createWalletResult.wi.address));
});
return wallet;
}
Expand Down Expand Up @@ -320,7 +320,16 @@ abstract class ZanoWalletBase
}
}

Future<void> init(String address) async {
Future<void> init() async {
await walletAddresses.init();
await walletAddresses.updateAddress(walletAddresses.address);
await updateTransactions();
_autoSaveTimer = Timer.periodic(Duration(seconds: _autoSaveIntervalSeconds), (_) async {
await save();
});
}

Future<void> zanoInit(String address) async {
await walletAddresses.init();
await walletAddresses.updateAddress(address);
await updateTransactions();
Expand Down Expand Up @@ -395,7 +404,7 @@ abstract class ZanoWalletBase
}

@override
Future<void> startSync() async {
Future<void> startSync({bool isBackgroundSync = false}) async {
try {
syncStatus = AttemptingSyncStatus();
_lastKnownBlockHeight = 0;
Expand Down
4 changes: 2 additions & 2 deletions cw_zano/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ packages:
dependency: "direct main"
description:
path: "impls/monero.dart"
ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
resolved-ref: "65608c09e9093f1cd42c6afd8e9131016c82574b"
ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
resolved-ref: "991a0d0c97bce6ae8671dc763dd03876dfa9ea8a"
url: "https://github.com/mrcyjanek/monero_c"
source: git
version: "0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cw_zano/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
monero:
git:
url: https://github.com/mrcyjanek/monero_c
ref: 65608c09e9093f1cd42c6afd8e9131016c82574b # monero_c hash
ref: 991a0d0c97bce6ae8671dc763dd03876dfa9ea8a # monero_c hash
path: impls/monero.dart
dev_dependencies:
flutter_test:
Expand Down
92 changes: 27 additions & 65 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,8 @@ PODS:
- Flutter
- ReachabilitySwift
- CryptoSwift (1.8.3)
- cw_haven (0.0.1):
- cw_haven/Boost (= 0.0.1)
- cw_haven/Haven (= 0.0.1)
- cw_haven/OpenSSL (= 0.0.1)
- cw_haven/Sodium (= 0.0.1)
- cw_shared_external
- Flutter
- cw_haven/Boost (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/Haven (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/OpenSSL (0.0.1):
- cw_shared_external
- Flutter
- cw_haven/Sodium (0.0.1):
- cw_shared_external
- Flutter
- cw_mweb (0.0.1):
- Flutter
- cw_shared_external (0.0.1):
- cw_shared_external/Boost (= 0.0.1)
- cw_shared_external/OpenSSL (= 0.0.1)
- cw_shared_external/Sodium (= 0.0.1)
- Flutter
- cw_shared_external/Boost (0.0.1):
- Flutter
- cw_shared_external/OpenSSL (0.0.1):
- Flutter
- cw_shared_external/Sodium (0.0.1):
- Flutter
- device_display_brightness (0.0.1):
- Flutter
- device_info_plus (0.0.1):
Expand Down Expand Up @@ -136,9 +106,7 @@ PODS:
DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- CryptoSwift
- cw_haven (from `.symlinks/plugins/cw_haven/ios`)
- cw_mweb (from `.symlinks/plugins/cw_mweb/ios`)
- cw_shared_external (from `.symlinks/plugins/cw_shared_external/ios`)
- device_display_brightness (from `.symlinks/plugins/device_display_brightness/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
Expand Down Expand Up @@ -179,12 +147,8 @@ SPEC REPOS:
EXTERNAL SOURCES:
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
cw_haven:
:path: ".symlinks/plugins/cw_haven/ios"
cw_mweb:
:path: ".symlinks/plugins/cw_mweb/ios"
cw_shared_external:
:path: ".symlinks/plugins/cw_shared_external/ios"
device_display_brightness:
:path: ".symlinks/plugins/device_display_brightness/ios"
device_info_plus:
Expand Down Expand Up @@ -237,44 +201,42 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/workmanager/ios"

SPEC CHECKSUMS:
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
connectivity_plus: 481668c94744c30c53b8895afb39159d1e619bdf
CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483
cw_haven: b3e54e1fbe7b8e6fda57a93206bc38f8e89b898a
cw_mweb: 87af74f9659fed0c1a2cbfb44413f1070e79e3ae
cw_shared_external: 2972d872b8917603478117c9957dfca611845a92
device_display_brightness: 1510e72c567a1f6ce6ffe393dcd9afd1426034f7
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
devicelocale: 35ba84dc7f45f527c3001535d8c8d104edd5d926
cw_mweb: 3aea2fb35b2bd04d8b2d21b83216f3b8fb768d85
device_display_brightness: 04374ebd653619292c1d996f00f42877ea19f17f
device_info_plus: 335f3ce08d2e174b9fdc3db3db0f4e3b1f66bd89
devicelocale: bd64aa714485a8afdaded0892c1e7d5b7f680cf8
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
fast_scanner: 44c00940355a51258cd6c2085734193cd23d95bc
file_picker: 15fd9539e4eb735dc54bae8c0534a7a9511a03de
fast_scanner: 2cb1ad3e69e645e9980fb4961396ce5804caa3e3
file_picker: 07c75322ede1d47ec9bb4ac82b27c94d3598251a
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4
flutter_local_authentication: 1172a4dd88f6306dadce067454e2c4caf07977bb
flutter_mailer: 2ef5a67087bc8c6c4cefd04a178bf1ae2c94cd83
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
in_app_review: a31b5257259646ea78e0e35fc914979b0031d011
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
flutter_inappwebview_ios: b89ba3482b96fb25e00c967aae065701b66e9b99
flutter_local_authentication: 989278c681612f1ee0e36019e149137f114b9d7f
flutter_mailer: 3a8cd4f36c960fb04528d5471097270c19fec1c4
flutter_secure_storage: 2c2ff13db9e0a5647389bff88b0ecac56e3f3418
fluttertoast: 76fea30fcf04176325f6864c87306927bd7d2038
in_app_review: 5596fe56fab799e8edb3561c03d053363ab13457
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
permission_handler_apple: 3787117e48f80715ff04a3830ca039283d6a4f29
ReachabilitySwift: 32793e867593cfc1177f5d16491e3a197d2fccda
SDWebImage: 8a6b7b160b4d710e2a22b6900e25301075c34cb3
sensitive_clipboard: d4866e5d176581536c27bb1618642ee83adca986
share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sp_scanner: eaa617fa827396b967116b7f1f43549ca62e9a12
sensitive_clipboard: 161e9abc3d56b3131309d8a321eb4690a803c16b
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sp_scanner: b1bc9321690980bdb44bba7ec85d5543e716d1b5
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
universal_ble: cf52a7b3fd2e7c14d6d7262e9fdadb72ab6b88a6
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
wakelock_plus: 373cfe59b235a6dd5837d0fb88791d2f13a90d56
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
uni_links: ed8c961e47ed9ce42b6d91e1de8049e38a4b3152
universal_ble: ff19787898040d721109c6324472e5dd4bc86adc
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
wakelock_plus: 04623e3f525556020ebd4034310f20fe7fda8b49
workmanager: 01be2de7f184bd15de93a1812936a2b7f42ef07e

PODFILE CHECKSUM: e448f662d4c41f0c0b1ccbb78afd57dbf895a597

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
Loading

0 comments on commit ce81a26

Please sign in to comment.