mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-25 12:06:05 +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.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_mnemonic_is_incorrect_exception.dart';
|
import 'package:cw_bitcoin/bitcoin_mnemonic_is_incorrect_exception.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_wallet_creation_credentials.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/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_service.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:hive/hive.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
class BitcoinWalletService extends WalletService<
|
class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
|
||||||
BitcoinNewWalletCredentials,
|
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
|
||||||
BitcoinRestoreWalletFromSeedCredentials,
|
|
||||||
BitcoinRestoreWalletFromWIFCredentials> {
|
|
||||||
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);
|
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);
|
||||||
|
|
||||||
final Box<WalletInfo> walletInfoSource;
|
final Box<WalletInfo> walletInfoSource;
|
||||||
|
@ -42,10 +41,12 @@ class BitcoinWalletService extends WalletService<
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BitcoinWallet> openWallet(String name, String password) async {
|
Future<BitcoinWallet> openWallet(String name, String password) async {
|
||||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
final walletInfo = walletInfoSource.values
|
||||||
(info) => info.id == WalletBase.idFor(name, getType()))!;
|
.firstWhereOrNull((info) => info.id == WalletBase.idFor(name, getType()))!;
|
||||||
final wallet = await BitcoinWalletBase.open(
|
final wallet = await BitcoinWalletBase.open(
|
||||||
password: password, name: name, walletInfo: walletInfo,
|
password: password,
|
||||||
|
name: name,
|
||||||
|
walletInfo: walletInfo,
|
||||||
unspentCoinsInfo: unspentCoinsInfoSource);
|
unspentCoinsInfo: unspentCoinsInfoSource);
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
return wallet;
|
return wallet;
|
||||||
|
@ -53,17 +54,16 @@ class BitcoinWalletService extends WalletService<
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> remove(String wallet) async {
|
Future<void> remove(String wallet) async {
|
||||||
File(await pathForWalletDir(name: wallet, type: getType()))
|
File(await pathForWalletDir(name: wallet, type: getType())).delete(recursive: true);
|
||||||
.delete(recursive: true);
|
final walletInfo = walletInfoSource.values
|
||||||
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
.firstWhereOrNull((info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
||||||
(info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
|
||||||
await walletInfoSource.delete(walletInfo.key);
|
await walletInfoSource.delete(walletInfo.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> rename(String currentName, String password, String newName) async {
|
Future<void> rename(String currentName, String password, String newName) async {
|
||||||
final currentWalletInfo = walletInfoSource.values.firstWhereOrNull(
|
final currentWalletInfo = walletInfoSource.values
|
||||||
(info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
.firstWhereOrNull((info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
||||||
final currentWallet = await BitcoinWalletBase.open(
|
final currentWallet = await BitcoinWalletBase.open(
|
||||||
password: password,
|
password: password,
|
||||||
name: currentName,
|
name: currentName,
|
||||||
|
@ -80,13 +80,11 @@ class BitcoinWalletService extends WalletService<
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BitcoinWallet> restoreFromKeys(
|
Future<BitcoinWallet> restoreFromKeys(BitcoinRestoreWalletFromWIFCredentials credentials) async =>
|
||||||
BitcoinRestoreWalletFromWIFCredentials credentials) async =>
|
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BitcoinWallet> restoreFromSeed(
|
Future<BitcoinWallet> restoreFromSeed(BitcoinRestoreWalletFromSeedCredentials credentials) async {
|
||||||
BitcoinRestoreWalletFromSeedCredentials credentials) async {
|
|
||||||
if (!validateMnemonic(credentials.mnemonic)) {
|
if (!validateMnemonic(credentials.mnemonic)) {
|
||||||
throw BitcoinMnemonicIsIncorrectException();
|
throw BitcoinMnemonicIsIncorrectException();
|
||||||
}
|
}
|
||||||
|
@ -100,4 +98,13 @@ class BitcoinWalletService extends WalletService<
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
return wallet;
|
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,
|
nano,
|
||||||
@HiveField(3)
|
@HiveField(3)
|
||||||
bip39,
|
bip39,
|
||||||
|
@HiveField(4)
|
||||||
|
StandardBIP44Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
@HiveType(typeId: WalletInfo.typeId)
|
@HiveType(typeId: WalletInfo.typeId)
|
||||||
|
|
|
@ -37,6 +37,29 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
|
||||||
var appStore = getIt.get<AppStore>();
|
var appStore = getIt.get<AppStore>();
|
||||||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||||
switch (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:
|
case WalletType.nano:
|
||||||
String? mnemonic = credentials['seed'] as String?;
|
String? mnemonic = credentials['seed'] as String?;
|
||||||
String? seedKey = credentials['seedKey'] 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/di.dart';
|
||||||
import 'package:cake_wallet/nano/nano.dart';
|
import 'package:cake_wallet/nano/nano.dart';
|
||||||
import 'package:cake_wallet/ethereum/ethereum.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.dart';
|
||||||
import 'package:cw_nano/nano_wallet_service.dart';
|
import 'package:cw_nano/nano_wallet_service.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -143,9 +144,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
// return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
return BitcoinWalletService.compareDerivationMethods(mnemonic: mnemonic, node: node);
|
||||||
// name: name, mnemonic: seed, password: password);
|
|
||||||
// case WalletType.litecoin:
|
// case WalletType.litecoin:
|
||||||
// return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
// return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||||
// name: name, mnemonic: seed, password: password);
|
// name: name, mnemonic: seed, password: password);
|
||||||
|
|
Loading…
Reference in a new issue