mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-03 12:24:19 +01:00
feat: initial hive -> SQLite (#2502)
* 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
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
late Database db;
|
||||
|
||||
Future<void> initDb({String? pathOverride}) async {
|
||||
db = await openDatabase(
|
||||
pathOverride ?? "cake.db",
|
||||
version: 1,
|
||||
onCreate: (Database db, int version) async {
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE WalletInfo (
|
||||
walletInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
"type" INTEGER NOT NULL,
|
||||
isRecovery INTEGER DEFAULT (0) NOT NULL,
|
||||
walletInfoDerivationInfoId INTEGER NOT NULL,
|
||||
restoreHeight INTEGER DEFAULT (0) NOT NULL,
|
||||
"timestamp" INTEGER DEFAULT (0) NOT NULL,
|
||||
dirPath TEXT NOT NULL,
|
||||
"path" TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
yatEid TEXT,
|
||||
yatLastUsedAddressRaw TEXT,
|
||||
showIntroCakePayCard INTEGER DEFAULT (1),
|
||||
addressPageType TEXT,
|
||||
network TEXT,
|
||||
hardwareWalletType INTEGER,
|
||||
parentAddress TEXT,
|
||||
hashedWalletIdentifier TEXT,
|
||||
isNonSeedWallet INTEGER DEFAULT (0) NOT NULL,
|
||||
sortOrder INTEGER DEFAULT (0) NOT NULL
|
||||
);
|
||||
''');
|
||||
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE WalletInfoDerivationInfo (
|
||||
walletInfoDerivationInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
address TEXT NOT NULL,
|
||||
balance TEXT NOT NULL,
|
||||
transactionsCount INTEGER DEFAULT (0) NOT NULL,
|
||||
derivationType INTEGER NOT NULL,
|
||||
derivationPath TEXT,
|
||||
scriptType TEXT,
|
||||
description TEXT
|
||||
);
|
||||
''');
|
||||
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE WalletInfoAddress (
|
||||
walletInfoAddressId INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
walletInfoId INTEGER,
|
||||
"type" INTEGER NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
CONSTRAINT WalletInfoAddress_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
|
||||
);
|
||||
''');
|
||||
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE WalletInfoAddressInfo (
|
||||
walletInfoAddressInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
walletInfoId INTEGER NOT NULL,
|
||||
mapKey INTEGER NOT NULL,
|
||||
mapValueAccountIndex INTEGER NOT NULL,
|
||||
mapValueAddress TEXT NOT NULL,
|
||||
mapValueLabel TEXT NOT NULL,
|
||||
CONSTRAINT WalletInfoAddressInfo_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
|
||||
);
|
||||
''');
|
||||
|
||||
await db.execute(
|
||||
'''
|
||||
CREATE TABLE "WalletInfoAddressMap" (
|
||||
walletInfoAddressMapId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
walletInfoId INTEGER NOT NULL,
|
||||
addressKey TEXT NOT NULL,
|
||||
addressValue TEXT NOT NULL,
|
||||
CONSTRAINT WalletInfoAddress_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
|
||||
);
|
||||
'''
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> dumpDb() async {
|
||||
try {
|
||||
return await _dumpDb();
|
||||
} catch (e) {
|
||||
return {
|
||||
"error": e.toString(),
|
||||
"stackTrace": StackTrace.current.toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> _getTableNames() async {
|
||||
final tableNames = await db.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
|
||||
return tableNames.map((e) => (e["name"]).toString()).toList();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _dumpDb() async {
|
||||
final tableNames = await _getTableNames();
|
||||
final ret = <String, dynamic>{};
|
||||
for (final tableName in tableNames) {
|
||||
ret[tableName] = await db.query(tableName);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:cw_core/address_info.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
@@ -9,8 +8,12 @@ abstract class WalletAddresses {
|
||||
allAddressesMap = {},
|
||||
addressInfos = {},
|
||||
usedAddresses = {},
|
||||
hiddenAddresses = walletInfo.hiddenAddresses?.toSet() ?? {},
|
||||
manualAddresses = walletInfo.manualAddresses?.toSet() ?? {};
|
||||
hiddenAddresses = {},
|
||||
manualAddresses = {} {
|
||||
walletInfo.getUsedAddresses().then((value) => usedAddresses = value);
|
||||
walletInfo.getHiddenAddresses().then((value) => hiddenAddresses = value);
|
||||
walletInfo.getManualAddresses().then((value) => manualAddresses = value);
|
||||
}
|
||||
|
||||
final WalletInfo walletInfo;
|
||||
|
||||
@@ -47,7 +50,7 @@ abstract class WalletAddresses {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Map<int, List<AddressInfo>> addressInfos;
|
||||
Map<int, List<WalletInfoAddressInfo>> addressInfos;
|
||||
|
||||
Set<String> usedAddresses;
|
||||
|
||||
@@ -62,15 +65,13 @@ abstract class WalletAddresses {
|
||||
Future<void> saveAddressesInBox() async {
|
||||
try {
|
||||
walletInfo.address = address;
|
||||
walletInfo.addresses = addressesMap;
|
||||
walletInfo.addressInfos = addressInfos;
|
||||
walletInfo.usedAddresses = usedAddresses.toList();
|
||||
walletInfo.hiddenAddresses = hiddenAddresses.toList();
|
||||
walletInfo.manualAddresses = manualAddresses.toList();
|
||||
walletInfo.setAddresses(addressesMap);
|
||||
walletInfo.setAddressInfos(addressInfos);
|
||||
walletInfo.setUsedAddresses(usedAddresses.toList());
|
||||
walletInfo.setHiddenAddresses(hiddenAddresses.toList());
|
||||
walletInfo.setManualAddresses(manualAddresses.toList());
|
||||
|
||||
if (walletInfo.isInBox) {
|
||||
await walletInfo.save();
|
||||
}
|
||||
await walletInfo.save();
|
||||
} catch (e) {
|
||||
printV(e.toString());
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import 'package:cw_core/wallet_addresses.dart';
|
||||
import 'package:cw_core/account_list.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
|
||||
abstract class WalletAddressesWithAccount<T> extends WalletAddresses {
|
||||
WalletAddressesWithAccount(WalletInfo walletInfo) : super(walletInfo);
|
||||
|
||||
// T get account;
|
||||
|
||||
// set account(T account);
|
||||
|
||||
AccountList<T> get accountList;
|
||||
}
|
||||
@@ -15,12 +15,13 @@ import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
abstract class WalletBase<BalanceType extends Balance, HistoryType extends TransactionHistoryBase,
|
||||
TransactionType extends TransactionInfo> {
|
||||
WalletBase(this.walletInfo);
|
||||
WalletBase(this.walletInfo, this.derivationInfo);
|
||||
|
||||
static String idFor(String name, WalletType type) =>
|
||||
walletTypeToString(type).toLowerCase() + '_' + name;
|
||||
|
||||
WalletInfo walletInfo;
|
||||
DerivationInfo derivationInfo;
|
||||
|
||||
WalletType get type => walletInfo.type;
|
||||
|
||||
|
||||
@@ -10,11 +10,7 @@ abstract class WalletCredentials {
|
||||
this.passphrase,
|
||||
this.derivationInfo,
|
||||
this.hardwareWalletType,
|
||||
}) {
|
||||
if (this.walletInfo != null && derivationInfo != null) {
|
||||
this.walletInfo!.derivationInfo = derivationInfo;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final String name;
|
||||
final int? height;
|
||||
|
||||
+456
-94
@@ -1,47 +1,239 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cw_core/address_info.dart';
|
||||
import 'package:cw_core/db/sqlite.dart';
|
||||
import 'package:cw_core/hive_type_ids.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/wallet_info_legacy.dart' as wiLegacy;
|
||||
|
||||
part 'wallet_info.g.dart';
|
||||
Future<void> performHiveMigration() async {
|
||||
try {
|
||||
if (!CakeHive.isAdapterRegistered(wiLegacy.WalletInfo.typeId)) {
|
||||
CakeHive.registerAdapter(wiLegacy.WalletInfoAdapter());
|
||||
}
|
||||
if (!CakeHive.isAdapterRegistered(DERIVATION_TYPE_TYPE_ID)) {
|
||||
CakeHive.registerAdapter(wiLegacy.DerivationTypeAdapter());
|
||||
}
|
||||
if (!CakeHive.isAdapterRegistered(wiLegacy.DerivationInfo.typeId)) {
|
||||
CakeHive.registerAdapter(wiLegacy.DerivationInfoAdapter());
|
||||
}
|
||||
if (!CakeHive.isAdapterRegistered(HARDWARE_WALLET_TYPE_TYPE_ID)) {
|
||||
CakeHive.registerAdapter(wiLegacy.HardwareWalletTypeAdapter());
|
||||
}
|
||||
final walletInfoBox = await CakeHive.openBox<wiLegacy.WalletInfo>(wiLegacy.WalletInfo.boxName);
|
||||
await wiLegacy.WalletInfo.migrateAllToSqlite(walletInfoBox);
|
||||
} catch (e) {
|
||||
printV('Error performing Hive migration: $e, continuing anyway');
|
||||
}
|
||||
}
|
||||
|
||||
@HiveType(typeId: DERIVATION_TYPE_TYPE_ID)
|
||||
enum DerivationType {
|
||||
@HiveField(0)
|
||||
unknown,
|
||||
@HiveField(1)
|
||||
def, // default is a reserved word
|
||||
@HiveField(2)
|
||||
nano,
|
||||
@HiveField(3)
|
||||
bip39,
|
||||
@HiveField(4)
|
||||
electrum,
|
||||
}
|
||||
|
||||
@HiveType(typeId: HARDWARE_WALLET_TYPE_TYPE_ID)
|
||||
enum HardwareWalletType {
|
||||
@HiveField(0)
|
||||
ledger,
|
||||
@HiveField(1)
|
||||
bitbox,
|
||||
@HiveField(2)
|
||||
cupcake,
|
||||
@HiveField(3)
|
||||
coldcard,
|
||||
@HiveField(4)
|
||||
seedsigner,
|
||||
@HiveField(5)
|
||||
keystone,
|
||||
@HiveField(6)
|
||||
trezor,
|
||||
}
|
||||
|
||||
@HiveType(typeId: DerivationInfo.typeId)
|
||||
class DerivationInfo extends HiveObject {
|
||||
enum WalletInfoAddressType {
|
||||
used,
|
||||
hidden,
|
||||
manual,
|
||||
}
|
||||
|
||||
class WalletInfoAddressInfo {
|
||||
WalletInfoAddressInfo({
|
||||
this.id = 0,
|
||||
required this.walletInfoId,
|
||||
required this.mapKey,
|
||||
required this.accountIndex,
|
||||
required this.address,
|
||||
required this.label,
|
||||
});
|
||||
|
||||
int id;
|
||||
int walletInfoId;
|
||||
int mapKey;
|
||||
int accountIndex;
|
||||
String address;
|
||||
String label;
|
||||
|
||||
static String get tableName => 'walletInfoAddressInfo';
|
||||
static String get selfIdColumn => "${tableName}Id";
|
||||
|
||||
static Future<List<WalletInfoAddressInfo>> selectList(int walletInfoId) async {
|
||||
final query = await db.query(tableName, where: 'walletInfoId = ?', whereArgs: [walletInfoId]);
|
||||
return List.generate(query.length, (index) => WalletInfoAddressInfo.fromJson(query[index]));
|
||||
}
|
||||
|
||||
static Future<int> deleteByWalletInfoId(int walletInfoId) async {
|
||||
return await db.delete(tableName, where: 'walletInfoId = ?', whereArgs: [walletInfoId]);
|
||||
}
|
||||
static Future<int> insert({
|
||||
required int walletInfoId,
|
||||
required int mapKey,
|
||||
required int accountIndex,
|
||||
required String address,
|
||||
required String label,
|
||||
}) async {
|
||||
return await db.insert(tableName, {
|
||||
"walletInfoId": walletInfoId,
|
||||
"mapKey": mapKey,
|
||||
"mapValueAccountIndex": accountIndex,
|
||||
"mapValueAddress": address,
|
||||
"mapValueLabel": label,
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
selfIdColumn: id,
|
||||
"walletInfoId": walletInfoId,
|
||||
"mapKey": mapKey,
|
||||
"mapValueAccountIndex": accountIndex,
|
||||
"mapValueAddress": address,
|
||||
"mapValueLabel": label,
|
||||
};
|
||||
}
|
||||
|
||||
factory WalletInfoAddressInfo.fromJson(Map<String, dynamic> json) {
|
||||
return WalletInfoAddressInfo(
|
||||
id: json[selfIdColumn] as int,
|
||||
walletInfoId: json['walletInfoId'] as int,
|
||||
mapKey: json['mapKey'] as int,
|
||||
accountIndex: json['mapValueAccountIndex'] as int,
|
||||
address: json['mapValueAddress'] as String,
|
||||
label: json['mapValueLabel'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WalletInfoAddressMap {
|
||||
WalletInfoAddressMap({
|
||||
required this.id,
|
||||
required this.walletInfoId,
|
||||
required this.addressKey,
|
||||
required this.addressValue,
|
||||
});
|
||||
|
||||
|
||||
int id;
|
||||
int walletInfoId;
|
||||
String addressKey;
|
||||
String addressValue;
|
||||
|
||||
static String get tableName => 'walletInfoAddressMap';
|
||||
static String get selfIdColumn => "${tableName}Id";
|
||||
|
||||
static Future<List<WalletInfoAddressMap>> selectList(int walletInfoId) async {
|
||||
final query = await db.query(tableName, where: 'walletInfoId = ?', whereArgs: [walletInfoId]);
|
||||
return List.generate(query.length, (index) => WalletInfoAddressMap.fromJson(query[index]));
|
||||
}
|
||||
static Future<int> deleteByWalletInfoId(int walletInfoId) async {
|
||||
return await db.delete(tableName, where: 'walletInfoId = ?', whereArgs: [walletInfoId]);
|
||||
}
|
||||
static Future<int> insert(int walletInfoId, String addressKey, String addressValue) async {
|
||||
return await db.insert(tableName, {
|
||||
"walletInfoId": walletInfoId,
|
||||
"addressKey": addressKey,
|
||||
"addressValue": addressValue,
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
selfIdColumn: id,
|
||||
"walletInfoId": walletInfoId,
|
||||
"addressKey": addressKey,
|
||||
"addressValue": addressValue,
|
||||
};
|
||||
}
|
||||
|
||||
factory WalletInfoAddressMap.fromJson(Map<String, dynamic> json) {
|
||||
return WalletInfoAddressMap(
|
||||
id: json[selfIdColumn] as int,
|
||||
walletInfoId: json['walletInfoId'] as int,
|
||||
addressKey: json['addressKey'] as String,
|
||||
addressValue: json['addressValue'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WalletInfoAddress {
|
||||
WalletInfoAddress({
|
||||
this.id = 0,
|
||||
required this.walletInfoId,
|
||||
required this.type,
|
||||
required this.address,
|
||||
});
|
||||
|
||||
int id;
|
||||
int walletInfoId;
|
||||
WalletInfoAddressType type;
|
||||
String address;
|
||||
|
||||
static String get tableName => 'walletInfoAddress';
|
||||
static String get selfIdColumn => "${tableName}Id";
|
||||
|
||||
static Future<List<WalletInfoAddress>> selectList(int walletInfoId, WalletInfoAddressType type) async {
|
||||
final query = await db.query(tableName, where: 'walletInfoId = ? AND type = ?', whereArgs: [walletInfoId, type.index]);
|
||||
return List.generate(query.length, (index) => WalletInfoAddress.fromJson(query[index]));
|
||||
}
|
||||
|
||||
static Future<int> deleteByAddress(int walletInfoId, WalletInfoAddressType type, String address) async {
|
||||
return await db.delete(tableName, where: 'walletInfoId = ? AND type = ? AND address = ?', whereArgs: [walletInfoId, type.index, address]);
|
||||
}
|
||||
|
||||
static Future<int> deleteByType(int walletInfoId, WalletInfoAddressType type) async {
|
||||
return await db.delete(tableName, where: 'walletInfoId = ? AND type = ?', whereArgs: [walletInfoId, type.index]);
|
||||
}
|
||||
|
||||
static Future<int> insert(int walletInfoId, WalletInfoAddressType type, String address) async {
|
||||
final select = await db.query(tableName, where: 'walletInfoId = ? AND type = ? AND address = ?', whereArgs: [walletInfoId, type.index, address]);
|
||||
if (select.isNotEmpty) {
|
||||
return select[0][selfIdColumn] as int;
|
||||
}
|
||||
return await db.insert(tableName, {
|
||||
"walletInfoId": walletInfoId,
|
||||
"type": type.index,
|
||||
"address": address,
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
selfIdColumn: id,
|
||||
"walletInfoId": walletInfoId,
|
||||
"type": type.index,
|
||||
"address": address,
|
||||
};
|
||||
}
|
||||
|
||||
factory WalletInfoAddress.fromJson(Map<String, dynamic> json) {
|
||||
return WalletInfoAddress(
|
||||
id: json[selfIdColumn] as int,
|
||||
walletInfoId: json['walletInfoId'] as int,
|
||||
type: WalletInfoAddressType.values[json['type'] as int],
|
||||
address: json['address'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DerivationInfo {
|
||||
DerivationInfo({
|
||||
this.id = 0,
|
||||
this.derivationType,
|
||||
this.derivationPath,
|
||||
this.balance = "",
|
||||
@@ -51,33 +243,77 @@ class DerivationInfo extends HiveObject {
|
||||
this.description,
|
||||
});
|
||||
|
||||
static const typeId = DERIVATION_INFO_TYPE_ID;
|
||||
int id;
|
||||
|
||||
static String get tableName => 'walletInfoDerivationInfo';
|
||||
static String get selfIdColumn => "${tableName}Id";
|
||||
|
||||
@HiveField(0, defaultValue: '')
|
||||
String address;
|
||||
|
||||
@HiveField(1, defaultValue: '')
|
||||
String balance;
|
||||
|
||||
@HiveField(2, defaultValue: 0)
|
||||
int transactionsCount;
|
||||
|
||||
@HiveField(3)
|
||||
DerivationType? derivationType;
|
||||
|
||||
@HiveField(4)
|
||||
String? derivationPath;
|
||||
String? scriptType;
|
||||
String? description;
|
||||
|
||||
@HiveField(5)
|
||||
final String? scriptType;
|
||||
static Future<List<DerivationInfo>> selectList(String where, List<dynamic> whereArgs) async {
|
||||
final query = await db.query(
|
||||
tableName,
|
||||
columns: [
|
||||
selfIdColumn,
|
||||
'address',
|
||||
'balance',
|
||||
'transactionsCount',
|
||||
'derivationType',
|
||||
'derivationPath',
|
||||
'scriptType',
|
||||
'description',
|
||||
],
|
||||
where: where.isNotEmpty ? where : "1 = 1",
|
||||
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
|
||||
);
|
||||
return List.generate(query.length, (index) => DerivationInfo.fromJson(query[index]));
|
||||
}
|
||||
|
||||
@HiveField(6)
|
||||
final String? description;
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
selfIdColumn: id,
|
||||
"address": address,
|
||||
"balance": balance,
|
||||
"transactionsCount": transactionsCount,
|
||||
"derivationType": derivationType?.index,
|
||||
"derivationPath": derivationPath,
|
||||
"scriptType": scriptType,
|
||||
"description": description,
|
||||
};
|
||||
}
|
||||
|
||||
factory DerivationInfo.fromJson(Map<String, dynamic> json ) {
|
||||
return DerivationInfo(
|
||||
id: json[selfIdColumn] as int,
|
||||
derivationType: DerivationType.values[json['derivationType'] as int? ?? 0],
|
||||
derivationPath: json['derivationPath'] as String?,
|
||||
balance: json['balance'] as String? ?? "",
|
||||
address: json['address'] as String? ?? "",
|
||||
transactionsCount: json['transactionsCount'] as int? ?? 0,
|
||||
scriptType: json['scriptType'] as String?,
|
||||
description: json['description'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> save() async {
|
||||
final json = toJson();
|
||||
if (json[selfIdColumn] == 0) {
|
||||
json[selfIdColumn] = null;
|
||||
}
|
||||
id = await db.insert(tableName, json, conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@HiveType(typeId: WalletInfo.typeId)
|
||||
class WalletInfo extends HiveObject {
|
||||
class WalletInfo {
|
||||
WalletInfo(
|
||||
this.internalId,
|
||||
this.id,
|
||||
this.name,
|
||||
this.type,
|
||||
@@ -90,11 +326,12 @@ class WalletInfo extends HiveObject {
|
||||
this.yatEid,
|
||||
this.yatLastUsedAddressRaw,
|
||||
this.showIntroCakePayCard,
|
||||
this.derivationInfo,
|
||||
this.derivationInfoId,
|
||||
this.hardwareWalletType,
|
||||
this.parentAddress,
|
||||
this.hashedWalletIdentifier,
|
||||
this.isNonSeedWallet,
|
||||
this.sortOrder,
|
||||
) : _yatLastUsedAddressController = StreamController<String>.broadcast();
|
||||
|
||||
factory WalletInfo.external({
|
||||
@@ -110,13 +347,15 @@ class WalletInfo extends HiveObject {
|
||||
bool? showIntroCakePayCard,
|
||||
String yatEid = '',
|
||||
String yatLastUsedAddressRaw = '',
|
||||
DerivationInfo? derivationInfo,
|
||||
int? derivationInfoId,
|
||||
HardwareWalletType? hardwareWalletType,
|
||||
String? parentAddress,
|
||||
String? hashedWalletIdentifier,
|
||||
bool? isNonSeedWallet,
|
||||
int? sortOrder,
|
||||
}) {
|
||||
return WalletInfo(
|
||||
0,
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
@@ -129,96 +368,135 @@ class WalletInfo extends HiveObject {
|
||||
yatEid,
|
||||
yatLastUsedAddressRaw,
|
||||
showIntroCakePayCard,
|
||||
derivationInfo,
|
||||
derivationInfoId ?? -1,
|
||||
hardwareWalletType,
|
||||
parentAddress,
|
||||
hashedWalletIdentifier,
|
||||
isNonSeedWallet ?? false,
|
||||
sortOrder ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
static const typeId = WALLET_INFO_TYPE_ID;
|
||||
static const boxName = 'WalletInfo';
|
||||
static String get tableName => 'walletInfo';
|
||||
static String get selfIdColumn => "${tableName}Id";
|
||||
|
||||
int internalId;
|
||||
|
||||
@HiveField(0, defaultValue: '')
|
||||
String id;
|
||||
|
||||
@HiveField(1, defaultValue: '')
|
||||
String name;
|
||||
|
||||
@HiveField(2)
|
||||
WalletType type;
|
||||
|
||||
@HiveField(3, defaultValue: false)
|
||||
bool isRecovery;
|
||||
|
||||
@HiveField(4, defaultValue: 0)
|
||||
int restoreHeight;
|
||||
|
||||
@HiveField(5, defaultValue: 0)
|
||||
int timestamp;
|
||||
|
||||
@HiveField(6, defaultValue: '')
|
||||
String dirPath;
|
||||
|
||||
@HiveField(7, defaultValue: '')
|
||||
String path;
|
||||
|
||||
@HiveField(8, defaultValue: '')
|
||||
String address;
|
||||
Future<Map<String, String>> getAddresses() async {
|
||||
final list = await WalletInfoAddressMap.selectList(internalId);
|
||||
return Map.fromEntries(list.map((e) => MapEntry(e.addressKey, e.addressValue)));
|
||||
}
|
||||
|
||||
@HiveField(10)
|
||||
Map<String, String>? addresses;
|
||||
Future<void> setAddresses(Map<String, String> addresses) async {
|
||||
await WalletInfoAddressMap.deleteByWalletInfoId(internalId);
|
||||
final keys = addresses.keys.toList();
|
||||
for (final address in keys) {
|
||||
await WalletInfoAddressMap.insert(internalId, address, addresses[address]!);
|
||||
}
|
||||
}
|
||||
|
||||
@HiveField(11)
|
||||
String? yatEid;
|
||||
|
||||
@HiveField(12)
|
||||
String? yatLastUsedAddressRaw;
|
||||
|
||||
@HiveField(13)
|
||||
bool? showIntroCakePayCard;
|
||||
Future<Map<int, List<WalletInfoAddressInfo>>> getAddressInfos() async {
|
||||
final list = await WalletInfoAddressInfo.selectList(internalId);
|
||||
final ret = <int, List<WalletInfoAddressInfo>>{};
|
||||
for (final e in list) {
|
||||
ret[e.mapKey] ??= [];
|
||||
ret[e.mapKey]!.add(e);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@HiveField(14)
|
||||
Map<int, List<AddressInfo>>? addressInfos;
|
||||
Future<void> setAddressInfos(Map<int, List<WalletInfoAddressInfo>> addressInfos) async {
|
||||
await WalletInfoAddressInfo.deleteByWalletInfoId(internalId);
|
||||
final entries = addressInfos.entries.toList();
|
||||
for (final addressInfo in entries) {
|
||||
for (final info in addressInfo.value) {
|
||||
await WalletInfoAddressInfo.insert(
|
||||
walletInfoId: internalId,
|
||||
mapKey: addressInfo.key,
|
||||
accountIndex: info.accountIndex,
|
||||
address: info.address,
|
||||
label: info.label,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@HiveField(15)
|
||||
List<String>? usedAddresses;
|
||||
Future<Set<String>> getUsedAddresses() async {
|
||||
final list = await WalletInfoAddress.selectList(internalId, WalletInfoAddressType.used);
|
||||
return list.map((e) => e.address).toSet();
|
||||
}
|
||||
Future<void> setUsedAddresses(List<String> addresses) async {
|
||||
await WalletInfoAddress.deleteByType(internalId, WalletInfoAddressType.used);
|
||||
for (final address in addresses) {
|
||||
await WalletInfoAddress.insert(internalId, WalletInfoAddressType.used, address);
|
||||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
@HiveField(16)
|
||||
DerivationType? derivationType; // no longer used
|
||||
Future<Set<String>> getHiddenAddresses() async {
|
||||
final list = await WalletInfoAddress.selectList(internalId, WalletInfoAddressType.hidden);
|
||||
return list.map((e) => e.address).toSet();
|
||||
}
|
||||
Future<void> setHiddenAddresses(List<String> addresses) async {
|
||||
await WalletInfoAddress.deleteByType(internalId, WalletInfoAddressType.hidden);
|
||||
for (final address in addresses) {
|
||||
await WalletInfoAddress.insert(internalId, WalletInfoAddressType.hidden, address);
|
||||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
@HiveField(17)
|
||||
String? derivationPath; // no longer used
|
||||
Future<Set<String>> getManualAddresses() async {
|
||||
final list = await WalletInfoAddress.selectList(internalId, WalletInfoAddressType.manual);
|
||||
return list.map((e) => e.address).toSet();
|
||||
}
|
||||
Future<void> setManualAddresses(List<String> addresses) async {
|
||||
await WalletInfoAddress.deleteByType(internalId, WalletInfoAddressType.manual);
|
||||
for (final address in addresses) {
|
||||
await WalletInfoAddress.insert(internalId, WalletInfoAddressType.manual, address);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addAddress(String address, WalletInfoAddressType type) async {
|
||||
await WalletInfoAddress.insert(internalId, type, address);
|
||||
}
|
||||
|
||||
@HiveField(18)
|
||||
String? addressPageType;
|
||||
|
||||
@HiveField(19)
|
||||
String? network;
|
||||
|
||||
@HiveField(20)
|
||||
DerivationInfo? derivationInfo;
|
||||
|
||||
@HiveField(21)
|
||||
int derivationInfoId;
|
||||
DerivationInfo? _derivationInfo;
|
||||
Future<DerivationInfo> getDerivationInfo() async {
|
||||
if (_derivationInfo != null) {
|
||||
return _derivationInfo!;
|
||||
}
|
||||
final list = await DerivationInfo.selectList('walletInfoDerivationInfoId = ?', [derivationInfoId]);
|
||||
if (list.isEmpty) {
|
||||
final di = DerivationInfo(
|
||||
id: 0,
|
||||
derivationType: DerivationType.unknown,
|
||||
);
|
||||
derivationInfoId = await di.save();
|
||||
_derivationInfo = di;
|
||||
return di;
|
||||
}
|
||||
_derivationInfo = list[0];
|
||||
return _derivationInfo!;
|
||||
}
|
||||
HardwareWalletType? hardwareWalletType;
|
||||
|
||||
@HiveField(22)
|
||||
String? parentAddress;
|
||||
|
||||
@HiveField(23)
|
||||
List<String>? hiddenAddresses;
|
||||
|
||||
@HiveField(24)
|
||||
List<String>? manualAddresses;
|
||||
|
||||
@HiveField(25)
|
||||
String? hashedWalletIdentifier;
|
||||
|
||||
@HiveField(26, defaultValue: false)
|
||||
bool isNonSeedWallet;
|
||||
|
||||
int sortOrder;
|
||||
|
||||
String get yatLastUsedAddress => yatLastUsedAddressRaw ?? '';
|
||||
|
||||
@@ -248,6 +526,90 @@ class WalletInfo extends HiveObject {
|
||||
|
||||
StreamController<String> _yatLastUsedAddressController;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
selfIdColumn: internalId,
|
||||
"id": id,
|
||||
"name": name,
|
||||
"type": type.index,
|
||||
"isRecovery": isRecovery ? 1 : 0,
|
||||
"restoreHeight": restoreHeight,
|
||||
"timestamp": timestamp,
|
||||
"dirPath": dirPath,
|
||||
"path": path,
|
||||
"address": address,
|
||||
"yatEid": yatEid,
|
||||
"yatLastUsedAddressRaw": yatLastUsedAddressRaw,
|
||||
"showIntroCakePayCard": showIntroCakePayCard == true ? 1 : 0, // SQL regression: null -> false
|
||||
"walletInfoDerivationInfoId": derivationInfoId,
|
||||
"hardwareWalletType": hardwareWalletType?.index,
|
||||
"parentAddress": parentAddress,
|
||||
"hashedWalletIdentifier": hashedWalletIdentifier,
|
||||
"isNonSeedWallet": isNonSeedWallet ? 1 : 0,
|
||||
"sortOrder": sortOrder,
|
||||
};
|
||||
|
||||
factory WalletInfo.fromJson(Map<String, dynamic> json) {
|
||||
return WalletInfo(
|
||||
json[selfIdColumn] as int,
|
||||
json['id'] as String,
|
||||
json['name'] as String,
|
||||
WalletType.values[json['type'] as int],
|
||||
(json['isRecovery'] as int) == 1,
|
||||
json['restoreHeight'] as int,
|
||||
json['timestamp'] as int,
|
||||
json['dirPath'] as String,
|
||||
json['path'] as String,
|
||||
json['address'] as String,
|
||||
json['yatEid'] as String?,
|
||||
json['yatLastUsedAddressRaw'] as String?,
|
||||
(json['showIntroCakePayCard'] as int) == 1,
|
||||
json['walletInfoDerivationInfoId'] as int,
|
||||
json['hardwareWalletType'] == null ? null : HardwareWalletType.values[json['hardwareWalletType'] as int],
|
||||
json['parentAddress'] as String?,
|
||||
json['hashedWalletIdentifier'] as String?,
|
||||
(json['isNonSeedWallet'] as int) == 1,
|
||||
json['sortOrder'] as int? ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> save() async {
|
||||
final json = toJson();
|
||||
if (json[selfIdColumn] == 0) {
|
||||
json[selfIdColumn] = null;
|
||||
}
|
||||
if (_derivationInfo != null) {
|
||||
derivationInfoId = await _derivationInfo!.save();
|
||||
}
|
||||
internalId = await db.insert(tableName, json, conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
return internalId;
|
||||
}
|
||||
|
||||
static Future<int> delete(WalletInfo walletInfo) async {
|
||||
return await db.delete(tableName, where: 'id = ?', whereArgs: [walletInfo.id]);
|
||||
}
|
||||
|
||||
static Future<List<WalletInfo>> selectList(String where, List<dynamic> whereArgs, {String orderBy = 'sortOrder'}) async {
|
||||
final list = await db.query(
|
||||
tableName,
|
||||
where: where.isNotEmpty ? where : "1 = 1",
|
||||
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
|
||||
orderBy: orderBy,
|
||||
);
|
||||
return List.generate(list.length, (index) => WalletInfo.fromJson(list[index]));
|
||||
}
|
||||
|
||||
static Future<List<WalletInfo>> getAll() async {
|
||||
return selectList('', []);
|
||||
}
|
||||
|
||||
static Future<WalletInfo?> get(String name, WalletType type) async {
|
||||
final list = await selectList('name = ? AND type = ?', [name, type.index]);
|
||||
if (list.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return list[0];
|
||||
}
|
||||
|
||||
Future<void> updateRestoreHeight(int height) async {
|
||||
restoreHeight = height;
|
||||
await save();
|
||||
|
||||
@@ -0,0 +1,308 @@
|
||||
// NOTE: This code was generated by Hive, but since Hive is on the way out, this
|
||||
// code no longer uses hive generators, so when we get rid of hive we also will
|
||||
// be able to get rid of
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_info.dart' as newWi;
|
||||
import 'package:cw_core/address_info.dart';
|
||||
import 'package:cw_core/hive_type_ids.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'wallet_info_legacy.part.dart';
|
||||
|
||||
// // @HiveType(typeId: DERIVATION_TYPE_TYPE_ID)
|
||||
// enum DerivationType {
|
||||
// // @HiveField(0)
|
||||
// unknown,
|
||||
// // @HiveField(1)
|
||||
// def, // default is a reserved word
|
||||
// // @HiveField(2)
|
||||
// nano,
|
||||
// // @HiveField(3)
|
||||
// bip39,
|
||||
// // @HiveField(4)
|
||||
// electrum,
|
||||
// }
|
||||
|
||||
// // @HiveType(typeId: HARDWARE_WALLET_TYPE_TYPE_ID)
|
||||
// enum HardwareWalletType {
|
||||
// // @HiveField(0)
|
||||
// ledger,
|
||||
// }
|
||||
|
||||
// @HiveType(typeId: DerivationInfo.typeId)
|
||||
class DerivationInfo extends HiveObject {
|
||||
DerivationInfo({
|
||||
this.derivationType,
|
||||
this.derivationPath,
|
||||
this.balance = "",
|
||||
this.address = "",
|
||||
this.transactionsCount = 0,
|
||||
this.scriptType,
|
||||
this.description,
|
||||
});
|
||||
|
||||
static const typeId = DERIVATION_INFO_TYPE_ID;
|
||||
|
||||
// @HiveField(0, defaultValue: '')
|
||||
String address;
|
||||
|
||||
// @HiveField(1, defaultValue: '')
|
||||
String balance;
|
||||
|
||||
// @HiveField(2, defaultValue: 0)
|
||||
int transactionsCount;
|
||||
|
||||
// @HiveField(3)
|
||||
newWi.DerivationType? derivationType;
|
||||
|
||||
// @HiveField(4)
|
||||
String? derivationPath;
|
||||
|
||||
// @HiveField(5)
|
||||
final String? scriptType;
|
||||
|
||||
// @HiveField(6)
|
||||
final String? description;
|
||||
}
|
||||
|
||||
// @HiveType(typeId: WalletInfo.typeId)
|
||||
class WalletInfo extends HiveObject {
|
||||
WalletInfo(
|
||||
this.id,
|
||||
this.name,
|
||||
this.type,
|
||||
this.isRecovery,
|
||||
this.restoreHeight,
|
||||
this.timestamp,
|
||||
this.dirPath,
|
||||
this.path,
|
||||
this.address,
|
||||
this.yatEid,
|
||||
this.yatLastUsedAddressRaw,
|
||||
this.showIntroCakePayCard,
|
||||
this.derivationInfo,
|
||||
this.hardwareWalletType,
|
||||
this.parentAddress,
|
||||
this.hashedWalletIdentifier,
|
||||
this.isNonSeedWallet,
|
||||
) : _yatLastUsedAddressController = StreamController<String>.broadcast();
|
||||
|
||||
factory WalletInfo.external({
|
||||
required String id,
|
||||
required String name,
|
||||
required WalletType type,
|
||||
required bool isRecovery,
|
||||
required int restoreHeight,
|
||||
required DateTime date,
|
||||
required String dirPath,
|
||||
required String path,
|
||||
required String address,
|
||||
bool? showIntroCakePayCard,
|
||||
String yatEid = '',
|
||||
String yatLastUsedAddressRaw = '',
|
||||
DerivationInfo? derivationInfo,
|
||||
newWi.HardwareWalletType? hardwareWalletType,
|
||||
String? parentAddress,
|
||||
String? hashedWalletIdentifier,
|
||||
bool? isNonSeedWallet,
|
||||
}) {
|
||||
return WalletInfo(
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
isRecovery,
|
||||
restoreHeight,
|
||||
date.millisecondsSinceEpoch,
|
||||
dirPath,
|
||||
path,
|
||||
address,
|
||||
yatEid,
|
||||
yatLastUsedAddressRaw,
|
||||
showIntroCakePayCard,
|
||||
derivationInfo,
|
||||
hardwareWalletType,
|
||||
parentAddress,
|
||||
hashedWalletIdentifier,
|
||||
isNonSeedWallet ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
static const typeId = WALLET_INFO_TYPE_ID;
|
||||
static const boxName = 'WalletInfo';
|
||||
|
||||
// @HiveField(0, defaultValue: '')
|
||||
String id;
|
||||
|
||||
// @HiveField(1, defaultValue: '')
|
||||
String name;
|
||||
|
||||
// @HiveField(2)
|
||||
WalletType type;
|
||||
|
||||
// @HiveField(3, defaultValue: false)
|
||||
bool isRecovery;
|
||||
|
||||
// @HiveField(4, defaultValue: 0)
|
||||
int restoreHeight;
|
||||
|
||||
// @HiveField(5, defaultValue: 0)
|
||||
int timestamp;
|
||||
|
||||
// @HiveField(6, defaultValue: '')
|
||||
String dirPath;
|
||||
|
||||
// @HiveField(7, defaultValue: '')
|
||||
String path;
|
||||
|
||||
// @HiveField(8, defaultValue: '')
|
||||
String address;
|
||||
|
||||
// @HiveField(10)
|
||||
Map<String, String>? addresses;
|
||||
|
||||
// @HiveField(11)
|
||||
String? yatEid;
|
||||
|
||||
// @HiveField(12)
|
||||
String? yatLastUsedAddressRaw;
|
||||
|
||||
// @HiveField(13)
|
||||
bool? showIntroCakePayCard;
|
||||
|
||||
// @HiveField(14)
|
||||
Map<int, List<AddressInfo>>? addressInfos;
|
||||
|
||||
// @HiveField(15)
|
||||
List<String>? usedAddresses;
|
||||
|
||||
@deprecated
|
||||
// @HiveField(16)
|
||||
newWi.DerivationType? derivationType; // no longer used
|
||||
|
||||
@deprecated
|
||||
// @HiveField(17)
|
||||
String? derivationPath; // no longer used
|
||||
|
||||
// @HiveField(18)
|
||||
String? addressPageType;
|
||||
|
||||
// @HiveField(19)
|
||||
String? network;
|
||||
|
||||
// @HiveField(20)
|
||||
DerivationInfo? derivationInfo;
|
||||
|
||||
// @HiveField(21)
|
||||
newWi.HardwareWalletType? hardwareWalletType;
|
||||
|
||||
// @HiveField(22)
|
||||
String? parentAddress;
|
||||
|
||||
// @HiveField(23)
|
||||
List<String>? hiddenAddresses;
|
||||
|
||||
// @HiveField(24)
|
||||
List<String>? manualAddresses;
|
||||
|
||||
// @HiveField(25)
|
||||
String? hashedWalletIdentifier;
|
||||
|
||||
// @HiveField(26, defaultValue: false)
|
||||
bool isNonSeedWallet;
|
||||
|
||||
String get yatLastUsedAddress => yatLastUsedAddressRaw ?? '';
|
||||
|
||||
set yatLastUsedAddress(String address) {
|
||||
yatLastUsedAddressRaw = address;
|
||||
_yatLastUsedAddressController.add(address);
|
||||
}
|
||||
|
||||
String get yatEmojiId => yatEid ?? '';
|
||||
|
||||
bool get isShowIntroCakePayCard {
|
||||
if (showIntroCakePayCard == null) {
|
||||
return type != WalletType.haven;
|
||||
}
|
||||
return showIntroCakePayCard!;
|
||||
}
|
||||
|
||||
bool get isHardwareWallet => hardwareWalletType != null;
|
||||
|
||||
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||
|
||||
Stream<String> get yatLastUsedAddressStream => _yatLastUsedAddressController.stream;
|
||||
|
||||
StreamController<String> _yatLastUsedAddressController;
|
||||
|
||||
Future<void> updateRestoreHeight(int height) async {
|
||||
restoreHeight = height;
|
||||
await save();
|
||||
}
|
||||
|
||||
Future<void> migrateToSqlite() async {
|
||||
final di = newWi.DerivationInfo(
|
||||
id: 0,
|
||||
derivationType: derivationInfo?.derivationType ?? derivationType ?? newWi.DerivationType.unknown,
|
||||
derivationPath: derivationInfo?.derivationPath ?? derivationPath ?? '',
|
||||
);
|
||||
final derivationInfoId = await di.save();
|
||||
final walletInfo = newWi.WalletInfo(
|
||||
0,
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
isRecovery,
|
||||
restoreHeight,
|
||||
timestamp,
|
||||
dirPath,
|
||||
path,
|
||||
address,
|
||||
yatEid,
|
||||
yatLastUsedAddressRaw,
|
||||
showIntroCakePayCard,
|
||||
derivationInfoId,
|
||||
hardwareWalletType,
|
||||
parentAddress,
|
||||
hashedWalletIdentifier,
|
||||
isNonSeedWallet,
|
||||
0,
|
||||
);
|
||||
final wiId = await walletInfo.save();
|
||||
for (final address in usedAddresses ?? <String>[]) {
|
||||
await newWi.WalletInfoAddress.insert(wiId, newWi.WalletInfoAddressType.used, address);
|
||||
}
|
||||
for (final address in hiddenAddresses ?? <String>[]) {
|
||||
await newWi.WalletInfoAddress.insert(wiId, newWi.WalletInfoAddressType.hidden, address);
|
||||
}
|
||||
for (final address in manualAddresses ?? <String>[]) {
|
||||
await newWi.WalletInfoAddress.insert(wiId, newWi.WalletInfoAddressType.manual, address);
|
||||
}
|
||||
for (int i = 0; i < (addressInfos?.length ?? 0); i++) {
|
||||
for (final address in addressInfos![i] ?? <AddressInfo>[]) {
|
||||
await newWi.WalletInfoAddressInfo.insert(
|
||||
walletInfoId: wiId,
|
||||
mapKey: i,
|
||||
accountIndex: address.accountIndex??0,
|
||||
address: address.address,
|
||||
label: address.label,
|
||||
);
|
||||
}
|
||||
}
|
||||
await walletInfo.setAddresses(addresses ?? <String, String>{});
|
||||
}
|
||||
|
||||
static Future<void> migrateAllToSqlite(final Box<WalletInfo> box) async {
|
||||
printV('Migrating WalletInfo to SQLite: start');
|
||||
final sw = Stopwatch()..start();
|
||||
final list = box.values.toList();
|
||||
for (final wi in list) {
|
||||
await wi.migrateToSqlite();
|
||||
await wi.delete();
|
||||
}
|
||||
printV('Migrating WalletInfo to SQLite: end (${sw.elapsedMilliseconds}ms)');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'wallet_info_legacy.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class DerivationInfoAdapter extends TypeAdapter<DerivationInfo> {
|
||||
@override
|
||||
final int typeId = 17;
|
||||
|
||||
@override
|
||||
DerivationInfo read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return DerivationInfo(
|
||||
derivationType: fields[3] as newWi.DerivationType?,
|
||||
derivationPath: fields[4] as String?,
|
||||
balance: fields[1] == null ? '' : fields[1] as String,
|
||||
address: fields[0] == null ? '' : fields[0] as String,
|
||||
transactionsCount: fields[2] == null ? 0 : fields[2] as int,
|
||||
scriptType: fields[5] as String?,
|
||||
description: fields[6] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, DerivationInfo obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(0)
|
||||
..write(obj.address)
|
||||
..writeByte(1)
|
||||
..write(obj.balance)
|
||||
..writeByte(2)
|
||||
..write(obj.transactionsCount)
|
||||
..writeByte(3)
|
||||
..write(obj.derivationType)
|
||||
..writeByte(4)
|
||||
..write(obj.derivationPath)
|
||||
..writeByte(5)
|
||||
..write(obj.scriptType)
|
||||
..writeByte(6)
|
||||
..write(obj.description);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is DerivationInfoAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class WalletInfoAdapter extends TypeAdapter<WalletInfo> {
|
||||
@override
|
||||
final int typeId = 4;
|
||||
|
||||
@override
|
||||
WalletInfo read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return WalletInfo(
|
||||
fields[0] == null ? '' : fields[0] as String,
|
||||
fields[1] == null ? '' : fields[1] as String,
|
||||
fields[2] as WalletType,
|
||||
fields[3] == null ? false : fields[3] as bool,
|
||||
fields[4] == null ? 0 : fields[4] as int,
|
||||
fields[5] == null ? 0 : fields[5] as int,
|
||||
fields[6] == null ? '' : fields[6] as String,
|
||||
fields[7] == null ? '' : fields[7] as String,
|
||||
fields[8] == null ? '' : fields[8] as String,
|
||||
fields[11] as String?,
|
||||
fields[12] as String?,
|
||||
fields[13] as bool?,
|
||||
fields[20] as DerivationInfo?,
|
||||
fields[21] as newWi.HardwareWalletType?,
|
||||
fields[22] as String?,
|
||||
fields[25] as String?,
|
||||
fields[26] == null ? false : fields[26] as bool,
|
||||
)
|
||||
..addresses = (fields[10] as Map?)?.cast<String, String>()
|
||||
..addressInfos = (fields[14] as Map?)?.map((dynamic k, dynamic v) =>
|
||||
MapEntry(k as int, (v as List).cast<AddressInfo>()))
|
||||
..usedAddresses = (fields[15] as List?)?.cast<String>()
|
||||
..derivationType = fields[16] as newWi.DerivationType?
|
||||
..derivationPath = fields[17] as String?
|
||||
..addressPageType = fields[18] as String?
|
||||
..network = fields[19] as String?
|
||||
..hiddenAddresses = (fields[23] as List?)?.cast<String>()
|
||||
..manualAddresses = (fields[24] as List?)?.cast<String>();
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, WalletInfo obj) {
|
||||
writer
|
||||
..writeByte(26)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.name)
|
||||
..writeByte(2)
|
||||
..write(obj.type)
|
||||
..writeByte(3)
|
||||
..write(obj.isRecovery)
|
||||
..writeByte(4)
|
||||
..write(obj.restoreHeight)
|
||||
..writeByte(5)
|
||||
..write(obj.timestamp)
|
||||
..writeByte(6)
|
||||
..write(obj.dirPath)
|
||||
..writeByte(7)
|
||||
..write(obj.path)
|
||||
..writeByte(8)
|
||||
..write(obj.address)
|
||||
..writeByte(10)
|
||||
..write(obj.addresses)
|
||||
..writeByte(11)
|
||||
..write(obj.yatEid)
|
||||
..writeByte(12)
|
||||
..write(obj.yatLastUsedAddressRaw)
|
||||
..writeByte(13)
|
||||
..write(obj.showIntroCakePayCard)
|
||||
..writeByte(14)
|
||||
..write(obj.addressInfos)
|
||||
..writeByte(15)
|
||||
..write(obj.usedAddresses)
|
||||
..writeByte(16)
|
||||
..write(obj.derivationType)
|
||||
..writeByte(17)
|
||||
..write(obj.derivationPath)
|
||||
..writeByte(18)
|
||||
..write(obj.addressPageType)
|
||||
..writeByte(19)
|
||||
..write(obj.network)
|
||||
..writeByte(20)
|
||||
..write(obj.derivationInfo)
|
||||
..writeByte(21)
|
||||
..write(obj.hardwareWalletType)
|
||||
..writeByte(22)
|
||||
..write(obj.parentAddress)
|
||||
..writeByte(23)
|
||||
..write(obj.hiddenAddresses)
|
||||
..writeByte(24)
|
||||
..write(obj.manualAddresses)
|
||||
..writeByte(25)
|
||||
..write(obj.hashedWalletIdentifier)
|
||||
..writeByte(26)
|
||||
..write(obj.isNonSeedWallet);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is WalletInfoAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class DerivationTypeAdapter extends TypeAdapter<newWi.DerivationType> {
|
||||
@override
|
||||
final int typeId = 15;
|
||||
|
||||
@override
|
||||
newWi.DerivationType read(BinaryReader reader) {
|
||||
switch (reader.readByte()) {
|
||||
case 0:
|
||||
return newWi.DerivationType.unknown;
|
||||
case 1:
|
||||
return newWi.DerivationType.def;
|
||||
case 2:
|
||||
return newWi.DerivationType.nano;
|
||||
case 3:
|
||||
return newWi.DerivationType.bip39;
|
||||
case 4:
|
||||
return newWi.DerivationType.electrum;
|
||||
default:
|
||||
return newWi.DerivationType.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, newWi.DerivationType obj) {
|
||||
switch (obj) {
|
||||
case newWi.DerivationType.unknown:
|
||||
writer.writeByte(0);
|
||||
break;
|
||||
case newWi.DerivationType.def:
|
||||
writer.writeByte(1);
|
||||
break;
|
||||
case newWi.DerivationType.nano:
|
||||
writer.writeByte(2);
|
||||
break;
|
||||
case newWi.DerivationType.bip39:
|
||||
writer.writeByte(3);
|
||||
break;
|
||||
case newWi.DerivationType.electrum:
|
||||
writer.writeByte(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is DerivationTypeAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class HardwareWalletTypeAdapter extends TypeAdapter<newWi.HardwareWalletType> {
|
||||
@override
|
||||
final int typeId = 19;
|
||||
|
||||
@override
|
||||
newWi.HardwareWalletType read(BinaryReader reader) {
|
||||
switch (reader.readByte()) {
|
||||
case 0:
|
||||
return newWi.HardwareWalletType.ledger;
|
||||
case 1:
|
||||
return newWi.HardwareWalletType.bitbox;
|
||||
case 2:
|
||||
return newWi.HardwareWalletType.cupcake;
|
||||
case 3:
|
||||
return newWi.HardwareWalletType.coldcard;
|
||||
case 4:
|
||||
return newWi.HardwareWalletType.seedsigner;
|
||||
case 5:
|
||||
return newWi.HardwareWalletType.keystone;
|
||||
case 6:
|
||||
return newWi.HardwareWalletType.trezor;
|
||||
default:
|
||||
return newWi.HardwareWalletType.ledger;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, newWi.HardwareWalletType obj) {
|
||||
switch (obj) {
|
||||
case newWi.HardwareWalletType.ledger:
|
||||
writer.writeByte(0);
|
||||
break;
|
||||
case newWi.HardwareWalletType.bitbox:
|
||||
writer.writeByte(1);
|
||||
break;
|
||||
case newWi.HardwareWalletType.cupcake:
|
||||
writer.writeByte(2);
|
||||
break;
|
||||
case newWi.HardwareWalletType.coldcard:
|
||||
writer.writeByte(3);
|
||||
break;
|
||||
case newWi.HardwareWalletType.seedsigner:
|
||||
writer.writeByte(4);
|
||||
break;
|
||||
case newWi.HardwareWalletType.keystone:
|
||||
writer.writeByte(5);
|
||||
break;
|
||||
case newWi.HardwareWalletType.trezor:
|
||||
writer.writeByte(6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is HardwareWalletTypeAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -64,5 +64,5 @@ abstract class WalletService<N extends WalletCredentials, RFS extends WalletCred
|
||||
|
||||
/// Check if the Wallet requires a hardware wallet to be connected during
|
||||
/// the opening flow. (Currently only the case for Monero)
|
||||
bool requireHardwareWalletConnection(String name) => false;
|
||||
Future<bool> requireHardwareWalletConnection(String name) async => false;
|
||||
}
|
||||
|
||||
@@ -674,6 +674,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.1"
|
||||
sqflite:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sqflite
|
||||
sha256: "2d7299468485dca85efeeadf5d38986909c5eb0cd71fd3db2c2f000e6c9454bb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
sqflite_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_android
|
||||
sha256: "78f489aab276260cdd26676d2169446c7ecd3484bbd5fead4ca14f3ed4dd9ee3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
sqflite_common:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_common
|
||||
sha256: "761b9740ecbd4d3e66b8916d784e581861fd3c3553eda85e167bc49fdb68f709"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.4+6"
|
||||
sqflite_common_ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sqflite_common_ffi
|
||||
sha256: "883dd810b2b49e6e8c3b980df1829ef550a94e3f87deab5d864917d27ca6bf36"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.4+4"
|
||||
sqflite_darwin:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_darwin
|
||||
sha256: "22adfd9a2c7d634041e96d6241e6e1c8138ca6817018afc5d443fef91dcefa9c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1+1"
|
||||
sqflite_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_platform_interface
|
||||
sha256: "8dd4515c7bdcae0a785b0062859336de775e8c65db81ae33dd5445f35be61920"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
sqlite3:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqlite3
|
||||
sha256: f393d92c71bdcc118d6203d07c991b9be0f84b1a6f89dd4f7eed348131329924
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.9.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -706,6 +762,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
synchronized:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: synchronized
|
||||
sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.3.0+3"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -14,7 +14,7 @@ dependencies:
|
||||
sdk: flutter
|
||||
http: ^1.1.0
|
||||
file: ^7.0.0
|
||||
path_provider: ^2.0.11
|
||||
path_provider: ^2.1.5
|
||||
mobx: ^2.0.7+4
|
||||
flutter_mobx: ^2.0.6+1
|
||||
intl: any
|
||||
@@ -44,6 +44,8 @@ dependencies:
|
||||
git:
|
||||
url: https://github.com/cake-tech/blockchain_utils
|
||||
ref: cake-update-v2
|
||||
sqflite: ^2.4.1
|
||||
sqflite_common_ffi: ^2.3.4+4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user