From 84ad97c0b01b1da850d43f0f87edc11ee9ac2448 Mon Sep 17 00:00:00 2001 From: M Date: Tue, 29 Dec 2020 18:55:58 +0200 Subject: [PATCH] Fixes for 4.0.94. Changed version for 4.0.94. --- .../exceptions/wallet_loading_exception.dart | 8 ----- .../exceptions/wallet_opening_exception.dart | 8 +++++ cw_monero/lib/wallet_manager.dart | 4 +-- lib/monero/monero_wallet_service.dart | 33 +++++++++---------- pubspec.yaml | 2 +- 5 files changed, 26 insertions(+), 29 deletions(-) delete mode 100644 cw_monero/lib/exceptions/wallet_loading_exception.dart create mode 100644 cw_monero/lib/exceptions/wallet_opening_exception.dart diff --git a/cw_monero/lib/exceptions/wallet_loading_exception.dart b/cw_monero/lib/exceptions/wallet_loading_exception.dart deleted file mode 100644 index b0594c6e5..000000000 --- a/cw_monero/lib/exceptions/wallet_loading_exception.dart +++ /dev/null @@ -1,8 +0,0 @@ -class WalletLoadingException implements Exception { - WalletLoadingException({this.message}); - - final String message; - - @override - String toString() => message; -} \ No newline at end of file diff --git a/cw_monero/lib/exceptions/wallet_opening_exception.dart b/cw_monero/lib/exceptions/wallet_opening_exception.dart new file mode 100644 index 000000000..8d84b0f7e --- /dev/null +++ b/cw_monero/lib/exceptions/wallet_opening_exception.dart @@ -0,0 +1,8 @@ +class WalletOpeningException implements Exception { + WalletOpeningException({this.message}); + + final String message; + + @override + String toString() => message; +} \ No newline at end of file diff --git a/cw_monero/lib/wallet_manager.dart b/cw_monero/lib/wallet_manager.dart index ad2087361..e48055cf9 100644 --- a/cw_monero/lib/wallet_manager.dart +++ b/cw_monero/lib/wallet_manager.dart @@ -1,4 +1,5 @@ import 'dart:ffi'; +import 'package:cw_monero/exceptions/wallet_opening_exception.dart'; import 'package:cw_monero/wallet.dart'; import 'package:ffi/ffi.dart'; import 'package:flutter/foundation.dart'; @@ -7,7 +8,6 @@ import 'package:cw_monero/signatures.dart'; import 'package:cw_monero/types.dart'; import 'package:cw_monero/monero_api.dart'; import 'package:cw_monero/exceptions/wallet_creation_exception.dart'; -import 'package:cw_monero/exceptions/wallet_loading_exception.dart'; import 'package:cw_monero/exceptions/wallet_restore_from_keys_exception.dart'; import 'package:cw_monero/exceptions/wallet_restore_from_seed_exception.dart'; @@ -146,7 +146,7 @@ void loadWallet({String path, String password, int nettype = 0}) { free(passwordPointer); if (!loaded) { - throw WalletLoadingException( + throw WalletOpeningException( message: convertUTF8ToString(pointer: errorStringNative())); } } diff --git a/lib/monero/monero_wallet_service.dart b/lib/monero/monero_wallet_service.dart index fb1bdb4c4..d964f0232 100644 --- a/lib/monero/monero_wallet_service.dart +++ b/lib/monero/monero_wallet_service.dart @@ -3,7 +3,7 @@ import 'package:cake_wallet/core/wallet_base.dart'; import 'package:hive/hive.dart'; import 'package:cw_monero/wallet_manager.dart' as monero_wallet_manager; import 'package:cw_monero/wallet.dart' as monero_wallet; -import 'package:cw_monero/exceptions/wallet_loading_exception.dart'; +import 'package:cw_monero/exceptions/wallet_opening_exception.dart'; import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/core/wallet_credentials.dart'; import 'package:cake_wallet/core/wallet_service.dart'; @@ -56,7 +56,7 @@ class MoneroWalletService extends WalletService< final Box walletInfoSource; - static void _removeCache(String name) async { + static Future _removeCache(String name) async { final path = await pathForWallet(name: name, type: WalletType.monero); final cacheFile = File(path); @@ -65,6 +65,9 @@ class MoneroWalletService extends WalletService< } } + static bool walletFilesExist(String path) => + !File(path).existsSync() && !File('$path.keys').existsSync(); + @override Future create(MoneroNewWalletCredentials credentials) async { try { @@ -104,7 +107,7 @@ class MoneroWalletService extends WalletService< try { final path = await pathForWallet(name: name, type: WalletType.monero); - if (!File(path).existsSync()) { + if (walletFilesExist(path)) { await repairOldAndroidWallet(name); } @@ -118,17 +121,9 @@ class MoneroWalletService extends WalletService< final isValid = wallet.validate(); if (!isValid) { - // if (wallet.seed?.isNotEmpty ?? false) { - // let restore from seed in this case; - // final seed = wallet.seed; - // final credentials = MoneroRestoreWalletFromSeedCredentials( - // name: name, password: password, mnemonic: seed, height: 2000000) - // ..walletInfo = walletInfo; - // await remove(name); - // return restoreFromSeed(credentials); - // } - - throw MoneroWalletLoadingException(); + await _removeCache(name); + wallet.close(); + return openWallet(name, password); } await wallet.init(); @@ -137,8 +132,11 @@ class MoneroWalletService extends WalletService< } catch (e) { // TODO: Implement Exception for wallet list service. - if (e.message == 'std::bad_alloc') { - _removeCache(name); + if (e.toString().contains('bad_alloc') || + (e is WalletOpeningException && + (e.message == 'std::bad_alloc' || + e.message.contains('bad_alloc')))) { + await _removeCache(name); return openWallet(name, password); } @@ -219,7 +217,7 @@ class MoneroWalletService extends WalletService< final dir = Directory(oldAndroidWalletDirPath); if (!dir.existsSync()) { - throw MoneroWalletLoadingException(); + return; } final newWalletDirPath = @@ -238,7 +236,6 @@ class MoneroWalletService extends WalletService< }); } catch (e) { print(e.toString()); - throw MoneroWalletLoadingException(); } } } diff --git a/pubspec.yaml b/pubspec.yaml index 3e680b605..851dec206 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: Cake Wallet. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 4.0.92+23 +version: 4.0.94+25 environment: sdk: ">=2.7.0 <3.0.0"