Try to reduce complexity
MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -182,7 +182,7 @@ namespace WalletWasabi.Services
foreach (int ongoingRoundId in State.GetActivelyMixingRounds())
{
- await TryHandleOngoingRoundAsync(ongoingRoundId);
+ await TryProcessRoundStateAsync(ongoingRoundId);
}
}
}
@@ -196,7 +196,7 @@ namespace WalletWasabi.Services
}
}
- private async Task TryHandleOngoingRoundAsync(int ongoingRoundId)
+ private async Task TryProcessRoundStateAsync(int ongoingRoundId)
{
try
{
@@ -207,15 +207,7 @@ namespace WalletWasabi.Services
{
if (ongoingRound.RoundHash == null) // If we didn't already obtained our roundHash obtain it.
{
- string roundHash = await ongoingRound.AliceClient.PostConfirmationAsync();
- if (roundHash == null)
- {
- throw new NotSupportedException("Coordinator didn't gave us the expected roundHash, even though it's in ConnectionConfirmation phase.");
- }
- else
- {
- ongoingRound.RoundHash = roundHash;
- }
+ await ObtainRoundHashAsync(ongoingRound);
}
}
else if (ongoingRound.State.Phase == CcjRoundPhase.OutputRegistration)
@@ -227,12 +219,7 @@ namespace WalletWasabi.Services
throw new NotSupportedException("Coordinator progressed to OutputRegistration phase, even though we didn't obtain roundHash.");
}
- using (var bobClient = new BobClient(CcjHostUri, TorSocks5EndPoint))
- {
- await bobClient.PostOutputAsync(ongoingRound.RoundHash, ongoingRound.ActiveOutputAddress, ongoingRound.UnblindedSignature);
- ongoingRound.PostedOutput = true;
- Logger.LogInfo<AliceClient>($"Round ({ongoingRound.State.RoundId})Bob Posted output.");
- }
+ await RegisterOutputAsync(ongoingRound);
}
}
else if (ongoingRound.State.Phase == CcjRoundPhase.Signing)
@@ -240,6 +227,25 @@ namespace WalletWasabi.Services
if (!ongoingRound.Signed)
{
Transaction unsignedCoinJoin = await ongoingRound.AliceClient.GetUnsignedCoinJoinAsync();
+ Dictionary<int, WitScript> myDic = SignCoinJoin(ongoingRound, unsignedCoinJoin);
+
+ await ongoingRound.AliceClient.PostSignaturesAsync(myDic);
+ ongoingRound.Signed = true;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.Message.StartsWith("NotFound", StringComparison.Ordinal)) // Alice timed out.
+ {
+ State.ClearRoundRegistration(ongoingRoundId);
+ }
+ Logger.LogError<CcjClient>(ex);
+ }
+ }
+
+ private static Dictionary<int, WitScript> SignCoinJoin(CcjClientRound ongoingRound, Transaction unsignedCoinJoin)
+ {
if (NBitcoinHelpers.HashOutpoints(unsignedCoinJoin.Inputs.Select(x => x.PrevOut)) != ongoingRound.RoundHash)
{
throw new NotSupportedException("Coordinator provided invalid roundHash.");
@@ -284,18 +290,29 @@ namespace WalletWasabi.Services
}
}
- await ongoingRound.AliceClient.PostSignaturesAsync(myDic);
- ongoingRound.Signed = true;
+ return myDic;
}
+
+ private async Task RegisterOutputAsync(CcjClientRound ongoingRound)
+ {
+ using (var bobClient = new BobClient(CcjHostUri, TorSocks5EndPoint))
+ {
+ await bobClient.PostOutputAsync(ongoingRound.RoundHash, ongoingRound.ActiveOutputAddress, ongoingRound.UnblindedSignature);
+ ongoingRound.PostedOutput = true;
+ Logger.LogInfo<AliceClient>($"Round ({ongoingRound.State.RoundId})Bob Posted output.");
}
}
- catch (Exception ex)
+
+ private static async Task ObtainRoundHashAsync(CcjClientRound ongoingRound)
{
- if (ex.Message.StartsWith("NotFound", StringComparison.Ordinal)) // Alice timed out.
+ string roundHash = await ongoingRound.AliceClient.PostConfirmationAsync();
+ if (roundHash == null)
{
- State.ClearRoundRegistration(ongoingRoundId);
+ throw new NotSupportedException("Coordinator didn't gave us the expected roundHash, even though it's in ConnectionConfirmation phase.");
}
- Logger.LogError<CcjClient>(ex);
+ else
+ {
+ ongoingRound.RoundHash = roundHash;
}
}

Try to reduce complexity