From e6556de97e854b4d0c69719c511b74a108909700 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 6 Nov 2023 12:26:33 -0600 Subject: [PATCH] refactor wallet constructors and add wownero shell --- .../crypto_currency/coins/bitcoin.dart | 2 +- .../crypto_currency/coins/bitcoincash.dart | 2 +- .../crypto_currency/coins/epiccash.dart | 2 +- .../crypto_currency/coins/wownero.dart | 19 +++++++ .../{ => intermediate}/bip39_currency.dart | 0 .../{ => intermediate}/bip39_hd_currency.dart | 2 +- .../intermediate/cryptonote_currency.dart | 5 ++ lib/wallets/wallet/impl/bitcoin_wallet.dart | 7 +-- .../wallet/impl/bitcoincash_wallet.dart | 7 +-- lib/wallets/wallet/impl/epiccash_wallet.dart | 8 ++- lib/wallets/wallet/impl/wownero_wallet.dart | 54 +++++++++++++++++++ .../wallet/intermediate/bip39_hd_wallet.dart | 4 +- .../wallet/intermediate/bip39_wallet.dart | 4 +- .../intermediate/cryptonote_wallet.dart | 20 ++----- .../wallet/mixins/mnemonic_based_wallet.dart | 3 +- 15 files changed, 102 insertions(+), 37 deletions(-) create mode 100644 lib/wallets/crypto_currency/coins/wownero.dart rename lib/wallets/crypto_currency/{ => intermediate}/bip39_currency.dart (100%) rename lib/wallets/crypto_currency/{ => intermediate}/bip39_hd_currency.dart (96%) create mode 100644 lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart create mode 100644 lib/wallets/wallet/impl/wownero_wallet.dart diff --git a/lib/wallets/crypto_currency/coins/bitcoin.dart b/lib/wallets/crypto_currency/coins/bitcoin.dart index 7cc1a690d..8ae233fe0 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin.dart @@ -3,8 +3,8 @@ import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; -import 'package:stackwallet/wallets/crypto_currency/bip39_hd_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_hd_currency.dart'; class Bitcoin extends Bip39HDCurrency { Bitcoin(super.network) { diff --git a/lib/wallets/crypto_currency/coins/bitcoincash.dart b/lib/wallets/crypto_currency/coins/bitcoincash.dart index dca68ac4b..fb70b6153 100644 --- a/lib/wallets/crypto_currency/coins/bitcoincash.dart +++ b/lib/wallets/crypto_currency/coins/bitcoincash.dart @@ -8,8 +8,8 @@ import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; -import 'package:stackwallet/wallets/crypto_currency/bip39_hd_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_hd_currency.dart'; class Bitcoincash extends Bip39HDCurrency { Bitcoincash(super.network) { diff --git a/lib/wallets/crypto_currency/coins/epiccash.dart b/lib/wallets/crypto_currency/coins/epiccash.dart index 68e8d4dfa..88dd391b6 100644 --- a/lib/wallets/crypto_currency/coins/epiccash.dart +++ b/lib/wallets/crypto_currency/coins/epiccash.dart @@ -1,7 +1,7 @@ import 'package:flutter_libepiccash/lib.dart' as epic; import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/wallets/crypto_currency/bip39_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart'; class Epiccash extends Bip39Currency { Epiccash(super.network) { diff --git a/lib/wallets/crypto_currency/coins/wownero.dart b/lib/wallets/crypto_currency/coins/wownero.dart new file mode 100644 index 000000000..48959ad96 --- /dev/null +++ b/lib/wallets/crypto_currency/coins/wownero.dart @@ -0,0 +1,19 @@ +import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart'; + +class Wownero extends CryptonoteCurrency { + Wownero(super.network); + + @override + // TODO: implement genesisHash + String get genesisHash => throw UnimplementedError(); + + @override + // TODO: implement minConfirms + int get minConfirms => throw UnimplementedError(); + + @override + bool validateAddress(String address) { + // TODO: implement validateAddress + throw UnimplementedError(); + } +} diff --git a/lib/wallets/crypto_currency/bip39_currency.dart b/lib/wallets/crypto_currency/intermediate/bip39_currency.dart similarity index 100% rename from lib/wallets/crypto_currency/bip39_currency.dart rename to lib/wallets/crypto_currency/intermediate/bip39_currency.dart diff --git a/lib/wallets/crypto_currency/bip39_hd_currency.dart b/lib/wallets/crypto_currency/intermediate/bip39_hd_currency.dart similarity index 96% rename from lib/wallets/crypto_currency/bip39_hd_currency.dart rename to lib/wallets/crypto_currency/intermediate/bip39_hd_currency.dart index 1f8bd68a5..41920d8e9 100644 --- a/lib/wallets/crypto_currency/bip39_hd_currency.dart +++ b/lib/wallets/crypto_currency/intermediate/bip39_hd_currency.dart @@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; -import 'package:stackwallet/wallets/crypto_currency/bip39_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart'; abstract class Bip39HDCurrency extends Bip39Currency { Bip39HDCurrency(super.network); diff --git a/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart b/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart new file mode 100644 index 000000000..d00b14c03 --- /dev/null +++ b/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart @@ -0,0 +1,5 @@ +import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; + +abstract class CryptonoteCurrency extends CryptoCurrency { + CryptonoteCurrency(super.network); +} diff --git a/lib/wallets/wallet/impl/bitcoin_wallet.dart b/lib/wallets/wallet/impl/bitcoin_wallet.dart index d8f08e046..7bbc8c6b5 100644 --- a/lib/wallets/wallet/impl/bitcoin_wallet.dart +++ b/lib/wallets/wallet/impl/bitcoin_wallet.dart @@ -15,12 +15,9 @@ class BitcoinWallet extends Bip39HDWallet with ElectrumXMixin { int get isarTransactionVersion => 2; BitcoinWallet( - super.cryptoCurrency, { + Bitcoin cryptoCurrency, { required NodeService nodeService, - }) { - // TODO: [prio=low] ensure this hack isn't needed - assert(cryptoCurrency is Bitcoin); - + }) : super(cryptoCurrency) { this.nodeService = nodeService; } diff --git a/lib/wallets/wallet/impl/bitcoincash_wallet.dart b/lib/wallets/wallet/impl/bitcoincash_wallet.dart index fa6d7d399..676ff6b9d 100644 --- a/lib/wallets/wallet/impl/bitcoincash_wallet.dart +++ b/lib/wallets/wallet/impl/bitcoincash_wallet.dart @@ -24,12 +24,9 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumXMixin { int get isarTransactionVersion => 2; BitcoincashWallet( - super.cryptoCurrency, { + Bitcoincash cryptoCurrency, { required NodeService nodeService, - }) { - // TODO: [prio=low] ensure this hack isn't needed - assert(cryptoCurrency is Bitcoincash); - + }) : super(cryptoCurrency) { this.nodeService = nodeService; } diff --git a/lib/wallets/wallet/impl/epiccash_wallet.dart b/lib/wallets/wallet/impl/epiccash_wallet.dart index 814402c94..9269490d2 100644 --- a/lib/wallets/wallet/impl/epiccash_wallet.dart +++ b/lib/wallets/wallet/impl/epiccash_wallet.dart @@ -4,13 +4,17 @@ import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/test_epic_box_connection.dart'; +import 'package:stackwallet/wallets/crypto_currency/coins/epiccash.dart'; import 'package:stackwallet/wallets/models/tx_data.dart'; import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; class EpiccashWallet extends Bip39Wallet { - final NodeService nodeService; + late final NodeService nodeService; - EpiccashWallet(super.cryptoCurrency, {required this.nodeService}); + EpiccashWallet( + Epiccash cryptoCurrency, { + required this.nodeService, + }) : super(cryptoCurrency); @override Future confirmSend({required TxData txData}) { diff --git a/lib/wallets/wallet/impl/wownero_wallet.dart b/lib/wallets/wallet/impl/wownero_wallet.dart new file mode 100644 index 000000000..4a38e759c --- /dev/null +++ b/lib/wallets/wallet/impl/wownero_wallet.dart @@ -0,0 +1,54 @@ +import 'package:stackwallet/models/paymint/fee_object_model.dart'; +import 'package:stackwallet/utilities/amount/amount.dart'; +import 'package:stackwallet/wallets/crypto_currency/coins/wownero.dart'; +import 'package:stackwallet/wallets/wallet/intermediate/cryptonote_wallet.dart'; + +class WowneroWallet extends CryptonoteWallet { + WowneroWallet(Wownero wownero) : super(wownero); + + @override + Future estimateFeeFor(Amount amount, int feeRate) { + // TODO: implement estimateFeeFor + throw UnimplementedError(); + } + + @override + // TODO: implement fees + Future get fees => throw UnimplementedError(); + + @override + Future pingCheck() { + // TODO: implement pingCheck + throw UnimplementedError(); + } + + @override + Future updateBalance() { + // TODO: implement updateBalance + throw UnimplementedError(); + } + + @override + Future updateChainHeight() { + // TODO: implement updateChainHeight + throw UnimplementedError(); + } + + @override + Future updateNode() { + // TODO: implement updateNode + throw UnimplementedError(); + } + + @override + Future updateTransactions() { + // TODO: implement updateTransactions + throw UnimplementedError(); + } + + @override + Future updateUTXOs() { + // TODO: implement updateUTXOs + throw UnimplementedError(); + } +} diff --git a/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart b/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart index 28c05ccf7..f2459124c 100644 --- a/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart +++ b/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart @@ -5,12 +5,12 @@ import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; -import 'package:stackwallet/wallets/crypto_currency/bip39_hd_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_hd_currency.dart'; import 'package:stackwallet/wallets/models/tx_data.dart'; import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; abstract class Bip39HDWallet extends Bip39Wallet { - Bip39HDWallet(super.cryptoCurrency); + Bip39HDWallet(T cryptoCurrency) : super(cryptoCurrency); /// Generates a receiving address of [info.mainAddressType]. If none /// are in the current wallet db it will generate at index 0, otherwise the diff --git a/lib/wallets/wallet/intermediate/bip39_wallet.dart b/lib/wallets/wallet/intermediate/bip39_wallet.dart index b4f79d96a..3e05903f4 100644 --- a/lib/wallets/wallet/intermediate/bip39_wallet.dart +++ b/lib/wallets/wallet/intermediate/bip39_wallet.dart @@ -1,10 +1,10 @@ -import 'package:stackwallet/wallets/crypto_currency/bip39_currency.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart'; import 'package:stackwallet/wallets/wallet/mixins/mnemonic_based_wallet.dart'; import 'package:stackwallet/wallets/wallet/wallet.dart'; abstract class Bip39Wallet extends Wallet with MnemonicBasedWallet { - Bip39Wallet(super.cryptoCurrency); + Bip39Wallet(T currency) : super(currency); // ========== Private ======================================================== diff --git a/lib/wallets/wallet/intermediate/cryptonote_wallet.dart b/lib/wallets/wallet/intermediate/cryptonote_wallet.dart index 4f68d592c..fe50f71c3 100644 --- a/lib/wallets/wallet/intermediate/cryptonote_wallet.dart +++ b/lib/wallets/wallet/intermediate/cryptonote_wallet.dart @@ -1,21 +1,11 @@ -import 'package:stackwallet/exceptions/sw_exception.dart'; +import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart'; import 'package:stackwallet/wallets/models/tx_data.dart'; +import 'package:stackwallet/wallets/wallet/mixins/mnemonic_based_wallet.dart'; import 'package:stackwallet/wallets/wallet/wallet.dart'; -abstract class CryptonoteWallet extends Wallet { - CryptonoteWallet(super.cryptoCurrency); - - Future getMnemonic() async { - final mnemonic = await secureStorageInterface.read( - key: Wallet.mnemonicKey(walletId: info.walletId), - ); - - if (mnemonic == null) { - throw SWException("mnemonic has not been set"); - } - - return mnemonic; - } +abstract class CryptonoteWallet extends Wallet + with MnemonicBasedWallet { + CryptonoteWallet(T currency) : super(currency); // ========== Overrides ====================================================== diff --git a/lib/wallets/wallet/mixins/mnemonic_based_wallet.dart b/lib/wallets/wallet/mixins/mnemonic_based_wallet.dart index 435083d0a..9a7dc9b97 100644 --- a/lib/wallets/wallet/mixins/mnemonic_based_wallet.dart +++ b/lib/wallets/wallet/mixins/mnemonic_based_wallet.dart @@ -1,8 +1,7 @@ import 'package:stackwallet/exceptions/sw_exception.dart'; +import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/wallet/wallet.dart'; -import '../../crypto_currency/crypto_currency.dart'; - mixin MnemonicBasedWallet on Wallet { Future getMnemonic() async { final mnemonic = await secureStorageInterface.read(