Add possibility to get latest status of rounds
MODIFY
WalletWasabi/WabiSabi/Client/RoundStateAwaiters/RoundStateAwaiter.cs
WalletWasabi/WabiSabi/Client/RoundStateAwaiters/RoundStateAwaiter.cs
using NBitcoin;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -35,7 +36,7 @@ public record RoundStateAwaiter
public Task<RoundState> Task => TaskCompletionSource.Task;
- public bool IsCompleted(Dictionary<uint256, RoundState> allRoundStates)
+ public bool IsCompleted(ImmutableDictionary<uint256, RoundState> allRoundStates)
{
if (Task.IsCompleted)
{

MODIFY
WalletWasabi/WabiSabi/Client/RoundStateAwaiters/RoundStateUpdater.cs
WalletWasabi/WabiSabi/Client/RoundStateAwaiters/RoundStateUpdater.cs
using NBitcoin;
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -19,7 +20,7 @@ public class RoundStateUpdater : PeriodicRunner
}
private IWabiSabiApiRequestHandler ArenaRequestHandler { get; }
- private Dictionary<uint256, RoundState> RoundStates { get; set; } = new();
+ private ImmutableDictionary<uint256, RoundState> RoundStates { get; set; } = ImmutableDictionary.Create<uint256, RoundState>();
public Dictionary<TimeSpan, FeeRate> CoinJoinFeeRateMedians { get; private set; } = new();
private List<RoundStateAwaiter> Awaiters { get; } = new();
@@ -50,7 +51,7 @@ public class RoundStateUpdater : PeriodicRunner
var newRoundStates = statusResponse
.Where(rs => !RoundStates.ContainsKey(rs.Id));
- RoundStates = newRoundStates.Concat(updatedRoundStates).ToDictionary(x => x.Id, x => x);
+ RoundStates = newRoundStates.Concat(updatedRoundStates).ToImmutableDictionary(x => x.Id, x => x);
lock (AwaitersLock)
{
@@ -99,6 +100,11 @@ public class RoundStateUpdater : PeriodicRunner
return CreateRoundAwaiter(null, phase, null, cancellationToken);
}
+ public bool TryGetRoundState(uint256 roundId, [NotNullWhen(true)] out RoundState? roundState)
+ {
+ return RoundStates.TryGetValue(roundId, out roundState);
+ }
+
public override Task StopAsync(CancellationToken cancellationToken)
{
lock (AwaitersLock)

Add possibility to get latest status of rounds