mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
extract wallet isar db to mixin
This commit is contained in:
parent
ccb9f254bd
commit
3f830218a4
11 changed files with 96 additions and 248 deletions
|
@ -23,6 +23,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
|
@ -37,7 +39,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -138,7 +139,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class BitcoinWallet extends CoinServiceAPI {
|
||||
class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
|
||||
|
@ -218,7 +219,7 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -674,7 +675,7 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
p2wpkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2wpkhReceiveAddressArray);
|
||||
|
@ -1173,22 +1174,6 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1200,7 +1185,7 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1277,8 +1262,6 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
BitcoinWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1493,7 +1476,7 @@ class BitcoinWallet extends CoinServiceAPI {
|
|||
_generateAddressForChain(1, 0, DerivePathType.bip49),
|
||||
]);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(initialAddresses);
|
||||
|
|
|
@ -25,6 +25,7 @@ import 'package:stackwallet/services/event_bus/events/global/updated_in_backgrou
|
|||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -38,7 +39,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -127,7 +127,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
||||
class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
final _prefs = Prefs.instance;
|
||||
|
@ -187,7 +187,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -610,7 +610,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
p2shChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2pkhReceiveAddressArray);
|
||||
|
@ -1095,22 +1095,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1128,7 +1112,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1232,8 +1216,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
BitcoinCashWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1408,7 +1390,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache {
|
|||
_generateAddressForChain(1, 0, DerivePathType.bip49),
|
||||
]);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(initialAddresses);
|
||||
|
|
|
@ -24,6 +24,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -37,7 +39,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -124,7 +125,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class DogecoinWallet extends CoinServiceAPI {
|
||||
class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
final _prefs = Prefs.instance;
|
||||
|
@ -185,7 +186,7 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -525,7 +526,7 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
p2pkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2pkhChangeAddressArray);
|
||||
|
@ -998,22 +999,6 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1025,7 +1010,7 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1102,8 +1087,6 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
DogecoinWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1262,7 +1245,7 @@ class DogecoinWallet extends CoinServiceAPI {
|
|||
final initialChangeAddressP2PKH =
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip44);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll([
|
||||
|
|
|
@ -23,6 +23,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||
|
@ -515,7 +517,7 @@ Future<dynamic> deleteSlate(
|
|||
}
|
||||
}
|
||||
|
||||
class EpicCashWallet extends CoinServiceAPI {
|
||||
class EpicCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
final m = Mutex();
|
||||
|
@ -525,8 +527,6 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
|
||||
NodeModel? _epicNode;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
EpicCashWallet(
|
||||
{required String walletId,
|
||||
required String walletName,
|
||||
|
@ -956,22 +956,6 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
return;
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet",
|
||||
|
@ -991,7 +975,7 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
}
|
||||
await _prefs.init();
|
||||
await updateNode(false);
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
await _refreshBalance();
|
||||
// TODO: is there anything else that should be set up here whenever this wallet is first loaded again?
|
||||
}
|
||||
|
@ -1090,7 +1074,7 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
await DB.instance
|
||||
.put<dynamic>(boxName: walletId, key: "isFavorite", value: false);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
bool refreshMutex = false;
|
||||
|
|
|
@ -26,6 +26,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -39,7 +41,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -745,7 +746,7 @@ Future<void> _setTestnetWrapper(bool isTestnet) async {
|
|||
}
|
||||
|
||||
/// Handles a single instance of a firo wallet
|
||||
class FiroWallet extends CoinServiceAPI {
|
||||
class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
|
||||
|
@ -1221,8 +1222,6 @@ class FiroWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
late TransactionNotificationTracker txTracker;
|
||||
|
||||
// Constructor
|
||||
|
@ -1837,22 +1836,6 @@ class FiroWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log(
|
||||
|
@ -1865,7 +1848,7 @@ class FiroWallet extends CoinServiceAPI {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
Future<bool> refreshIfThereIsNewData() async {
|
||||
|
@ -2138,7 +2121,7 @@ class FiroWallet extends CoinServiceAPI {
|
|||
final initialReceivingAddress = await _generateAddressForChain(0, 0);
|
||||
final initialChangeAddress = await _generateAddressForChain(1, 0);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll([
|
||||
|
@ -4279,7 +4262,7 @@ class FiroWallet extends CoinServiceAPI {
|
|||
Logging.instance
|
||||
.log("PROCESSORS ${Platform.numberOfProcessors}", level: LogLevel.Info);
|
||||
try {
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
final latestSetId = await getLatestSetId();
|
||||
final setDataMap = getSetDataMap(latestSetId);
|
||||
|
|
|
@ -24,6 +24,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -36,7 +38,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -137,7 +138,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class LitecoinWallet extends CoinServiceAPI {
|
||||
class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
|
||||
|
@ -217,7 +218,7 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -691,7 +692,7 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
p2wpkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2wpkhReceiveAddressArray);
|
||||
|
@ -1190,22 +1191,6 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1216,7 +1201,7 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1293,8 +1278,6 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
LitecoinWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1509,7 +1492,7 @@ class LitecoinWallet extends CoinServiceAPI {
|
|||
_generateAddressForChain(1, 0, DerivePathType.bip49),
|
||||
]);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(initialAddresses);
|
||||
|
|
|
@ -34,6 +34,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||
|
@ -47,14 +49,12 @@ import 'package:stackwallet/utilities/stack_file_system.dart';
|
|||
|
||||
const int MINIMUM_CONFIRMATIONS = 10;
|
||||
|
||||
class MoneroWallet extends CoinServiceAPI {
|
||||
class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
final String _walletId;
|
||||
final Coin _coin;
|
||||
final SecureStorageInterface _secureStorage;
|
||||
final Prefs _prefs;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
String _walletName;
|
||||
bool _shouldAutoSync = false;
|
||||
bool _isConnected = false;
|
||||
|
@ -87,22 +87,6 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
_secureStorage = secureStorage,
|
||||
_prefs = prefs ?? Prefs.instance;
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isFavorite {
|
||||
try {
|
||||
|
@ -222,7 +206,7 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
_autoSaveTimer?.cancel();
|
||||
await walletBase?.save(prioritySave: true);
|
||||
walletBase?.close();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +270,7 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
keysStorage = KeyService(_secureStorage);
|
||||
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
// final data =
|
||||
// DB.instance.get<dynamic>(boxName: walletId, key: "latest_tx_model")
|
||||
// as TransactionData?;
|
||||
|
@ -421,7 +405,7 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
// Generate and add addresses to relevant arrays
|
||||
final initialReceivingAddress = await _generateAddressForChain(0, 0);
|
||||
// final initialChangeAddress = await _generateAddressForChain(1, 0);
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.put(initialReceivingAddress);
|
||||
|
|
|
@ -24,6 +24,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -36,7 +38,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -134,7 +135,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class NamecoinWallet extends CoinServiceAPI {
|
||||
class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
|
||||
|
@ -212,7 +213,7 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -681,7 +682,7 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
p2wpkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2wpkhReceiveAddressArray);
|
||||
|
@ -1180,22 +1181,6 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1206,7 +1191,7 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1283,8 +1268,6 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
NamecoinWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1487,7 +1470,7 @@ class NamecoinWallet extends CoinServiceAPI {
|
|||
_generateAddressForChain(1, 0, DerivePathType.bip49),
|
||||
]);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(initialAddresses);
|
||||
|
|
|
@ -23,6 +23,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/notifications_api.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -35,7 +37,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
@ -130,7 +131,7 @@ bip32.BIP32 getBip32RootWrapper(Tuple2<String, NetworkType> args) {
|
|||
return getBip32Root(args.item1, args.item2);
|
||||
}
|
||||
|
||||
class ParticlWallet extends CoinServiceAPI {
|
||||
class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
static const integrationTestFlag =
|
||||
bool.fromEnvironment("IS_INTEGRATION_TEST");
|
||||
|
||||
|
@ -207,7 +208,7 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
timer?.cancel();
|
||||
timer = null;
|
||||
stopNetworkAlivePinging();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
|
||||
bool _hasCalledExit = false;
|
||||
|
@ -615,7 +616,7 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
p2wpkhChangeAddressArray.add(address);
|
||||
}
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(p2wpkhReceiveAddressArray);
|
||||
|
@ -1109,22 +1110,6 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
]);
|
||||
}
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> initializeExisting() async {
|
||||
Logging.instance.log("Opening existing ${coin.prettyName} wallet.",
|
||||
|
@ -1135,7 +1120,7 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
}
|
||||
|
||||
// TODO make sure this copied implementation from bitcoin_wallet.dart applies for particl just as well--or import it
|
||||
|
@ -1213,8 +1198,6 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
|
||||
late SecureStorageInterface _secureStore;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
ParticlWallet({
|
||||
required String walletId,
|
||||
required String walletName,
|
||||
|
@ -1399,7 +1382,7 @@ class ParticlWallet extends CoinServiceAPI {
|
|||
_generateAddressForChain(1, 0, DerivePathType.bip44),
|
||||
]);
|
||||
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.putAll(initialAddresses);
|
||||
|
|
|
@ -36,6 +36,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
|
|||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||
|
@ -49,14 +51,12 @@ import 'package:stackwallet/utilities/stack_file_system.dart';
|
|||
|
||||
const int MINIMUM_CONFIRMATIONS = 10;
|
||||
|
||||
class WowneroWallet extends CoinServiceAPI {
|
||||
class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||
final String _walletId;
|
||||
final Coin _coin;
|
||||
final SecureStorageInterface _secureStorage;
|
||||
final Prefs _prefs;
|
||||
|
||||
late Isar isar;
|
||||
|
||||
String _walletName;
|
||||
bool _shouldAutoSync = false;
|
||||
bool _isConnected = false;
|
||||
|
@ -89,22 +89,6 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
_secureStorage = secureStorage,
|
||||
_prefs = prefs ?? Prefs.instance;
|
||||
|
||||
Future<void> _isarInit() async {
|
||||
isar = await Isar.open(
|
||||
[
|
||||
isar_models.TransactionSchema,
|
||||
isar_models.TransactionNoteSchema,
|
||||
isar_models.InputSchema,
|
||||
isar_models.OutputSchema,
|
||||
isar_models.UTXOSchema,
|
||||
isar_models.AddressSchema,
|
||||
],
|
||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||
inspector: false,
|
||||
name: walletId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isFavorite {
|
||||
try {
|
||||
|
@ -245,7 +229,7 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
_autoSaveTimer?.cancel();
|
||||
await walletBase?.save(prioritySave: true);
|
||||
walletBase?.close();
|
||||
await isar.close();
|
||||
await isarClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,13 +294,7 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
keysStorage = KeyService(_secureStorage);
|
||||
|
||||
await _prefs.init();
|
||||
await _isarInit();
|
||||
// final data =
|
||||
// DB.instance.get<dynamic>(boxName: walletId, key: "latest_tx_model")
|
||||
// as TransactionData?;
|
||||
// if (data != null) {
|
||||
// _transactionData = Future(() => data);
|
||||
// }
|
||||
await isarInit(walletId);
|
||||
|
||||
String? password;
|
||||
try {
|
||||
|
@ -331,16 +309,6 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
"Opened existing ${coin.prettyName} wallet $walletName",
|
||||
level: LogLevel.Info,
|
||||
);
|
||||
// Wallet already exists, triggers for a returning user
|
||||
//
|
||||
// String indexKey = "receivingIndex";
|
||||
// final curIndex =
|
||||
// await DB.instance.get<dynamic>(boxName: walletId, key: indexKey) as int;
|
||||
// // Use new index to derive a new receiving address
|
||||
// final newReceivingAddress = await _generateAddressForChain(0, curIndex);
|
||||
// Logging.instance.log(
|
||||
// "wownero address in init existing: $newReceivingAddress",
|
||||
// level: LogLevel.Info);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -436,7 +404,7 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
// Generate and add addresses to relevant arrays
|
||||
final initialReceivingAddress = await _generateAddressForChain(0, 0);
|
||||
// final initialChangeAddress = await _generateAddressForChain(1, 0);
|
||||
await _isarInit();
|
||||
await isarInit(walletId);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.addresses.put(initialReceivingAddress);
|
||||
|
|
32
lib/services/mixins/wallet_db.dart
Normal file
32
lib/services/mixins/wallet_db.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
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: false,
|
||||
name: walletId,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> isarClose() async => await _isar?.close() ?? false;
|
||||
}
|
Loading…
Reference in a new issue