From ad0059508c26104ea3b5f1f1889690c4b322f15a Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 Feb 2023 16:48:16 -0600 Subject: [PATCH] move wallet constructors below class declaration --- .../coins/bitcoin/bitcoin_wallet.dart | 88 +++++++++---------- .../coins/bitcoincash/bitcoincash_wallet.dart | 42 ++++----- .../coins/dogecoin/dogecoin_wallet.dart | 84 +++++++++--------- .../coins/epiccash/epiccash_wallet.dart | 18 ++-- lib/services/coins/firo/firo_wallet.dart | 62 ++++++------- .../coins/litecoin/litecoin_wallet.dart | 42 ++++----- lib/services/coins/monero/monero_wallet.dart | 34 +++---- .../coins/namecoin/namecoin_wallet.dart | 42 ++++----- .../coins/particl/particl_wallet.dart | 42 ++++----- .../coins/wownero/wownero_wallet.dart | 34 +++---- 10 files changed, 245 insertions(+), 243 deletions(-) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index a9b6620b0..ac42df4bb 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -95,6 +95,50 @@ String constructDerivePath({ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB, ElectrumXParsing, PaynymWalletInterface { + BitcoinWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + initPaynymWalletInterface( + walletId: walletId, + walletName: walletName, + network: _network, + coin: coin, + db: db, + electrumXClient: electrumXClient, + secureStorage: secureStore, + getMnemonicString: () => mnemonicString, + getMnemonicPassphrase: () => mnemonicPassphrase, + getChainHeight: () => chainHeight, + getCurrentChangeAddress: () => currentChangeAddressP2PKH, + estimateTxFee: estimateTxFee, + prepareSend: prepareSend, + getTxCount: getTxCount, + fetchBuildTxData: fetchBuildTxData, + refresh: refresh, + checkChangeAddressForTransactions: + _checkP2PKHChangeAddressForTransactions, + addDerivation: addDerivation, + dustLimitP2PKH: DUST_LIMIT_P2PKH, + minConfirms: MINIMUM_CONFIRMATIONS, + ); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); @@ -1296,50 +1340,6 @@ class BitcoinWallet extends CoinServiceAPI late SecureStorageInterface _secureStore; - BitcoinWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - initPaynymWalletInterface( - walletId: walletId, - walletName: walletName, - network: _network, - coin: coin, - db: db, - electrumXClient: electrumXClient, - secureStorage: secureStore, - getMnemonicString: () => mnemonicString, - getMnemonicPassphrase: () => mnemonicPassphrase, - getChainHeight: () => chainHeight, - getCurrentChangeAddress: () => currentChangeAddressP2PKH, - estimateTxFee: estimateTxFee, - prepareSend: prepareSend, - getTxCount: getTxCount, - fetchBuildTxData: fetchBuildTxData, - refresh: refresh, - checkChangeAddressForTransactions: - _checkP2PKHChangeAddressForTransactions, - addDerivation: addDerivation, - dustLimitP2PKH: DUST_LIMIT_P2PKH, - minConfirms: MINIMUM_CONFIRMATIONS, - ); - } - @override Future updateNode(bool shouldRefresh) async { final failovers = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index e56511732..098f93b3e 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -89,6 +89,27 @@ String constructDerivePath({ } class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { + BitcoinCashWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); final _prefs = Prefs.instance; @@ -1266,27 +1287,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { late SecureStorageInterface _secureStore; - BitcoinCashWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } - @override Future updateNode(bool shouldRefresh) async { final failovers = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index a262efc4d..4f2ca7090 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -86,6 +86,48 @@ String constructDerivePath({ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB, ElectrumXParsing { + DogecoinWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + + // paynym stuff + // initPaynymWalletInterface( + // walletId: walletId, + // walletName: walletName, + // network: network, + // coin: coin, + // db: db, + // electrumXClient: electrumXClient, + // getMnemonic: () => mnemonic, + // getChainHeight: () => chainHeight, + // getCurrentChangeAddress: () => currentChangeAddress, + // estimateTxFee: estimateTxFee, + // prepareSend: prepareSend, + // getTxCount: getTxCount, + // fetchBuildTxData: fetchBuildTxData, + // refresh: refresh, + // checkChangeAddressForTransactions: checkChangeAddressForTransactions, + // addDerivation: addDerivation, + // addDerivations: addDerivations, + // ); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); final _prefs = Prefs.instance; @@ -1093,48 +1135,6 @@ class DogecoinWallet extends CoinServiceAPI late SecureStorageInterface _secureStore; - DogecoinWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - - // paynym stuff - // initPaynymWalletInterface( - // walletId: walletId, - // walletName: walletName, - // network: network, - // coin: coin, - // db: db, - // electrumXClient: electrumXClient, - // getMnemonic: () => mnemonic, - // getChainHeight: () => chainHeight, - // getCurrentChangeAddress: () => currentChangeAddress, - // estimateTxFee: estimateTxFee, - // prepareSend: prepareSend, - // getTxCount: getTxCount, - // fetchBuildTxData: fetchBuildTxData, - // refresh: refresh, - // checkChangeAddressForTransactions: checkChangeAddressForTransactions, - // addDerivation: addDerivation, - // addDerivations: addDerivations, - // ); - } - @override Future updateNode(bool shouldRefresh) async { final failovers = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index e6c9deab9..85c5ec046 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -520,15 +520,6 @@ Future deleteSlate( class EpicCashWallet extends CoinServiceAPI with WalletCache, WalletDB, EpicCashHive { - static const integrationTestFlag = - bool.fromEnvironment("IS_INTEGRATION_TEST"); - final m = Mutex(); - final syncMutex = Mutex(); - - final _prefs = Prefs.instance; - - NodeModel? _epicNode; - EpicCashWallet({ required String walletId, required String walletName, @@ -552,6 +543,15 @@ class EpicCashWallet extends CoinServiceAPI isolates.clear(); } + static const integrationTestFlag = + bool.fromEnvironment("IS_INTEGRATION_TEST"); + final m = Mutex(); + final syncMutex = Mutex(); + + final _prefs = Prefs.instance; + + NodeModel? _epicNode; + @override Future updateNode(bool shouldRefresh) async { _epicNode = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index d2a01b27f..2a34b6a62 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -772,6 +772,37 @@ Future _setTestnetWrapper(bool isTestnet) async { /// Handles a single instance of a firo wallet class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive { + // Constructor + FiroWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initFiroHive(walletId); + initWalletDB(mockableOverride: mockableOverride); + + Logging.instance.log("$walletName isolates length: ${isolates.length}", + level: LogLevel.Info); + // investigate possible issues killing shared isolates between multiple firo instances + for (final isolate in isolates.values) { + isolate.kill(priority: Isolate.immediate); + } + isolates.clear(); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); @@ -1238,37 +1269,6 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive { late TransactionNotificationTracker txTracker; - // Constructor - FiroWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initFiroHive(walletId); - initWalletDB(mockableOverride: mockableOverride); - - Logging.instance.log("$walletName isolates length: ${isolates.length}", - level: LogLevel.Info); - // investigate possible issues killing shared isolates between multiple firo instances - for (final isolate in isolates.values) { - isolate.kill(priority: Isolate.immediate); - } - isolates.clear(); - } - int estimateTxFee({required int vSize, required int feeRatePerKB}) { return vSize * (feeRatePerKB / 1000).ceil(); } diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index 3e8d90879..5141f0a3a 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -91,6 +91,27 @@ String constructDerivePath({ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB, ElectrumXParsing { + LitecoinWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); @@ -1242,26 +1263,7 @@ class LitecoinWallet extends CoinServiceAPI late SecureStorageInterface _secureStore; - LitecoinWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } + @override Future updateNode(bool shouldRefresh) async { diff --git a/lib/services/coins/monero/monero_wallet.dart b/lib/services/coins/monero/monero_wallet.dart index 29e456b62..886bda1b8 100644 --- a/lib/services/coins/monero/monero_wallet.dart +++ b/lib/services/coins/monero/monero_wallet.dart @@ -52,6 +52,23 @@ import 'package:tuple/tuple.dart'; const int MINIMUM_CONFIRMATIONS = 10; class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB { + MoneroWallet({ + required String walletId, + required String walletName, + required Coin coin, + required SecureStorageInterface secureStorage, + Prefs? prefs, + MainDB? mockableOverride, + }) { + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _secureStorage = secureStorage; + _prefs = prefs ?? Prefs.instance; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + late final String _walletId; late final Coin _coin; late final SecureStorageInterface _secureStorage; @@ -78,23 +95,6 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB { Mutex prepareSendMutex = Mutex(); Mutex estimateFeeMutex = Mutex(); - MoneroWallet({ - required String walletId, - required String walletName, - required Coin coin, - required SecureStorageInterface secureStorage, - Prefs? prefs, - MainDB? mockableOverride, - }) { - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _secureStorage = secureStorage; - _prefs = prefs ?? Prefs.instance; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } - @override set isFavorite(bool markFavorite) { _isFavorite = markFavorite; diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 91862e165..43982875e 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -88,6 +88,27 @@ String constructDerivePath({ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB, ElectrumXParsing { + NamecoinWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); @@ -1232,27 +1253,6 @@ class NamecoinWallet extends CoinServiceAPI late SecureStorageInterface _secureStore; - NamecoinWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } - @override Future updateNode(bool shouldRefresh) async { final failovers = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index 75e029ea4..6b0275fdc 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -82,6 +82,27 @@ String constructDerivePath({ } class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { + ParticlWallet({ + required String walletId, + required String walletName, + required Coin coin, + required ElectrumX client, + required CachedElectrumX cachedClient, + required TransactionNotificationTracker tracker, + required SecureStorageInterface secureStore, + MainDB? mockableOverride, + }) { + txTracker = tracker; + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _electrumXClient = client; + _cachedElectrumXClient = cachedClient; + _secureStore = secureStore; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + static const integrationTestFlag = bool.fromEnvironment("IS_INTEGRATION_TEST"); @@ -1159,27 +1180,6 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { late SecureStorageInterface _secureStore; - ParticlWallet({ - required String walletId, - required String walletName, - required Coin coin, - required ElectrumX client, - required CachedElectrumX cachedClient, - required TransactionNotificationTracker tracker, - required SecureStorageInterface secureStore, - MainDB? mockableOverride, - }) { - txTracker = tracker; - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _electrumXClient = client; - _cachedElectrumXClient = cachedClient; - _secureStore = secureStore; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } - @override Future updateNode(bool shouldRefresh) async { final failovers = NodeService(secureStorageInterface: _secureStore) diff --git a/lib/services/coins/wownero/wownero_wallet.dart b/lib/services/coins/wownero/wownero_wallet.dart index 9a326c881..12343f036 100644 --- a/lib/services/coins/wownero/wownero_wallet.dart +++ b/lib/services/coins/wownero/wownero_wallet.dart @@ -54,6 +54,23 @@ import 'package:tuple/tuple.dart'; const int MINIMUM_CONFIRMATIONS = 10; class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB { + WowneroWallet({ + required String walletId, + required String walletName, + required Coin coin, + required SecureStorageInterface secureStorage, + Prefs? prefs, + MainDB? mockableOverride, + }) { + _walletId = walletId; + _walletName = walletName; + _coin = coin; + _secureStorage = secureStorage; + _prefs = prefs ?? Prefs.instance; + initCache(walletId, coin); + initWalletDB(mockableOverride: mockableOverride); + } + late final String _walletId; late final Coin _coin; late final SecureStorageInterface _secureStorage; @@ -80,23 +97,6 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB { Mutex prepareSendMutex = Mutex(); Mutex estimateFeeMutex = Mutex(); - WowneroWallet({ - required String walletId, - required String walletName, - required Coin coin, - required SecureStorageInterface secureStorage, - Prefs? prefs, - MainDB? mockableOverride, - }) { - _walletId = walletId; - _walletName = walletName; - _coin = coin; - _secureStorage = secureStorage; - _prefs = prefs ?? Prefs.instance; - initCache(walletId, coin); - initWalletDB(mockableOverride: mockableOverride); - } - @override set isFavorite(bool markFavorite) { _isFavorite = markFavorite;