2024-02-07 15:44:29 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:cw_core/pathForWallet.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/wallet_credentials.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
abstract class WalletService<N extends WalletCredentials, RFS extends WalletCredentials,
|
|
|
|
RFK extends WalletCredentials> {
|
2021-12-24 12:52:08 +00:00
|
|
|
WalletType getType();
|
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
Future<WalletBase> create(N credentials, {bool? isTestnet});
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
Future<WalletBase> restoreFromSeed(RFS credentials, {bool? isTestnet});
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-03-04 19:42:57 +00:00
|
|
|
Future<WalletBase> restoreFromKeys(RFK credentials, {bool? isTestnet});
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
Future<WalletBase> openWallet(String name, String password);
|
|
|
|
|
|
|
|
Future<bool> isWalletExit(String name);
|
|
|
|
|
|
|
|
Future<void> remove(String wallet);
|
2023-07-12 23:20:11 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Future<void> rename(String currentName, String password, String newName);
|
2024-02-07 15:44:29 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|