Skip to content

Commit 10aa19f

Browse files
committed
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
1 parent 6b7f4a9 commit 10aa19f

24 files changed

+444
-374
lines changed

cw_bitcoin/lib/bitcoin_wallet_creation_credentials.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class BitcoinNewWalletCredentials extends WalletCredentials {
1616
walletInfo: walletInfo,
1717
password: password,
1818
passphrase: passphrase,
19+
derivationInfo: DerivationInfo(
20+
derivationType: derivationType,
21+
derivationPath: derivationPath,
22+
),
1923
);
2024

2125
final String? mnemonic;

cw_bitcoin/lib/bitcoin_wallet_service.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class BitcoinWalletService extends WalletService<
3939

4040
final String mnemonic;
4141
final derivationInfo = await credentials.walletInfo!.getDerivationInfo();
42+
derivationInfo.derivationType = credentials.derivationInfo?.derivationType ?? derivationInfo.derivationType;
43+
derivationInfo.derivationPath = credentials.derivationInfo?.derivationPath ?? derivationInfo.derivationPath;
44+
derivationInfo.description = credentials.derivationInfo?.description ?? derivationInfo.description;
45+
derivationInfo.scriptType = credentials.derivationInfo?.scriptType ?? derivationInfo.scriptType;
46+
await derivationInfo.save();
4247
switch (derivationInfo.derivationType) {
4348
case DerivationType.bip39:
4449
final strength = credentials.seedPhraseLength == 24 ? 256 : 128;

cw_bitcoin/lib/litecoin_wallet_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LitecoinWalletService extends WalletService<
5050
password: credentials.password!,
5151
passphrase: credentials.passphrase,
5252
walletInfo: credentials.walletInfo!,
53-
derivationInfo: credentials.derivationInfo!,
53+
derivationInfo: credentials.derivationInfo ?? (await credentials.walletInfo!.getDerivationInfo()),
5454
unspentCoinsInfo: unspentCoinsInfoSource,
5555
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
5656
);
@@ -202,7 +202,7 @@ class LitecoinWalletService extends WalletService<
202202
passphrase: credentials.passphrase,
203203
mnemonic: credentials.mnemonic,
204204
walletInfo: credentials.walletInfo!,
205-
derivationInfo: credentials.derivationInfo!,
205+
derivationInfo: credentials.derivationInfo ?? (await credentials.walletInfo!.getDerivationInfo()),
206206
unspentCoinsInfo: unspentCoinsInfoSource,
207207
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
208208
);

cw_bitcoin/pubspec.lock

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ packages:
4242
dependency: transitive
4343
description:
4444
name: async
45-
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
45+
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
4646
url: "https://pub.dev"
4747
source: hosted
48-
version: "2.11.0"
48+
version: "2.12.0"
4949
bbqrdart:
5050
dependency: "direct main"
5151
description:
@@ -119,10 +119,10 @@ packages:
119119
dependency: transitive
120120
description:
121121
name: boolean_selector
122-
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
122+
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
123123
url: "https://pub.dev"
124124
source: hosted
125-
version: "2.1.1"
125+
version: "2.1.2"
126126
bs58check:
127127
dependency: transitive
128128
description:
@@ -216,10 +216,10 @@ packages:
216216
dependency: transitive
217217
description:
218218
name: characters
219-
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
219+
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
220220
url: "https://pub.dev"
221221
source: hosted
222-
version: "1.3.0"
222+
version: "1.4.0"
223223
checked_yaml:
224224
dependency: transitive
225225
description:
@@ -240,10 +240,10 @@ packages:
240240
dependency: transitive
241241
description:
242242
name: clock
243-
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
243+
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
244244
url: "https://pub.dev"
245245
source: hosted
246-
version: "1.1.1"
246+
version: "1.1.2"
247247
code_builder:
248248
dependency: transitive
249249
description:
@@ -256,10 +256,10 @@ packages:
256256
dependency: transitive
257257
description:
258258
name: collection
259-
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
259+
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
260260
url: "https://pub.dev"
261261
source: hosted
262-
version: "1.19.0"
262+
version: "1.19.1"
263263
convert:
264264
dependency: transitive
265265
description:
@@ -350,10 +350,10 @@ packages:
350350
dependency: transitive
351351
description:
352352
name: fake_async
353-
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
353+
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
354354
url: "https://pub.dev"
355355
source: hosted
356-
version: "1.3.1"
356+
version: "1.3.2"
357357
ffi:
358358
dependency: "direct overridden"
359359
description:
@@ -573,18 +573,18 @@ packages:
573573
dependency: transitive
574574
description:
575575
name: leak_tracker
576-
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
576+
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
577577
url: "https://pub.dev"
578578
source: hosted
579-
version: "10.0.7"
579+
version: "10.0.8"
580580
leak_tracker_flutter_testing:
581581
dependency: transitive
582582
description:
583583
name: leak_tracker_flutter_testing
584-
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
584+
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
585585
url: "https://pub.dev"
586586
source: hosted
587-
version: "3.0.8"
587+
version: "3.0.9"
588588
leak_tracker_testing:
589589
dependency: transitive
590590
description:
@@ -647,10 +647,10 @@ packages:
647647
dependency: transitive
648648
description:
649649
name: matcher
650-
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
650+
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
651651
url: "https://pub.dev"
652652
source: hosted
653-
version: "0.12.16+1"
653+
version: "0.12.17"
654654
material_color_utilities:
655655
dependency: transitive
656656
description:
@@ -663,10 +663,10 @@ packages:
663663
dependency: transitive
664664
description:
665665
name: meta
666-
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
666+
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
667667
url: "https://pub.dev"
668668
source: hosted
669-
version: "1.15.0"
669+
version: "1.16.0"
670670
mime:
671671
dependency: transitive
672672
description:
@@ -720,10 +720,10 @@ packages:
720720
dependency: transitive
721721
description:
722722
name: path
723-
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
723+
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
724724
url: "https://pub.dev"
725725
source: hosted
726-
version: "1.9.0"
726+
version: "1.9.1"
727727
path_provider:
728728
dependency: "direct main"
729729
description:
@@ -992,10 +992,10 @@ packages:
992992
dependency: transitive
993993
description:
994994
name: source_span
995-
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
995+
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
996996
url: "https://pub.dev"
997997
source: hosted
998-
version: "1.10.0"
998+
version: "1.10.1"
999999
sp_scanner:
10001000
dependency: "direct main"
10011001
description:
@@ -1065,18 +1065,18 @@ packages:
10651065
dependency: transitive
10661066
description:
10671067
name: stack_trace
1068-
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
1068+
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
10691069
url: "https://pub.dev"
10701070
source: hosted
1071-
version: "1.12.0"
1071+
version: "1.12.1"
10721072
stream_channel:
10731073
dependency: transitive
10741074
description:
10751075
name: stream_channel
1076-
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
1076+
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
10771077
url: "https://pub.dev"
10781078
source: hosted
1079-
version: "2.1.2"
1079+
version: "2.1.4"
10801080
stream_transform:
10811081
dependency: transitive
10821082
description:
@@ -1089,10 +1089,10 @@ packages:
10891089
dependency: transitive
10901090
description:
10911091
name: string_scanner
1092-
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
1092+
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
10931093
url: "https://pub.dev"
10941094
source: hosted
1095-
version: "1.3.0"
1095+
version: "1.4.1"
10961096
synchronized:
10971097
dependency: transitive
10981098
description:
@@ -1105,18 +1105,18 @@ packages:
11051105
dependency: transitive
11061106
description:
11071107
name: term_glyph
1108-
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
1108+
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
11091109
url: "https://pub.dev"
11101110
source: hosted
1111-
version: "1.2.1"
1111+
version: "1.2.2"
11121112
test_api:
11131113
dependency: transitive
11141114
description:
11151115
name: test_api
1116-
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
1116+
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
11171117
url: "https://pub.dev"
11181118
source: hosted
1119-
version: "0.7.3"
1119+
version: "0.7.4"
11201120
timing:
11211121
dependency: transitive
11221122
description:
@@ -1193,10 +1193,10 @@ packages:
11931193
dependency: transitive
11941194
description:
11951195
name: vm_service
1196-
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
1196+
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
11971197
url: "https://pub.dev"
11981198
source: hosted
1199-
version: "14.3.0"
1199+
version: "14.3.1"
12001200
watcher:
12011201
dependency: "direct overridden"
12021202
description:
@@ -1262,5 +1262,5 @@ packages:
12621262
source: hosted
12631263
version: "2.2.2"
12641264
sdks:
1265-
dart: ">=3.6.2 <4.0.0"
1265+
dart: ">=3.7.0-0 <4.0.0"
12661266
flutter: ">=3.27.0"

cw_core/lib/db/sqlite.dart

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
import 'package:sqflite/sqflite.dart';
3+
4+
late Database db;
5+
6+
Future<void> initDb({String? pathOverride}) async {
7+
db = await openDatabase(
8+
pathOverride ?? "cake.db",
9+
version: 1,
10+
onCreate: (Database db, int version) async {
11+
await db.execute(
12+
'''
13+
CREATE TABLE WalletInfo (
14+
walletInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
15+
id TEXT NOT NULL,
16+
name TEXT NOT NULL,
17+
"type" INTEGER NOT NULL,
18+
isRecovery INTEGER DEFAULT (0) NOT NULL,
19+
walletInfoDerivationInfoId INTEGER NOT NULL,
20+
restoreHeight INTEGER DEFAULT (0) NOT NULL,
21+
"timestamp" INTEGER DEFAULT (0) NOT NULL,
22+
dirPath TEXT NOT NULL,
23+
"path" TEXT NOT NULL,
24+
address TEXT NOT NULL,
25+
yatEid TEXT,
26+
yatLastUsedAddressRaw TEXT,
27+
showIntroCakePayCard INTEGER DEFAULT (1),
28+
addressPageType TEXT,
29+
network TEXT,
30+
hardwareWalletType INTEGER,
31+
parentAddress TEXT,
32+
hashedWalletIdentifier TEXT,
33+
isNonSeedWallet INTEGER DEFAULT (0) NOT NULL,
34+
sortOrder INTEGER DEFAULT (0) NOT NULL
35+
);
36+
''');
37+
38+
await db.execute(
39+
'''
40+
CREATE TABLE WalletInfoDerivationInfo (
41+
walletInfoDerivationInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
42+
address TEXT NOT NULL,
43+
balance TEXT NOT NULL,
44+
transactionsCount INTEGER DEFAULT (0) NOT NULL,
45+
derivationType INTEGER NOT NULL,
46+
derivationPath TEXT,
47+
scriptType TEXT,
48+
description TEXT
49+
);
50+
''');
51+
52+
await db.execute(
53+
'''
54+
CREATE TABLE WalletInfoAddress (
55+
walletInfoAddressId INTEGER PRIMARY KEY AUTOINCREMENT,
56+
walletInfoId INTEGER,
57+
"type" INTEGER NOT NULL,
58+
address TEXT NOT NULL,
59+
CONSTRAINT WalletInfoAddress_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
60+
);
61+
''');
62+
63+
await db.execute(
64+
'''
65+
CREATE TABLE WalletInfoAddressInfo (
66+
walletInfoAddressInfoId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
67+
walletInfoId INTEGER NOT NULL,
68+
mapKey INTEGER NOT NULL,
69+
mapValueAccountIndex INTEGER NOT NULL,
70+
mapValueAddress TEXT NOT NULL,
71+
mapValueLabel TEXT NOT NULL,
72+
CONSTRAINT WalletInfoAddressInfo_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
73+
);
74+
''');
75+
76+
await db.execute(
77+
'''
78+
CREATE TABLE "WalletInfoAddressMap" (
79+
walletInfoAddressMapId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
80+
walletInfoId INTEGER NOT NULL,
81+
addressKey TEXT NOT NULL,
82+
addressValue TEXT NOT NULL,
83+
CONSTRAINT WalletInfoAddress_WalletInfo_FK FOREIGN KEY (walletInfoId) REFERENCES WalletInfo(walletInfoId)
84+
);
85+
'''
86+
);
87+
}
88+
);
89+
}
90+
91+
Future<Map<String, dynamic>> dumpDb() async {
92+
try {
93+
return await _dumpDb();
94+
} catch (e) {
95+
return {
96+
"error": e.toString(),
97+
"stackTrace": StackTrace.current.toString(),
98+
};
99+
}
100+
}
101+
102+
Future<List<String>> _getTableNames() async {
103+
final tableNames = await db.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
104+
return tableNames.map((e) => (e["name"]).toString()).toList();
105+
}
106+
107+
Future<Map<String, dynamic>> _dumpDb() async {
108+
final tableNames = await _getTableNames();
109+
final ret = <String, dynamic>{};
110+
for (final tableName in tableNames) {
111+
ret[tableName] = await db.query(tableName);
112+
}
113+
return ret;
114+
}

0 commit comments

Comments
 (0)