2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
|
2023-04-10 23:16:13 +00:00
|
|
|
import 'package:cw_bitcoin/encryption_file_utils.dart';
|
2022-10-12 17:09:57 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/unspent_coins_info.dart';
|
|
|
|
import 'package:cw_bitcoin/litecoin_wallet_addresses.dart';
|
|
|
|
import 'package:cw_core/transaction_priority.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:cw_bitcoin/electrum_wallet_snapshot.dart';
|
|
|
|
import 'package:cw_bitcoin/electrum_wallet.dart';
|
|
|
|
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
|
|
|
import 'package:cw_bitcoin/electrum_balance.dart';
|
|
|
|
import 'package:cw_bitcoin/litecoin_network.dart';
|
|
|
|
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
|
|
|
|
|
|
|
part 'litecoin_wallet.g.dart';
|
|
|
|
|
|
|
|
class LitecoinWallet = LitecoinWalletBase with _$LitecoinWallet;
|
|
|
|
|
|
|
|
abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|
|
|
LitecoinWalletBase(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required String mnemonic,
|
|
|
|
required String password,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
|
|
|
required Uint8List seedBytes,
|
2023-04-10 23:16:13 +00:00
|
|
|
required EncryptionFileUtils encryptionFileUtils,
|
2022-10-12 17:09:57 +00:00
|
|
|
List<BitcoinAddressRecord>? initialAddresses,
|
|
|
|
ElectrumBalance? initialBalance,
|
2022-01-18 16:27:33 +00:00
|
|
|
int initialRegularAddressIndex = 0,
|
|
|
|
int initialChangeAddressIndex = 0})
|
2021-12-24 12:52:08 +00:00
|
|
|
: super(
|
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
networkType: litecoinNetwork,
|
|
|
|
initialAddresses: initialAddresses,
|
2022-10-12 17:09:57 +00:00
|
|
|
initialBalance: initialBalance,
|
|
|
|
seedBytes: seedBytes,
|
2023-04-10 23:16:13 +00:00
|
|
|
encryptionFileUtils: encryptionFileUtils,
|
2022-10-12 17:09:57 +00:00
|
|
|
currency: CryptoCurrency.ltc) {
|
2021-12-24 12:52:08 +00:00
|
|
|
walletAddresses = LitecoinWalletAddresses(
|
|
|
|
walletInfo,
|
2022-01-18 16:27:33 +00:00
|
|
|
electrumClient: electrumClient,
|
2021-12-24 12:52:08 +00:00
|
|
|
initialAddresses: initialAddresses,
|
2022-01-18 16:27:33 +00:00
|
|
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
|
|
|
initialChangeAddressIndex: initialChangeAddressIndex,
|
2021-12-24 12:52:08 +00:00
|
|
|
mainHd: hd,
|
|
|
|
sideHd: bitcoin.HDWallet
|
2022-10-12 17:09:57 +00:00
|
|
|
.fromSeed(seedBytes, network: networkType)
|
2021-12-24 12:52:08 +00:00
|
|
|
.derivePath("m/0'/1"),
|
|
|
|
networkType: networkType,);
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
static Future<LitecoinWallet> create({
|
|
|
|
required String mnemonic,
|
|
|
|
required String password,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
2023-04-10 23:16:13 +00:00
|
|
|
required EncryptionFileUtils encryptionFileUtils,
|
2022-10-12 17:09:57 +00:00
|
|
|
List<BitcoinAddressRecord>? initialAddresses,
|
|
|
|
ElectrumBalance? initialBalance,
|
|
|
|
int initialRegularAddressIndex = 0,
|
|
|
|
int initialChangeAddressIndex = 0
|
|
|
|
}) async {
|
|
|
|
return LitecoinWallet(
|
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
initialAddresses: initialAddresses,
|
|
|
|
initialBalance: initialBalance,
|
|
|
|
seedBytes: await mnemonicToSeedBytes(mnemonic),
|
2023-04-10 23:16:13 +00:00
|
|
|
encryptionFileUtils: encryptionFileUtils,
|
2022-10-12 17:09:57 +00:00
|
|
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
|
|
|
initialChangeAddressIndex: initialChangeAddressIndex);
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
static Future<LitecoinWallet> open({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
|
|
|
required WalletInfo walletInfo,
|
|
|
|
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
|
|
|
required String password,
|
2023-04-10 23:16:13 +00:00
|
|
|
required EncryptionFileUtils encryptionFileUtils
|
2021-12-24 12:52:08 +00:00
|
|
|
}) async {
|
2023-04-10 23:16:13 +00:00
|
|
|
final snp = await ElectrumWallletSnapshot.load(encryptionFileUtils, name, walletInfo.type, password);
|
2021-12-24 12:52:08 +00:00
|
|
|
return LitecoinWallet(
|
|
|
|
mnemonic: snp.mnemonic,
|
|
|
|
password: password,
|
|
|
|
walletInfo: walletInfo,
|
|
|
|
unspentCoinsInfo: unspentCoinsInfo,
|
|
|
|
initialAddresses: snp.addresses,
|
|
|
|
initialBalance: snp.balance,
|
2022-10-12 17:09:57 +00:00
|
|
|
seedBytes: await mnemonicToSeedBytes(snp.mnemonic),
|
2023-04-10 23:16:13 +00:00
|
|
|
encryptionFileUtils: encryptionFileUtils,
|
2022-01-18 16:27:33 +00:00
|
|
|
initialRegularAddressIndex: snp.regularAddressIndex,
|
|
|
|
initialChangeAddressIndex: snp.changeAddressIndex);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int feeRate(TransactionPriority priority) {
|
|
|
|
if (priority is LitecoinTransactionPriority) {
|
|
|
|
switch (priority) {
|
|
|
|
case LitecoinTransactionPriority.slow:
|
|
|
|
return 1;
|
|
|
|
case LitecoinTransactionPriority.medium:
|
|
|
|
return 2;
|
|
|
|
case LitecoinTransactionPriority.fast:
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|