some frost clean up

This commit is contained in:
julian 2024-01-25 02:20:37 -06:00
parent 444afb88ae
commit 1e67f3585a
9 changed files with 69 additions and 34 deletions

View file

@ -21,6 +21,7 @@ import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/stack_file_system.dart';
import 'package:stackwallet/wallets/isar/models/frost_wallet_info.dart';
import 'package:stackwallet/wallets/isar/models/spark_coin.dart';
import 'package:stackwallet/wallets/isar/models/token_wallet_info.dart';
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
@ -67,6 +68,7 @@ class MainDB {
SparkCoinSchema,
WalletInfoMetaSchema,
TokenWalletInfoSchema,
FrostWalletInfoSchema,
],
directory: (await StackFileSystem.applicationIsarDirectory()).path,
// inspector: kDebugMode,

View file

@ -4,7 +4,7 @@ import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:frostdart/frostdart.dart';
import 'package:frostdart/frostdart.dart' as frost;
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/home_view/home_view.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart';
@ -70,7 +70,7 @@ class _RestoreFrostMsWalletViewState
final keys = keysFieldController.text;
final config = configFieldController.text;
final myNameIndex = getParticipantIndexFromKeys(serializedKeys: keys);
final myNameIndex = frost.getParticipantIndexFromKeys(serializedKeys: keys);
final participants = Frost.getParticipants(multisigConfig: config);
final myName = participants[myNameIndex];
@ -92,7 +92,7 @@ class _RestoreFrostMsWalletViewState
knownSalts: [],
participants: participants,
myName: myName,
threshold: multisigThreshold(
threshold: frost.multisigThreshold(
multisigConfig: config,
),
);

View file

@ -7,13 +7,13 @@ import 'package:stackwallet/pages/send_view/frost_ms/frost_continue_sign_config_
import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart';
import 'package:stackwallet/providers/frost_wallet/frost_wallet_providers.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/coins/bitcoin/frost_wallet.dart';
import 'package:stackwallet/services/frost.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/wallet/impl/bitcoin_frost_wallet.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';
@ -72,15 +72,14 @@ class _FrostAttemptSignConfigViewState
@override
void initState() {
final wallet = ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.wallet as FrostWallet;
final wallet =
ref.read(pWallets).getWallet(widget.walletId) as BitcoinFrostWallet;
final frostInfo = wallet.frostInfo;
myName = wallet.myName;
threshold = wallet.threshold;
participantsWithoutMe = wallet.participants;
myIndex = participantsWithoutMe.indexOf(wallet.myName);
myName = frostInfo.myName;
threshold = frostInfo.threshold;
participantsWithoutMe = frostInfo.participants;
myIndex = participantsWithoutMe.indexOf(frostInfo.myName);
myPreprocess = ref.read(pFrostAttemptSignData.state).state!.preprocess;
participantsWithoutMe.removeAt(myIndex);

View file

@ -139,8 +139,8 @@ class _FrostCompleteSignViewState extends ConsumerState<FrostCompleteSignView> {
Exception? ex;
final txData = await showLoading(
whileFuture: ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.read(pWallets)
.getWallet(widget.walletId)
.confirmSend(
txData: ref.read(pFrostTxData.state).state!,
),

View file

@ -9,13 +9,13 @@ import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart';
import 'package:stackwallet/providers/frost_wallet/frost_wallet_providers.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/coins/bitcoin/frost_wallet.dart';
import 'package:stackwallet/services/frost.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/wallet/impl/bitcoin_frost_wallet.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';
@ -61,17 +61,17 @@ class _FrostContinueSignViewState extends ConsumerState<FrostContinueSignView> {
@override
void initState() {
final wallet = ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.wallet as FrostWallet;
final wallet =
ref.read(pWallets).getWallet(widget.walletId) as BitcoinFrostWallet;
myName = wallet.myName;
participantsAll = wallet.participants;
myIndex = wallet.participants.indexOf(wallet.myName);
final frostInfo = wallet.frostInfo;
myName = frostInfo.myName;
participantsAll = frostInfo.participants;
myIndex = frostInfo.participants.indexOf(frostInfo.myName);
myShare = ref.read(pFrostContinueSignData.state).state!.share;
participantsWithoutMe = wallet.participants
participantsWithoutMe = frostInfo.participants
.toSet()
.intersection(
ref.read(pFrostSelectParticipantsUnordered.state).state!.toSet())

View file

@ -92,7 +92,9 @@ class _FrostImportSignConfigViewState
// TODO add more data from 'data' and display to user ?
ref.read(pFrostTxData.notifier).state = TxData(
frostMSConfig: config,
recipients: data.recipients,
recipients: data.recipients
.map((e) => (address: e.address, amount: e.amount, isChange: false))
.toList(),
utxos: utxos.toSet(),
);

View file

@ -84,7 +84,7 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
final recipients = recipientWidgetIndexes
.map((i) => ref.read(pRecipient(i).state).state)
.map((e) => (address: e!.address, amount: e.amount!, isChange: false))
.map((e) => (address: e!.address, amount: e!.amount!, isChange: false))
.toList(growable: false);
final txData = await wallet.frostCreateSignConfig(

View file

@ -83,6 +83,7 @@ import 'package:stackwallet/pages/receive_view/addresses/wallet_addresses_view.d
import 'package:stackwallet/pages/receive_view/generate_receiving_uri_qr_code_view.dart';
import 'package:stackwallet/pages/receive_view/receive_view.dart';
import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
import 'package:stackwallet/pages/send_view/frost_ms/frost_send_view.dart';
import 'package:stackwallet/pages/send_view/send_view.dart';
import 'package:stackwallet/pages/send_view/token_send_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/about_view.dart';

View file

@ -29,12 +29,6 @@ import 'package:stackwallet/wallets/models/tx_data.dart';
import 'package:stackwallet/wallets/wallet/wallet.dart';
class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
@override
int get isarTransactionVersion => 2;
@override
bool get supportsMultiRecipient => true;
BitcoinFrostWallet(CryptoCurrencyNetwork network)
: super(BitcoinFrost(network) as T);
@ -89,7 +83,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
await _saveMultisigId(multisigId);
await _saveMultisigConfig(multisigConfig);
await mainDB.isar.frostWalletInfo.put(frostWalletInfo);
await mainDB.isar.writeTxn(() async {
await mainDB.isar.frostWalletInfo.put(frostWalletInfo);
});
final keys = frost.deserializeKeys(keys: serializedKeys);
@ -299,6 +295,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
// ==================== Overrides ============================================
@override
bool get supportsMultiRecipient => true;
@override
int get isarTransactionVersion => 2;
@ -527,8 +526,40 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
@override
Future<void> checkSaveInitialReceivingAddress() async {
// should not be needed for frost as we explicitly save the address
// on new init and restore
final address = await getCurrentReceivingAddress();
if (address == null) {
final serializedKeys = await getSerializedKeys();
if (serializedKeys != null) {
final keys = frost.deserializeKeys(keys: serializedKeys);
final addressString = frost.addressForKeys(
network: cryptoCurrency.network == CryptoCurrencyNetwork.main
? Network.Mainnet
: Network.Testnet,
keys: keys,
);
final publicKey = frost.scriptPubKeyForKeys(keys: keys);
final address = Address(
walletId: walletId,
value: addressString,
publicKey: publicKey.toUint8ListFromHex,
derivationIndex: 0,
derivationPath: null,
subType: AddressSubType.receiving,
type: AddressType.frostMS,
);
await mainDB.updateOrPutAddresses([address]);
} else {
Logging.instance.log(
"$runtimeType.checkSaveInitialReceivingAddress() failed due"
" to missing serialized keys",
level: LogLevel.Fatal,
);
}
}
}
@override