mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
decred: Add restore from seed.
This commit is contained in:
parent
4029b512bb
commit
2acb68e64c
11 changed files with 2093 additions and 7 deletions
|
@ -28,11 +28,15 @@ void initLibdcrwallet(String logDir) {
|
|||
/// createWalletAsync calls the libdcrwallet's createWallet function
|
||||
/// asynchronously.
|
||||
Future<void> createWalletAsync(
|
||||
{required String name, required String dataDir, required String password}) {
|
||||
{required String name,
|
||||
required String dataDir,
|
||||
required String password,
|
||||
String? mnemonic}) {
|
||||
final args = <String, String>{
|
||||
"name": name,
|
||||
"dataDir": dataDir,
|
||||
"password": password,
|
||||
"mnemonic": mnemonic ?? "",
|
||||
};
|
||||
return compute(createWalletSync, args);
|
||||
}
|
||||
|
@ -43,11 +47,13 @@ void createWalletSync(Map<String, String> args) {
|
|||
final name = args["name"]!.toCString();
|
||||
final dataDir = args["dataDir"]!.toCString();
|
||||
final password = args["password"]!.toCString();
|
||||
final mnemonic = args["mnemonic"]!.toCString();
|
||||
final network = "testnet".toCString();
|
||||
|
||||
executePayloadFn(
|
||||
fn: () => dcrwalletApi.createWallet(name, dataDir, network, password),
|
||||
ptrsToFree: [name, dataDir, network, password],
|
||||
fn: () =>
|
||||
dcrwalletApi.createWallet(name, dataDir, network, password, mnemonic),
|
||||
ptrsToFree: [name, dataDir, network, password, mnemonic],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
2050
cw_decred/lib/mnemonic.dart
Normal file
2050
cw_decred/lib/mnemonic.dart
Normal file
File diff suppressed because it is too large
Load diff
|
@ -78,7 +78,6 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
|
||||
@override
|
||||
Object get keys {
|
||||
// throw UnimplementedError();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,16 @@ class DecredWalletService extends WalletService<
|
|||
Future<DecredWallet> restoreFromSeed(
|
||||
DecredRestoreWalletFromSeedCredentials credentials,
|
||||
{bool? isTestnet}) async {
|
||||
throw UnimplementedError();
|
||||
await createWalletAsync(
|
||||
name: credentials.walletInfo!.name,
|
||||
dataDir: credentials.walletInfo!.dirPath,
|
||||
password: credentials.password!,
|
||||
mnemonic: credentials.mnemonic,
|
||||
);
|
||||
final wallet = DecredWallet(credentials.walletInfo!, credentials.password!,
|
||||
this.unspentCoinsInfoSource);
|
||||
await wallet.init();
|
||||
return wallet;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:cake_wallet/polygon/polygon.dart';
|
|||
import 'package:cake_wallet/solana/solana.dart';
|
||||
import 'package:cake_wallet/tron/tron.dart';
|
||||
import 'package:cake_wallet/wownero/wownero.dart';
|
||||
import 'package:cake_wallet/decred/decred.dart';
|
||||
import 'package:cake_wallet/utils/language_list.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
|
@ -46,6 +47,8 @@ class SeedValidator extends Validator<MnemonicItem> {
|
|||
return tron!.getTronWordList(language);
|
||||
case WalletType.wownero:
|
||||
return wownero!.getWowneroWordList(language);
|
||||
case WalletType.decred:
|
||||
return decred!.getDecredWordList();
|
||||
case WalletType.none:
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -116,4 +116,7 @@ class CWDecred extends Decred {
|
|||
// TODO: Remove this and just rescan from the wallet birthday.
|
||||
return (minutesDiff / 5).toInt();
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> getDecredWordList() => wordlist;
|
||||
}
|
||||
|
|
|
@ -284,13 +284,19 @@ class WalletRestorePage extends BasePage {
|
|||
|
||||
// bip39:
|
||||
final validBip39SeedLengths = [12, 18, 24];
|
||||
final nonBip39WalletTypes = [WalletType.monero, WalletType.wownero, WalletType.haven];
|
||||
final nonBip39WalletTypes = [WalletType.monero, WalletType.wownero, WalletType.haven, WalletType.decred];
|
||||
// if it's a bip39 wallet and the length is not valid return false
|
||||
if (!nonBip39WalletTypes.contains(walletRestoreViewModel.type) &&
|
||||
!(validBip39SeedLengths.contains(seedWords.length))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((walletRestoreViewModel.type == WalletType.decred) &&
|
||||
seedWords.length !=
|
||||
WalletRestoreViewModelBase.decredSeedMnemonicLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final words =
|
||||
walletRestoreFromSeedFormKey.currentState!.seedWidgetStateKey.currentState!.words.toSet();
|
||||
return seedWords.toSet().difference(words).toSet().isEmpty;
|
||||
|
|
|
@ -22,7 +22,8 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
WalletKeysViewModelBase(this._appStore)
|
||||
: title = _appStore.wallet!.type == WalletType.bitcoin ||
|
||||
_appStore.wallet!.type == WalletType.litecoin ||
|
||||
_appStore.wallet!.type == WalletType.bitcoinCash
|
||||
_appStore.wallet!.type == WalletType.bitcoinCash ||
|
||||
_appStore.wallet!.type == WalletType.decred
|
||||
? S.current.wallet_seed
|
||||
: S.current.wallet_keys,
|
||||
_walletName = _appStore.wallet!.type.name,
|
||||
|
@ -226,6 +227,7 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
|
||||
if (_appStore.wallet!.type == WalletType.bitcoin ||
|
||||
_appStore.wallet!.type == WalletType.litecoin ||
|
||||
_appStore.wallet!.type == WalletType.decred ||
|
||||
_appStore.wallet!.type == WalletType.bitcoinCash) {
|
||||
// final keys = bitcoin!.getWalletKeys(_appStore.wallet!);
|
||||
|
||||
|
@ -330,6 +332,8 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
return 'tron-wallet';
|
||||
case WalletType.wownero:
|
||||
return 'wownero-wallet';
|
||||
case WalletType.decred:
|
||||
return 'decred-wallet';
|
||||
default:
|
||||
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type.toString()}');
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
|||
return seedSettingsViewModel.nanoSeedType == NanoSeedType.bip39
|
||||
? advancedPrivacySettingsViewModel.seedPhraseLength.value
|
||||
: 24;
|
||||
case WalletType.decred:
|
||||
return 15;
|
||||
default:
|
||||
return 24;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
static const moneroSeedMnemonicLength = 25;
|
||||
static const electrumSeedMnemonicLength = 24;
|
||||
static const electrumShortSeedMnemonicLength = 12;
|
||||
static const decredSeedMnemonicLength = 15;
|
||||
|
||||
late List<WalletRestoreMode> availableModes;
|
||||
final bool hasSeedLanguageSelector;
|
||||
|
|
|
@ -1427,6 +1427,7 @@ import 'package:cw_decred/wallet_service.dart';
|
|||
import 'package:cw_decred/wallet_creation_credentials.dart';
|
||||
import 'package:cw_decred/amount_format.dart';
|
||||
import 'package:cw_decred/transaction_credentials.dart';
|
||||
import 'package:cw_decred/mnemonic.dart';
|
||||
""";
|
||||
const decredCwPart = "part 'cw_decred.dart';";
|
||||
const decredContent = """
|
||||
|
@ -1463,6 +1464,8 @@ abstract class Decred {
|
|||
void updateUnspents(Object wallet);
|
||||
|
||||
int heightByDate(DateTime date);
|
||||
|
||||
List<String> getDecredWordList();
|
||||
}
|
||||
""";
|
||||
|
||||
|
|
Loading…
Reference in a new issue