From d067df8a51cf0b40720970756284cbf578914678 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 3 Apr 2020 15:27:13 +0300 Subject: [PATCH 1/3] Added migration for android wallets and hives files. --- lib/src/domain/common/fs_migration.dart | 70 +++++++++++++++++++ .../domain/monero/monero_wallets_manager.dart | 18 ++--- 2 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 lib/src/domain/common/fs_migration.dart diff --git a/lib/src/domain/common/fs_migration.dart b/lib/src/domain/common/fs_migration.dart new file mode 100644 index 000000000..537523aa4 --- /dev/null +++ b/lib/src/domain/common/fs_migration.dart @@ -0,0 +1,70 @@ +import 'dart:io'; +import 'package:path_provider/path_provider.dart'; + +const reservedNames = ["flutter_assets", "wallets", "db"]; + +Future migrate_fs() async { + final appDocDir = await getApplicationDocumentsDirectory(); + + await migrate_hives(appDocDir: appDocDir); + await migrate_wallets(appDocDir: appDocDir); + + appDocDir.listSync(recursive: true).forEach((item) => print(item.path)); +} + +Future migrate_hives({Directory appDocDir}) async { + final dbDir = Directory('${appDocDir.path}/db'); + final files = List(); + + appDocDir.listSync().forEach((FileSystemEntity item) { + final ext = item.path.split('.').last; + + if (item is File && (ext == "hive" || ext == "lock")) { + files.add(item); + } + }); + + if (!dbDir.existsSync()) { + dbDir.createSync(); + } + + files.forEach((File hive) { + final name = hive.path.split('/').last; + hive.copySync('${dbDir.path}/$name'); + hive.deleteSync(); + }); +} + +Future migrate_wallets({Directory appDocDir}) async { + final walletsDir = Directory('${appDocDir.path}/wallets'); + final moneroWalletsDir = Directory('${walletsDir.path}/monero'); + final dirs = List(); + + appDocDir.listSync().forEach((FileSystemEntity item) { + final name = item.path.split('/').last; + + if (item is Directory && !reservedNames.contains(name)) { + dirs.add(item); + } + }); + + if (!moneroWalletsDir.existsSync()) { + await moneroWalletsDir.create(recursive: true); + } + + dirs.forEach((Directory dir) { + final name = dir.path.split('/').last; + final newDir = Directory('${moneroWalletsDir.path}/$name'); + newDir.createSync(); + + dir.listSync().forEach((file) { + if (file is File) { + final fileName = file.path.split('/').last; + file.copySync('${newDir.path}/$fileName'); + file.deleteSync(); + } + }); + + dir.deleteSync(); + }); +} diff --git a/lib/src/domain/monero/monero_wallets_manager.dart b/lib/src/domain/monero/monero_wallets_manager.dart index 38abcf5d7..655f530b0 100644 --- a/lib/src/domain/monero/monero_wallets_manager.dart +++ b/lib/src/domain/monero/monero_wallets_manager.dart @@ -11,9 +11,10 @@ import 'package:cake_wallet/src/domain/common/wallet.dart'; import 'package:cake_wallet/src/domain/monero/monero_wallet.dart'; import 'package:cake_wallet/src/domain/common/wallet_description.dart'; -Future pathForWallet({String name}) async { +Future pathForWallet( + {@required WalletType type, @required String name}) async { final directory = await getApplicationDocumentsDirectory(); - final pathDir = directory.path + '/$name'; + final pathDir = directory.path + '/wallets/${walletTypeToString(type).toLowerCase()}' + '/$name'; final dir = Directory(pathDir); if (!await dir.exists()) { @@ -34,9 +35,10 @@ class MoneroWalletsManager extends WalletsManager { Future create(String name, String password, String language) async { try { const isRecovery = false; - final path = await pathForWallet(name: name); + final path = await pathForWallet(type: WalletType.monero, name: name); - await monero_wallet_manager.createWallet(path: path, password: password, language: language); + await monero_wallet_manager.createWallet( + path: path, password: password, language: language); final wallet = await MoneroWallet.createdWallet( walletInfoSource: walletInfoSource, @@ -56,7 +58,7 @@ class MoneroWalletsManager extends WalletsManager { String name, String password, String seed, int restoreHeight) async { try { const isRecovery = true; - final path = await pathForWallet(name: name); + final path = await pathForWallet(type: WalletType.monero, name: name); await monero_wallet_manager.restoreFromSeed( path: path, @@ -89,7 +91,7 @@ class MoneroWalletsManager extends WalletsManager { String spendKey) async { try { const isRecovery = true; - final path = await pathForWallet(name: name); + final path = await pathForWallet(type: WalletType.monero, name: name); await monero_wallet_manager.restoreFromKeys( path: path, @@ -117,7 +119,7 @@ class MoneroWalletsManager extends WalletsManager { @override Future openWallet(String name, String password) async { try { - final path = await pathForWallet(name: name); + final path = await pathForWallet(type: WalletType.monero, name: name); monero_wallet_manager.openWallet(path: path, password: password); final wallet = await MoneroWallet.load(walletInfoSource, name, type); await wallet.updateInfo(); @@ -132,7 +134,7 @@ class MoneroWalletsManager extends WalletsManager { @override Future isWalletExit(String name) async { try { - final path = await pathForWallet(name: name); + final path = await pathForWallet(type: WalletType.monero, name: name); return monero_wallet_manager.isWalletExist(path: path); } catch (e) { print('MoneroWalletsManager Error: $e'); From ac0723e9183d41b41f928f7bcd20d8b8660cf014 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 3 Apr 2020 16:21:00 +0300 Subject: [PATCH 2/3] Splitted android and ios migraions --- lib/src/domain/common/fs_migration.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/domain/common/fs_migration.dart b/lib/src/domain/common/fs_migration.dart index 537523aa4..d79d07dfe 100644 --- a/lib/src/domain/common/fs_migration.dart +++ b/lib/src/domain/common/fs_migration.dart @@ -3,13 +3,17 @@ import 'package:path_provider/path_provider.dart'; const reservedNames = ["flutter_assets", "wallets", "db"]; -Future migrate_fs() async { +Future migrate_android_v1() async { final appDocDir = await getApplicationDocumentsDirectory(); await migrate_hives(appDocDir: appDocDir); await migrate_wallets(appDocDir: appDocDir); +} - appDocDir.listSync(recursive: true).forEach((item) => print(item.path)); +Future migrate_ios_v1() async { + final appDocDir = await getApplicationDocumentsDirectory(); + + } Future migrate_hives({Directory appDocDir}) async { @@ -68,3 +72,8 @@ Future migrate_wallets({Directory appDocDir}) async { dir.deleteSync(); }); } + +Future migrate_ios_wallets({Directory appDocDir}) async { + // final oldWalletsDir = Directory('${appDocDir.path}/wallets'); + +} \ No newline at end of file From 8e9033fce43a4377544bdd016ea8cdd33ea97a15 Mon Sep 17 00:00:00 2001 From: M Date: Mon, 6 Apr 2020 19:10:49 +0300 Subject: [PATCH 3/3] Started working on iOS migrations. Addeed migrations for wallets info and address book. Fixed build for iOS --- cw_monero/ios/cw_monero.podspec | 9 +++- ios/Podfile.lock | 27 ++++++++-- ios/Runner.xcodeproj/project.pbxproj | 9 ++-- ios/Runner/Info.plist | 2 +- lib/src/domain/common/fs_migration.dart | 65 ++++++++++++++++++++++--- 5 files changed, 98 insertions(+), 14 deletions(-) diff --git a/cw_monero/ios/cw_monero.podspec b/cw_monero/ios/cw_monero.podspec index 1fd4a89c2..a48f9e09b 100644 --- a/cw_monero/ios/cw_monero.podspec +++ b/cw_monero/ios/cw_monero.podspec @@ -48,4 +48,11 @@ A new flutter plugin project. sodium.libraries = 'sodium' sodium.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/sodium/include/**" } end -end \ No newline at end of file + + s.subspec 'lmdb' do |sodium| +# sodium.preserve_paths = 'External/ios/libs/sodium/include/**/*.h' + sodium.vendored_libraries = 'External/ios/libs/lmdb/liblmdb.a' + sodium.libraries = 'lmdb' +# sodium.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/External/ios/libs/sodium/include/**" } + end +end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index e7f54fa8f..e1c1978b8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -4,24 +4,33 @@ PODS: - MTBBarcodeScanner - cw_monero (0.0.2): - cw_monero/Boost (= 0.0.2) + - cw_monero/lmdb (= 0.0.2) - cw_monero/Monero (= 0.0.2) - cw_monero/OpenSSL (= 0.0.2) - cw_monero/Sodium (= 0.0.2) - Flutter - cw_monero/Boost (0.0.2): - Flutter + - cw_monero/lmdb (0.0.2): + - Flutter - cw_monero/Monero (0.0.2): - Flutter - cw_monero/OpenSSL (0.0.2): - Flutter - cw_monero/Sodium (0.0.2): - Flutter + - devicelocale (0.0.1): + - Flutter - esys_flutter_share (0.0.1): - Flutter - Flutter (1.0.0) - flutter_secure_storage (3.3.1): - Flutter + - local_auth (0.0.1): + - Flutter - MTBBarcodeScanner (5.0.11) + - package_info (0.0.1): + - Flutter - path_provider (0.0.1): - Flutter - share (0.5.2): @@ -36,9 +45,12 @@ PODS: DEPENDENCIES: - barcode_scan (from `.symlinks/plugins/barcode_scan/ios`) - cw_monero (from `.symlinks/plugins/cw_monero/ios`) + - devicelocale (from `.symlinks/plugins/devicelocale/ios`) - esys_flutter_share (from `.symlinks/plugins/esys_flutter_share/ios`) - - Flutter (from `.symlinks/flutter/ios-release`) + - Flutter (from `.symlinks/flutter/ios`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) + - local_auth (from `.symlinks/plugins/local_auth/ios`) + - package_info (from `.symlinks/plugins/package_info/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`) - share (from `.symlinks/plugins/share/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) @@ -54,12 +66,18 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/barcode_scan/ios" cw_monero: :path: ".symlinks/plugins/cw_monero/ios" + devicelocale: + :path: ".symlinks/plugins/devicelocale/ios" esys_flutter_share: :path: ".symlinks/plugins/esys_flutter_share/ios" Flutter: - :path: ".symlinks/flutter/ios-release" + :path: ".symlinks/flutter/ios" flutter_secure_storage: :path: ".symlinks/plugins/flutter_secure_storage/ios" + local_auth: + :path: ".symlinks/plugins/local_auth/ios" + package_info: + :path: ".symlinks/plugins/package_info/ios" path_provider: :path: ".symlinks/plugins/path_provider/ios" share: @@ -73,11 +91,14 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: barcode_scan: 33f586d02270046fc6559135038b34b5754eaa4f - cw_monero: ca40a57b99f7753ed93d3b50af671a637277eb89 + cw_monero: 2e1f79929880cc2293b5bc1b25e28152e4d84649 + devicelocale: feebbe5e7a30adb8c4f83185de1b50ff19b44f00 esys_flutter_share: 403498dab005b36ce1f8d7aff377e81f0621b0b4 Flutter: 0e3d915762c693b495b44d77113d4970485de6ec flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec + local_auth: 2571c49920ae469f46d5557435fad8fa473a5e88 MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb + package_info: 48b108e75b8802c2d5e126f208ef540561c98aef path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d share: bae0a282aab4483288913fc4dc0b935d4b491f2e shared_preferences: 430726339841afefe5142b9c1f50cb6bd7793e01 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ef5c8ce46..53b0fb3ed 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -399,7 +399,8 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet; + MARKETING_VERSION = 3.1.28; + PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -534,7 +535,8 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet; + MARKETING_VERSION = 3.1.28; + PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -564,7 +566,8 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet; + MARKETING_VERSION = 3.1.28; + PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 31d748e9a..40f292e53 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) + $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion diff --git a/lib/src/domain/common/fs_migration.dart b/lib/src/domain/common/fs_migration.dart index d79d07dfe..db17cd134 100644 --- a/lib/src/domain/common/fs_migration.dart +++ b/lib/src/domain/common/fs_migration.dart @@ -1,4 +1,12 @@ import 'dart:io'; +import 'dart:convert'; +import 'package:cake_wallet/src/domain/common/contact.dart'; +import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/src/domain/common/wallet_info.dart'; +import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/src/domain/exchange/trade.dart'; +import 'package:flutter/foundation.dart'; +import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; const reservedNames = ["flutter_assets", "wallets", "db"]; @@ -12,8 +20,6 @@ Future migrate_android_v1() async { Future migrate_ios_v1() async { final appDocDir = await getApplicationDocumentsDirectory(); - - } Future migrate_hives({Directory appDocDir}) async { @@ -73,7 +79,54 @@ Future migrate_wallets({Directory appDocDir}) async { }); } -Future migrate_ios_wallets({Directory appDocDir}) async { - // final oldWalletsDir = Directory('${appDocDir.path}/wallets'); - -} \ No newline at end of file +Future migrate_ios_wallet_info( + {@required Directory appDocDir, + @required Box walletsInfo}) async { + final walletsDir = Directory('${appDocDir.path}/wallets'); + final moneroWalletsDir = Directory('${walletsDir.path}/monero'); + + moneroWalletsDir.listSync().forEach((item) async { + try { + if (item is Directory) { + final name = item.path.split('/').last; + final configFile = File('${item.path}/$name.json'); + final config = + json.decode(configFile.readAsStringSync()) as Map; + final isRecovery = config["isRecovery"] as bool ?? false; + final id = + walletTypeToString(WalletType.monero).toLowerCase() + '_' + name; + final walletInfo = + WalletInfo(id: id, name: name, isRecovery: isRecovery); + + await walletsInfo.add(walletInfo); + } + } catch (e) { + print(e.toString()); + } + }); +} + +Future migrate_ios_trades_list( + {@required Directory appDocDir, @required Box trades}) async { + final adderessBookJSON = File('${appDocDir.path}/trades_list.json'); + final List trades = + json.decode(adderessBookJSON.readAsStringSync()) as List; +} + +Future migrate_ios_address_book( + {@required Directory appDocDir, @required Box contacts}) async { + final adderessBookJSON = File('${appDocDir.path}/address_book.json'); + final List addresses = + json.decode(adderessBookJSON.readAsStringSync()) as List; + + addresses.forEach((dynamic item) async { + final _item = item as Map; + final type = _item["type"] as String; + final address = _item["address"] as String; + final name = _item["name"] as String; + final contact = Contact( + address: address, name: name, type: CryptoCurrency.fromString(type)); + + await contacts.add(contact); + }); +}