This commit is contained in:
Matthew Fosse 2024-05-08 11:51:25 -07:00
parent 51a04dee2f
commit 6a4a6b8639
3 changed files with 23 additions and 10 deletions

View file

@ -65,6 +65,7 @@ abstract class ElectrumWalletBase
getAccountHDWallet(currency, networkType, seedBytes, xpub, walletInfo.derivationInfo),
syncStatus = NotConnectedSyncStatus(),
_password = password,
mnemonic = mnemonic,
_feeRates = <int>[],
_isTransactionUpdating = false,
isEnabledAutoGenerateSubaddress = true,
@ -79,7 +80,6 @@ abstract class ElectrumWalletBase
this.unspentCoinsInfo = unspentCoinsInfo,
this.network = _getNetwork(networkType, currency),
this.isTestnet = networkType == bitcoin.testnet,
this._mnemonic = mnemonic,
super(walletInfo) {
this.electrumClient = electrumClient ?? ElectrumClient();
this.walletInfo = walletInfo;
@ -114,7 +114,7 @@ abstract class ElectrumWalletBase
inputsCount * 68 + outputsCounts * 34 + 10;
final bitcoin.HDWallet accountHD;
final String? _mnemonic;
final String? mnemonic;
bitcoin.HDWallet get hd => accountHD.derive(0);
final String? passphrase;
@ -149,7 +149,7 @@ abstract class ElectrumWalletBase
String get xpub => accountHD.base58!;
@override
String? get seed => _mnemonic;
String? get seed => mnemonic;
bitcoin.NetworkType networkType;
BasedUtxoNetwork network;
@ -711,7 +711,7 @@ abstract class ElectrumWalletBase
throw UnimplementedError();
String toJSON() => json.encode({
'mnemonic': _mnemonic,
'mnemonic': mnemonic,
'xpub': xpub,
'passphrase': passphrase ?? '',
'account_index': walletAddresses.currentReceiveAddressIndexByType,

View file

@ -52,8 +52,8 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
}) : _isTransactionUpdating = false,
syncStatus = NotConnectedSyncStatus(),
_balance = ObservableMap<CryptoCurrency, LightningBalance>(),
mnemonic = mnemonic,
super(
mnemonic: mnemonic,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
@ -65,7 +65,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
) {
_balance[CryptoCurrency.btcln] =
initialBalance ?? LightningBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
String derivationPath = walletInfo.derivationInfo!.derivationPath!;
String derivationPath = walletInfo.derivationInfo!.derivationPath!;
String sideDerivationPath = derivationPath.substring(0, derivationPath.length - 1) + "1";
final hd = bitcoin.HDWallet.fromSeed(seedBytes, network: networkType);
walletAddresses = BitcoinWalletAddresses(
@ -130,7 +130,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
final snp =
await ElectrumWalletSnapshot.load(name, walletInfo.type, password, BitcoinNetwork.mainnet);
return LightningWallet(
mnemonic: snp.mnemonic,
mnemonic: snp.mnemonic!,
password: password,
walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfo,
@ -140,7 +140,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
unconfirmed: snp.balance.unconfirmed,
frozen: snp.balance.frozen,
),
seedBytes: await mnemonicToSeedBytes(snp.mnemonic),
seedBytes: await mnemonicToSeedBytes(snp.mnemonic!),
initialRegularAddressIndex: snp.regularAddressIndex,
initialChangeAddressIndex: snp.changeAddressIndex,
addressPageType: snp.addressPageType,
@ -337,6 +337,9 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
// balance is updated automatically
}
@override
String mnemonic;
@override
String get seed => mnemonic;

View file

@ -13,8 +13,11 @@ import 'package:cw_lightning/lightning_wallet.dart';
import 'package:hive/hive.dart';
import 'package:collection/collection.dart';
class LightningWalletService extends WalletService<BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
class LightningWalletService extends WalletService<
BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials,
BitcoinRestoreWalletFromWIFCredentials,
BitcoinRestoreWalletFromHardware> {
LightningWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);
final Box<WalletInfo> walletInfoSource;
@ -67,6 +70,13 @@ class LightningWalletService extends WalletService<BitcoinNewWalletCredentials,
}
}
@override
Future<LightningWallet> restoreFromHardwareWallet(BitcoinRestoreWalletFromHardware credentials,
{bool? isTestnet}) {
throw UnimplementedError(
"Restoring a Lightning wallet from a hardware wallet is not yet supported!");
}
@override
Future<void> remove(String wallet) async {
File(await pathForWalletDir(name: wallet, type: getType())).delete(recursive: true);