stack_wallet/lib/services/mixins/wallet_db.dart

33 lines
870 B
Dart
Raw Normal View History

2023-01-12 18:46:01 +00:00
import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/utilities/stack_file_system.dart';
mixin WalletDB {
Isar? _isar;
Isar get isar => _isar!;
/// open the db if it was not already open
/// returns true if the db was not yet open
/// returns false if the db was already open
Future<bool> isarInit(String walletId) async {
if (_isar != null && isar.isOpen) return false;
_isar = await Isar.open(
[
TransactionSchema,
TransactionNoteSchema,
InputSchema,
OutputSchema,
UTXOSchema,
AddressSchema,
],
directory: (await StackFileSystem.applicationIsarDirectory()).path,
inspector: true,
2023-01-12 18:46:01 +00:00
name: walletId,
);
return true;
}
Future<bool> isarClose() async => await _isar?.close() ?? false;
}