2021-07-05 13:52:24 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/unspent_coins_info.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2020-09-15 20:35:49 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
2021-05-07 07:36:38 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/electrum_wallet_snapshot.dart';
|
|
|
|
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_info.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
|
2021-05-07 07:36:38 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/electrum_balance.dart';
|
2021-07-13 05:46:34 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin_wallet_addresses.dart';
|
2020-05-12 12:04:54 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
part 'bitcoin_wallet.g.dart';
|
2020-05-12 12:04:54 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
class BitcoinWallet = BitcoinWalletBase with _$BitcoinWallet;
|
2020-05-12 12:04:54 +00:00
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
|
|
|
BitcoinWalletBase(
|
2020-05-12 12:04:54 +00:00
|
|
|
{@required String mnemonic,
|
|
|
|
@required String password,
|
2020-11-12 16:31:53 +00:00
|
|
|
@required WalletInfo walletInfo,
|
2021-07-05 13:52:24 +00:00
|
|
|
@required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
2020-06-20 07:10:00 +00:00
|
|
|
List<BitcoinAddressRecord> initialAddresses,
|
2021-05-07 07:36:38 +00:00
|
|
|
ElectrumBalance initialBalance,
|
|
|
|
int accountIndex = 0})
|
|
|
|
: super(
|
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
2021-07-05 13:52:24 +00:00
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
2021-05-07 07:36:38 +00:00
|
|
|
networkType: bitcoin.bitcoin,
|
|
|
|
initialAddresses: initialAddresses,
|
2021-07-13 05:46:34 +00:00
|
|
|
initialBalance: initialBalance) {
|
|
|
|
walletAddresses = BitcoinWalletAddresses(
|
|
|
|
walletInfo,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
accountIndex: accountIndex,
|
|
|
|
hd: hd,
|
|
|
|
networkType: networkType);
|
|
|
|
}
|
2021-05-07 07:36:38 +00:00
|
|
|
|
|
|
|
static Future<BitcoinWallet> open({
|
|
|
|
@required String name,
|
|
|
|
@required WalletInfo walletInfo,
|
2021-07-05 13:52:24 +00:00
|
|
|
@required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
2021-05-07 07:36:38 +00:00
|
|
|
@required String password,
|
|
|
|
}) async {
|
|
|
|
final snp = ElectrumWallletSnapshot(name, walletInfo.type, password);
|
|
|
|
await snp.load();
|
|
|
|
return BitcoinWallet(
|
|
|
|
mnemonic: snp.mnemonic,
|
2020-05-12 12:04:54 +00:00
|
|
|
password: password,
|
2021-05-07 07:36:38 +00:00
|
|
|
walletInfo: walletInfo,
|
2021-07-05 13:52:24 +00:00
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
2021-05-07 07:36:38 +00:00
|
|
|
initialAddresses: snp.addresses,
|
|
|
|
initialBalance: snp.balance,
|
|
|
|
accountIndex: snp.accountIndex);
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
2020-05-12 12:04:54 +00:00
|
|
|
}
|