WalletService InitializeAsync Refactor
MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -301,6 +301,7 @@ namespace WalletWasabi.Services
var unconfirmedTransactions = new SmartTransaction[0];
var confirmedTransactions = new SmartTransaction[0];
+ // Fetch previous wallet state from transactions file
if (File.Exists(TransactionsFilePath))
{
try
@@ -321,7 +322,21 @@ namespace WalletWasabi.Services
}
}
- // Go through the keymanager's index.
+ await LoadWalletStateAsync(confirmedTransactions, cancel);
+
+ // Load in dummy mempool
+ if (unconfirmedTransactions != null && unconfirmedTransactions.Any())
+ {
+ await LoadDummyMempoolAsync(unconfirmedTransactions);
+ }
+
+ }
+ Coins.CollectionChanged += Coins_CollectionChanged;
+ RefreshCoinHistories();
+ }
+
+ private async Task LoadWalletStateAsync(SmartTransaction[] confirmedTransactions, CancellationToken cancel)
+ {
KeyManager.AssertNetworkOrClearBlockState(Network);
Height bestKeyManagerHeight = KeyManager.GetBestHeight();
@@ -332,7 +347,7 @@ namespace WalletWasabi.Services
await ProcessBlockAsync(blockState.BlockHeight, block, blockState.TransactionIndices, relevantTransactions);
}
- // Go through the filters and que to download the matches.
+ // Go through the filters and queue to download the matches.
await BitcoinStore.IndexStore.ForeachFiltersAsync(async (filterModel) =>
{
if (filterModel.Filter != null) // Filter can be null if there is no bech32 tx.
@@ -340,11 +355,9 @@ namespace WalletWasabi.Services
await ProcessFilterModelAsync(filterModel, cancel);
}
}, new Height(bestKeyManagerHeight.Value + 1));
+ }
- // Load in dummy mempool
- try
- {
- if (unconfirmedTransactions != null && unconfirmedTransactions.Any())
+ private async Task LoadDummyMempoolAsync(SmartTransaction[] unconfirmedTransactions)
{
try
{
@@ -374,8 +387,9 @@ namespace WalletWasabi.Services
SerializeTransactionCache();
}
}
+
}
- catch
+ catch (Exception ex)
{
// When there's a connection failure do not clean the transactions, add it to processing.
foreach (var tx in unconfirmedTransactions)
@@ -385,12 +399,6 @@ namespace WalletWasabi.Services
Mempool.TransactionHashes.TryAdd(tx.GetHash());
}
- throw;
- }
- }
- }
- catch (Exception ex)
- {
Logger.LogWarning<WalletService>(ex);
}
finally
@@ -398,9 +406,6 @@ namespace WalletWasabi.Services
UnconfirmedTransactionsInitialized = true;
}
}
- Coins.CollectionChanged += Coins_CollectionChanged;
- RefreshCoinHistories();
- }
private async Task ProcessFilterModelAsync(FilterModel filterModel, CancellationToken cancel)
{

WalletService InitializeAsync Refactor