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;
|
2020-08-25 16:32:40 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/utils.dart';
|
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';
|
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,
|
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,
|
|
|
|
networkType: bitcoin.bitcoin,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
initialBalance: initialBalance,
|
|
|
|
accountIndex: accountIndex);
|
|
|
|
|
|
|
|
static Future<BitcoinWallet> open({
|
|
|
|
@required String name,
|
|
|
|
@required WalletInfo walletInfo,
|
|
|
|
@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,
|
|
|
|
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
|
|
|
|
|
|
|
@override
|
2021-05-07 07:36:38 +00:00
|
|
|
String getAddress({@required int index, @required bitcoin.HDWallet hd}) =>
|
|
|
|
generateP2WPKHAddress(hd: hd, index: index, networkType: networkType);
|
2020-05-12 12:04:54 +00:00
|
|
|
}
|