This commit is contained in:
fosse 2023-08-23 08:37:36 -04:00
parent beafd2d37f
commit 5aa8fd401d
5 changed files with 59 additions and 20 deletions

View file

@ -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);
}

View file

@ -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<BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
@ -104,7 +106,53 @@ class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
return [DerivationType.bip39, DerivationType.StandardBIP44Legacy];
}
static Future<dynamic> getInfoFromSeed() {
static Future<List<DerivationInfo>> 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<dynamic> getInfoFromSeed({required String seed, required Node node}) async {
throw UnimplementedError();
}
}

View file

@ -117,7 +117,6 @@ abstract class NanoWalletBase
@override
Future<void> changePassword(String password) {
print("e");
throw UnimplementedError("changePassword");
}

View file

@ -29,7 +29,7 @@ class WalletRestoreChooseDerivationPage extends BasePage {
@override
Widget body(BuildContext context) {
return Observer(
builder: (_) => FutureBuilder<List<Derivation>>(
builder: (_) => FutureBuilder<List<DerivationInfo>>(
future: walletRestoreChooseDerivationViewModel.derivations,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {

View file

@ -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<List<Derivation>> get derivations async {
var list = <Derivation>[];
Future<List<DerivationInfo>> get derivations async {
var list = <DerivationInfo>[];
var walletType = credentials["walletType"] as WalletType;
var appStore = getIt.get<AppStore>();
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(