mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
various other structure fixes and updates
This commit is contained in:
parent
daa9ccd099
commit
dd73a0f86b
9 changed files with 34 additions and 96 deletions
|
@ -29,7 +29,7 @@ import 'package:stackwallet/utilities/constants.dart';
|
|||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.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/custom_buttons/app_bar_icon_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;
|
||||
|
||||
Future<void> generateNewAddress() async {
|
||||
// TODO: [prio=med] handle other wallet cases
|
||||
final wallet = ref.read(pWallets).getWallet(walletId);
|
||||
|
||||
if (wallet is Bip39HDWallet) {
|
||||
if (wallet is MultiAddress) {
|
||||
bool shouldPop = false;
|
||||
unawaited(
|
||||
showDialog(
|
||||
|
|
|
@ -60,58 +60,6 @@ import 'package:stackwallet/widgets/crypto_notifications.dart';
|
|||
import 'package:tuple/tuple.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
|
||||
with
|
||||
WalletCache,
|
||||
|
|
|
@ -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/stellar/stellar_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/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -248,13 +247,7 @@ abstract class CoinServiceAPI {
|
|||
);
|
||||
|
||||
case Coin.wownero:
|
||||
return WowneroWallet(
|
||||
walletId: walletId,
|
||||
walletName: walletName,
|
||||
coin: coin,
|
||||
secureStorage: secureStorageInterface,
|
||||
// tracker: tracker,
|
||||
);
|
||||
throw UnimplementedError("moved");
|
||||
|
||||
case Coin.namecoin:
|
||||
return NamecoinWallet(
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:isar/isar.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/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
|
||||
|
@ -14,12 +13,7 @@ class BitcoinWallet extends Bip39HDWallet with ElectrumXMixin {
|
|||
@override
|
||||
int get isarTransactionVersion => 2;
|
||||
|
||||
BitcoinWallet(
|
||||
Bitcoin cryptoCurrency, {
|
||||
required NodeService nodeService,
|
||||
}) : super(cryptoCurrency) {
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
BitcoinWallet(Bitcoin cryptoCurrency) : super(cryptoCurrency);
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
|
@ -114,4 +108,10 @@ class BitcoinWallet extends Bip39HDWallet with ElectrumXMixin {
|
|||
fractionDigits: info.coin.decimals,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> checkReceivingAddressForTransactions() {
|
||||
// TODO: implement checkReceivingAddressForTransactions
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/cashtokens.dart'
|
||||
as cash_tokens;
|
||||
import 'package:stackwallet/services/node_service.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';
|
||||
|
@ -23,12 +22,7 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumXMixin {
|
|||
@override
|
||||
int get isarTransactionVersion => 2;
|
||||
|
||||
BitcoincashWallet(
|
||||
Bitcoincash cryptoCurrency, {
|
||||
required NodeService nodeService,
|
||||
}) : super(cryptoCurrency) {
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
BitcoincashWallet(Bitcoincash cryptoCurrency) : super(cryptoCurrency);
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
|
@ -392,4 +386,10 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumXMixin {
|
|||
fractionDigits: info.coin.decimals,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> checkReceivingAddressForTransactions() {
|
||||
// TODO: implement checkReceivingAddressForTransactions
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
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/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';
|
||||
|
@ -9,12 +8,7 @@ import 'package:stackwallet/wallets/models/tx_data.dart';
|
|||
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
|
||||
|
||||
class EpiccashWallet extends Bip39Wallet {
|
||||
late final NodeService nodeService;
|
||||
|
||||
EpiccashWallet(
|
||||
Epiccash cryptoCurrency, {
|
||||
required this.nodeService,
|
||||
}) : super(cryptoCurrency);
|
||||
EpiccashWallet(Epiccash cryptoCurrency) : super(cryptoCurrency);
|
||||
|
||||
@override
|
||||
Future<TxData> confirmSend({required TxData txData}) {
|
||||
|
|
|
@ -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/models/tx_data.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);
|
||||
|
||||
/// Generates a receiving address of [info.mainAddressType]. If none
|
||||
/// are in the current wallet db it will generate at index 0, otherwise the
|
||||
/// highest index found in the current wallet db.
|
||||
Future<Address> generateNewReceivingAddress() async {
|
||||
@override
|
||||
Future<void> generateNewReceivingAddress() async {
|
||||
final current = await getCurrentReceivingAddress();
|
||||
final index = current?.derivationIndex ?? 0;
|
||||
const chain = 0; // receiving address
|
||||
|
@ -51,8 +54,6 @@ abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T> {
|
|||
newAddress: address.value,
|
||||
isar: mainDB.isar,
|
||||
);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
// ========== Private ========================================================
|
||||
|
|
|
@ -8,9 +8,7 @@ import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
|||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.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/default_nodes.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
|
||||
|
@ -19,7 +17,6 @@ import 'package:uuid/uuid.dart';
|
|||
mixin ElectrumXMixin on Bip39HDWallet {
|
||||
late ElectrumX electrumX;
|
||||
late CachedElectrumX electrumXCached;
|
||||
late NodeService nodeService;
|
||||
|
||||
Future<int> fetchChainHeight() async {
|
||||
try {
|
||||
|
@ -79,9 +76,8 @@ mixin ElectrumXMixin on Bip39HDWallet {
|
|||
return txnsData;
|
||||
}
|
||||
|
||||
Future<ElectrumXNode> getCurrentNode() async {
|
||||
final node = nodeService.getPrimaryNodeFor(coin: cryptoCurrency.coin) ??
|
||||
DefaultNodes.getNodeFor(cryptoCurrency.coin);
|
||||
Future<ElectrumXNode> getCurrentElectrumXNode() async {
|
||||
final node = getCurrentNode();
|
||||
|
||||
return ElectrumXNode(
|
||||
address: node.host,
|
||||
|
@ -104,7 +100,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
|
|||
))
|
||||
.toList();
|
||||
|
||||
final newNode = await getCurrentNode();
|
||||
final newNode = await getCurrentElectrumXNode();
|
||||
electrumX = ElectrumX.from(
|
||||
node: newNode,
|
||||
prefs: prefs,
|
||||
|
@ -471,7 +467,7 @@ mixin ElectrumXMixin on Bip39HDWallet {
|
|||
|
||||
@override
|
||||
Future<void> updateNode() async {
|
||||
final node = await getCurrentNode();
|
||||
final node = await getCurrentElectrumXNode();
|
||||
await updateElectrumX(newNode: node);
|
||||
}
|
||||
|
||||
|
|
7
lib/wallets/wallet/mixins/multi_address.dart
Normal file
7
lib/wallets/wallet/mixins/multi_address.dart
Normal 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();
|
||||
}
|
Loading…
Reference in a new issue