mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
creating and restoring a wallet
This commit is contained in:
parent
ec1d565658
commit
afcfab9796
22 changed files with 332 additions and 323 deletions
3
assets/bitcoin_cash_electrum_server_list.yml
Normal file
3
assets/bitcoin_cash_electrum_server_list.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
-
|
||||
uri: bitcoincash.stackwallet.com:50002
|
||||
is_default: true
|
|
@ -2,7 +2,9 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:bitcoin_flutter/bitcoin_flutter.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
@ -34,45 +36,63 @@ import 'package:cw_bitcoin/electrum.dart';
|
|||
import 'package:hex/hex.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:bip32/bip32.dart';
|
||||
|
||||
part 'electrum_wallet.g.dart';
|
||||
|
||||
class ElectrumWallet = ElectrumWalletBase with _$ElectrumWallet;
|
||||
|
||||
abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
||||
ElectrumTransactionHistory, ElectrumTransactionInfo> with Store {
|
||||
abstract class ElectrumWalletBase
|
||||
extends WalletBase<ElectrumBalance, ElectrumTransactionHistory, ElectrumTransactionInfo>
|
||||
with Store {
|
||||
ElectrumWalletBase(
|
||||
{required String password,
|
||||
required WalletInfo walletInfo,
|
||||
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
||||
required this.networkType,
|
||||
required this.mnemonic,
|
||||
required Uint8List seedBytes,
|
||||
List<BitcoinAddressRecord>? initialAddresses,
|
||||
ElectrumClient? electrumClient,
|
||||
ElectrumBalance? initialBalance,
|
||||
CryptoCurrency? currency})
|
||||
: hd = bitcoin.HDWallet.fromSeed(seedBytes, network: networkType)
|
||||
.derivePath("m/0'/0"),
|
||||
required WalletInfo walletInfo,
|
||||
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
||||
required this.networkType,
|
||||
required this.mnemonic,
|
||||
required Uint8List seedBytes,
|
||||
List<BitcoinAddressRecord>? initialAddresses,
|
||||
ElectrumClient? electrumClient,
|
||||
ElectrumBalance? initialBalance,
|
||||
CryptoCurrency? currency})
|
||||
: hd = currency == CryptoCurrency.bch
|
||||
? bitcoinCashHDWallet(seedBytes)
|
||||
: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/0"),
|
||||
syncStatus = NotConnectedSyncStatus(),
|
||||
_password = password,
|
||||
_feeRates = <int>[],
|
||||
_isTransactionUpdating = false,
|
||||
unspentCoins = [],
|
||||
_scripthashesUpdateSubject = {},
|
||||
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of(
|
||||
currency != null
|
||||
? {currency: initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0,
|
||||
frozen: 0)}
|
||||
: {}),
|
||||
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of(currency != null
|
||||
? {
|
||||
currency:
|
||||
initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0)
|
||||
}
|
||||
: {}),
|
||||
this.unspentCoinsInfo = unspentCoinsInfo,
|
||||
super(walletInfo) {
|
||||
this.electrumClient = electrumClient ?? ElectrumClient();
|
||||
this.walletInfo = walletInfo;
|
||||
transactionHistory =
|
||||
ElectrumTransactionHistory(walletInfo: walletInfo, password: password);
|
||||
transactionHistory = ElectrumTransactionHistory(walletInfo: walletInfo, password: password);
|
||||
}
|
||||
|
||||
static bitcoin.NetworkType bitcoinCashNetworkType = bitcoin.NetworkType(
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: bitcoin.Bip32Type(
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4,
|
||||
),
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80);
|
||||
|
||||
static HDWallet bitcoinCashHDWallet(Uint8List seedBytes) =>
|
||||
bitcoin.HDWallet.fromSeed(seedBytes, network: bitcoinCashNetworkType)
|
||||
.derivePath("m/44'/145'/0'/0/0");
|
||||
|
||||
static int estimatedTransactionSize(int inputsCount, int outputsCounts) =>
|
||||
inputsCount * 146 + outputsCounts * 33 + 8;
|
||||
|
||||
|
@ -98,9 +118,9 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
.toList();
|
||||
|
||||
List<String> get publicScriptHashes => walletAddresses.addresses
|
||||
.where((addr) => !addr.isHidden)
|
||||
.map((addr) => scriptHash(addr.address, networkType: networkType))
|
||||
.toList();
|
||||
.where((addr) => !addr.isHidden)
|
||||
.map((addr) => scriptHash(addr.address, networkType: networkType))
|
||||
.toList();
|
||||
|
||||
String get xpub => hd.base58!;
|
||||
|
||||
|
@ -110,8 +130,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
bitcoin.NetworkType networkType;
|
||||
|
||||
@override
|
||||
BitcoinWalletKeys get keys => BitcoinWalletKeys(
|
||||
wif: hd.wif!, privateKey: hd.privKey!, publicKey: hd.pubKey!);
|
||||
BitcoinWalletKeys get keys =>
|
||||
BitcoinWalletKeys(wif: hd.wif!, privateKey: hd.privKey!, publicKey: hd.pubKey!);
|
||||
|
||||
String _password;
|
||||
List<BitcoinUnspent> unspentCoins;
|
||||
|
@ -132,15 +152,17 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
Future<void> startSync() async {
|
||||
try {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
await walletAddresses.discoverAddresses();
|
||||
if (walletInfo.type != WalletType.bitcoinCash) { //TODO: BCH: remove this check when supported
|
||||
await walletAddresses.discoverAddresses();
|
||||
}
|
||||
await updateTransactions();
|
||||
_subscribeForUpdates();
|
||||
await updateUnspent();
|
||||
await updateBalance();
|
||||
_feeRates = await electrumClient.feeRates();
|
||||
|
||||
Timer.periodic(const Duration(minutes: 1),
|
||||
(timer) async => _feeRates = await electrumClient.feeRates());
|
||||
Timer.periodic(
|
||||
const Duration(minutes: 1), (timer) async => _feeRates = await electrumClient.feeRates());
|
||||
|
||||
syncStatus = SyncedSyncStatus();
|
||||
} catch (e, stacktrace) {
|
||||
|
@ -169,8 +191,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
|
||||
@override
|
||||
Future<PendingBitcoinTransaction> createTransaction(
|
||||
Object credentials) async {
|
||||
Future<PendingBitcoinTransaction> createTransaction(Object credentials) async {
|
||||
const minAmount = 546;
|
||||
final transactionCredentials = credentials as BitcoinTransactionCredentials;
|
||||
final inputs = <BitcoinUnspent>[];
|
||||
|
@ -204,13 +225,11 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
var fee = 0;
|
||||
|
||||
if (hasMultiDestination) {
|
||||
if (outputs.any((item) => item.sendAll
|
||||
|| item.formattedCryptoAmount! <= 0)) {
|
||||
if (outputs.any((item) => item.sendAll || item.formattedCryptoAmount! <= 0)) {
|
||||
throw BitcoinTransactionWrongBalanceException(currency);
|
||||
}
|
||||
|
||||
credentialsAmount = outputs.fold(0, (acc, value) =>
|
||||
acc + value.formattedCryptoAmount!);
|
||||
credentialsAmount = outputs.fold(0, (acc, value) => acc + value.formattedCryptoAmount!);
|
||||
|
||||
if (allAmount - credentialsAmount < minAmount) {
|
||||
throw BitcoinTransactionWrongBalanceException(currency);
|
||||
|
@ -227,9 +246,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
} else {
|
||||
final output = outputs.first;
|
||||
credentialsAmount = !output.sendAll
|
||||
? output.formattedCryptoAmount!
|
||||
: 0;
|
||||
credentialsAmount = !output.sendAll ? output.formattedCryptoAmount! : 0;
|
||||
|
||||
if (credentialsAmount > allAmount) {
|
||||
throw BitcoinTransactionWrongBalanceException(currency);
|
||||
|
@ -291,8 +308,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
final p2wpkh = bitcoin
|
||||
.P2WPKH(
|
||||
data: generatePaymentData(
|
||||
hd: input.address.isHidden ? walletAddresses.sideHd : walletAddresses.mainHd,
|
||||
index: input.address.index),
|
||||
hd: input.address.isHidden ? walletAddresses.sideHd : walletAddresses.mainHd,
|
||||
index: input.address.index),
|
||||
network: networkType)
|
||||
.data;
|
||||
|
||||
|
@ -303,19 +320,12 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
});
|
||||
|
||||
outputs.forEach((item) {
|
||||
final outputAmount = hasMultiDestination
|
||||
? item.formattedCryptoAmount
|
||||
: amount;
|
||||
final outputAddress = item.isParsedAddress
|
||||
? item.extractedAddress!
|
||||
: item.address;
|
||||
txb.addOutput(
|
||||
addressToOutputScript(outputAddress, networkType),
|
||||
outputAmount!);
|
||||
final outputAmount = hasMultiDestination ? item.formattedCryptoAmount : amount;
|
||||
final outputAddress = item.isParsedAddress ? item.extractedAddress! : item.address;
|
||||
txb.addOutput(addressToOutputScript(outputAddress, networkType), outputAmount!);
|
||||
});
|
||||
|
||||
final estimatedSize =
|
||||
estimatedTransactionSize(inputs.length, outputs.length + 1);
|
||||
final estimatedSize = estimatedTransactionSize(inputs.length, outputs.length + 1);
|
||||
var feeAmount = 0;
|
||||
|
||||
if (transactionCredentials.feeRate != null) {
|
||||
|
@ -350,12 +360,12 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
|
||||
String toJSON() => json.encode({
|
||||
'mnemonic': mnemonic,
|
||||
'account_index': walletAddresses.currentReceiveAddressIndex.toString(),
|
||||
'change_address_index': walletAddresses.currentChangeAddressIndex.toString(),
|
||||
'addresses': walletAddresses.addresses.map((addr) => addr.toJSON()).toList(),
|
||||
'balance': balance[currency]?.toJSON()
|
||||
});
|
||||
'mnemonic': mnemonic,
|
||||
'account_index': walletAddresses.currentReceiveAddressIndex.toString(),
|
||||
'change_address_index': walletAddresses.currentChangeAddressIndex.toString(),
|
||||
'addresses': walletAddresses.addresses.map((addr) => addr.toJSON()).toList(),
|
||||
'balance': balance[currency]?.toJSON()
|
||||
});
|
||||
|
||||
int feeRate(TransactionPriority priority) {
|
||||
try {
|
||||
|
@ -364,34 +374,29 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
|
||||
return 0;
|
||||
} catch(_) {
|
||||
} catch (_) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int feeAmountForPriority(BitcoinTransactionPriority priority, int inputsCount,
|
||||
int outputsCount) =>
|
||||
int feeAmountForPriority(
|
||||
BitcoinTransactionPriority priority, int inputsCount, int outputsCount) =>
|
||||
feeRate(priority) * estimatedTransactionSize(inputsCount, outputsCount);
|
||||
|
||||
int feeAmountWithFeeRate(int feeRate, int inputsCount,
|
||||
int outputsCount) =>
|
||||
int feeAmountWithFeeRate(int feeRate, int inputsCount, int outputsCount) =>
|
||||
feeRate * estimatedTransactionSize(inputsCount, outputsCount);
|
||||
|
||||
@override
|
||||
int calculateEstimatedFee(TransactionPriority? priority, int? amount,
|
||||
{int? outputsCount}) {
|
||||
int calculateEstimatedFee(TransactionPriority? priority, int? amount, {int? outputsCount}) {
|
||||
if (priority is BitcoinTransactionPriority) {
|
||||
return calculateEstimatedFeeWithFeeRate(
|
||||
feeRate(priority),
|
||||
amount,
|
||||
outputsCount: outputsCount);
|
||||
return calculateEstimatedFeeWithFeeRate(feeRate(priority), amount,
|
||||
outputsCount: outputsCount);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int calculateEstimatedFeeWithFeeRate(int feeRate, int? amount,
|
||||
{int? outputsCount}) {
|
||||
int calculateEstimatedFeeWithFeeRate(int feeRate, int? amount, {int? outputsCount}) {
|
||||
int inputsCount = 0;
|
||||
|
||||
if (amount != null) {
|
||||
|
@ -420,8 +425,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
// If send all, then we have no change value
|
||||
final _outputsCount = outputsCount ?? (amount != null ? 2 : 1);
|
||||
|
||||
return feeAmountWithFeeRate(
|
||||
feeRate, inputsCount, _outputsCount);
|
||||
return feeAmountWithFeeRate(feeRate, inputsCount, _outputsCount);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -436,8 +440,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
|
||||
final currentWalletFile = File(currentWalletPath);
|
||||
|
||||
final currentDirPath =
|
||||
await pathForWalletDir(name: walletInfo.name, type: type);
|
||||
final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
|
||||
final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
|
||||
|
||||
// Copies current wallet files into new wallet name's dir and files
|
||||
|
@ -474,21 +477,18 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<String> makePath() async =>
|
||||
pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
||||
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
||||
|
||||
Future<void> updateUnspent() async {
|
||||
final unspent = await Future.wait(walletAddresses
|
||||
.addresses.map((address) => electrumClient
|
||||
final unspent = await Future.wait(walletAddresses.addresses.map((address) => electrumClient
|
||||
.getListUnspentWithAddress(address.address, networkType)
|
||||
.then((unspent) => unspent
|
||||
.map((unspent) {
|
||||
try {
|
||||
return BitcoinUnspent.fromJSON(address, unspent);
|
||||
} catch(_) {
|
||||
return null;
|
||||
}
|
||||
}).whereNotNull())));
|
||||
.then((unspent) => unspent.map((unspent) {
|
||||
try {
|
||||
return BitcoinUnspent.fromJSON(address, unspent);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}).whereNotNull())));
|
||||
unspentCoins = unspent.expand((e) => e).toList();
|
||||
|
||||
if (unspentCoinsInfo.isEmpty) {
|
||||
|
@ -498,8 +498,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
|
||||
if (unspentCoins.isNotEmpty) {
|
||||
unspentCoins.forEach((coin) {
|
||||
final coinInfoList = unspentCoinsInfo.values.where((element) =>
|
||||
element.walletId.contains(id) && element.hash.contains(coin.hash));
|
||||
final coinInfoList = unspentCoinsInfo.values
|
||||
.where((element) => element.walletId.contains(id) && element.hash.contains(coin.hash));
|
||||
|
||||
if (coinInfoList.isNotEmpty) {
|
||||
final coinInfo = coinInfoList.first;
|
||||
|
@ -518,14 +518,14 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
|
||||
Future<void> _addCoinInfo(BitcoinUnspent coin) async {
|
||||
final newInfo = UnspentCoinsInfo(
|
||||
walletId: id,
|
||||
hash: coin.hash,
|
||||
isFrozen: coin.isFrozen,
|
||||
isSending: coin.isSending,
|
||||
noteRaw: coin.note,
|
||||
address: coin.address.address,
|
||||
value: coin.value,
|
||||
vout: coin.vout,
|
||||
walletId: id,
|
||||
hash: coin.hash,
|
||||
isFrozen: coin.isFrozen,
|
||||
isSending: coin.isSending,
|
||||
noteRaw: coin.note,
|
||||
address: coin.address.address,
|
||||
value: coin.value,
|
||||
vout: coin.vout,
|
||||
);
|
||||
|
||||
await unspentCoinsInfo.add(newInfo);
|
||||
|
@ -534,8 +534,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
Future<void> _refreshUnspentCoinsInfo() async {
|
||||
try {
|
||||
final List<dynamic> keys = <dynamic>[];
|
||||
final currentWalletUnspentCoins = unspentCoinsInfo.values
|
||||
.where((element) => element.walletId.contains(id));
|
||||
final currentWalletUnspentCoins =
|
||||
unspentCoinsInfo.values.where((element) => element.walletId.contains(id));
|
||||
|
||||
if (currentWalletUnspentCoins.isNotEmpty) {
|
||||
currentWalletUnspentCoins.forEach((element) {
|
||||
|
@ -571,27 +571,19 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
ins.add(tx);
|
||||
}
|
||||
|
||||
return ElectrumTransactionBundle(
|
||||
original,
|
||||
ins: ins,
|
||||
time: time,
|
||||
confirmations: confirmations);
|
||||
return ElectrumTransactionBundle(original, ins: ins, time: time, confirmations: confirmations);
|
||||
}
|
||||
|
||||
Future<ElectrumTransactionInfo?> fetchTransactionInfo(
|
||||
{required String hash, required int height}) async {
|
||||
try {
|
||||
final tx = await getTransactionExpanded(hash: hash, height: height);
|
||||
final addresses = walletAddresses.addresses.map((addr) => addr.address).toSet();
|
||||
return ElectrumTransactionInfo.fromElectrumBundle(
|
||||
tx,
|
||||
walletInfo.type,
|
||||
networkType,
|
||||
addresses: addresses,
|
||||
height: height);
|
||||
} catch(_) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final tx = await getTransactionExpanded(hash: hash, height: height);
|
||||
final addresses = walletAddresses.addresses.map((addr) => addr.address).toSet();
|
||||
return ElectrumTransactionInfo.fromElectrumBundle(tx, walletInfo.type, networkType,
|
||||
addresses: addresses, height: height);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -602,10 +594,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
final sh = scriptHash(addressRecord.address, networkType: networkType);
|
||||
addressHashes[sh] = addressRecord;
|
||||
});
|
||||
final histories =
|
||||
addressHashes.keys.map((scriptHash) => electrumClient
|
||||
.getHistory(scriptHash)
|
||||
.then((history) => {scriptHash: history}));
|
||||
final histories = addressHashes.keys.map((scriptHash) =>
|
||||
electrumClient.getHistory(scriptHash).then((history) => {scriptHash: history}));
|
||||
final historyResults = await Future.wait(histories);
|
||||
historyResults.forEach((history) {
|
||||
history.entries.forEach((historyItem) {
|
||||
|
@ -616,19 +606,16 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
});
|
||||
});
|
||||
final historiesWithDetails = await Future.wait(
|
||||
normalizedHistories
|
||||
.map((transaction) {
|
||||
try {
|
||||
return fetchTransactionInfo(
|
||||
hash: transaction['tx_hash'] as String,
|
||||
height: transaction['height'] as int);
|
||||
} catch(_) {
|
||||
return Future.value(null);
|
||||
}
|
||||
}));
|
||||
return historiesWithDetails.fold<Map<String, ElectrumTransactionInfo>>(
|
||||
<String, ElectrumTransactionInfo>{}, (acc, tx) {
|
||||
final historiesWithDetails = await Future.wait(normalizedHistories.map((transaction) {
|
||||
try {
|
||||
return fetchTransactionInfo(
|
||||
hash: transaction['tx_hash'] as String, height: transaction['height'] as int);
|
||||
} catch (_) {
|
||||
return Future.value(null);
|
||||
}
|
||||
}));
|
||||
return historiesWithDetails
|
||||
.fold<Map<String, ElectrumTransactionInfo>>(<String, ElectrumTransactionInfo>{}, (acc, tx) {
|
||||
if (tx == null) {
|
||||
return acc;
|
||||
}
|
||||
|
@ -680,8 +667,11 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
Future<ElectrumBalance> _fetchBalances() async {
|
||||
final addresses = walletAddresses.addresses.toList();
|
||||
final balanceFutures = <Future<Map<String, dynamic>>>[];
|
||||
var counter = addresses.length;
|
||||
|
||||
for (var i = 0; i < addresses.length; i++) {
|
||||
if (walletInfo.type == WalletType.bitcoinCash) counter = 1; //TODO: BCH: remove this check when supported
|
||||
|
||||
for (var i = 0; i < counter; i++) {
|
||||
final addressRecord = addresses[i];
|
||||
final sh = scriptHash(addressRecord.address, networkType: networkType);
|
||||
final balanceFuture = electrumClient.getBalance(sh);
|
||||
|
@ -691,8 +681,10 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
var totalFrozen = 0;
|
||||
unspentCoinsInfo.values.forEach((info) {
|
||||
unspentCoins.forEach((element) {
|
||||
if (element.hash == info.hash && info.isFrozen && element.address.address == info.address
|
||||
&& element.value == info.value) {
|
||||
if (element.hash == info.hash &&
|
||||
info.isFrozen &&
|
||||
element.address.address == info.address &&
|
||||
element.value == info.value) {
|
||||
totalFrozen += element.value;
|
||||
}
|
||||
});
|
||||
|
@ -715,8 +707,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
}
|
||||
}
|
||||
|
||||
return ElectrumBalance(confirmed: totalConfirmed, unconfirmed: totalUnconfirmed,
|
||||
frozen: totalFrozen);
|
||||
return ElectrumBalance(
|
||||
confirmed: totalConfirmed, unconfirmed: totalUnconfirmed, frozen: totalFrozen);
|
||||
}
|
||||
|
||||
Future<void> updateBalance() async {
|
||||
|
@ -727,9 +719,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
String getChangeAddress() {
|
||||
const minCountOfHiddenAddresses = 5;
|
||||
final random = Random();
|
||||
var addresses = walletAddresses.addresses
|
||||
.where((addr) => addr.isHidden)
|
||||
.toList();
|
||||
var addresses = walletAddresses.addresses.where((addr) => addr.isHidden).toList();
|
||||
|
||||
if (addresses.length < minCountOfHiddenAddresses) {
|
||||
addresses = walletAddresses.addresses.toList();
|
||||
|
@ -740,4 +730,4 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
|
||||
@override
|
||||
void setExceptionHandler(void Function(FlutterErrorDetails) onError) => _onError = onError;
|
||||
}
|
||||
}
|
|
@ -78,6 +78,8 @@ class Node extends HiveObject with Keyable {
|
|||
return Uri.http(uriRaw, '');
|
||||
case WalletType.ethereum:
|
||||
return Uri.https(uriRaw, '');
|
||||
case WalletType.bitcoinCash:
|
||||
return createUriFromElectrumAddress(uriRaw);
|
||||
default:
|
||||
throw Exception('Unexpected type ${type.toString()} for Node uri');
|
||||
}
|
||||
|
@ -129,6 +131,8 @@ class Node extends HiveObject with Keyable {
|
|||
return requestMoneroNode();
|
||||
case WalletType.ethereum:
|
||||
return requestElectrumServer();
|
||||
case WalletType.bitcoinCash:
|
||||
return requestElectrumServer();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ WalletType deserializeFromInt(int raw) {
|
|||
return WalletType.haven;
|
||||
case 4:
|
||||
return WalletType.ethereum;
|
||||
case 4:
|
||||
case 5:
|
||||
return WalletType.bitcoinCash;
|
||||
default:
|
||||
throw Exception('Unexpected token: $raw for WalletType deserializeFromInt');
|
||||
|
|
|
@ -672,5 +672,5 @@ packages:
|
|||
source: hosted
|
||||
version: "3.1.1"
|
||||
sdks:
|
||||
dart: ">=2.19.0 <3.0.0"
|
||||
dart: ">=2.19.0 <4.0.0"
|
||||
flutter: ">=3.0.0"
|
||||
|
|
|
@ -20,149 +20,17 @@ class CWBitcoinCash extends BitcoinCash {
|
|||
}) =>
|
||||
BitcoinCashNewWalletCredentials(name: name, walletInfo: walletInfo);
|
||||
|
||||
// @override
|
||||
// TransactionPriority getMediumTransactionPriority() => BitcoinTransactionPriority.medium;
|
||||
//
|
||||
// @override
|
||||
// WalletCredentials createBitcoinRestoreWalletFromSeedCredentials({
|
||||
// required String name,
|
||||
// required String mnemonic,
|
||||
// required String password})
|
||||
// => BitcoinRestoreWalletFromSeedCredentials(name: name, mnemonic: mnemonic, password: password);
|
||||
//
|
||||
// @override
|
||||
// WalletCredentials createBitcoinRestoreWalletFromWIFCredentials({
|
||||
// required String name,
|
||||
// required String password,
|
||||
// required String wif,
|
||||
// WalletInfo? walletInfo})
|
||||
// => BitcoinRestoreWalletFromWIFCredentials(name: name, password: password, wif: wif, walletInfo: walletInfo);
|
||||
//
|
||||
// @override
|
||||
// WalletCredentials createBitcoinNewWalletCredentials({
|
||||
// required String name,
|
||||
// WalletInfo? walletInfo})
|
||||
// => BitcoinNewWalletCredentials(name: name, walletInfo: walletInfo);
|
||||
//
|
||||
//
|
||||
// @override
|
||||
// Map<String, String> getWalletKeys(Object wallet) {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// final keys = bitcoinWallet.keys;
|
||||
//
|
||||
// return <String, String>{
|
||||
// 'wif': keys.wif,
|
||||
// 'privateKey': keys.privateKey,
|
||||
// 'publicKey': keys.publicKey
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// List<TransactionPriority> getTransactionPriorities()
|
||||
// => BitcoinTransactionPriority.all;
|
||||
//
|
||||
// List<TransactionPriority> getLitecoinTransactionPriorities()
|
||||
// => LitecoinTransactionPriority.all;
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority deserializeBitcoinTransactionPriority(int raw)
|
||||
// => BitcoinTransactionPriority.deserialize(raw: raw);
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority deserializeLitecoinTransactionPriority(int raw)
|
||||
// => LitecoinTransactionPriority.deserialize(raw: raw);
|
||||
//
|
||||
// @override
|
||||
// int getFeeRate(Object wallet, TransactionPriority priority) {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// return bitcoinWallet.feeRate(priority);
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Future<void> generateNewAddress(Object wallet) async {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// await bitcoinWallet.walletAddresses.generateNewAddress();
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Object createBitcoinTransactionCredentials(List<Output> outputs, {required TransactionPriority priority, int? feeRate})
|
||||
// => 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(),
|
||||
// priority: priority as BitcoinTransactionPriority,
|
||||
// feeRate: feeRate);
|
||||
//
|
||||
// @override
|
||||
// Object createBitcoinTransactionCredentialsRaw(List<OutputInfo> outputs, {TransactionPriority? priority, required int feeRate})
|
||||
// => BitcoinTransactionCredentials(
|
||||
// outputs,
|
||||
// priority: priority != null ? priority as BitcoinTransactionPriority : null,
|
||||
// feeRate: feeRate);
|
||||
//
|
||||
// @override
|
||||
// List<String> getAddresses(Object wallet) {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// return bitcoinWallet.walletAddresses.addresses
|
||||
// .map((BitcoinAddressRecord addr) => addr.address)
|
||||
// .toList();
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// String getAddress(Object wallet) {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// return bitcoinWallet.walletAddresses.address;
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// String formatterBitcoinAmountToString({required int amount})
|
||||
// => bitcoinAmountToString(amount: amount);
|
||||
//
|
||||
// @override
|
||||
// double formatterBitcoinAmountToDouble({required int amount})
|
||||
// => bitcoinAmountToDouble(amount: amount);
|
||||
//
|
||||
// @override
|
||||
// int formatterStringDoubleToBitcoinAmount(String amount)
|
||||
// => stringDoubleToBitcoinAmount(amount);
|
||||
//
|
||||
// @override
|
||||
// String bitcoinTransactionPriorityWithLabel(TransactionPriority priority, int rate)
|
||||
// => (priority as BitcoinTransactionPriority).labelWithRate(rate);
|
||||
//
|
||||
// void updateUnspents(Object wallet) async {
|
||||
// final bitcoinWallet = wallet as ElectrumWallet;
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority getBitcoinTransactionPriorityMedium()
|
||||
// => BitcoinTransactionPriority.medium;
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority getLitecoinTransactionPriorityMedium()
|
||||
// => LitecoinTransactionPriority.medium;
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority getBitcoinTransactionPrioritySlow()
|
||||
// => BitcoinTransactionPriority.slow;
|
||||
//
|
||||
// @override
|
||||
// TransactionPriority getLitecoinTransactionPrioritySlow()
|
||||
// => LitecoinTransactionPriority.slow;
|
||||
@override
|
||||
WalletCredentials createBitcoinCashRestoreWalletFromSeedCredentials(
|
||||
{required String name, required String mnemonic, required String password}) =>
|
||||
BitcoinCashRestoreWalletFromSeedCredentials(
|
||||
name: name, mnemonic: mnemonic, password: password);
|
||||
|
||||
@override
|
||||
TransactionPriority deserializeBitcoinCashTransactionPriority(int raw) =>
|
||||
BitcoinCashTransactionPriority.deserialize(raw: raw);
|
||||
|
||||
@override
|
||||
TransactionPriority getDefaultTransactionPriority() =>
|
||||
throw UnimplementedError('getDefaultTransactionPriority');
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ class SeedValidator extends Validator<MnemonicItem> {
|
|||
return haven!.getMoneroWordList(language);
|
||||
case WalletType.ethereum:
|
||||
return ethereum!.getEthereumWordList(language);
|
||||
case WalletType.bitcoinCash:
|
||||
return getBitcoinWordList(language);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:cake_wallet/anonpay/anonpay_api.dart';
|
|||
import 'package:cake_wallet/anonpay/anonpay_info_base.dart';
|
||||
import 'package:cake_wallet/anonpay/anonpay_invoice_info.dart';
|
||||
import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart';
|
||||
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
||||
import 'package:cake_wallet/buy/payfura/payfura_buy_provider.dart';
|
||||
import 'package:cake_wallet/core/yat_service.dart';
|
||||
import 'package:cake_wallet/entities/background_tasks.dart';
|
||||
|
@ -759,6 +760,8 @@ Future setup({
|
|||
return bitcoin!.createLitecoinWalletService(_walletInfoSource, _unspentCoinsInfoSource!);
|
||||
case WalletType.ethereum:
|
||||
return ethereum!.createEthereumWalletService(_walletInfoSource);
|
||||
case WalletType.bitcoinCash:
|
||||
return bitcoinCash!.createBitcoinCashWalletService(_walletInfoSource, _unspentCoinsInfoSource!);
|
||||
default:
|
||||
throw Exception('Unexpected token: ${param1.toString()} for generating of WalletService');
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
|
|||
const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
|
||||
const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
|
||||
const ethereumDefaultNodeUri = 'ethereum.publicnode.com';
|
||||
const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002';
|
||||
|
||||
Future defaultSettingsMigration(
|
||||
{required int version,
|
||||
|
@ -84,6 +85,8 @@ Future defaultSettingsMigration(
|
|||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
await changeHavenCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
await changeBitcoinCashCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
@ -163,6 +166,11 @@ Future defaultSettingsMigration(
|
|||
await changeEthereumCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
break;
|
||||
case 22:
|
||||
await addBitcoinCashElectrumServerList(nodes: nodes);
|
||||
await changeBitcoinCurrentElectrumServerToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -255,6 +263,12 @@ Node? getEthereumDefaultNode({required Box<Node> nodes}) {
|
|||
?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.ethereum);
|
||||
}
|
||||
|
||||
Node? getBitcoinCashDefaultElectrumServer({required Box<Node> nodes}) {
|
||||
return nodes.values.firstWhereOrNull(
|
||||
(Node node) => node.uriRaw == cakeWalletBitcoinCashDefaultNodeUri)
|
||||
?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.bitcoinCash);
|
||||
}
|
||||
|
||||
Node getMoneroDefaultNode({required Box<Node> nodes}) {
|
||||
final timeZone = DateTime.now().timeZoneOffset.inHours;
|
||||
var nodeUri = '';
|
||||
|
@ -293,6 +307,15 @@ Future<void> changeLitecoinCurrentElectrumServerToDefault(
|
|||
await sharedPreferences.setInt(PreferencesKey.currentLitecoinElectrumSererIdKey, serverId);
|
||||
}
|
||||
|
||||
Future<void> changeBitcoinCashCurrentNodeToDefault(
|
||||
{required SharedPreferences sharedPreferences,
|
||||
required Box<Node> nodes}) async {
|
||||
final server = getBitcoinCashDefaultElectrumServer(nodes: nodes);
|
||||
final serverId = server?.key as int ?? 0;
|
||||
|
||||
await sharedPreferences.setInt(PreferencesKey.currentBitcoinCashNodeIdKey, serverId);
|
||||
}
|
||||
|
||||
Future<void> changeHavenCurrentNodeToDefault(
|
||||
{required SharedPreferences sharedPreferences,
|
||||
required Box<Node> nodes}) async {
|
||||
|
@ -351,6 +374,15 @@ Future<void> addLitecoinElectrumServerList({required Box<Node> nodes}) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> addBitcoinCashElectrumServerList({required Box<Node> nodes}) async {
|
||||
final serverList = await loadBitcoinCashElectrumServerList();
|
||||
for (var node in serverList) {
|
||||
if (nodes.values.firstWhereOrNull((element) => element.uriRaw == node.uriRaw) == null) {
|
||||
await nodes.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addHavenNodeList({required Box<Node> nodes}) async {
|
||||
final nodeList = await loadDefaultHavenNodes();
|
||||
for (var node in nodeList) {
|
||||
|
@ -453,6 +485,8 @@ Future<void> checkCurrentNodes(
|
|||
.getInt(PreferencesKey.currentHavenNodeIdKey);
|
||||
final currentEthereumNodeId = sharedPreferences
|
||||
.getInt(PreferencesKey.currentEthereumNodeIdKey);
|
||||
final currentBitcoinCashNodeId = sharedPreferences
|
||||
.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
|
||||
final currentMoneroNode = nodeSource.values.firstWhereOrNull(
|
||||
(node) => node.key == currentMoneroNodeId);
|
||||
final currentBitcoinElectrumServer = nodeSource.values.firstWhereOrNull(
|
||||
|
@ -463,6 +497,8 @@ Future<void> checkCurrentNodes(
|
|||
(node) => node.key == currentHavenNodeId);
|
||||
final currentEthereumNodeServer = nodeSource.values.firstWhereOrNull(
|
||||
(node) => node.key == currentEthereumNodeId);
|
||||
final currentBitcoinCashNodeServer = nodeSource.values.firstWhereOrNull(
|
||||
(node) => node.key == currentBitcoinCashNodeId);
|
||||
|
||||
if (currentMoneroNode == null) {
|
||||
final newCakeWalletNode =
|
||||
|
@ -503,6 +539,13 @@ Future<void> checkCurrentNodes(
|
|||
await sharedPreferences.setInt(
|
||||
PreferencesKey.currentEthereumNodeIdKey, node.key as int);
|
||||
}
|
||||
|
||||
if (currentBitcoinCashNodeServer == null) {
|
||||
final node = Node(uri: cakeWalletBitcoinCashDefaultNodeUri, type: WalletType.bitcoinCash);
|
||||
await nodeSource.add(node);
|
||||
await sharedPreferences.setInt(
|
||||
PreferencesKey.currentBitcoinCashNodeIdKey, node.key as int);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resetBitcoinElectrumServer(
|
||||
|
|
|
@ -66,7 +66,7 @@ Future<List<Node>> loadDefaultHavenNodes() async {
|
|||
nodes.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,33 @@ Future<List<Node>> loadDefaultEthereumNodes() async {
|
|||
return nodes;
|
||||
}
|
||||
|
||||
Future<List<Node>> loadBitcoinCashElectrumServerList() async {
|
||||
final serverListRaw =
|
||||
await rootBundle.loadString('assets/bitcoin_cash_electrum_server_list.yml');
|
||||
final loadedServerList = loadYaml(serverListRaw) as YamlList;
|
||||
final serverList = <Node>[];
|
||||
|
||||
for (final raw in loadedServerList) {
|
||||
if (raw is Map) {
|
||||
final node = Node.fromMap(Map<String, Object>.from(raw));
|
||||
node.type = WalletType.bitcoinCash;
|
||||
serverList.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
return serverList;
|
||||
}
|
||||
|
||||
Future resetToDefault(Box<Node> nodeSource) async {
|
||||
final moneroNodes = await loadDefaultNodes();
|
||||
final bitcoinElectrumServerList = await loadBitcoinElectrumServerList();
|
||||
final litecoinElectrumServerList = await loadLitecoinElectrumServerList();
|
||||
final bitcoinCashElectrumServerList = await loadBitcoinCashElectrumServerList();
|
||||
final havenNodes = await loadDefaultHavenNodes();
|
||||
final nodes =
|
||||
moneroNodes +
|
||||
final nodes = moneroNodes +
|
||||
bitcoinElectrumServerList +
|
||||
litecoinElectrumServerList +
|
||||
bitcoinCashElectrumServerList +
|
||||
havenNodes;
|
||||
|
||||
await nodeSource.clear();
|
||||
|
|
|
@ -7,6 +7,7 @@ class PreferencesKey {
|
|||
static const currentHavenNodeIdKey = 'current_node_id_xhv';
|
||||
static const currentEthereumNodeIdKey = 'current_node_id_eth';
|
||||
static const currentFiatCurrencyKey = 'current_fiat_currency';
|
||||
static const currentBitcoinCashNodeIdKey = 'current_node_id_bch';
|
||||
static const currentTransactionPriorityKeyLegacy = 'current_fee_priority';
|
||||
static const currentBalanceDisplayModeKey = 'current_balance_display_mode';
|
||||
static const shouldSaveRecipientAddressKey = 'save_recipient_address';
|
||||
|
|
|
@ -153,7 +153,7 @@ Future<void> initializeAppConfigs() async {
|
|||
transactionDescriptions: transactionDescriptions,
|
||||
secureStorage: secureStorage,
|
||||
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
||||
initialMigrationVersion: 21);
|
||||
initialMigrationVersion: 22);
|
||||
}
|
||||
|
||||
Future<void> initialSetup(
|
||||
|
|
|
@ -30,7 +30,8 @@ class MenuWidgetState extends State<MenuWidget> {
|
|||
this.bitcoinIcon = Image.asset('assets/images/bitcoin_menu.png'),
|
||||
this.litecoinIcon = Image.asset('assets/images/litecoin_menu.png'),
|
||||
this.havenIcon = Image.asset('assets/images/haven_menu.png'),
|
||||
this.ethereumIcon = Image.asset('assets/images/eth_icon.png');
|
||||
this.ethereumIcon = Image.asset('assets/images/eth_icon.png'),
|
||||
this.bitcoinCashIcon = Image.asset('assets/images/bch_icon.png');
|
||||
|
||||
final largeScreen = 731;
|
||||
|
||||
|
@ -48,6 +49,7 @@ class MenuWidgetState extends State<MenuWidget> {
|
|||
Image litecoinIcon;
|
||||
Image havenIcon;
|
||||
Image ethereumIcon;
|
||||
Image bitcoinCashIcon;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -217,6 +219,8 @@ class MenuWidgetState extends State<MenuWidget> {
|
|||
return havenIcon;
|
||||
case WalletType.ethereum:
|
||||
return ethereumIcon;
|
||||
case WalletType.bitcoinCash:
|
||||
return bitcoinCashIcon;
|
||||
default:
|
||||
throw Exception('No icon for ${type.toString()}');
|
||||
}
|
||||
|
|
|
@ -41,16 +41,20 @@ class WalletListBody extends StatefulWidget {
|
|||
}
|
||||
|
||||
class WalletListBodyState extends State<WalletListBody> {
|
||||
final moneroIcon = Image.asset('assets/images/monero_logo.png', height: 24, width: 24);
|
||||
final bitcoinIcon = Image.asset('assets/images/bitcoin.png', height: 24, width: 24);
|
||||
final litecoinIcon = Image.asset('assets/images/litecoin_icon.png', height: 24, width: 24);
|
||||
final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24);
|
||||
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
||||
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
||||
final scrollController = ScrollController();
|
||||
final nonWalletTypeIconPath = 'assets/images/close.png';
|
||||
final double tileHeight = 60;
|
||||
Flushbar<void>? _progressBar;
|
||||
|
||||
Image getIconByWalletType(WalletType type, bool isEnabled) {
|
||||
if (!isEnabled) {
|
||||
return Image.asset(nonWalletTypeIconPath, height: 24, width: 24);
|
||||
}
|
||||
|
||||
final path = walletTypeToCryptoCurrency(type).iconPath ?? nonWalletTypeIconPath;
|
||||
print('path: $path type: $type');
|
||||
return Image.asset(path, height: 24, width: 24);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final newWalletImage =
|
||||
|
@ -100,9 +104,7 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
wallet.isEnabled
|
||||
? _imageFor(type: wallet.type)
|
||||
: nonWalletTypeIcon,
|
||||
getIconByWalletType(wallet.type, wallet.isEnabled),
|
||||
SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
|
@ -221,23 +223,6 @@ class WalletListBodyState extends State<WalletListBody> {
|
|||
);
|
||||
}
|
||||
|
||||
Image _imageFor({required WalletType type}) {
|
||||
switch (type) {
|
||||
case WalletType.bitcoin:
|
||||
return bitcoinIcon;
|
||||
case WalletType.monero:
|
||||
return moneroIcon;
|
||||
case WalletType.litecoin:
|
||||
return litecoinIcon;
|
||||
case WalletType.haven:
|
||||
return havenIcon;
|
||||
case WalletType.ethereum:
|
||||
return ethereumIcon;
|
||||
default:
|
||||
return nonWalletTypeIcon;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadWallet(WalletListItem wallet) async {
|
||||
await widget.authService.authenticateAction(
|
||||
context,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
||||
import 'package:cake_wallet/entities/cake_2fa_preset_options.dart';
|
||||
import 'package:cake_wallet/entities/background_tasks.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
|
@ -80,7 +81,8 @@ abstract class SettingsStoreBase with Store {
|
|||
TransactionPriority? initialMoneroTransactionPriority,
|
||||
TransactionPriority? initialHavenTransactionPriority,
|
||||
TransactionPriority? initialLitecoinTransactionPriority,
|
||||
TransactionPriority? initialEthereumTransactionPriority})
|
||||
TransactionPriority? initialEthereumTransactionPriority,
|
||||
TransactionPriority? initialBitcoinCashTransactionPriority})
|
||||
: nodes = ObservableMap<WalletType, Node>.of(nodes),
|
||||
_sharedPreferences = sharedPreferences,
|
||||
_backgroundTasks = backgroundTasks,
|
||||
|
@ -138,6 +140,10 @@ abstract class SettingsStoreBase with Store {
|
|||
priority[WalletType.ethereum] = initialEthereumTransactionPriority;
|
||||
}
|
||||
|
||||
if (initialBitcoinTransactionPriority != null) {
|
||||
priority[WalletType.bitcoinCash] = initialBitcoinTransactionPriority;
|
||||
}
|
||||
|
||||
reaction(
|
||||
(_) => fiatCurrency,
|
||||
(FiatCurrency fiatCurrency) => sharedPreferences.setString(
|
||||
|
@ -166,6 +172,9 @@ abstract class SettingsStoreBase with Store {
|
|||
case WalletType.ethereum:
|
||||
key = PreferencesKey.ethereumTransactionPriority;
|
||||
break;
|
||||
case WalletType.bitcoinCash:
|
||||
key = PreferencesKey.bitcoinTransactionPriority;
|
||||
break;
|
||||
default:
|
||||
key = null;
|
||||
}
|
||||
|
@ -495,6 +504,7 @@ abstract class SettingsStoreBase with Store {
|
|||
TransactionPriority? havenTransactionPriority;
|
||||
TransactionPriority? litecoinTransactionPriority;
|
||||
TransactionPriority? ethereumTransactionPriority;
|
||||
TransactionPriority? bitcoinCashTransactionPriority;
|
||||
|
||||
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
|
||||
havenTransactionPriority = monero?.deserializeMoneroTransactionPriority(
|
||||
|
@ -508,12 +518,17 @@ abstract class SettingsStoreBase with Store {
|
|||
ethereumTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
|
||||
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!);
|
||||
}
|
||||
if (sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority) != null) {
|
||||
bitcoinCashTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
|
||||
sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!);
|
||||
}
|
||||
|
||||
moneroTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
||||
bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority();
|
||||
havenTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
||||
litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium();
|
||||
ethereumTransactionPriority ??= ethereum?.getDefaultTransactionPriority();
|
||||
bitcoinCashTransactionPriority ??= bitcoinCash?.getDefaultTransactionPriority();
|
||||
|
||||
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
|
||||
raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
||||
|
@ -592,6 +607,8 @@ abstract class SettingsStoreBase with Store {
|
|||
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
|
||||
final litecoinElectrumServerId =
|
||||
sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
|
||||
final bitcoinCashElectrumServerId =
|
||||
sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
|
||||
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
|
||||
final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
|
||||
final moneroNode = nodeSource.get(nodeId);
|
||||
|
@ -599,6 +616,7 @@ abstract class SettingsStoreBase with Store {
|
|||
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
|
||||
final havenNode = nodeSource.get(havenNodeId);
|
||||
final ethereumNode = nodeSource.get(ethereumNodeId);
|
||||
final bitcoinCashElectrumServer = nodeSource.get(bitcoinCashElectrumServerId);
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
final deviceName = await _getDeviceName() ?? '';
|
||||
final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
|
||||
|
@ -625,6 +643,10 @@ abstract class SettingsStoreBase with Store {
|
|||
nodes[WalletType.ethereum] = ethereumNode;
|
||||
}
|
||||
|
||||
if (bitcoinCashElectrumServer != null) {
|
||||
nodes[WalletType.bitcoinCash] = bitcoinCashElectrumServer;
|
||||
}
|
||||
|
||||
final savedSyncMode = SyncMode.all.firstWhere((element) {
|
||||
return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 1);
|
||||
});
|
||||
|
@ -708,6 +730,11 @@ abstract class SettingsStoreBase with Store {
|
|||
sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!) ??
|
||||
priority[WalletType.ethereum]!;
|
||||
}
|
||||
if (sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority) != null) {
|
||||
priority[WalletType.bitcoinCash] = bitcoinCash?.deserializeBitcoinCashTransactionPriority(
|
||||
sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority)!) ??
|
||||
priority[WalletType.bitcoinCash]!;
|
||||
}
|
||||
|
||||
balanceDisplayMode = BalanceDisplayMode.deserialize(
|
||||
raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
||||
|
@ -787,6 +814,8 @@ abstract class SettingsStoreBase with Store {
|
|||
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
|
||||
final litecoinElectrumServerId =
|
||||
sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
|
||||
final bitcoinCashElectrumServerId =
|
||||
sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
|
||||
final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
|
||||
final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
|
||||
final moneroNode = nodeSource.get(nodeId);
|
||||
|
@ -794,6 +823,7 @@ abstract class SettingsStoreBase with Store {
|
|||
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
|
||||
final havenNode = nodeSource.get(havenNodeId);
|
||||
final ethereumNode = nodeSource.get(ethereumNodeId);
|
||||
final bitcoinCashNode = nodeSource.get(bitcoinCashElectrumServerId);
|
||||
|
||||
if (moneroNode != null) {
|
||||
nodes[WalletType.monero] = moneroNode;
|
||||
|
@ -814,6 +844,10 @@ abstract class SettingsStoreBase with Store {
|
|||
if (ethereumNode != null) {
|
||||
nodes[WalletType.ethereum] = ethereumNode;
|
||||
}
|
||||
|
||||
if (bitcoinCashNode != null) {
|
||||
nodes[WalletType.bitcoinCash] = bitcoinCashNode;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
|
||||
|
@ -835,6 +869,9 @@ abstract class SettingsStoreBase with Store {
|
|||
case WalletType.ethereum:
|
||||
await _sharedPreferences.setInt(PreferencesKey.currentEthereumNodeIdKey, node.key as int);
|
||||
break;
|
||||
case WalletType.bitcoinCash:
|
||||
await _sharedPreferences.setInt(PreferencesKey.currentBitcoinCashNodeIdKey, node.key as int);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,9 @@ abstract class NodeListViewModelBase with Store {
|
|||
case WalletType.ethereum:
|
||||
node = getEthereumDefaultNode(nodes: _nodeSource)!;
|
||||
break;
|
||||
case WalletType.bitcoinCash:
|
||||
node = getBitcoinCashDefaultElectrumServer(nodes: _nodeSource)!;
|
||||
break;
|
||||
default:
|
||||
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}');
|
||||
}
|
||||
|
|
|
@ -110,6 +110,24 @@ class EthereumURI extends PaymentURI {
|
|||
}
|
||||
}
|
||||
|
||||
class BitcoinCashURI extends PaymentURI {
|
||||
BitcoinCashURI({
|
||||
required String amount,
|
||||
required String address})
|
||||
: super(amount: amount, address: address);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
var base = address;
|
||||
|
||||
if (amount.isNotEmpty) {
|
||||
base += '?amount=${amount.replaceAll(',', '.')}';
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WalletAddressListViewModelBase with Store {
|
||||
WalletAddressListViewModelBase({
|
||||
required AppStore appStore,
|
||||
|
@ -172,6 +190,10 @@ abstract class WalletAddressListViewModelBase with Store {
|
|||
return EthereumURI(amount: amount, address: address.address);
|
||||
}
|
||||
|
||||
if (_wallet.type == WalletType.bitcoinCash) {
|
||||
return BitcoinCashURI(amount: amount, address: address.address);
|
||||
}
|
||||
|
||||
throw Exception('Unexpected type: ${type.toString()}');
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,8 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
return 'haven-wallet';
|
||||
case WalletType.ethereum:
|
||||
return 'ethereum-wallet';
|
||||
case WalletType.bitcoinCash:
|
||||
return 'bitcoinCash-wallet';
|
||||
default:
|
||||
throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
|
@ -45,8 +46,10 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
|||
name: name, language: options as String);
|
||||
case WalletType.ethereum:
|
||||
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
||||
case WalletType.bitcoinCash:
|
||||
return bitcoinCash!.createBitcoinCashNewWalletCredentials(name: name);
|
||||
default:
|
||||
throw Exception('Unexpected type: ${type.toString()}');;
|
||||
throw Exception('Unexpected type: ${type.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:cake_wallet/core/mnemonic_length.dart';
|
|||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
|
@ -91,6 +92,11 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
name: name,
|
||||
mnemonic: seed,
|
||||
password: password);
|
||||
case WalletType.bitcoinCash:
|
||||
return bitcoinCash!.createBitcoinCashRestoreWalletFromSeedCredentials(
|
||||
name: name,
|
||||
mnemonic: seed,
|
||||
password: password);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ flutter:
|
|||
- assets/bitcoin_electrum_server_list.yml
|
||||
- assets/litecoin_electrum_server_list.yml
|
||||
- assets/ethereum_server_list.yml
|
||||
- assets/bitcoin_cash_electrum_server_list.yml
|
||||
- assets/text/
|
||||
- assets/faq/
|
||||
- assets/animation/
|
||||
|
|
|
@ -564,6 +564,8 @@ Future<void> generateBitcoinCash(bool hasImplementation) async {
|
|||
const bitcoinCashCommonHeaders = """
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/wallet_credentials.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
|
@ -577,9 +579,21 @@ import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';
|
|||
const bitcoinCashContent = """
|
||||
abstract class BitcoinCash {
|
||||
String getMnemonic(int? strength);
|
||||
|
||||
Uint8List getSeedFromMnemonic(String seed);
|
||||
WalletService createBitcoinCashWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
|
||||
WalletCredentials createBitcoinCashNewWalletCredentials({required String name, WalletInfo? walletInfo});
|
||||
|
||||
WalletService createBitcoinCashWalletService(
|
||||
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
|
||||
|
||||
WalletCredentials createBitcoinCashNewWalletCredentials(
|
||||
{required String name, WalletInfo? walletInfo});
|
||||
|
||||
WalletCredentials createBitcoinCashRestoreWalletFromSeedCredentials(
|
||||
{required String name, required String mnemonic, required String password});
|
||||
|
||||
TransactionPriority deserializeBitcoinCashTransactionPriority(int raw);
|
||||
|
||||
TransactionPriority getDefaultTransactionPriority();
|
||||
}
|
||||
""";
|
||||
|
||||
|
|
Loading…
Reference in a new issue