mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 21:04:53 +00:00
initial changes
This commit is contained in:
parent
6dcc713f8d
commit
8a9adf8350
4 changed files with 52 additions and 20 deletions
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_mnemonic_is_incorrect_exception.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/wallet_service.dart';
|
||||
|
@ -12,10 +13,8 @@ import 'package:cw_core/wallet_type.dart';
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class BitcoinWalletService extends WalletService<
|
||||
BitcoinNewWalletCredentials,
|
||||
BitcoinRestoreWalletFromSeedCredentials,
|
||||
BitcoinRestoreWalletFromWIFCredentials> {
|
||||
class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
|
||||
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
|
||||
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);
|
||||
|
||||
final Box<WalletInfo> walletInfoSource;
|
||||
|
@ -42,10 +41,12 @@ class BitcoinWalletService extends WalletService<
|
|||
|
||||
@override
|
||||
Future<BitcoinWallet> openWallet(String name, String password) async {
|
||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||
final walletInfo = walletInfoSource.values
|
||||
.firstWhereOrNull((info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||
final wallet = await BitcoinWalletBase.open(
|
||||
password: password, name: name, walletInfo: walletInfo,
|
||||
password: password,
|
||||
name: name,
|
||||
walletInfo: walletInfo,
|
||||
unspentCoinsInfo: unspentCoinsInfoSource);
|
||||
await wallet.init();
|
||||
return wallet;
|
||||
|
@ -53,17 +54,16 @@ class BitcoinWalletService extends WalletService<
|
|||
|
||||
@override
|
||||
Future<void> remove(String wallet) async {
|
||||
File(await pathForWalletDir(name: wallet, type: getType()))
|
||||
.delete(recursive: true);
|
||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
||||
File(await pathForWalletDir(name: wallet, type: getType())).delete(recursive: true);
|
||||
final walletInfo = walletInfoSource.values
|
||||
.firstWhereOrNull((info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
||||
await walletInfoSource.delete(walletInfo.key);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> rename(String currentName, String password, String newName) async {
|
||||
final currentWalletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||
(info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
||||
final currentWalletInfo = walletInfoSource.values
|
||||
.firstWhereOrNull((info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
||||
final currentWallet = await BitcoinWalletBase.open(
|
||||
password: password,
|
||||
name: currentName,
|
||||
|
@ -80,13 +80,11 @@ class BitcoinWalletService extends WalletService<
|
|||
}
|
||||
|
||||
@override
|
||||
Future<BitcoinWallet> restoreFromKeys(
|
||||
BitcoinRestoreWalletFromWIFCredentials credentials) async =>
|
||||
Future<BitcoinWallet> restoreFromKeys(BitcoinRestoreWalletFromWIFCredentials credentials) async =>
|
||||
throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Future<BitcoinWallet> restoreFromSeed(
|
||||
BitcoinRestoreWalletFromSeedCredentials credentials) async {
|
||||
Future<BitcoinWallet> restoreFromSeed(BitcoinRestoreWalletFromSeedCredentials credentials) async {
|
||||
if (!validateMnemonic(credentials.mnemonic)) {
|
||||
throw BitcoinMnemonicIsIncorrectException();
|
||||
}
|
||||
|
@ -100,4 +98,13 @@ class BitcoinWalletService extends WalletService<
|
|||
await wallet.init();
|
||||
return wallet;
|
||||
}
|
||||
|
||||
static Future<List<DerivationType>> compareDerivationMethods(
|
||||
{required mnemonic, required Node node}) async {
|
||||
return [DerivationType.bip39, DerivationType.StandardBIP44Legacy];
|
||||
}
|
||||
|
||||
static Future<dynamic> getInfoFromSeed() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ enum DerivationType {
|
|||
nano,
|
||||
@HiveField(3)
|
||||
bip39,
|
||||
@HiveField(4)
|
||||
StandardBIP44Legacy
|
||||
}
|
||||
|
||||
@HiveType(typeId: WalletInfo.typeId)
|
||||
|
|
|
@ -37,6 +37,29 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
|
|||
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.getInfoFromSeedOrMnemonic(DerivationType.bip39,
|
||||
// mnemonic: mnemonic, seedKey: seedKey, node: node);
|
||||
// var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic(
|
||||
// DerivationType.nano,
|
||||
// mnemonic: mnemonic,
|
||||
// seedKey: seedKey,
|
||||
// node: node,
|
||||
// );
|
||||
|
||||
// if (bip39Info["balance"] != null) {
|
||||
// list.add(Derivation(
|
||||
// NanoUtil.getRawAsUsableString(bip39Info["balance"] as String, NanoUtil.rawPerNano),
|
||||
// bip39Info["address"] as String,
|
||||
// DerivationType.bip39,
|
||||
// int.tryParse(
|
||||
// bip39Info["confirmation_height"] as String? ?? "",
|
||||
// ) ??
|
||||
// 0,
|
||||
// ));
|
||||
// }
|
||||
break;
|
||||
case WalletType.nano:
|
||||
String? mnemonic = credentials['seed'] as String?;
|
||||
String? seedKey = credentials['seedKey'] as String?;
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/nano/nano.dart';
|
||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet_service.dart';
|
||||
import 'package:cw_nano/nano_wallet.dart';
|
||||
import 'package:cw_nano/nano_wallet_service.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
@ -143,9 +144,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||
|
||||
switch (type) {
|
||||
// case WalletType.bitcoin:
|
||||
// return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||
// name: name, mnemonic: seed, password: password);
|
||||
case WalletType.bitcoin:
|
||||
return BitcoinWalletService.compareDerivationMethods(mnemonic: mnemonic, node: node);
|
||||
// case WalletType.litecoin:
|
||||
// return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||
// name: name, mnemonic: seed, password: password);
|
||||
|
|
Loading…
Reference in a new issue