mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 18:54:47 +00:00
fix: restore not getting all wallet addresses by type
This commit is contained in:
parent
021347ae87
commit
23d6221302
1 changed files with 38 additions and 28 deletions
|
@ -1359,34 +1359,8 @@ abstract class ElectrumWalletBase
|
||||||
final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet();
|
final addressesSet = walletAddresses.allAddresses.map((addr) => addr.address).toSet();
|
||||||
currentChainTip ??= await electrumClient.getCurrentBlockChainTip() ?? 0;
|
currentChainTip ??= await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||||
|
|
||||||
await Future.wait(ADDRESS_TYPES.map((type) {
|
await Future.wait(ADDRESS_TYPES.map(
|
||||||
final addressesByType = walletAddresses.allAddresses.where((addr) => addr.type == type);
|
(type) => fetchTransactionsForAddressType(addressesSet, historiesWithDetails, type)));
|
||||||
|
|
||||||
return Future.wait(addressesByType.map((addressRecord) async {
|
|
||||||
final history = await _fetchAddressHistory(addressRecord, addressesSet, currentChainTip!);
|
|
||||||
|
|
||||||
if (history.isNotEmpty) {
|
|
||||||
addressRecord.txCount = history.length;
|
|
||||||
historiesWithDetails.addAll(history);
|
|
||||||
|
|
||||||
final matchedAddresses =
|
|
||||||
addressesByType.where((addr) => addr.isHidden == addressRecord.isHidden);
|
|
||||||
|
|
||||||
final isLastUsedAddress =
|
|
||||||
history.isNotEmpty && addressRecord.address == matchedAddresses.last.address;
|
|
||||||
|
|
||||||
if (isLastUsedAddress) {
|
|
||||||
await walletAddresses.discoverAddresses(
|
|
||||||
matchedAddresses.toList(),
|
|
||||||
addressRecord.isHidden,
|
|
||||||
(address, addressesSet) =>
|
|
||||||
_fetchAddressHistory(address, addressesSet, currentChainTip!)
|
|
||||||
.then((history) => history.isNotEmpty ? address.address : null),
|
|
||||||
type: type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}));
|
|
||||||
|
|
||||||
return historiesWithDetails;
|
return historiesWithDetails;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -1395,6 +1369,42 @@ abstract class ElectrumWalletBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> fetchTransactionsForAddressType(
|
||||||
|
Set<String> addressesSet,
|
||||||
|
Map<String, ElectrumTransactionInfo> historiesWithDetails,
|
||||||
|
BitcoinAddressType type,
|
||||||
|
) async {
|
||||||
|
final addressesByType = walletAddresses.allAddresses.where((addr) => addr.type == type);
|
||||||
|
final hiddenAddresses = addressesByType.where((addr) => addr.isHidden == true);
|
||||||
|
final receiveAddresses = addressesByType.where((addr) => addr.isHidden == false);
|
||||||
|
|
||||||
|
await Future.wait(addressesByType.map((addressRecord) async {
|
||||||
|
final history = await _fetchAddressHistory(addressRecord, addressesSet, currentChainTip!);
|
||||||
|
|
||||||
|
if (history.isNotEmpty) {
|
||||||
|
addressRecord.txCount = history.length;
|
||||||
|
historiesWithDetails.addAll(history);
|
||||||
|
|
||||||
|
final matchedAddresses = addressRecord.isHidden ? hiddenAddresses : receiveAddresses;
|
||||||
|
final isLastUsedAddress = history.isNotEmpty && matchedAddresses.last == addressRecord;
|
||||||
|
|
||||||
|
if (isLastUsedAddress) {
|
||||||
|
// The last address by gap limit is used, discover new addresses for the same address type
|
||||||
|
await walletAddresses.discoverAddresses(
|
||||||
|
matchedAddresses.toList(),
|
||||||
|
addressRecord.isHidden,
|
||||||
|
(address, addressesSet) => _fetchAddressHistory(address, addressesSet, currentChainTip!)
|
||||||
|
.then((history) => history.isNotEmpty ? address.address : null),
|
||||||
|
type: type,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Continue until the last address by this address type is not used yet
|
||||||
|
await fetchTransactionsForAddressType(addressesSet, historiesWithDetails, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
Future<Map<String, ElectrumTransactionInfo>> _fetchAddressHistory(
|
Future<Map<String, ElectrumTransactionInfo>> _fetchAddressHistory(
|
||||||
BitcoinAddressRecord addressRecord, Set<String> addressesSet, int currentHeight) async {
|
BitcoinAddressRecord addressRecord, Set<String> addressesSet, int currentHeight) async {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue