various other structure fixes and updates

This commit is contained in:
julian 2023-11-06 15:37:44 -06:00
parent daa9ccd099
commit dd73a0f86b
9 changed files with 34 additions and 96 deletions

View file

@ -29,7 +29,7 @@ import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart'; import 'package:stackwallet/wallets/wallet/mixins/multi_address.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
@ -60,10 +60,9 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {
late final ClipboardInterface clipboard; late final ClipboardInterface clipboard;
Future<void> generateNewAddress() async { Future<void> generateNewAddress() async {
// TODO: [prio=med] handle other wallet cases
final wallet = ref.read(pWallets).getWallet(walletId); final wallet = ref.read(pWallets).getWallet(walletId);
if (wallet is Bip39HDWallet) { if (wallet is MultiAddress) {
bool shouldPop = false; bool shouldPop = false;
unawaited( unawaited(
showDialog( showDialog(

View file

@ -60,58 +60,6 @@ import 'package:stackwallet/widgets/crypto_notifications.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
const int MINIMUM_CONFIRMATIONS = 1;
final Amount DUST_LIMIT = Amount(
rawValue: BigInt.from(294),
fractionDigits: Coin.bitcoin.decimals,
);
final Amount DUST_LIMIT_P2PKH = Amount(
rawValue: BigInt.from(546),
fractionDigits: Coin.bitcoin.decimals,
);
const String GENESIS_HASH_MAINNET =
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
const String GENESIS_HASH_TESTNET =
"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
String constructDerivePath({
required DerivePathType derivePathType,
required int networkWIF,
int account = 0,
required int chain,
required int index,
}) {
String coinType;
switch (networkWIF) {
case 0x80: // btc mainnet wif
coinType = "0"; // btc mainnet
break;
case 0xef: // btc testnet wif
coinType = "1"; // btc testnet
break;
default:
throw Exception("Invalid Bitcoin network wif used!");
}
int purpose;
switch (derivePathType) {
case DerivePathType.bip44:
purpose = 44;
break;
case DerivePathType.bip49:
purpose = 49;
break;
case DerivePathType.bip84:
purpose = 84;
break;
default:
throw Exception("DerivePathType $derivePathType not supported");
}
return "m/$purpose'/$coinType'/$account'/$chain/$index";
}
class BitcoinWallet extends CoinServiceAPI class BitcoinWallet extends CoinServiceAPI
with with
WalletCache, WalletCache,

View file

@ -29,7 +29,6 @@ import 'package:stackwallet/services/coins/nano/nano_wallet.dart';
import 'package:stackwallet/services/coins/particl/particl_wallet.dart'; import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
import 'package:stackwallet/services/coins/stellar/stellar_wallet.dart'; import 'package:stackwallet/services/coins/stellar/stellar_wallet.dart';
import 'package:stackwallet/services/coins/tezos/tezos_wallet.dart'; import 'package:stackwallet/services/coins/tezos/tezos_wallet.dart';
import 'package:stackwallet/services/coins/wownero/wownero_wallet.dart';
import 'package:stackwallet/services/transaction_notification_tracker.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
@ -248,13 +247,7 @@ abstract class CoinServiceAPI {
); );
case Coin.wownero: case Coin.wownero:
return WowneroWallet( throw UnimplementedError("moved");
walletId: walletId,
walletName: walletName,
coin: coin,
secureStorage: secureStorageInterface,
// tracker: tracker,
);
case Coin.namecoin: case Coin.namecoin:
return NamecoinWallet( return NamecoinWallet(

View file

@ -2,7 +2,6 @@ import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart'; import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart'; import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
@ -14,12 +13,7 @@ class BitcoinWallet extends Bip39HDWallet with ElectrumXMixin {
@override @override
int get isarTransactionVersion => 2; int get isarTransactionVersion => 2;
BitcoinWallet( BitcoinWallet(Bitcoin cryptoCurrency) : super(cryptoCurrency);
Bitcoin cryptoCurrency, {
required NodeService nodeService,
}) : super(cryptoCurrency) {
this.nodeService = nodeService;
}
// =========================================================================== // ===========================================================================
@ -114,4 +108,10 @@ class BitcoinWallet extends Bip39HDWallet with ElectrumXMixin {
fractionDigits: info.coin.decimals, fractionDigits: info.coin.decimals,
); );
} }
@override
Future<void> checkReceivingAddressForTransactions() {
// TODO: implement checkReceivingAddressForTransactions
throw UnimplementedError();
}
} }

View file

@ -9,7 +9,6 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2
import 'package:stackwallet/services/coins/bitcoincash/bch_utils.dart'; import 'package:stackwallet/services/coins/bitcoincash/bch_utils.dart';
import 'package:stackwallet/services/coins/bitcoincash/cashtokens.dart' import 'package:stackwallet/services/coins/bitcoincash/cashtokens.dart'
as cash_tokens; as cash_tokens;
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
@ -23,12 +22,7 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumXMixin {
@override @override
int get isarTransactionVersion => 2; int get isarTransactionVersion => 2;
BitcoincashWallet( BitcoincashWallet(Bitcoincash cryptoCurrency) : super(cryptoCurrency);
Bitcoincash cryptoCurrency, {
required NodeService nodeService,
}) : super(cryptoCurrency) {
this.nodeService = nodeService;
}
// =========================================================================== // ===========================================================================
@ -392,4 +386,10 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumXMixin {
fractionDigits: info.coin.decimals, fractionDigits: info.coin.decimals,
); );
} }
@override
Future<void> checkReceivingAddressForTransactions() {
// TODO: implement checkReceivingAddressForTransactions
throw UnimplementedError();
}
} }

View file

@ -1,6 +1,5 @@
import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart'; import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/test_epic_box_connection.dart'; import 'package:stackwallet/utilities/test_epic_box_connection.dart';
@ -9,12 +8,7 @@ import 'package:stackwallet/wallets/models/tx_data.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
class EpiccashWallet extends Bip39Wallet { class EpiccashWallet extends Bip39Wallet {
late final NodeService nodeService; EpiccashWallet(Epiccash cryptoCurrency) : super(cryptoCurrency);
EpiccashWallet(
Epiccash cryptoCurrency, {
required this.nodeService,
}) : super(cryptoCurrency);
@override @override
Future<TxData> confirmSend({required TxData txData}) { Future<TxData> confirmSend({required TxData txData}) {

View file

@ -8,14 +8,17 @@ import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/wallets/crypto_currency/intermediate/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/models/tx_data.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart'; import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
import 'package:stackwallet/wallets/wallet/mixins/multi_address.dart';
abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T> { abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T>
with MultiAddress<T> {
Bip39HDWallet(T cryptoCurrency) : super(cryptoCurrency); Bip39HDWallet(T cryptoCurrency) : super(cryptoCurrency);
/// Generates a receiving address of [info.mainAddressType]. If none /// Generates a receiving address of [info.mainAddressType]. If none
/// are in the current wallet db it will generate at index 0, otherwise the /// are in the current wallet db it will generate at index 0, otherwise the
/// highest index found in the current wallet db. /// highest index found in the current wallet db.
Future<Address> generateNewReceivingAddress() async { @override
Future<void> generateNewReceivingAddress() async {
final current = await getCurrentReceivingAddress(); final current = await getCurrentReceivingAddress();
final index = current?.derivationIndex ?? 0; final index = current?.derivationIndex ?? 0;
const chain = 0; // receiving address const chain = 0; // receiving address
@ -51,8 +54,6 @@ abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T> {
newAddress: address.value, newAddress: address.value,
isar: mainDB.isar, isar: mainDB.isar,
); );
return address;
} }
// ========== Private ======================================================== // ========== Private ========================================================

View file

@ -8,9 +8,7 @@ import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart'; import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
@ -19,7 +17,6 @@ import 'package:uuid/uuid.dart';
mixin ElectrumXMixin on Bip39HDWallet { mixin ElectrumXMixin on Bip39HDWallet {
late ElectrumX electrumX; late ElectrumX electrumX;
late CachedElectrumX electrumXCached; late CachedElectrumX electrumXCached;
late NodeService nodeService;
Future<int> fetchChainHeight() async { Future<int> fetchChainHeight() async {
try { try {
@ -79,9 +76,8 @@ mixin ElectrumXMixin on Bip39HDWallet {
return txnsData; return txnsData;
} }
Future<ElectrumXNode> getCurrentNode() async { Future<ElectrumXNode> getCurrentElectrumXNode() async {
final node = nodeService.getPrimaryNodeFor(coin: cryptoCurrency.coin) ?? final node = getCurrentNode();
DefaultNodes.getNodeFor(cryptoCurrency.coin);
return ElectrumXNode( return ElectrumXNode(
address: node.host, address: node.host,
@ -104,7 +100,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
)) ))
.toList(); .toList();
final newNode = await getCurrentNode(); final newNode = await getCurrentElectrumXNode();
electrumX = ElectrumX.from( electrumX = ElectrumX.from(
node: newNode, node: newNode,
prefs: prefs, prefs: prefs,
@ -471,7 +467,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
@override @override
Future<void> updateNode() async { Future<void> updateNode() async {
final node = await getCurrentNode(); final node = await getCurrentElectrumXNode();
await updateElectrumX(newNode: node); await updateElectrumX(newNode: node);
} }

View file

@ -0,0 +1,7 @@
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/wallets/wallet/wallet.dart';
mixin MultiAddress<T extends CryptoCurrency> on Wallet<T> {
Future<void> generateNewReceivingAddress();
Future<void> checkReceivingAddressForTransactions();
}