mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
* feat(zcash): initial commit - initial work on cw_zcash - use single .db for everything zcash to speed up sync and scanning - implement silent autoshielding of non-orchard funds - use FFI for everything to fetch the data - add support for passphrase by adding extra word to seed phrase - enforce lints on CI for cw_zcash directory - use correct zcash name, and call transparent zcash tZEC - minor cleanups outsite of cw_zcash - gitmodules, gitignore - db debug - fix broken addressPageType in WalletInfo - enable debug options in kDebugMode and kProfileMode * feat: T address rotation (and cache) wip: minor fixes * wip: shield tx list * fix fiat amounts fix derrivation of rotation account addresses screen for zcash block height fix T address shields improvements Amount in disposable T shields UI improvements show pending outgoing tx in tx history * fix null check on passphrase page fix tx showing as pending rename auto shield txs fixed send all to include fee use rotating address in addressForExchange wrap all calls of WarpApi.getLatestHeight in try catch to prevent leaking errors other minor fixes from notion * wallet group debug cache sent tx address wallet T address rotation fixes automatically pick the fee for auto-shield * fix T address cache deserialization fix autoshield icon fix autoshield text getCachedDestinationAddress fix send address cache * address comments from review * wip: iOS fix * fix swap * Allow cakepay payment from zcash wallet * fix: ios (I'm stupid) fix: reorder addresses to make orchard default fix: send all balance * 5.6.6 bump fix: ios apple review add transport error to ignored exceptions * fix: leaving dust behind when sweeping all * Change wallets order * fix: reflect balance of pending out txs fix: restore height support * linux support (disabled) * fix: date picker for zcash on restore screen fix: build script for linux match WarpApi.warpSync args with upstream * fix: linter script * ensure all exchange providers support ZEC (#2802) * ensure all exchange providers support ZEC * remove zaddr and tzec currencies and refactor providers * Update lib/exchange/provider/near_Intents_exchange_provider.dart * add back old zcash currencies for backward compatibility, thanks Czarek * minor fix [skip ci] --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update android/app/src/main/AndroidManifestBase.xml [skip ci] * Update ios/Runner/InfoBase.plist [skip ci] * fix: remove unused code fix: macos fix: disable on linux and macos * update build numbers [skip ci] * Add zcash to birdpay --------- Co-authored-by: Czarek Nakamoto <cyjan@mrcyjanek.net> Co-authored-by: Serhii <borodenko.sv@gmail.com>
140 lines
3.9 KiB
Dart
140 lines
3.9 KiB
Dart
|
|
import 'dart:io';
|
|
|
|
import 'package:cw_core/root_dir.dart';
|
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
|
|
|
late Database db;
|
|
|
|
Future<void> initDb({String? pathOverride}) async {
|
|
if (Platform.isLinux || Platform.isWindows) {
|
|
databaseFactory = databaseFactoryFfi;
|
|
}
|
|
|
|
// getAppDir is predictable on all platforms and ensures the db gets included in backups.
|
|
final dbFileOld = File("${await getDatabasesPath()}/cake.db");
|
|
final dbFile = File("${(await getAppDir()).path}/cake.db");
|
|
|
|
if (Platform.isAndroid && dbFileOld.existsSync() && dbFileOld.path != dbFile.path) {
|
|
final copied = dbFileOld.copySync(dbFile.path);
|
|
if (copied.existsSync()) {
|
|
dbFileOld.deleteSync();
|
|
}
|
|
}
|
|
|
|
db = await openDatabase(dbFile.path, 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(Database db) 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(db);
|
|
final ret = <String, dynamic>{};
|
|
for (final tableName in tableNames) {
|
|
ret[tableName] = await db.query(tableName);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> dumpCustomDb(String path) async {
|
|
final db = await openDatabase(path);
|
|
final tableNames = await _getTableNames(db);
|
|
final ret = <String, dynamic>{};
|
|
for (final tableName in tableNames) {
|
|
ret[tableName] = await db.query(tableName);
|
|
}
|
|
return ret;
|
|
} |