2023-11-30 17:28:29 +00:00
|
|
|
import 'package:bitcoin_flutter/bitcoin_flutter.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
|
2023-10-12 22:50:16 +00:00
|
|
|
import 'package:cw_bitcoin/utils.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
|
|
|
|
part 'bitcoin_wallet_addresses.g.dart';
|
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
class BitcoinWalletAddresses = BitcoinWalletAddressesBase with _$BitcoinWalletAddresses;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with Store {
|
2023-11-30 17:28:29 +00:00
|
|
|
BitcoinWalletAddressesBase(
|
|
|
|
WalletInfo walletInfo, {
|
|
|
|
required super.mainHd,
|
|
|
|
required super.sideHd,
|
|
|
|
required super.networkType,
|
|
|
|
required super.transactionHistory,
|
|
|
|
super.initialAddresses,
|
|
|
|
super.initialRegularAddressIndex = 0,
|
|
|
|
super.initialChangeAddressIndex = 0,
|
|
|
|
super.silentAddress,
|
|
|
|
}) : super(walletInfo);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-30 17:28:29 +00:00
|
|
|
String getAddress({required int index, required HDWallet hd, AddressType? addressType}) {
|
|
|
|
if (addressType == AddressType.p2pkh)
|
2023-11-30 10:01:58 +00:00
|
|
|
return generateP2PKHAddress(hd: hd, index: index, networkType: networkType);
|
|
|
|
|
2023-11-30 17:28:29 +00:00
|
|
|
if (addressType == AddressType.p2tr)
|
2023-11-30 10:01:58 +00:00
|
|
|
return generateP2TRAddress(hd: hd, index: index, networkType: networkType);
|
|
|
|
|
|
|
|
return generateP2WPKHAddress(hd: hd, index: index, networkType: networkType);
|
|
|
|
}
|
2023-10-12 22:50:16 +00:00
|
|
|
}
|