mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-28 22:49:49 +00:00
315c4c911c
* fix checkbox
* save the output state
* add note as a header
* Allow copy the Amount and Address
* add frozen balance to dashboard
* add block explorer
* fix url launcher
* code formatting
* minor fixes
* Revert "minor fixes"
This reverts commit d230b6a07b
.
* fix missing implementations error
* [skip ci] update localization
* fix unspent with same txid
* add amount check
* add vout check
* remove formattedTotalAvailableBalance
* remove unrelated mac os files
59 lines
1.9 KiB
Dart
59 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
|
import 'package:cw_bitcoin/electrum_balance.dart';
|
|
import 'package:cw_bitcoin/file.dart';
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
class ElectrumWallletSnapshot {
|
|
ElectrumWallletSnapshot({
|
|
required this.name,
|
|
required this.type,
|
|
required this.password,
|
|
required this.mnemonic,
|
|
required this.addresses,
|
|
required this.balance,
|
|
required this.regularAddressIndex,
|
|
required this.changeAddressIndex});
|
|
|
|
final String name;
|
|
final String password;
|
|
final WalletType type;
|
|
|
|
String mnemonic;
|
|
List<BitcoinAddressRecord> addresses;
|
|
ElectrumBalance balance;
|
|
int regularAddressIndex;
|
|
int changeAddressIndex;
|
|
|
|
static Future<ElectrumWallletSnapshot> load(String name, WalletType type, String password) async {
|
|
final path = await pathForWallet(name: name, type: type);
|
|
final jsonSource = await read(path: path, password: password);
|
|
final data = json.decode(jsonSource) as Map;
|
|
final addressesTmp = data['addresses'] as List? ?? <Object>[];
|
|
final mnemonic = data['mnemonic'] as String;
|
|
final addresses = addressesTmp
|
|
.whereType<String>()
|
|
.map((addr) => BitcoinAddressRecord.fromJSON(addr))
|
|
.toList();
|
|
final balance = ElectrumBalance.fromJSON(data['balance'] as String) ??
|
|
ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
|
|
var regularAddressIndex = 0;
|
|
var changeAddressIndex = 0;
|
|
|
|
try {
|
|
regularAddressIndex = int.parse(data['account_index'] as String? ?? '0');
|
|
changeAddressIndex = int.parse(data['change_address_index'] as String? ?? '0');
|
|
} catch (_) {}
|
|
|
|
return ElectrumWallletSnapshot(
|
|
name: name,
|
|
type: type,
|
|
password: password,
|
|
mnemonic: mnemonic,
|
|
addresses: addresses,
|
|
balance: balance,
|
|
regularAddressIndex: regularAddressIndex,
|
|
changeAddressIndex: changeAddressIndex);
|
|
}
|
|
}
|