Cw 528 backup wallet files (#1281)

* monero wallet backup changes

* [skipci] updates

* monero fixes

* start work for bitcoin/eth

* cleanup

* [skipci] more cleanup

* add all other coins

* merge fixes

* add corrupted test

* build for testing

* actually be able to test monero

* review fixes

* more review fixes
This commit is contained in:
Matthew Fosse
2024-02-07 17:44:29 +02:00
committed by GitHub
parent e4ddf82e69
commit 26fe28891d
12 changed files with 264 additions and 117 deletions
+15 -4
View File
@@ -54,6 +54,17 @@ Future<void> restoreWalletFiles(String name) async {
}
}
Future<void> resetCache(String name) async {
await removeCache(name);
final walletDirPath = await pathForWalletDir(name: name, type: WalletType.monero);
final cacheFilePath = '$walletDirPath/$name';
final backupCacheFile = File(backupFileName(cacheFilePath));
if (backupCacheFile.existsSync()) {
await backupCacheFile.copy(cacheFilePath);
}
}
Future<bool> backupWalletFilesExists(String name) async {
final walletDirPath = await pathForWalletDir(name: name, type: WalletType.monero);
final cacheFilePath = '$walletDirPath/$name';
@@ -63,9 +74,9 @@ Future<bool> backupWalletFilesExists(String name) async {
final backupKeysFile = File(backupFileName(keysFilePath));
final backupAddressListFile = File(backupFileName(addressListFilePath));
return backupCacheFile.existsSync()
&& backupKeysFile.existsSync()
&& backupAddressListFile.existsSync();
return backupCacheFile.existsSync() &&
backupKeysFile.existsSync() &&
backupAddressListFile.existsSync();
}
Future<void> removeCache(String name) async {
@@ -85,4 +96,4 @@ Future<void> restoreOrResetWalletFiles(String name) async {
}
removeCache(name);
}
}
+21 -2
View File
@@ -1,7 +1,8 @@
import 'package:cw_core/node.dart';
import 'dart:io';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
abstract class WalletService<N extends WalletCredentials, RFS extends WalletCredentials,
@@ -21,4 +22,22 @@ abstract class WalletService<N extends WalletCredentials, RFS extends WalletCred
Future<void> remove(String wallet);
Future<void> rename(String currentName, String password, String newName);
Future<void> restoreWalletFilesFromBackup(String name) async {
final backupWalletDirPath = await pathForWalletDir(name: "$name.backup", type: getType());
final walletDirPath = await pathForWalletDir(name: name, type: getType());
if (File(backupWalletDirPath).existsSync()) {
await File(backupWalletDirPath).copy(walletDirPath);
}
}
Future<void> saveBackup(String name) async {
final backupWalletDirPath = await pathForWalletDir(name: "$name.backup", type: getType());
final walletDirPath = await pathForWalletDir(name: name, type: getType());
if (File(walletDirPath).existsSync()) {
await File(walletDirPath).copy(backupWalletDirPath);
}
}
}