From 5aa8fd401d2c5b26330409802eb52aa889f0690e Mon Sep 17 00:00:00 2001 From: fosse Date: Wed, 23 Aug 2023 08:37:36 -0400 Subject: [PATCH] save --- cw_bitcoin/lib/bitcoin_wallet.dart | 2 +- cw_bitcoin/lib/bitcoin_wallet_service.dart | 50 ++++++++++++++++++- cw_nano/lib/nano_wallet.dart | 1 - .../wallet_restore_choose_derivation.dart | 2 +- ..._restore_choose_derivation_view_model.dart | 24 +++------ 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/cw_bitcoin/lib/bitcoin_wallet.dart b/cw_bitcoin/lib/bitcoin_wallet.dart index c4675df1c..844aa27f6 100644 --- a/cw_bitcoin/lib/bitcoin_wallet.dart +++ b/cw_bitcoin/lib/bitcoin_wallet.dart @@ -45,7 +45,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialChangeAddressIndex: initialChangeAddressIndex, mainHd: hd, sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType) - .derivePath("m/0'/1"), + .derivePath(walletInfo.derivationPath!),// "m/0'/1" networkType: networkType); } diff --git a/cw_bitcoin/lib/bitcoin_wallet_service.dart b/cw_bitcoin/lib/bitcoin_wallet_service.dart index 8885fff21..e3c058b7c 100644 --- a/cw_bitcoin/lib/bitcoin_wallet_service.dart +++ b/cw_bitcoin/lib/bitcoin_wallet_service.dart @@ -12,6 +12,8 @@ import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:hive/hive.dart'; import 'package:collection/collection.dart'; +import 'package:mobx/mobx.dart'; +import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; class BitcoinWalletService extends WalletService { @@ -104,7 +106,53 @@ class BitcoinWalletService extends WalletService getInfoFromSeed() { + static Future> getDerivationsFromMnemonic( + {required String mnemonic, required Node node}) async { + // throw UnimplementedError(); + + var list = []; + + // default derivation path: + var wallet = + bitcoin.HDWallet.fromSeed(await mnemonicToSeedBytes(mnemonic), network: bitcoin.bitcoin) + .derivePath("m/0'/1"); + + print(wallet.address); + print("@@@@@@@@@@@@@"); + + // final wallet = await BitcoinWalletBase.create( + // password: "password", + // mnemonic: mnemonic, + // walletInfo: WalletInfo( + // "id", + // "test", + // WalletType.bitcoin, + // false, + // 0, + // 0, + // "dirPath", + // "path", + // "", + // null, + // "yatLastUsedAddressRaw", + // false, + // DerivationType.bip39, + // "derivationPath", + // ), + // unspentCoinsInfo: unspentCoinsInfoSource); + + list.add(DerivationInfo( + "0.00000", + "address", + 0, + DerivationType.bip39, + null, + )); + + return []; + } + + static Future getInfoFromSeed({required String seed, required Node node}) async { throw UnimplementedError(); } } diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index f440624a2..925e9b6f1 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -117,7 +117,6 @@ abstract class NanoWalletBase @override Future changePassword(String password) { - print("e"); throw UnimplementedError("changePassword"); } diff --git a/lib/src/screens/restore/wallet_restore_choose_derivation.dart b/lib/src/screens/restore/wallet_restore_choose_derivation.dart index f89c1e01d..4127c8fc3 100644 --- a/lib/src/screens/restore/wallet_restore_choose_derivation.dart +++ b/lib/src/screens/restore/wallet_restore_choose_derivation.dart @@ -29,7 +29,7 @@ class WalletRestoreChooseDerivationPage extends BasePage { @override Widget body(BuildContext context) { return Observer( - builder: (_) => FutureBuilder>( + builder: (_) => FutureBuilder>( future: walletRestoreChooseDerivationViewModel.derivations, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { diff --git a/lib/view_model/wallet_restore_choose_derivation_view_model.dart b/lib/view_model/wallet_restore_choose_derivation_view_model.dart index ca8bff5a4..75cd18c49 100644 --- a/lib/view_model/wallet_restore_choose_derivation_view_model.dart +++ b/lib/view_model/wallet_restore_choose_derivation_view_model.dart @@ -2,7 +2,6 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:cw_bitcoin/bitcoin_wallet_service.dart'; import 'package:cw_core/wallet_info.dart'; -import 'package:cw_nano/nano_balance.dart'; import 'package:cw_nano/nano_util.dart'; import 'package:cw_nano/nano_wallet_service.dart'; import 'package:mobx/mobx.dart'; @@ -14,15 +13,7 @@ part 'wallet_restore_choose_derivation_view_model.g.dart'; class WalletRestoreChooseDerivationViewModel = WalletRestoreChooseDerivationViewModelBase with _$WalletRestoreChooseDerivationViewModel; -class Derivation { - Derivation(this.balance, this.address, this.height, this.derivationType, this.derivationPath); - final String balance; - final String address; - final int height; - final DerivationType derivationType; - final String? derivationPath; -} abstract class WalletRestoreChooseDerivationViewModelBase with Store { WalletRestoreChooseDerivationViewModelBase({required this.credentials}) @@ -33,16 +24,17 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { @observable WalletRestoreMode mode; - Future> get derivations async { - var list = []; + Future> get derivations async { + var list = []; var walletType = credentials["walletType"] as WalletType; var appStore = getIt.get(); var node = appStore.settingsStore.getCurrentNode(walletType); switch (walletType) { case WalletType.bitcoin: String? mnemonic = credentials['seed'] as String?; - var bip39Info = await BitcoinWalletService.getInfoFromSeed(DerivationType.bip39, - mnemonic: mnemonic, seedKey: seedKey, node: node); + await BitcoinWalletService.getDerivationsFromMnemonic(mnemonic: mnemonic!, node: node); + + // var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic( // DerivationType.nano, // mnemonic: mnemonic, @@ -50,7 +42,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { // node: node, // ); - list.add(Derivation( + list.add(DerivationInfo( "0.00000", "address", 0, @@ -83,7 +75,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { ); if (standardInfo["balance"] != null) { - list.add(Derivation( + list.add(DerivationInfo( NanoUtil.getRawAsUsableString(standardInfo["balance"] as String, NanoUtil.rawPerNano), standardInfo["address"] as String, int.tryParse( @@ -96,7 +88,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { } if (bip39Info["balance"] != null) { - list.add(Derivation( + list.add(DerivationInfo( NanoUtil.getRawAsUsableString(bip39Info["balance"] as String, NanoUtil.rawPerNano), bip39Info["address"] as String, int.tryParse(