2021-12-24 12:52:08 +00:00
|
|
|
part of 'bitcoin.dart';
|
|
|
|
|
|
|
|
class CWBitcoin extends Bitcoin {
|
|
|
|
@override
|
|
|
|
TransactionPriority getMediumTransactionPriority() => BitcoinTransactionPriority.medium;
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
WalletCredentials createBitcoinRestoreWalletFromSeedCredentials({
|
|
|
|
required String name,
|
|
|
|
required String mnemonic,
|
|
|
|
required String password})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> BitcoinRestoreWalletFromSeedCredentials(name: name, mnemonic: mnemonic, password: password);
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
WalletCredentials createBitcoinRestoreWalletFromWIFCredentials({
|
|
|
|
required String name,
|
|
|
|
required String password,
|
|
|
|
required String wif,
|
|
|
|
WalletInfo? walletInfo})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> BitcoinRestoreWalletFromWIFCredentials(name: name, password: password, wif: wif, walletInfo: walletInfo);
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
WalletCredentials createBitcoinNewWalletCredentials({
|
|
|
|
required String name,
|
|
|
|
WalletInfo? walletInfo})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> BitcoinNewWalletCredentials(name: name, walletInfo: walletInfo);
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<String> getWordList() => wordlist;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, String> getWalletKeys(Object wallet) {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
final keys = bitcoinWallet.keys;
|
|
|
|
|
|
|
|
return <String, String>{
|
|
|
|
'wif': keys.wif,
|
|
|
|
'privateKey': keys.privateKey,
|
|
|
|
'publicKey': keys.publicKey
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<TransactionPriority> getTransactionPriorities()
|
|
|
|
=> BitcoinTransactionPriority.all;
|
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
@override
|
2022-01-12 16:13:16 +00:00
|
|
|
List<TransactionPriority> getLitecoinTransactionPriorities()
|
|
|
|
=> LitecoinTransactionPriority.all;
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
TransactionPriority deserializeBitcoinTransactionPriority(int raw)
|
|
|
|
=> BitcoinTransactionPriority.deserialize(raw: raw);
|
|
|
|
|
2022-12-08 15:23:17 +00:00
|
|
|
@override
|
|
|
|
TransactionPriority deserializeLitecoinTransactionPriority(int raw)
|
|
|
|
=> LitecoinTransactionPriority.deserialize(raw: raw);
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
int getFeeRate(Object wallet, TransactionPriority priority) {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
return bitcoinWallet.feeRate(priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-01-23 05:15:24 +00:00
|
|
|
Future<void> generateNewAddress(Object wallet, String label) async {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2024-01-23 05:15:24 +00:00
|
|
|
await bitcoinWallet.walletAddresses.generateNewAddress(label: label);
|
|
|
|
await wallet.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> updateAddress(Object wallet,String address, String label) async {
|
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
|
|
|
bitcoinWallet.walletAddresses.updateAddress(address, label);
|
|
|
|
await wallet.save();
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Object createBitcoinTransactionCredentials(List<Output> outputs, {required TransactionPriority priority, int? feeRate})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> BitcoinTransactionCredentials(
|
|
|
|
outputs.map((out) => OutputInfo(
|
|
|
|
fiatAmount: out.fiatAmount,
|
|
|
|
cryptoAmount: out.cryptoAmount,
|
|
|
|
address: out.address,
|
|
|
|
note: out.note,
|
|
|
|
sendAll: out.sendAll,
|
|
|
|
extractedAddress: out.extractedAddress,
|
|
|
|
isParsedAddress: out.isParsedAddress,
|
|
|
|
formattedCryptoAmount: out.formattedCryptoAmount))
|
|
|
|
.toList(),
|
2023-08-04 17:01:49 +00:00
|
|
|
priority: priority as BitcoinTransactionPriority,
|
2022-07-28 17:03:16 +00:00
|
|
|
feeRate: feeRate);
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Object createBitcoinTransactionCredentialsRaw(List<OutputInfo> outputs, {TransactionPriority? priority, required int feeRate})
|
2022-07-28 17:03:16 +00:00
|
|
|
=> BitcoinTransactionCredentials(
|
|
|
|
outputs,
|
|
|
|
priority: priority != null ? priority as BitcoinTransactionPriority : null,
|
|
|
|
feeRate: feeRate);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<String> getAddresses(Object wallet) {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
return bitcoinWallet.walletAddresses.addresses
|
|
|
|
.map((BitcoinAddressRecord addr) => addr.address)
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
2024-01-23 05:15:24 +00:00
|
|
|
@override
|
|
|
|
@computed
|
|
|
|
List<ElectrumSubAddress> getSubAddresses(Object wallet) {
|
|
|
|
final electrumWallet = wallet as ElectrumWallet;
|
|
|
|
return electrumWallet.walletAddresses.addresses
|
|
|
|
.map((BitcoinAddressRecord addr) => ElectrumSubAddress(
|
|
|
|
id: addr.index,
|
|
|
|
name: addr.name,
|
|
|
|
address: electrumWallet.type == WalletType.bitcoinCash ? addr.cashAddr : addr.address,
|
|
|
|
txCount: addr.txCount,
|
|
|
|
balance: addr.balance,
|
|
|
|
isChange: addr.isHidden))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
String getAddress(Object wallet) {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
return bitcoinWallet.walletAddresses.address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
String formatterBitcoinAmountToString({required int amount})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> bitcoinAmountToString(amount: amount);
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
double formatterBitcoinAmountToDouble({required int amount})
|
2021-12-24 12:52:08 +00:00
|
|
|
=> bitcoinAmountToDouble(amount: amount);
|
|
|
|
|
|
|
|
@override
|
|
|
|
int formatterStringDoubleToBitcoinAmount(String amount)
|
|
|
|
=> stringDoubleToBitcoinAmount(amount);
|
|
|
|
|
2022-10-28 22:09:27 +00:00
|
|
|
@override
|
|
|
|
String bitcoinTransactionPriorityWithLabel(TransactionPriority priority, int rate)
|
|
|
|
=> (priority as BitcoinTransactionPriority).labelWithRate(rate);
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
2023-10-12 22:50:16 +00:00
|
|
|
List<BitcoinUnspent> getUnspents(Object wallet) {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2023-10-12 22:50:16 +00:00
|
|
|
return bitcoinWallet.unspentCoins;
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 17:57:47 +00:00
|
|
|
Future<void> updateUnspents(Object wallet) async {
|
2022-01-12 13:33:56 +00:00
|
|
|
final bitcoinWallet = wallet as ElectrumWallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
await bitcoinWallet.updateUnspent();
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletService createBitcoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource) {
|
|
|
|
return BitcoinWalletService(walletInfoSource, unspentCoinSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletService createLitecoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource) {
|
|
|
|
return LitecoinWalletService(walletInfoSource, unspentCoinSource);
|
|
|
|
}
|
2022-11-03 23:13:13 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getBitcoinTransactionPriorityMedium()
|
|
|
|
=> BitcoinTransactionPriority.medium;
|
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getLitecoinTransactionPriorityMedium()
|
|
|
|
=> LitecoinTransactionPriority.medium;
|
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getBitcoinTransactionPrioritySlow()
|
|
|
|
=> BitcoinTransactionPriority.slow;
|
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getLitecoinTransactionPrioritySlow()
|
|
|
|
=> LitecoinTransactionPriority.slow;
|
2023-10-05 01:09:07 +00:00
|
|
|
}
|