mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
* feat: initial hive -> SQLite Includes migration script and initial work done to remove dependency on hive generators. Also contains some refactoring to make sync code async. Features new dev screen that lists all SQLite tables Aspects that need testing: - backups (from this version, and from previous versions as well) - wallet loading / wallet list - almost everything else - renaming - deletion - sorting in wallet list - wallet groups - wallet seed/keys - wallet switching - wallet creation / restore - all methods - wallet address page - hardware wallet connection (and prompts from mall screens) - contacts - advanced settings in wallet creation - derivation paths - some minor wownero fixes - base, hardware wallets * fix: build errors * fix: Bad state: No element in backup restore * address comments from review * fix: HardwareWalletType
83 lines
2.5 KiB
Dart
83 lines
2.5 KiB
Dart
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
abstract class WalletAddresses {
|
|
WalletAddresses(this.walletInfo)
|
|
: addressesMap = {},
|
|
allAddressesMap = {},
|
|
addressInfos = {},
|
|
usedAddresses = {},
|
|
hiddenAddresses = {},
|
|
manualAddresses = {} {
|
|
walletInfo.getUsedAddresses().then((value) => usedAddresses = value);
|
|
walletInfo.getHiddenAddresses().then((value) => hiddenAddresses = value);
|
|
walletInfo.getManualAddresses().then((value) => manualAddresses = value);
|
|
}
|
|
|
|
final WalletInfo walletInfo;
|
|
|
|
String get address;
|
|
|
|
String get latestAddress {
|
|
if (walletInfo.type == WalletType.monero || walletInfo.type == WalletType.wownero) {
|
|
if (addressesMap.keys.length == 0) return address;
|
|
return addressesMap[addressesMap.keys.last] ?? address;
|
|
}
|
|
return _localAddress ?? address;
|
|
}
|
|
|
|
String get primaryAddress => address;
|
|
|
|
String? _localAddress;
|
|
|
|
set address(String address) => _localAddress = address;
|
|
|
|
String get addressForExchange => address;
|
|
|
|
Map<String, String> addressesMap;
|
|
Map<String, String> allAddressesMap;
|
|
|
|
Map<String, String> get usableAddressesMap {
|
|
final tmp = addressesMap.map((key, value) => MapEntry(key, value)); // copy address map
|
|
tmp.removeWhere((key, value) => hiddenAddresses.contains(key) || manualAddresses.contains(key));
|
|
return tmp;
|
|
}
|
|
|
|
Map<String, String> get usableAllAddressesMap {
|
|
final tmp = allAddressesMap.map((key, value) => MapEntry(key, value)); // copy address map
|
|
tmp.removeWhere((key, value) => hiddenAddresses.contains(key) || manualAddresses.contains(key));
|
|
return tmp;
|
|
}
|
|
|
|
Map<int, List<WalletInfoAddressInfo>> addressInfos;
|
|
|
|
Set<String> usedAddresses;
|
|
|
|
Set<String> hiddenAddresses;
|
|
|
|
Set<String> manualAddresses;
|
|
|
|
Future<void> init();
|
|
|
|
Future<void> updateAddressesInBox();
|
|
|
|
Future<void> saveAddressesInBox() async {
|
|
try {
|
|
walletInfo.address = address;
|
|
walletInfo.setAddresses(addressesMap);
|
|
walletInfo.setAddressInfos(addressInfos);
|
|
walletInfo.setUsedAddresses(usedAddresses.toList());
|
|
walletInfo.setHiddenAddresses(hiddenAddresses.toList());
|
|
walletInfo.setManualAddresses(manualAddresses.toList());
|
|
|
|
await walletInfo.save();
|
|
} catch (e) {
|
|
printV(e.toString());
|
|
}
|
|
}
|
|
|
|
bool containsAddress(String address) =>
|
|
addressesMap.containsKey(address) || allAddressesMap.containsKey(address);
|
|
}
|