apply new cash fusion wallet mixin and some other small clean up

This commit is contained in:
julian 2023-11-14 15:49:37 -06:00
parent 58271caf8a
commit f799b68a69
13 changed files with 34 additions and 193 deletions

View file

@ -20,11 +20,11 @@ import 'package:stackwallet/pages/cashfusion/fusion_rounds_selection_sheet.dart'
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.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';
@ -62,7 +62,7 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
Future<void> _startFusion() async {
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as FusionWalletInterface;
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
try {
fusionWallet.uiState = ref.read(

View file

@ -16,11 +16,11 @@ import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
@ -67,8 +67,8 @@ class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
);
if (shouldCancel == true && mounted) {
final fusionWallet = ref.read(pWallets).getWallet(widget.walletId)
as FusionWalletInterface;
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
await showLoading(
whileFuture: Future.wait([
@ -224,7 +224,7 @@ class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
/// Fuse again.
void _fuseAgain() async {
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as FusionWalletInterface;
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
final fusionInfo = ref.read(prefsChangeNotifierProvider).fusionServerInfo;

View file

@ -9,27 +9,18 @@
*/
import 'dart:async';
import 'dart:typed_data';
import 'package:bitbox/bitbox.dart' as bb;
import 'package:bitcoindart/bitcoindart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx_client.dart';
import 'package:stackwallet/electrumx_rpc/electrumx_client.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/providers/global/debug_service_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
import 'package:stackwallet/services/mixins/electrum_x_parsing.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/address_utils.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/background.dart';
@ -359,75 +350,11 @@ class HiddenSettings extends StatelessWidget {
builder: (_, ref, __) {
return GestureDetector(
onTap: () async {
try {
final p = TT();
final n = ref
.read(nodeServiceChangeNotifierProvider)
.getPrimaryNodeFor(
coin: Coin.bitcoincash)!;
final e = ElectrumXClient.from(
node: ElectrumXNode(
address: n.host,
port: n.port,
name: n.name,
id: n.id,
useSSL: n.useSSL,
),
prefs:
ref.read(prefsChangeNotifierProvider),
failovers: [],
);
final ce =
CachedElectrumXClient(electrumXClient: e);
final txids = [
"", // cashTokenTxid
"6a0444358bc41913c5b04a8dc06896053184b3641bc62502d18f954865b6ce1e", // normalTxid
"67f13c375f9be897036cac77b7900dc74312c4ba6fe22f419f5cb21d4151678c", // fusionTxid
"c0ac3f88b238a023d2a87226dc90c3b0f9abc3eeb227e2730087b0b95ee5b3f9", // slpTokenSendTxid
"7a427a156fe70f83d3ccdd17e75804cc0df8c95c64ce04d256b3851385002a0b", // slpTokenGenesisTxid
];
// final json =
// await e.getTransaction(txHash: txids[1]);
// await p.parseBchTx(json, "NORMAL TXID:");
//
// final json2 =
// await e.getTransaction(txHash: txids[2]);
// await p.parseBchTx(json2, "FUSION TXID:");
//
// // print("CASH TOKEN TXID:");
// // final json3 =
// // await e.getTransaction(txHash: txids[2]);
// // await p.parseBchTx(json3);
//
await p.getTransaction(
txids[3],
Coin.bitcoincash,
"lol",
ce,
"SLP TOKEN SEND TXID:");
await p.getTransaction(
"009d31380d2dbfb5c91500c861d55b531a8b762b0abb19353db884548dbac8b6",
Coin.bitcoincash,
"lol",
ce,
"COINBASE TXID:");
// final json5 =
// await e.getTransaction(txHash: txids[4]);
// await p.parseBchTx(
// json5, "SLP TOKEN GENESIS TXID:");
} catch (e, s) {
print("$e\n$s");
}
//
},
child: RoundedWhiteContainer(
child: Text(
"Parse BCH tx test",
"Do nothing",
style: STextStyles.button(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
@ -444,80 +371,11 @@ class HiddenSettings extends StatelessWidget {
builder: (_, ref, __) {
return GestureDetector(
onTap: () async {
try {
final p = TT();
final n = ref
.read(nodeServiceChangeNotifierProvider)
.getPrimaryNodeFor(
coin: Coin.bitcoincash)!;
final e = ElectrumXClient.from(
node: ElectrumXNode(
address: n.host,
port: n.port,
name: n.name,
id: n.id,
useSSL: n.useSSL,
),
prefs:
ref.read(prefsChangeNotifierProvider),
failovers: [],
);
final address =
"qzmd5vxgh9m22m6fgvm57yd6kjnjl9qnwyztz2p80d";
List<int> _base32Decode(String string) {
final data = Uint8List(string.length);
for (int i = 0; i < string.length; i++) {
final value = string[i];
if (!_CHARSET_INVERSE_INDEX
.containsKey(value))
throw FormatException(
"Invalid character '$value'");
data[i] =
_CHARSET_INVERSE_INDEX[string[i]]!;
}
return data.sublist(1);
}
final dec = _base32Decode(address);
final pd = PaymentData(
pubkey: Uint8List.fromList(dec));
final p2pkh =
P2PKH(data: pd, network: bitcoincash);
// final addr = p2pkh.data.address!;
final addr = bb.Address.toLegacyAddress(
"bitcoincash:qp352c2skpdxwzzd090mec3v37au5dmfwgwfw686sz",
);
final scripthash =
AddressUtils.convertToScriptHash(
addr, bitcoincash);
final utxos =
await e.getUTXOs(scripthash: scripthash);
Util.printJson(utxos, "UTXOS for $address");
final hist = await e.getTransaction(
txHash: utxos.first["tx_hash"] as String,
);
Util.printJson(hist, "HISTORY for $address");
} catch (e, s) {
print("$e\n$s");
}
//
},
child: RoundedWhiteContainer(
child: Text(
"UTXOs",
"Do nothing",
style: STextStyles.button(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!

View file

@ -54,7 +54,6 @@ import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/services/mixins/ordinals_interface.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
@ -71,6 +70,7 @@ import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
@ -83,6 +83,7 @@ import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/buy_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/coin_control_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/exchange_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/fusion_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/ordinals_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/paynym_nav_icon.dart';
import 'package:stackwallet/widgets/wallet_navigation_bar/components/icons/receive_nav_icon.dart';
@ -91,8 +92,6 @@ import 'package:stackwallet/widgets/wallet_navigation_bar/components/wallet_navi
import 'package:stackwallet/widgets/wallet_navigation_bar/wallet_navigation_bar.dart';
import 'package:tuple/tuple.dart';
import '../../widgets/wallet_navigation_bar/components/icons/fusion_nav_icon.dart';
/// [eventBus] should only be set during testing
class WalletView extends ConsumerStatefulWidget {
const WalletView({
@ -1119,8 +1118,7 @@ class _WalletViewState extends ConsumerState<WalletView> {
),
if (ref.watch(
pWallets.select(
(value) => value.getWallet(widget.walletId)
is FusionWalletInterface,
(value) => value.getWallet(widget.walletId) is CashFusion,
),
))
WalletNavigationBarItemData(

View file

@ -22,11 +22,11 @@ import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.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/desktop/desktop_app_bar.dart';
@ -66,7 +66,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
Future<void> _startFusion() async {
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as FusionWalletInterface;
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
try {
fusionWallet.uiState = ref.read(

View file

@ -6,10 +6,10 @@ import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
@ -119,8 +119,8 @@ class _FusionDialogViewState extends ConsumerState<FusionDialogView> {
);
if (shouldCancel == true && mounted) {
final fusionWallet = ref.read(pWallets).getWallet(widget.walletId)
as FusionWalletInterface;
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
await showLoading(
whileFuture: Future.wait([
@ -282,7 +282,7 @@ class _FusionDialogViewState extends ConsumerState<FusionDialogView> {
/// Fuse again.
void _fuseAgain() async {
final fusionWallet =
ref.read(pWallets).getWallet(widget.walletId) as FusionWalletInterface;
ref.read(pWallets).getWallet(widget.walletId) as CashFusion;
final fusionInfo = ref.read(prefsChangeNotifierProvider).fusionServerInfo;

View file

@ -31,7 +31,6 @@ import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/providers/wallet/my_paynym_account_state_provider.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/services/mixins/ordinals_interface.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
@ -42,6 +41,7 @@ import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
@ -361,7 +361,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
// manager.hasWhirlpoolSupport ||
coin == Coin.banano ||
wallet is OrdinalsInterface ||
wallet is FusionWalletInterface;
wallet is CashFusion;
return Row(
children: [

View file

@ -14,13 +14,13 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/services/mixins/ordinals_interface.dart';
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/rounded_container.dart';
@ -129,7 +129,7 @@ class _MoreFeaturesDialogState extends ConsumerState<MoreFeaturesDialog> {
iconAsset: Assets.svg.monkey,
onPressed: () => widget.onMonkeyPressed?.call(),
),
if (wallet is FusionWalletInterface)
if (wallet is CashFusion)
_MoreFeaturesItem(
label: "CashFusion",
detail: "Decentralized Bitcoin Cash mixing protocol",

View file

@ -15,7 +15,6 @@ import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
import 'package:stackwallet/models/node_model.dart';
import 'package:stackwallet/models/paymint/fee_object_model.dart';
import 'package:stackwallet/services/coins/banano/banano_wallet.dart';
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
@ -131,26 +130,10 @@ abstract class CoinServiceAPI {
throw UnimplementedError("moved");
case Coin.bitcoincash:
return BitcoinCashWallet(
walletId: walletId,
walletName: walletName,
coin: coin,
secureStore: secureStorageInterface,
client: client,
cachedClient: cachedClient,
tracker: tracker,
);
throw UnimplementedError("moved");
case Coin.bitcoincashTestnet:
return BitcoinCashWallet(
walletId: walletId,
walletName: walletName,
coin: coin,
secureStore: secureStorageInterface,
client: client,
cachedClient: cachedClient,
tracker: tracker,
);
throw UnimplementedError("moved");
case Coin.dogecoin:
throw UnimplementedError("moved");

View file

@ -23,10 +23,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/util.dart' as util;
import 'package:tuple/tuple.dart';
class TT with ElectrumXParsing {
//
}
mixin ElectrumXParsing {
Future<TransactionV2> getTransaction(
String txHash,

View file

@ -12,13 +12,13 @@ import 'package:flutter/cupertino.dart';
import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/services/event_bus/events/global/tor_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
import 'package:stackwallet/utilities/amount/amount_unit.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/languages_enum.dart';
import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:uuid/uuid.dart';
class Prefs extends ChangeNotifier {

View file

@ -15,9 +15,12 @@ import 'package:stackwallet/utilities/extensions/extensions.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoincash.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/wallets/wallet/mixins/coin_control.dart';
import 'package:stackwallet/wallets/wallet/mixins/electrumx.dart';
class BitcoincashWallet extends Bip39HDWallet with ElectrumX {
class BitcoincashWallet extends Bip39HDWallet
with ElectrumX, CoinControl, CashFusion {
@override
int get isarTransactionVersion => 2;

View file

@ -15,9 +15,12 @@ import 'package:stackwallet/utilities/extensions/extensions.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/ecash.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
import 'package:stackwallet/wallets/wallet/mixins/cash_fusion.dart';
import 'package:stackwallet/wallets/wallet/mixins/coin_control.dart';
import 'package:stackwallet/wallets/wallet/mixins/electrumx.dart';
class EcashWallet extends Bip39HDWallet with ElectrumX {
class EcashWallet extends Bip39HDWallet
with ElectrumX, CoinControl, CashFusion {
@override
int get isarTransactionVersion => 2;