Skip to content

Commit f5f4567

Browse files
authored
Merge pull request #1135 from cypherstack/testing
Testing
2 parents 53cac99 + 3743590 commit f5f4567

File tree

146 files changed

+19523
-16989
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+19523
-16989
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ linter:
9292
constant_identifier_names: false
9393
prefer_final_locals: true
9494
prefer_final_in_for_each: true
95-
require_trailing_commas: true
95+
# require_trailing_commas: true // causes issues with dart 3.7
9696
# avoid_print: false # Uncomment to disable the `avoid_print` rule
9797
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
9898

lib/db/drift/database.dart

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* This file is part of Stack Wallet.
3+
*
4+
* Copyright (c) 2025 Cypher Stack
5+
* All Rights Reserved.
6+
* The code is distributed under GPLv3 license, see LICENSE file for details.
7+
* Generated by Cypher Stack on 2025-05-06
8+
*
9+
*/
10+
11+
import 'dart:async';
12+
13+
import 'package:drift/drift.dart';
14+
import 'package:drift_flutter/drift_flutter.dart';
15+
import 'package:path/path.dart' as path;
16+
17+
import '../../utilities/stack_file_system.dart';
18+
19+
part 'database.g.dart';
20+
21+
abstract final class Drift {
22+
static bool _didInit = false;
23+
24+
static final Map<String, WalletDatabase> _map = {};
25+
26+
static WalletDatabase get(String walletId) {
27+
if (!_didInit) {
28+
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
29+
_didInit = true;
30+
}
31+
32+
return _map[walletId] ??= WalletDatabase._(walletId);
33+
}
34+
}
35+
36+
class SparkNames extends Table {
37+
TextColumn get name =>
38+
text().customConstraint("UNIQUE NOT NULL COLLATE NOCASE")();
39+
TextColumn get address => text()();
40+
IntColumn get validUntil => integer()();
41+
TextColumn get additionalInfo => text().nullable()();
42+
43+
@override
44+
Set<Column> get primaryKey => {name};
45+
}
46+
47+
@DriftDatabase(tables: [SparkNames])
48+
final class WalletDatabase extends _$WalletDatabase {
49+
WalletDatabase._(String walletId, [QueryExecutor? executor])
50+
: super(executor ?? _openConnection(walletId));
51+
52+
@override
53+
int get schemaVersion => 1;
54+
55+
static QueryExecutor _openConnection(String walletId) {
56+
return driftDatabase(
57+
name: walletId,
58+
native: DriftNativeOptions(
59+
shareAcrossIsolates: true,
60+
databasePath: () async {
61+
final dir = await StackFileSystem.applicationDriftDirectory();
62+
return path.join(dir.path, "wallets", walletId, "$walletId.db");
63+
},
64+
),
65+
);
66+
}
67+
68+
Future<void> upsertSparkNames(
69+
List<
70+
({String name, String address, int validUntil, String? additionalInfo})
71+
>
72+
names,
73+
) async {
74+
await transaction(() async {
75+
for (final name in names) {
76+
await into(sparkNames).insertOnConflictUpdate(
77+
SparkNamesCompanion(
78+
name: Value(name.name),
79+
address: Value(name.address),
80+
validUntil: Value(name.validUntil),
81+
additionalInfo: Value(name.additionalInfo),
82+
),
83+
);
84+
}
85+
});
86+
}
87+
}

0 commit comments

Comments
 (0)