Files
hash-wallet/lib/view_model/restore/restore_wallet.dart
T
77812016ac LCW-1144 cupcake litecoin (#2557)
* Add psbt rpcs

* Only build arm64

* Rebuild protos

* Update proto

* Add psbt create rpc

* Restore wallet stuff

* more stuff

* more stuff

* more stuff

* Fix open wallet

* Fix mweb enabled

* Start of buildPsbt

* Update proto

* Psbt add recipients

* fixes

* slightly better

* more fixes

* decode ur

* add more commit code

* Update proto

* use new proto

* Don't eat psbt rpc errors

* Use unix domain socket for mwebd

* add gitignore

* Undo build only arm64

* fix pure mweb txns

* fix mweb txids

* fix ci

* fix blank pegin address

* chore: update cw_mweb dependencies
chore: remove cw_core as dependency from cw_mweb

* fix: Ltub restore

* fix: address review crashes, fix non-mweb view only wallets

* minor fixes

---------

Co-authored-by: Hector Chu <hectorchu@gmail.com>
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2025-11-24 17:58:12 +01:00

105 lines
3.4 KiB
Dart

import 'dart:convert';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cw_core/utils/zpub.dart';
import 'package:cw_core/wallet_type.dart';
class RestoredWallet {
RestoredWallet(
{required this.restoreMode,
required this.type,
required this.address,
this.name,
this.txId,
this.spendKey,
this.viewKey,
this.scanSecret,
this.spendPubkey,
this.mnemonicSeed,
this.passphrase,
this.txAmount,
this.txDescription,
this.recipientName,
this.height,
this.privateKey});
final WalletRestoreMode restoreMode;
final WalletType type;
final String? name;
final String? address;
final String? txId;
final String? spendKey;
final String? viewKey;
final String? scanSecret;
final String? spendPubkey;
final String? mnemonicSeed;
final String? passphrase;
final String? txAmount;
final String? txDescription;
final String? recipientName;
final int? height;
final String? privateKey;
factory RestoredWallet.fromKey(Map<String, dynamic> json) {
try {
final codeParsed = jsonDecode(json['raw_qr'].toString());
if (codeParsed["version"] == 0) {
json['address'] = codeParsed["primaryAddress"];
json['view_key'] = codeParsed["privateViewKey"];
json['height'] = codeParsed["restoreHeight"].toString();
json['label'] = codeParsed["label"];
}
} catch (e) {
// fine, we don't care, it is only for monero anyway
}
if (json['ltub'] != null) {
json['xpub'] = convertLtubToXpub(json['ltub'] as String);
}
if (json['zpub'] != null) {
json['xpub'] = convertZpubToXpub(json['zpub'] as String);
}
json['xpub'] = convertAnyToXpub(json['xpub'] as String);
json['view_key'] ??= json['xpub'];
final height = json['height'] as String?;
return RestoredWallet(
name: json['label'] as String?,
restoreMode: json['mode'] as WalletRestoreMode,
type: json['type'] as WalletType,
address: json['address'] as String?,
spendKey: json['spend_key'] as String?,
viewKey: json['view_key'] as String?,
scanSecret: json['scan_secret'] as String?,
spendPubkey: json['spend_pubkey'] as String?,
height: height != null ? int.tryParse(height) ?? 0 : 0,
privateKey: json['private_key'] as String?,
);
}
factory RestoredWallet.fromSeed(Map<String, dynamic> json) {
final height = json['height'] as String?;
final mnemonic_seed = json['mnemonic_seed'] as String?;
final seed = json['seed'] as String? ?? json['hexSeed'] as String?;
final passphrase = json['passphrase'] as String?;
return RestoredWallet(
restoreMode: json['mode'] as WalletRestoreMode,
type: json['type'] as WalletType,
address: json['address'] as String?,
mnemonicSeed: mnemonic_seed ?? seed,
passphrase: passphrase,
height: height != null ? int.parse(height) : 0,
);
}
factory RestoredWallet.fromTxIds(Map<String, dynamic> json) {
return RestoredWallet(
restoreMode: json['mode'] as WalletRestoreMode,
type: json['type'] as WalletType,
address: json['address'] as String?,
txId: json['tx_payment_id'] as String,
txAmount: json['tx_amount'] as String,
txDescription: json['tx_description'] as String?,
recipientName: json['recipient_name'] as String?,
);
}
}